Jump to content
Ultimaker Community of 3D Printing Experts

Developing plugin - issue with i18nc


vitalbir
 Share

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
     Share

    • Our picks

      • Ultimaker showcase | April 2022 | 4pm CEST | 10am EDT
        I'm excited because I've personally produced this showcase event, so if you are curious what else I'm up to nowadays, come check it out and say hi in the chat! It would mean a lot! 
          • Thanks
          • Like
        • 4 replies
      • New here? Get ahead with a free onboarding course
        Hi,
         
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 11 replies
    ×
    ×
    • Create New...