Jump to content

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.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 18 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...