Jump to content
UltiMaker Community of 3D Printing Experts

Developing plugin - issue with i18nc


vitalbir

Recommended Posts

Posted · Developing plugin - issue with i18nc

I'm developing a new plugin for Cura 4.5

 

But even not using the i18n in the code, like this:

from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")

 

 

I received this error when I put my plugin code folder on C:\Users\xxxxx\AppData\Roaming\cura\4.5\plugins and try to start the Cura 4.5:

2020-04-30 11:38:17,592 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [66]: An uncaught error has occurred!
2020-04-30 11:38:17,599 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [69]: Traceback (most recent call last):
2020-04-30 11:38:17,605 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [69]:   File "X:\4.5-exe\build\inst\lib\python3.5\site-packages\cura\CuraApplication.py", line 1023, in event
2020-04-30 11:38:17,614 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [69]:   File "X:\4.5-exe\build\inst\lib\python3.5\site-packages\UM\Qt\QtApplication.py", line 456, in event
2020-04-30 11:38:17,622 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [69]:   File "X:\4.5-exe\build\inst\lib\python3.5\site-packages\UM\Event.py", line 189, in call
2020-04-30 11:38:17,633 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [69]:   File "X:\4.5-exe\build\inst\lib\python3.5\site-packages\cura\Settings\MachineManager.py", line 157, in setInitialActiveMachine
2020-04-30 11:38:17,640 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [69]:   File "X:\4.5-exe\build\inst\lib\python3.5\site-packages\cura\Settings\MachineManager.py", line 312, in setActiveMachine
2020-04-30 11:38:17,663 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [69]:   File "X:\4.5-exe\build\inst\lib\python3.5\site-packages\cura\CuraApplication.py", line 645, in setGlobalContainerStack
2020-04-30 11:38:17,686 - CRITICAL - [MainThread] cura.CrashHandler.__init__ [69]: AttributeError: 'NoneType' object has no attribute 'i18nc'

 

 

  • Link to post
    Share on other sites

    Posted · Developing plugin - issue with i18nc

    Can you show more of your code? It seems you are trying to access the global container stack before Cura is ready for you to access it.

  • Link to post
    Share on other sites

    • 2 weeks later...
    Posted · Developing plugin - issue with i18nc
    On 4/30/2020 at 12:28 PM, ahoeben said:

    Can you show more of your code? It seems you are trying to access the global container stack before Cura is ready for you to access it.

    Yes, sure

     

    from PyQt5.QtWidgets import QFileDialog, QMessageBox
    
    import os.path
    import sys
    
    from UM.Extension import Extension
    from UM.Application import Application
    from UM.Logger import Logger
    from UM.Message import Message
    
    from UM.i18n import i18nCatalog
    catalog = i18nCatalog("cura")
    
    class SettingsPDFReportPlugin(Extension):
        
        def __init__(self):
            super().__init__()
            Logger.log("d", "Initializing the Settings PDF Report Plugin.")
    
            self._application = Application.getInstance()
            self._machine_manager = self._application.getMachineManager()
            self._global_stack = self._machine_manager.activeMachine
            

     

  • Link to post
    Share on other sites

    Posted (edited) · Developing plugin - issue with i18nc

    You are indeed trying to access the global container stack before Cura is ready for you to access it. Don't try to retreive the global stack from the machine manager in your __init__ method, because your plugin gets initialised before the global stack is created. The best way to get the global stack is to connect a method to the globalContainerStackChanged signal of the CuraApplication instance:

     

        def __init__(self) -> None:    
            ...
            self._application.globalContainerStackChanged.connect(self._onGlobalStackChanged)
            ...
    
        def _onGlobalStackChanged(self) -> None:
            self._global_stack = ...

     

    Edited by ahoeben
  • Link to post
    Share on other sites

    Posted · Developing plugin - issue with i18nc
    20 minutes ago, ahoeben said:

    You are indeed trying to access the global container stack before Cura is ready for you to access it. Don't try to retreive the global stack from the machine manager in your __init__ method, because your plugin gets initialised before the global stack is created. The best way to get the global stack is to connect a method to the globalContainerStackChanged signal of the CuraApplication instance:

     

    
        def __init__(self) -> None:    
            ...
            self._application.globalContainerStackChanged.connect(self._onGlobalStackChanged)
            ...
    
        def _onGlobalStackChanged(self) -> None:
            self._global_stack = ...

     

     

    thanks!

    where can i find this information? isn't that in the documentation? just analyzing the code of the cure to understand this?

  • Link to post
    Share on other sites

    Posted (edited) · Developing plugin - issue with i18nc
    8 minutes ago, vitalbir said:

    just analyzing the code of the cure to understand this?

    yes.

     

    By the way, looking at the name of your plugin, I think you want your plugin to respond to a menu item in the Extension menu, and then export the settings, right? In that case, there's not much use in listing to every time the global stack is changed, but just get the global stack when that menu item is selected.

     

    See https://github.com/Ultimaker/UraniumExampleExtensionPlugin/blob/master/ExampleExtension.py

    You would get the global stack when you need it, ie in the sayHello method in that example.

     

    Tip: if you say what you want to achieve instead just what is currently bugging you, I can give you better help.

    Edited by ahoeben
  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • UltiMaker Cura 5.3 stable released
        In this stable release, Cura 5.3 achieves yet another huge leap forward in 3D printing thanks to material interlocking! As well as introducing an expanded recommended print settings menu and lots of print quality improvements. Not to mention, a whole bunch of new printer profiles for non-UltiMaker printers!
        • 22 replies
      • Here it is. The new UltiMaker S7
        The UltiMaker S7 is built on the success of the UltiMaker S5 and its design decisions were heavily based on feedback from customers.
         
         
        So what’s new?
        The obvious change is the S7’s height. It now includes an integrated Air Manager. This filters the exhaust air of every print and also improves build temperature stability. To further enclose the build chamber the S7 only has one magnetically latched door.
         
        The build stack has also been completely redesigned. A PEI-coated flexible steel build plate makes a big difference to productivity. Not only do you not need tools to pop a printed part off. But we also don’t recommend using or adhesion structures for UltiMaker materials (except PC, because...it’s PC). Along with that, 4 pins and 25 magnets make it easy to replace the flex plate perfectly – even with one hand.
         
        The re-engineered print head has an inductive sensor which reduces noise when probing the build plate. This effectively makes it much harder to not achieve a perfect first layer, improving overall print success. We also reversed the front fan direction (fewer plastic hairs, less maintenance), made the print core door magnets stronger, and add a sensor that helps avoid flooding.
         

         
        The UltiMaker S7 also includes quality of life improvements:
        Reliable bed tilt compensation (no more thumbscrews) 2.4 and 5 GHz Wi-Fi A 1080p camera (mounted higher for a better view) Compatibility with 280+ Marketplace materials Compatibility with S5 project files (no reslicing needed) And a whole lot more  
        Curious to see the S7 in action?
        We’re hosting a free tech demo on February 7.
        It will be live and you can ask any questions to our CTO, Miguel Calvo.
        Register here for the Webinar
        • 18 replies
      • UltiMaker Cura Alpha 🎄 Tree Support Spotlight 🎄
        Are you a fan of tree support, but dislike the removal process and the amount of filament it uses? Then we would like to invite you to try this special release of UltiMaker Cura. Brought to you by our special community contributor @thomasrahm
         
        We generated a special version of Cura 5.2 called 5.3.0 Alpha + Xmas. The only changes we introduced compared to UltiMaker Cura 5.2.1 are those which are needed for the new supports. So keep in mind, this is not a sneak peek for Cura 5.3 (there are some really cool new features coming up) but a spotlight release highlighting this new version of tree supports.  
          • Heart
          • Like
        • 22 replies
    ×
    ×
    • Create New...