Coder Social home page Coder Social logo

freecad-stubs's People

Contributors

ostr00000 avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

freecad-stubs's Issues

ProgressIndicator is in FreeCAD.Base

Describe the bug
ProgressIndicator is in another module (FreeCAD.Base).

To Reproduce

import FreeCAD
progressBar = FreeCAD.Base.ProgressIndicator()

The code is correct, but stubs say it cannot reference it.

Expected behavior
No error in type checker.

Include in FreeCAD proper?

Hello, and thank you for a great project.
I am curious if you considered asking the "FreeCAD people" to include this as standard part of FreeCAD distribution?
Why? I would hope that would motivate "them" to fix multiple errors and omissions in cpp/py bridge faster :-)

Pylance: wont find stubs for native library with submodules

Describe the bug
VS code with Pylance: wont find stubs for native library with submodules.
According https://peps.python.org/pep-0484/#stub-files

  • Modules and variables imported into the stub are not considered exported from the stub unless the import uses the import ... as ... form or the equivalent from ... import ... as ... form.
  • Just like in normal Python files, submodules automatically become exported attributes of their parent module when imported. For example, if the spam package has the following directory structure:
spam/
    __init__.pyi
    ham.pyi

where __init__.pyi contains a line such as from . import ham or from .ham import Ham, then ham is an exported attribute of spam.

To Reproduce
Steps to reproduce the behavior:

  1. FreeCAD 0.21.2 installed
  2. C:\Program Files\FreeCAD 0.21\bin> python -m pip install freecad-stubs
  3. In VS Code in a new folder created test.py file with code
 #!/usr/bin/env python
import sys
import FreeCAD as FreeCAD
import FreeCADGui as Gui
import Part
from PySide import QtGui

if __name__ == "__main__":
    # This will start FreeCAD and draw a box. 
    app = QtGui.QApplication(sys.argv)
    Gui.showMainWindow()
    
    doc = FreeCAD.newDocument()
    box = Part.makeBox(100, 100, 100)
    FreeCAD.Console.PrintMessage('Hello, World!')
    
        
    Part.show(box)
    sys.exit(app.exec_())

and .env file

FREECAD_BIN="C:/Program Files/FreeCAD 0.21/bin"
FREECAD_BIN_LIB="C:/Program Files/FreeCAD 0.21/bin/Lib"
FREECAD_BIN_LIB_PAC="C:/Program Files/FreeCAD 0.21/bin/Lib/site-packages"
FREECAD_LIB="C:/Program Files/FreeCAD 0.21/lib"
FREECAD_MOD="C:/Program Files/FreeCAD 0.21/Mod"
FREECAD_EXT="C:/Program Files/FreeCAD 0.21/EXT"
PYTHONPATH=${FREECAD_BIN};${FREECAD_LIB};${FREECAD_MOD};${FREECAD_EXT};${FREECAD_BIN_LIB};${FREECAD_BIN_LIB_PAC}
  1. If the mouse cursor hover on FreeCAD.Console.PrintMessage there is no information about the function.

Expected behavior
If the mouse cursor hover on Part.makeBox there is information about the function.

Used versions (please complete the following information):

  • FreeCAD version 0.21.2
  • FreeCAD-stub version 1.0.16

Additional context
To fix the issue I've added from . import Console instead of import FreeCAD.Console to the file __init__.pyi in the C:\Program Files\FreeCAD 0.21\bin\Lib\site-packages\FreeCAD-stubs\ folder.

dependency resolution: qtpy vs PySide or better: pth

Hello again. I hacked around the limitations described below with my own scripts and have no problem,
but would like to see "stubs" be more cool. :-) Therefore:

OPTION ONE

currently, there is a qtpy dependency:

dependencies = [
    # 'pivy', # cannot install it in a normal way, should be installed by FreeCAD anyway
    'qtpy',
]

