Jump to content

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.9 stable released!
        Here comes Cura 5.9 and in this stable release we have lots of material and printer profiles for UltiMaker printers, including the newly released Sketch Sprint. Additionally, scarf seams have been introduced alongside even more print settings and improvements.  Check out the rest of this article to find out the details on all of that and more
          • Like
        • 5 replies
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Heart
          • Thanks
          • Like
        • 4 replies
    ×
    ×
    • Create New...