thiagoralves / OpenPLC_Editor

OpenPLC Editor - IDE capable of creating programs for the OpenPLC Runtime
GNU General Public License v2.0
387 stars 191 forks source link

Dev python3: Fix a bug of EditorToolBar #38

Closed zarekvane closed 2 years ago

zarekvane commented 2 years ago

There are two main problem:

problem 1 (fixed)

EditorToolBar can't be shown.

problem 2 (not fixed)

EVT_MENU event is triggered only once and there is not responding when I click the EditorToolBar item the second time, meanwhile, it throws some Exceptions. This seems to be the bug of wxpython4?

wx._core.wxAssertionError: C++ assertion "CanBeToggled()" failed at ../src/common/tbarbase.cpp(86) in Toggle(): can't toggle this tool

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.CommandEvent'> returned a result with an error set
zarekvane commented 2 years ago

Maybe I have already known the reason for the second problem.

such as function OnVariableTool:

def OnVariableTool(self, event):
    self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARVARIABLE)
    selected = self.TabsOpened.GetSelection()
    if selected != -1:
        self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE)

ResetToolToggle is to set the toggle of relative toolbar item to False. It prevents the next event. I guess the original code may be to prevent users from accidentally clicking on the toolbar button before the add dialog box pops up. But he forgot to reset the value to True when the dialog closed. After some basic tests, I found that this code is unnecessary.

see: https://github.com/thiagoralves/OpenPLC_Editor/pull/39