and FreeCAD also provides its own package proxy called PySide
https://github.com/FreeCAD/FreeCAD/blob/main/cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake
which is deployed on the target system at:
/usr/lib/freecad/Ext

and used throughout the internal code, for example:
https://github.com/FreeCAD/FreeCAD/blob/main/src/Mod/Path/Path/Tool/Gui/BitCmd.py#L28

So: would it make sense for "stubs" to drop qtpy and include PySide form the FreeCAD instead?

Why? so that templates.py could be copied as is :-) and all other PySide imports resolve OK
https://github.com/ostr00000/freecad-stubs/blob/main/freecad_stubs/FreeCADTemplates/templates.py

OPTION TWO

Alternatively, "stubs" could go even further, and instead run FreeCAD folder discovery,
and generate during pip install automagically a freecad.pth file:

${PROJECT_DIR}/.venv/lib/python3.11/site-packages/freecad.pth

with content similar to this:

/usr/lib/freecad/lib
/usr/lib/freecad/Ext
/usr/lib/freecad/Mod/AddonManager

that would also take care of dll/so dependency, so that tests of the plugin-under-development could run from the same venv against the production FreeCAD installation

more info on the pth files:
https://docs.python.org/3/library/site.html

templates.py: future-proof

after upgrading to the latest stubs:
https://pypi.org/project/freecad-stubs/1.0.16/

and building to the latest FreeCAD:

OS: Arch Linux (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.35325 (Git)
Build type: None
Branch: makepkg
Hash: 5c2eedbd149536f88cf70b085d7afff101fa2037
Python 3.11.6, Qt 5.15.11, Coin 4.0.1, Vtk 9.3.0, OCC 7.7.2

and copying templates.py "almost-as-is" into the plugin-under-development,

there is an import error on startup:

During initialization the error "module 'FreeCADGui' has no attribute 'View3DInventorViewerPy'" occurred ...

without bothering about "why and where", one way to future-proof against this is to include in templates.py:

from __future__ import annotations

import errors

Hi,

thanks for all your work, this is great and I was looking a long time for something like this. And sorry for creating an issue, I didn't know how to reach you.

I have a question regarding an import error message and intellisense.
image
I read that this kind of error occures when no library and only definition is found? (Issue here).

But I would expect that intellisense should find the package when typing?
image

Or do I misunderstand something here?

Thanks!

Generate full C++ files from macros and parse C++ files

Describe the bug
Currently, there are many hacky ways to generate stubs:

  • properties,
  • xml,
  • parsing c++,
  • parsing macros.

A better solution is to generate files with replaced macros and then based on these files generate stub files.

Also, maybe we should use a more advanced library for parsing C++ code: this library looks very promising.

__rmul__ missing from generated functions at least in Vector.

This repo is great, thanks for putting it together.

While using it for the first time today, I noticed that for the Vector class in the generated stub file Base.pyi, the mul magic method is included but rmul is not.

This results in no mypy errors for something like:
Vector(1,1,1) * 10
But an error of: 'Unsupported operand types for * ("float" and "Vector")' error for:
10 * Vector(1,1,1)

Once I get time, I'll poke around the generation code to try and add this in or would be happy for someone else to do so.

wrong return type: `FreeCAD.getDocument() -> FreeCADGui.Document`

currently, in the stubs:

def getDocument(pstr: str, /) -> FreeCADGui.Document:

while verification in python console shows:

>>> FreeCAD.Document
<class 'App.Document'>

>>> FreeCADGui.Document
<class 'Gui.Document'>

>>> type(FreeCAD.getDocument("your_document_name"))
<class 'App.Document'>

local setup:

OS: Arch Linux (KDE/plasmax11)
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.36733 (Git)
Build type: None
Branch: makepkg
Hash: 99da05f8a63fbe8870dab34dbdc9e94ab922c670
Python 3.11.8, Qt 5.15.12, Coin 4.0.2, Vtk 9.3.0, OCC 7.7.2
Locale: English/United States (en_US)

missing: src/Gui/WorkbenchManipulatorPython.h

https://github.com/FreeCAD/FreeCAD/blob/1e212c32bc8ddf13443c1d61c1e403a9c5d6a5b6/src/Gui/ApplicationPy.cpp#L361

  {"addWorkbenchManipulator",  (PyCFunction) Application::sAddWbManipulator, METH_VARARGS,
   "addWorkbenchManipulator(obj) -> None\n"

https://github.com/FreeCAD/FreeCAD/blob/1e212c32bc8ddf13443c1d61c1e403a9c5d6a5b6/src/Gui/WorkbenchManipulatorPython.h#L46

    /*!
     * \brief modifyMenuBar
     * Method to manipulate the menu structure of a workbench.
     */
    void modifyMenuBar(MenuItem* menuBar) override;
    /*!
     * \brief modifyContextMenu
     * Method to manipulate the contextmenu structure of a workbench.
     */
    void modifyContextMenu(const char* recipient, MenuItem* menuBar) override;
    /*!
     * \brief modifyToolBars
     * Method to manipulate the toolbar structure of a workbench
     */
    void modifyToolBars(ToolBarItem* toolBar) override;
    /*!
     * \brief modifyDockWindows
     * Method to manipulate the dock window structure of a workbench
     */
    void modifyDockWindows(DockWindowItems* dockWindow) override;

https://github.com/FreeCAD/FreeCAD/blob/1e212c32bc8ddf13443c1d61c1e403a9c5d6a5b6/src/Gui/WorkbenchManipulatorPython.cpp#L62

/*!
 * \brief WorkbenchManipulatorPython::modifyMenuBar
 * \param menuBar
 * The Python manipulator can be implemented as
 * \code
 * class Manipulator:
 *   def modifyMenuBar(self):
 *     return [{"remove" : "Std_Quit"},
 *             {"append" : "Std_About", "menuItem" : "Std_DlgMacroRecord"},
 *             {"insert" : "Std_About", "menuItem" : "Std_DlgParameter"}
 *             {"insert" : "Std_Windows", "menuItem" : "Std_DlgParameter", "after" : ""}]
 *
 * manip = Manipulator()
 * Gui.addWorkbenchManipulator(manip)
 * \endcode
 * This manipulator removes the Std_Quit command, appends the Std_About command
 * to the Macro menu, inserts it to the Tools menu before the Std_DlgParameter
 * and adds the Std_Windows after the Std_DlgParameter command.
 */
void WorkbenchManipulatorPython::modifyMenuBar(MenuItem* menuBar)

missing: src/Gui/SelectionObserverPython.h

SelectionObserverPython has no xml and so it is missing from the stubs:

https://forum.freecad.org/viewtopic.php?p=497885

https://github.com/FreeCAD/FreeCAD/blob/1e212c32bc8ddf13443c1d61c1e403a9c5d6a5b6/src/Gui/SelectionObserverPython.h#L64

#define FC_PY_SEL_OBSERVER \
    FC_PY_ELEMENT(onSelectionChanged) \
    FC_PY_ELEMENT(addSelection) \
    FC_PY_ELEMENT(removeSelection) \
    FC_PY_ELEMENT(setSelection) \
    FC_PY_ELEMENT(clearSelection) \
    FC_PY_ELEMENT(setPreselection) \
    FC_PY_ELEMENT(removePreselection) \
    FC_PY_ELEMENT(pickedListChanged)

[Question] App is not defined

Hi! I've just found this project and it seems like it would be very useful for people who create workbench or macro for freecad.

I'm currently writing a macro and I've installed this package. The problem is that error message from lsp such as "App" is not defined shows up.

I know that it is because I don't define App in my code. Freecad would use the App variable inside the program when I run the macro. But are there any way I can get rid of this error message?

Another thing is when I write doc = App.ActiveDocument, the doc type would be Unknown. How can I change the type into Document?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.