449 self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP) |
449 self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP) |
450 self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
450 self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
451 |
451 |
452 def _init_coll_PLCConfigMainSizer_Items(self, parent): |
452 def _init_coll_PLCConfigMainSizer_Items(self, parent): |
453 parent.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
453 parent.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
454 parent.AddSizer(self.PluginTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT) |
454 parent.AddSizer(self.ConfNodeTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT) |
455 |
455 |
456 def _init_coll_PLCConfigMainSizer_Growables(self, parent): |
456 def _init_coll_PLCConfigMainSizer_Growables(self, parent): |
457 parent.AddGrowableCol(0) |
457 parent.AddGrowableCol(0) |
458 parent.AddGrowableRow(1) |
458 parent.AddGrowableRow(1) |
459 |
459 |
460 def _init_coll_PluginTreeSizer_Growables(self, parent): |
460 def _init_coll_ConfNodeTreeSizer_Growables(self, parent): |
461 parent.AddGrowableCol(0) |
461 parent.AddGrowableCol(0) |
462 parent.AddGrowableCol(1) |
462 parent.AddGrowableCol(1) |
463 |
463 |
464 def _init_beremiz_sizers(self): |
464 def _init_beremiz_sizers(self): |
465 self.PLCConfigMainSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) |
465 self.PLCConfigMainSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) |
466 self.PLCParamsSizer = wx.BoxSizer(wx.VERTICAL) |
466 self.PLCParamsSizer = wx.BoxSizer(wx.VERTICAL) |
467 #self.PluginTreeSizer = wx.FlexGridSizer(cols=3, hgap=0, rows=0, vgap=2) |
467 #self.ConfNodeTreeSizer = wx.FlexGridSizer(cols=3, hgap=0, rows=0, vgap=2) |
468 self.PluginTreeSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=0, vgap=2) |
468 self.ConfNodeTreeSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=0, vgap=2) |
469 |
469 |
470 self._init_coll_PLCConfigMainSizer_Items(self.PLCConfigMainSizer) |
470 self._init_coll_PLCConfigMainSizer_Items(self.PLCConfigMainSizer) |
471 self._init_coll_PLCConfigMainSizer_Growables(self.PLCConfigMainSizer) |
471 self._init_coll_PLCConfigMainSizer_Growables(self.PLCConfigMainSizer) |
472 self._init_coll_PluginTreeSizer_Growables(self.PluginTreeSizer) |
472 self._init_coll_ConfNodeTreeSizer_Growables(self.ConfNodeTreeSizer) |
473 |
473 |
474 self.PLCConfig.SetSizer(self.PLCConfigMainSizer) |
474 self.PLCConfig.SetSizer(self.PLCConfigMainSizer) |
475 |
475 |
476 def _init_ctrls(self, prnt): |
476 def _init_ctrls(self, prnt): |
477 IDEFrame._init_ctrls(self, prnt) |
477 IDEFrame._init_ctrls(self, prnt) |
848 |
848 |
849 def RefreshPLCParams(self): |
849 def RefreshPLCParams(self): |
850 self.Freeze() |
850 self.Freeze() |
851 self.ClearSizer(self.PLCParamsSizer) |
851 self.ClearSizer(self.PLCParamsSizer) |
852 |
852 |
853 if self.PluginRoot is not None: |
853 if self.CTR is not None: |
854 plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
854 plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
855 if self.PluginRoot.PlugTestModified(): |
855 if self.CTR.PlugTestModified(): |
856 bkgdclr = CHANGED_TITLE_COLOUR |
856 bkgdclr = CHANGED_TITLE_COLOUR |
857 else: |
857 else: |
858 bkgdclr = TITLE_COLOUR |
858 bkgdclr = TITLE_COLOUR |
859 |
859 |
860 if self.PluginRoot not in self.PluginInfos: |
860 if self.CTR not in self.ConfNodeInfos: |
861 self.PluginInfos[self.PluginRoot] = {"right_visible" : False} |
861 self.ConfNodeInfos[self.CTR] = {"right_visible" : False} |
862 |
862 |
863 plcwindow.SetBackgroundColour(TITLE_COLOUR) |
863 plcwindow.SetBackgroundColour(TITLE_COLOUR) |
864 plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
864 plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
865 self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) |
865 self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) |
866 |
866 |
867 plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
867 plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
868 plcwindow.SetSizer(plcwindowsizer) |
868 plcwindow.SetSizer(plcwindowsizer) |
869 |
869 |
870 st = wx.StaticText(plcwindow, -1) |
870 st = wx.StaticText(plcwindow, -1) |
871 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
871 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
872 st.SetLabel(self.PluginRoot.GetProjectName()) |
872 st.SetLabel(self.CTR.GetProjectName()) |
873 plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
873 plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
874 |
874 |
875 addbutton_id = wx.NewId() |
875 addbutton_id = wx.NewId() |
876 addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')), |
876 addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')), |
877 name='AddPluginButton', parent=plcwindow, pos=wx.Point(0, 0), |
877 name='AddConfNodeButton', parent=plcwindow, pos=wx.Point(0, 0), |
878 size=wx.Size(16, 16), style=wx.NO_BORDER) |
878 size=wx.Size(16, 16), style=wx.NO_BORDER) |
879 addbutton.SetToolTipString(_("Add a sub plugin")) |
879 addbutton.SetToolTipString(_("Add a sub confnode")) |
880 addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(self.PluginRoot), id=addbutton_id) |
880 addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddConfNodeMenu(self.CTR), id=addbutton_id) |
881 plcwindowsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
881 plcwindowsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
882 |
882 |
883 plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
883 plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
884 plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL) |
884 plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL) |
885 |
885 |
886 plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
886 plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
887 plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) |
887 plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) |
888 |
888 |
889 msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["right_visible"]) |
889 msizer = self.GenerateMethodButtonSizer(self.CTR, plcwindow, not self.ConfNodeInfos[self.CTR]["right_visible"]) |
890 plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
890 plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
891 |
891 |
892 paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
892 paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
893 paramswindow.SetBackgroundColour(TITLE_COLOUR) |
893 paramswindow.SetBackgroundColour(TITLE_COLOUR) |
894 paramswindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
894 paramswindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
895 plcwindowbuttonsizer.AddWindow(paramswindow, 0, border=0, flag=0) |
895 plcwindowbuttonsizer.AddWindow(paramswindow, 0, border=0, flag=0) |
896 |
896 |
897 psizer = wx.BoxSizer(wx.HORIZONTAL) |
897 psizer = wx.BoxSizer(wx.HORIZONTAL) |
898 paramswindow.SetSizer(psizer) |
898 paramswindow.SetSizer(psizer) |
899 |
899 |
900 plugin_infos = self.PluginRoot.GetParamsAttributes() |
900 confnode_infos = self.CTR.GetParamsAttributes() |
901 self.RefreshSizerElement(paramswindow, psizer, self.PluginRoot, plugin_infos, None, False) |
901 self.RefreshSizerElement(paramswindow, psizer, self.CTR, confnode_infos, None, False) |
902 |
902 |
903 if not self.PluginInfos[self.PluginRoot]["right_visible"]: |
903 if not self.ConfNodeInfos[self.CTR]["right_visible"]: |
904 paramswindow.Hide() |
904 paramswindow.Hide() |
905 |
905 |
906 minimizebutton_id = wx.NewId() |
906 minimizebutton_id = wx.NewId() |
907 minimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=minimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')), |
907 minimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=minimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')), |
908 name='MinimizeButton', parent=plcwindow, pos=wx.Point(0, 0), |
908 name='MinimizeButton', parent=plcwindow, pos=wx.Point(0, 0), |
909 size=wx.Size(24, 24), style=wx.NO_BORDER) |
909 size=wx.Size(24, 24), style=wx.NO_BORDER) |
910 make_genbitmaptogglebutton_flat(minimizebutton) |
910 make_genbitmaptogglebutton_flat(minimizebutton) |
911 minimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png'))) |
911 minimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png'))) |
912 minimizebutton.SetToggle(self.PluginInfos[self.PluginRoot]["right_visible"]) |
912 minimizebutton.SetToggle(self.ConfNodeInfos[self.CTR]["right_visible"]) |
913 plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL) |
913 plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL) |
914 |
914 |
915 def togglewindow(event): |
915 def togglewindow(event): |
916 if minimizebutton.GetToggle(): |
916 if minimizebutton.GetToggle(): |
917 paramswindow.Show() |
917 paramswindow.Show() |
918 msizer.SetCols(1) |
918 msizer.SetCols(1) |
919 else: |
919 else: |
920 paramswindow.Hide() |
920 paramswindow.Hide() |
921 msizer.SetCols(len(self.PluginRoot.PluginMethods)) |
921 msizer.SetCols(len(self.CTR.ConfNodeMethods)) |
922 self.PluginInfos[self.PluginRoot]["right_visible"] = minimizebutton.GetToggle() |
922 self.ConfNodeInfos[self.CTR]["right_visible"] = minimizebutton.GetToggle() |
923 self.PLCConfigMainSizer.Layout() |
923 self.PLCConfigMainSizer.Layout() |
924 self.RefreshScrollBars() |
924 self.RefreshScrollBars() |
925 event.Skip() |
925 event.Skip() |
926 minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id) |
926 minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id) |
927 |
927 |
928 self.PluginInfos[self.PluginRoot]["main"] = plcwindow |
928 self.ConfNodeInfos[self.CTR]["main"] = plcwindow |
929 self.PluginInfos[self.PluginRoot]["params"] = paramswindow |
929 self.ConfNodeInfos[self.CTR]["params"] = paramswindow |
930 |
930 |
931 self.PLCConfigMainSizer.Layout() |
931 self.PLCConfigMainSizer.Layout() |
932 self.RefreshScrollBars() |
932 self.RefreshScrollBars() |
933 self.Thaw() |
933 self.Thaw() |
934 |
934 |
935 def GenerateEnableButton(self, parent, sizer, plugin): |
935 def GenerateEnableButton(self, parent, sizer, confnode): |
936 enabled = plugin.PlugEnabled() |
936 enabled = confnode.PlugEnabled() |
937 if enabled is not None: |
937 if enabled is not None: |
938 enablebutton_id = wx.NewId() |
938 enablebutton_id = wx.NewId() |
939 enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')), |
939 enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')), |
940 name='EnableButton', parent=parent, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER) |
940 name='EnableButton', parent=parent, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER) |
941 enablebutton.SetToolTipString(_("Enable/Disable this plugin")) |
941 enablebutton.SetToolTipString(_("Enable/Disable this confnode")) |
942 make_genbitmaptogglebutton_flat(enablebutton) |
942 make_genbitmaptogglebutton_flat(enablebutton) |
943 enablebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Enabled.png'))) |
943 enablebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Enabled.png'))) |
944 enablebutton.SetToggle(enabled) |
944 enablebutton.SetToggle(enabled) |
945 def toggleenablebutton(event): |
945 def toggleenablebutton(event): |
946 res = self.SetPluginParamsAttribute(plugin, "BaseParams.Enabled", enablebutton.GetToggle()) |
946 res = self.SetConfNodeParamsAttribute(confnode, "BaseParams.Enabled", enablebutton.GetToggle()) |
947 enablebutton.SetToggle(res) |
947 enablebutton.SetToggle(res) |
948 event.Skip() |
948 event.Skip() |
949 enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id) |
949 enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id) |
950 sizer.AddWindow(enablebutton, 0, border=0, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
950 sizer.AddWindow(enablebutton, 0, border=0, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
951 else: |
951 else: |
952 sizer.AddSpacer(wx.Size(16, 16)) |
952 sizer.AddSpacer(wx.Size(16, 16)) |
953 |
953 |
954 def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True): |
954 def GenerateMethodButtonSizer(self, confnode, parent, horizontal = True): |
955 normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) |
955 normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) |
956 mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) |
956 mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) |
957 if horizontal: |
957 if horizontal: |
958 msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods)) |
958 msizer = wx.FlexGridSizer(cols=len(confnode.ConfNodeMethods)) |
959 else: |
959 else: |
960 msizer = wx.FlexGridSizer(cols=1) |
960 msizer = wx.FlexGridSizer(cols=1) |
961 for plugin_method in plugin.PluginMethods: |
961 for confnode_method in confnode.ConfNodeMethods: |
962 if "method" in plugin_method and plugin_method.get("shown",True): |
962 if "method" in confnode_method and confnode_method.get("shown",True): |
963 id = wx.NewId() |
963 id = wx.NewId() |
964 label = plugin_method["name"] |
964 label = confnode_method["name"] |
965 button = GenBitmapTextButton(id=id, parent=parent, |
965 button = GenBitmapTextButton(id=id, parent=parent, |
966 bitmap=wx.Bitmap(Bpath( "%s.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=label, |
966 bitmap=wx.Bitmap(Bpath( "%s.png"%confnode_method.get("bitmap", os.path.join("images", "Unknown")))), label=label, |
967 name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER) |
967 name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER) |
968 button.SetFont(normal_bt_font) |
968 button.SetFont(normal_bt_font) |
969 button.SetToolTipString(plugin_method["tooltip"]) |
969 button.SetToolTipString(confnode_method["tooltip"]) |
970 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id) |
970 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode, confnode_method["method"]), id=id) |
971 # a fancy underline on mouseover |
971 # a fancy underline on mouseover |
972 def setFontStyle(b, s): |
972 def setFontStyle(b, s): |
973 def fn(event): |
973 def fn(event): |
974 b.SetFont(s) |
974 b.SetFont(s) |
975 b.Refresh() |
975 b.Refresh() |
976 event.Skip() |
976 event.Skip() |
977 return fn |
977 return fn |
978 button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font)) |
978 button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font)) |
979 button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font)) |
979 button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font)) |
980 #hack to force size to mini |
980 #hack to force size to mini |
981 if not plugin_method.get("enabled",True): |
981 if not confnode_method.get("enabled",True): |
982 button.Disable() |
982 button.Disable() |
983 msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER) |
983 msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER) |
984 return msizer |
984 return msizer |
985 |
985 |
986 def GenerateParamsPanel(self, plugin, bkgdclr, top_offset=0): |
986 def GenerateParamsPanel(self, confnode, bkgdclr, top_offset=0): |
987 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
987 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
988 rightwindow.SetBackgroundColour(bkgdclr) |
988 rightwindow.SetBackgroundColour(bkgdclr) |
989 |
989 |
990 rightwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
990 rightwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
991 rightwindow.SetSizer(rightwindowmainsizer) |
991 rightwindow.SetSizer(rightwindowmainsizer) |
993 rightwindowsizer = wx.FlexGridSizer(cols=2, rows=1) |
993 rightwindowsizer = wx.FlexGridSizer(cols=2, rows=1) |
994 rightwindowsizer.AddGrowableCol(1) |
994 rightwindowsizer.AddGrowableCol(1) |
995 rightwindowsizer.AddGrowableRow(0) |
995 rightwindowsizer.AddGrowableRow(0) |
996 rightwindowmainsizer.AddSizer(rightwindowsizer, 0, border=0, flag=wx.GROW) |
996 rightwindowmainsizer.AddSizer(rightwindowsizer, 0, border=0, flag=wx.GROW) |
997 |
997 |
998 msizer = self.GenerateMethodButtonSizer(plugin, rightwindow, not self.PluginInfos[plugin]["right_visible"]) |
998 msizer = self.GenerateMethodButtonSizer(confnode, rightwindow, not self.ConfNodeInfos[confnode]["right_visible"]) |
999 rightwindowsizer.AddSizer(msizer, 0, border=top_offset, flag=wx.TOP|wx.GROW) |
999 rightwindowsizer.AddSizer(msizer, 0, border=top_offset, flag=wx.TOP|wx.GROW) |
1000 |
1000 |
1001 rightparamssizer = wx.BoxSizer(wx.HORIZONTAL) |
1001 rightparamssizer = wx.BoxSizer(wx.HORIZONTAL) |
1002 rightwindowsizer.AddSizer(rightparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT) |
1002 rightwindowsizer.AddSizer(rightparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT) |
1003 |
1003 |
1004 paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1)) |
1004 paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1)) |
1005 paramswindow.SetBackgroundColour(bkgdclr) |
1005 paramswindow.SetBackgroundColour(bkgdclr) |
1006 |
1006 |
1007 psizer = wx.BoxSizer(wx.VERTICAL) |
1007 psizer = wx.BoxSizer(wx.VERTICAL) |
1008 paramswindow.SetSizer(psizer) |
1008 paramswindow.SetSizer(psizer) |
1009 self.PluginInfos[plugin]["params"] = paramswindow |
1009 self.ConfNodeInfos[confnode]["params"] = paramswindow |
1010 |
1010 |
1011 rightparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL) |
1011 rightparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL) |
1012 |
1012 |
1013 plugin_infos = plugin.GetParamsAttributes() |
1013 confnode_infos = confnode.GetParamsAttributes() |
1014 if len(plugin_infos) > 0: |
1014 if len(confnode_infos) > 0: |
1015 self.RefreshSizerElement(paramswindow, psizer, plugin, plugin_infos, None, False) |
1015 self.RefreshSizerElement(paramswindow, psizer, confnode, confnode_infos, None, False) |
1016 |
1016 |
1017 if not self.PluginInfos[plugin]["right_visible"]: |
1017 if not self.ConfNodeInfos[confnode]["right_visible"]: |
1018 paramswindow.Hide() |
1018 paramswindow.Hide() |
1019 |
1019 |
1020 rightminimizebutton_id = wx.NewId() |
1020 rightminimizebutton_id = wx.NewId() |
1021 rightminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=rightminimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')), |
1021 rightminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=rightminimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')), |
1022 name='MinimizeButton', parent=rightwindow, pos=wx.Point(0, 0), |
1022 name='MinimizeButton', parent=rightwindow, pos=wx.Point(0, 0), |
1023 size=wx.Size(24, 24), style=wx.NO_BORDER) |
1023 size=wx.Size(24, 24), style=wx.NO_BORDER) |
1024 make_genbitmaptogglebutton_flat(rightminimizebutton) |
1024 make_genbitmaptogglebutton_flat(rightminimizebutton) |
1025 rightminimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png'))) |
1025 rightminimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png'))) |
1026 rightminimizebutton.SetToggle(self.PluginInfos[plugin]["right_visible"]) |
1026 rightminimizebutton.SetToggle(self.ConfNodeInfos[confnode]["right_visible"]) |
1027 rightparamssizer.AddWindow(rightminimizebutton, 0, border=5, flag=wx.ALL) |
1027 rightparamssizer.AddWindow(rightminimizebutton, 0, border=5, flag=wx.ALL) |
1028 |
1028 |
1029 def togglerightwindow(event): |
1029 def togglerightwindow(event): |
1030 if rightminimizebutton.GetToggle(): |
1030 if rightminimizebutton.GetToggle(): |
1031 rightparamssizer.Show(0) |
1031 rightparamssizer.Show(0) |
1032 msizer.SetCols(1) |
1032 msizer.SetCols(1) |
1033 else: |
1033 else: |
1034 rightparamssizer.Hide(0) |
1034 rightparamssizer.Hide(0) |
1035 msizer.SetCols(len(plugin.PluginMethods)) |
1035 msizer.SetCols(len(confnode.ConfNodeMethods)) |
1036 self.PluginInfos[plugin]["right_visible"] = rightminimizebutton.GetToggle() |
1036 self.ConfNodeInfos[confnode]["right_visible"] = rightminimizebutton.GetToggle() |
1037 self.PLCConfigMainSizer.Layout() |
1037 self.PLCConfigMainSizer.Layout() |
1038 self.RefreshScrollBars() |
1038 self.RefreshScrollBars() |
1039 event.Skip() |
1039 event.Skip() |
1040 rightminimizebutton.Bind(wx.EVT_BUTTON, togglerightwindow, id=rightminimizebutton_id) |
1040 rightminimizebutton.Bind(wx.EVT_BUTTON, togglerightwindow, id=rightminimizebutton_id) |
1041 |
1041 |
1042 return rightwindow |
1042 return rightwindow |
1043 |
1043 |
1044 |
1044 |
1045 def RefreshPluginTree(self): |
1045 def RefreshConfNodeTree(self): |
1046 self.Freeze() |
1046 self.Freeze() |
1047 self.ClearSizer(self.PluginTreeSizer) |
1047 self.ClearSizer(self.ConfNodeTreeSizer) |
1048 if self.PluginRoot is not None: |
1048 if self.CTR is not None: |
1049 for child in self.PluginRoot.IECSortedChilds(): |
1049 for child in self.CTR.IECSortedChilds(): |
1050 self.GenerateTreeBranch(child) |
1050 self.GenerateTreeBranch(child) |
1051 if not self.PluginInfos[child]["expanded"]: |
1051 if not self.ConfNodeInfos[child]["expanded"]: |
1052 self.CollapsePlugin(child) |
1052 self.CollapseConfNode(child) |
1053 self.PLCConfigMainSizer.Layout() |
1053 self.PLCConfigMainSizer.Layout() |
1054 self.RefreshScrollBars() |
1054 self.RefreshScrollBars() |
1055 self.Thaw() |
1055 self.Thaw() |
1056 |
1056 |
1057 def SetPluginParamsAttribute(self, plugin, *args, **kwargs): |
1057 def SetConfNodeParamsAttribute(self, confnode, *args, **kwargs): |
1058 res, StructChanged = plugin.SetParamsAttribute(*args, **kwargs) |
1058 res, StructChanged = confnode.SetParamsAttribute(*args, **kwargs) |
1059 if StructChanged: |
1059 if StructChanged: |
1060 wx.CallAfter(self.RefreshPluginTree) |
1060 wx.CallAfter(self.RefreshConfNodeTree) |
1061 else: |
1061 else: |
1062 if plugin == self.PluginRoot: |
1062 if confnode == self.CTR: |
1063 bkgdclr = CHANGED_TITLE_COLOUR |
1063 bkgdclr = CHANGED_TITLE_COLOUR |
1064 items = ["main", "params"] |
1064 items = ["main", "params"] |
1065 else: |
1065 else: |
1066 bkgdclr = CHANGED_WINDOW_COLOUR |
1066 bkgdclr = CHANGED_WINDOW_COLOUR |
1067 items = ["left", "right", "params"] |
1067 items = ["left", "right", "params"] |
1068 for i in items: |
1068 for i in items: |
1069 self.PluginInfos[plugin][i].SetBackgroundColour(bkgdclr) |
1069 self.ConfNodeInfos[confnode][i].SetBackgroundColour(bkgdclr) |
1070 self.PluginInfos[plugin][i].Refresh() |
1070 self.ConfNodeInfos[confnode][i].Refresh() |
1071 self._Refresh(TITLE, FILEMENU) |
1071 self._Refresh(TITLE, FILEMENU) |
1072 return res |
1072 return res |
1073 |
1073 |
1074 def ExpandPlugin(self, plugin, force = False): |
1074 def ExpandConfNode(self, confnode, force = False): |
1075 for child in self.PluginInfos[plugin]["children"]: |
1075 for child in self.ConfNodeInfos[confnode]["children"]: |
1076 self.PluginInfos[child]["left"].Show() |
1076 self.ConfNodeInfos[child]["left"].Show() |
1077 self.PluginInfos[child]["right"].Show() |
1077 self.ConfNodeInfos[child]["right"].Show() |
1078 if force or self.PluginInfos[child]["expanded"]: |
1078 if force or self.ConfNodeInfos[child]["expanded"]: |
1079 self.ExpandPlugin(child, force) |
1079 self.ExpandConfNode(child, force) |
1080 if force: |
1080 if force: |
1081 self.PluginInfos[child]["expanded"] = True |
1081 self.ConfNodeInfos[child]["expanded"] = True |
1082 locations_infos = self.PluginInfos[plugin].get("locations_infos", None) |
1082 locations_infos = self.ConfNodeInfos[confnode].get("locations_infos", None) |
1083 if locations_infos is not None: |
1083 if locations_infos is not None: |
1084 if force or locations_infos["root"]["expanded"]: |
1084 if force or locations_infos["root"]["expanded"]: |
1085 self.ExpandLocation(locations_infos, "root", force) |
1085 self.ExpandLocation(locations_infos, "root", force) |
1086 if force: |
1086 if force: |
1087 locations_infos["root"]["expanded"] = True |
1087 locations_infos["root"]["expanded"] = True |
1088 |
1088 |
1089 def CollapsePlugin(self, plugin, force = False): |
1089 def CollapseConfNode(self, confnode, force = False): |
1090 for child in self.PluginInfos[plugin]["children"]: |
1090 for child in self.ConfNodeInfos[confnode]["children"]: |
1091 self.PluginInfos[child]["left"].Hide() |
1091 self.ConfNodeInfos[child]["left"].Hide() |
1092 self.PluginInfos[child]["right"].Hide() |
1092 self.ConfNodeInfos[child]["right"].Hide() |
1093 self.CollapsePlugin(child, force) |
1093 self.CollapseConfNode(child, force) |
1094 if force: |
1094 if force: |
1095 self.PluginInfos[child]["expanded"] = False |
1095 self.ConfNodeInfos[child]["expanded"] = False |
1096 locations_infos = self.PluginInfos[plugin].get("locations_infos", None) |
1096 locations_infos = self.ConfNodeInfos[confnode].get("locations_infos", None) |
1097 if locations_infos is not None: |
1097 if locations_infos is not None: |
1098 self.CollapseLocation(locations_infos, "root", force) |
1098 self.CollapseLocation(locations_infos, "root", force) |
1099 if force: |
1099 if force: |
1100 locations_infos["root"]["expanded"] = False |
1100 locations_infos["root"]["expanded"] = False |
1101 |
1101 |
1169 leftbuttonsizer.AddSizer(leftsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1169 leftbuttonsizer.AddSizer(leftsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1170 |
1170 |
1171 rolesizer = wx.BoxSizer(wx.HORIZONTAL) |
1171 rolesizer = wx.BoxSizer(wx.HORIZONTAL) |
1172 leftsizer.AddSizer(rolesizer, 0, border=0, flag=wx.GROW|wx.RIGHT) |
1172 leftsizer.AddSizer(rolesizer, 0, border=0, flag=wx.GROW|wx.RIGHT) |
1173 |
1173 |
1174 #self.GenerateEnableButton(leftwindow, rolesizer, plugin) |
1174 #self.GenerateEnableButton(leftwindow, rolesizer, confnode) |
1175 |
1175 |
1176 roletext = wx.StaticText(leftwindow, -1) |
1176 roletext = wx.StaticText(leftwindow, -1) |
1177 roletext.SetLabel(plugin.PlugHelp) |
1177 roletext.SetLabel(confnode.PlugHelp) |
1178 rolesizer.AddWindow(roletext, 0, border=5, flag=wx.RIGHT|wx.ALIGN_LEFT) |
1178 rolesizer.AddWindow(roletext, 0, border=5, flag=wx.RIGHT|wx.ALIGN_LEFT) |
1179 |
1179 |
1180 plugin_IECChannel = plugin.BaseParams.getIEC_Channel() |
1180 confnode_IECChannel = confnode.BaseParams.getIEC_Channel() |
1181 |
1181 |
1182 iecsizer = wx.BoxSizer(wx.HORIZONTAL) |
1182 iecsizer = wx.BoxSizer(wx.HORIZONTAL) |
1183 leftsizer.AddSizer(iecsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1183 leftsizer.AddSizer(iecsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1184 |
1184 |
1185 st = wx.StaticText(leftwindow, -1) |
1185 st = wx.StaticText(leftwindow, -1) |
1186 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1186 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1187 st.SetLabel(plugin.GetFullIEC_Channel()) |
1187 st.SetLabel(confnode.GetFullIEC_Channel()) |
1188 iecsizer.AddWindow(st, 0, border=0, flag=0) |
1188 iecsizer.AddWindow(st, 0, border=0, flag=0) |
1189 |
1189 |
1190 updownsizer = wx.BoxSizer(wx.VERTICAL) |
1190 updownsizer = wx.BoxSizer(wx.VERTICAL) |
1191 iecsizer.AddSizer(updownsizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) |
1191 iecsizer.AddSizer(updownsizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) |
1192 |
1192 |
1193 if plugin_IECChannel > 0: |
1193 if confnode_IECChannel > 0: |
1194 ieccdownbutton_id = wx.NewId() |
1194 ieccdownbutton_id = wx.NewId() |
1195 ieccdownbutton = wx.lib.buttons.GenBitmapButton(id=ieccdownbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'IECCDown.png')), |
1195 ieccdownbutton = wx.lib.buttons.GenBitmapButton(id=ieccdownbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'IECCDown.png')), |
1196 name='IECCDownButton', parent=leftwindow, pos=wx.Point(0, 0), |
1196 name='IECCDownButton', parent=leftwindow, pos=wx.Point(0, 0), |
1197 size=wx.Size(16, 16), style=wx.NO_BORDER) |
1197 size=wx.Size(16, 16), style=wx.NO_BORDER) |
1198 ieccdownbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel - 1), id=ieccdownbutton_id) |
1198 ieccdownbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(confnode, confnode_IECChannel - 1), id=ieccdownbutton_id) |
1199 updownsizer.AddWindow(ieccdownbutton, 0, border=0, flag=wx.ALIGN_LEFT) |
1199 updownsizer.AddWindow(ieccdownbutton, 0, border=0, flag=wx.ALIGN_LEFT) |
1200 |
1200 |
1201 ieccupbutton_id = wx.NewId() |
1201 ieccupbutton_id = wx.NewId() |
1202 ieccupbutton = wx.lib.buttons.GenBitmapTextButton(id=ieccupbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'IECCUp.png')), |
1202 ieccupbutton = wx.lib.buttons.GenBitmapTextButton(id=ieccupbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'IECCUp.png')), |
1203 name='IECCUpButton', parent=leftwindow, pos=wx.Point(0, 0), |
1203 name='IECCUpButton', parent=leftwindow, pos=wx.Point(0, 0), |
1204 size=wx.Size(16, 16), style=wx.NO_BORDER) |
1204 size=wx.Size(16, 16), style=wx.NO_BORDER) |
1205 ieccupbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel + 1), id=ieccupbutton_id) |
1205 ieccupbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(confnode, confnode_IECChannel + 1), id=ieccupbutton_id) |
1206 updownsizer.AddWindow(ieccupbutton, 0, border=0, flag=wx.ALIGN_LEFT) |
1206 updownsizer.AddWindow(ieccupbutton, 0, border=0, flag=wx.ALIGN_LEFT) |
1207 |
1207 |
1208 adddeletesizer = wx.BoxSizer(wx.VERTICAL) |
1208 adddeletesizer = wx.BoxSizer(wx.VERTICAL) |
1209 iecsizer.AddSizer(adddeletesizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) |
1209 iecsizer.AddSizer(adddeletesizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) |
1210 |
1210 |
1211 deletebutton_id = wx.NewId() |
1211 deletebutton_id = wx.NewId() |
1212 deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Delete.png')), |
1212 deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Delete.png')), |
1213 name='DeletePluginButton', parent=leftwindow, pos=wx.Point(0, 0), |
1213 name='DeleteConfNodeButton', parent=leftwindow, pos=wx.Point(0, 0), |
1214 size=wx.Size(16, 16), style=wx.NO_BORDER) |
1214 size=wx.Size(16, 16), style=wx.NO_BORDER) |
1215 deletebutton.SetToolTipString(_("Delete this plugin")) |
1215 deletebutton.SetToolTipString(_("Delete this confnode")) |
1216 deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id) |
1216 deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(confnode), id=deletebutton_id) |
1217 adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
1217 adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
1218 |
1218 |
1219 if len(plugin.PlugChildsTypes) > 0: |
1219 if len(confnode.PlugChildsTypes) > 0: |
1220 addbutton_id = wx.NewId() |
1220 addbutton_id = wx.NewId() |
1221 addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')), |
1221 addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')), |
1222 name='AddPluginButton', parent=leftwindow, pos=wx.Point(0, 0), |
1222 name='AddConfNodeButton', parent=leftwindow, pos=wx.Point(0, 0), |
1223 size=wx.Size(16, 16), style=wx.NO_BORDER) |
1223 size=wx.Size(16, 16), style=wx.NO_BORDER) |
1224 addbutton.SetToolTipString(_("Add a sub plugin")) |
1224 addbutton.SetToolTipString(_("Add a sub confnode")) |
1225 addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(plugin), id=addbutton_id) |
1225 addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddConfNodeMenu(confnode), id=addbutton_id) |
1226 adddeletesizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
1226 adddeletesizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
1227 |
1227 |
1228 expandbutton_id = wx.NewId() |
1228 expandbutton_id = wx.NewId() |
1229 expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')), |
1229 expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')), |
1230 name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0), |
1230 name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0), |
1265 iecsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1265 iecsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1266 |
1266 |
1267 tc_id = wx.NewId() |
1267 tc_id = wx.NewId() |
1268 tc = wx.TextCtrl(leftwindow, tc_id, size=wx.Size(150, 25), style=wx.NO_BORDER) |
1268 tc = wx.TextCtrl(leftwindow, tc_id, size=wx.Size(150, 25), style=wx.NO_BORDER) |
1269 tc.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1269 tc.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1270 tc.ChangeValue(plugin.MandatoryParams[1].getName()) |
1270 tc.ChangeValue(confnode.MandatoryParams[1].getName()) |
1271 tc.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(tc, plugin, "BaseParams.Name"), id=tc_id) |
1271 tc.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(tc, confnode, "BaseParams.Name"), id=tc_id) |
1272 iecsizer.AddWindow(tc, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1272 iecsizer.AddWindow(tc, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1273 |
1273 |
1274 rightwindow = self.GenerateParamsPanel(plugin, bkgdclr, 8) |
1274 rightwindow = self.GenerateParamsPanel(confnode, bkgdclr, 8) |
1275 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1275 self.ConfNodeTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1276 |
1276 |
1277 self.PluginInfos[plugin]["left"] = leftwindow |
1277 self.ConfNodeInfos[confnode]["left"] = leftwindow |
1278 self.PluginInfos[plugin]["right"] = rightwindow |
1278 self.ConfNodeInfos[confnode]["right"] = rightwindow |
1279 for child in self.PluginInfos[plugin]["children"]: |
1279 for child in self.ConfNodeInfos[confnode]["children"]: |
1280 self.GenerateTreeBranch(child) |
1280 self.GenerateTreeBranch(child) |
1281 if not self.PluginInfos[child]["expanded"]: |
1281 if not self.ConfNodeInfos[child]["expanded"]: |
1282 self.CollapsePlugin(child) |
1282 self.CollapseConfNode(child) |
1283 |
1283 |
1284 if len(plugin_locations) > 0: |
1284 if len(confnode_locations) > 0: |
1285 locations_infos = self.PluginInfos[plugin]["locations_infos"] |
1285 locations_infos = self.ConfNodeInfos[confnode]["locations_infos"] |
1286 treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize, |
1286 treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize, |
1287 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT) |
1287 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT) |
1288 treectrl.SetImageList(self.LocationImageList) |
1288 treectrl.SetImageList(self.LocationImageList) |
1289 treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos)) |
1289 treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos)) |
1290 treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True)) |
1290 treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True)) |
1291 treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False)) |
1291 treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False)) |
1292 treectrl.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelTreeCtrl) |
1292 treectrl.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelTreeCtrl) |
1293 |
1293 |
1294 treectrl.AddRoot("") |
1294 treectrl.AddRoot("") |
1295 self.PluginTreeSizer.AddWindow(treectrl, 0, border=0, flag=0) |
1295 self.ConfNodeTreeSizer.AddWindow(treectrl, 0, border=0, flag=0) |
1296 |
1296 |
1297 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1297 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1298 rightwindow.SetBackgroundColour(wx.WHITE) |
1298 rightwindow.SetBackgroundColour(wx.WHITE) |
1299 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1299 self.ConfNodeTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1300 |
1300 |
1301 locations_infos["root"]["left"] = treectrl |
1301 locations_infos["root"]["left"] = treectrl |
1302 locations_infos["root"]["right"] = rightwindow |
1302 locations_infos["root"]["right"] = rightwindow |
1303 for location in plugin_locations: |
1303 for location in confnode_locations: |
1304 locations_infos["root"]["children"].append("root.%s" % location["name"]) |
1304 locations_infos["root"]["children"].append("root.%s" % location["name"]) |
1305 self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location) |
1305 self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location) |
1306 if locations_infos["root"]["expanded"]: |
1306 if locations_infos["root"]["expanded"]: |
1307 self.PluginTreeSizer.Layout() |
1307 self.ConfNodeTreeSizer.Layout() |
1308 self.ExpandLocation(locations_infos, "root") |
1308 self.ExpandLocation(locations_infos, "root") |
1309 else: |
1309 else: |
1310 self.RefreshTreeCtrlSize(treectrl) |
1310 self.RefreshTreeCtrlSize(treectrl) |
1311 |
1311 |
1312 def GenerateLocationTreeBranch(self, treectrl, root, locations_infos, parent, location): |
1312 def GenerateLocationTreeBranch(self, treectrl, root, locations_infos, parent, location): |
1397 event.Skip() |
1397 event.Skip() |
1398 return OnLocationExpandedFunction |
1398 return OnLocationExpandedFunction |
1399 |
1399 |
1400 def RefreshAll(self): |
1400 def RefreshAll(self): |
1401 self.RefreshPLCParams() |
1401 self.RefreshPLCParams() |
1402 self.RefreshPluginTree() |
1402 self.RefreshConfNodeTree() |
1403 |
1403 |
1404 def GetItemChannelChangedFunction(self, plugin, value): |
1404 def GetItemChannelChangedFunction(self, confnode, value): |
1405 def OnPluginTreeItemChannelChanged(event): |
1405 def OnConfNodeTreeItemChannelChanged(event): |
1406 res = self.SetPluginParamsAttribute(plugin, "BaseParams.IEC_Channel", value) |
1406 res = self.SetConfNodeParamsAttribute(confnode, "BaseParams.IEC_Channel", value) |
1407 event.Skip() |
1407 event.Skip() |
1408 return OnPluginTreeItemChannelChanged |
1408 return OnConfNodeTreeItemChannelChanged |
1409 |
1409 |
1410 def _GetAddPluginFunction(self, name, plugin): |
1410 def _GetAddConfNodeFunction(self, name, confnode): |
1411 def OnPluginMenu(event): |
1411 def OnConfNodeMenu(event): |
1412 wx.CallAfter(self.AddPlugin, name, plugin) |
1412 wx.CallAfter(self.AddConfNode, name, confnode) |
1413 return OnPluginMenu |
1413 return OnConfNodeMenu |
1414 |
1414 |
1415 def Gen_AddPluginMenu(self, plugin): |
1415 def Gen_AddConfNodeMenu(self, confnode): |
1416 def AddPluginMenu(event): |
1416 def AddConfNodeMenu(event): |
1417 main_menu = wx.Menu(title='') |
1417 main_menu = wx.Menu(title='') |
1418 if len(plugin.PlugChildsTypes) > 0: |
1418 if len(confnode.PlugChildsTypes) > 0: |
1419 for name, XSDClass, help in plugin.PlugChildsTypes: |
1419 for name, XSDClass, help in confnode.PlugChildsTypes: |
1420 new_id = wx.NewId() |
1420 new_id = wx.NewId() |
1421 main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Append ")+help) |
1421 main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Append ")+help) |
1422 self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id) |
1422 self.Bind(wx.EVT_MENU, self._GetAddConfNodeFunction(name, confnode), id=new_id) |
1423 self.PopupMenuXY(main_menu) |
1423 self.PopupMenuXY(main_menu) |
1424 main_menu.Destroy() |
1424 main_menu.Destroy() |
1425 return AddPluginMenu |
1425 return AddConfNodeMenu |
1426 |
1426 |
1427 def GetButtonCallBackFunction(self, plugin, method): |
1427 def GetButtonCallBackFunction(self, confnode, method): |
1428 """ Generate the callbackfunc for a given plugin method""" |
1428 """ Generate the callbackfunc for a given confnode method""" |
1429 def OnButtonClick(event): |
1429 def OnButtonClick(event): |
1430 # Disable button to prevent re-entrant call |
1430 # Disable button to prevent re-entrant call |
1431 event.GetEventObject().Disable() |
1431 event.GetEventObject().Disable() |
1432 # Call |
1432 # Call |
1433 getattr(plugin,method)() |
1433 getattr(confnode,method)() |
1434 # Re-enable button |
1434 # Re-enable button |
1435 event.GetEventObject().Enable() |
1435 event.GetEventObject().Enable() |
1436 # Trigger refresh on Idle |
1436 # Trigger refresh on Idle |
1437 wx.CallAfter(self.RefreshAll) |
1437 wx.CallAfter(self.RefreshAll) |
1438 event.Skip() |
1438 event.Skip() |
1439 return OnButtonClick |
1439 return OnButtonClick |
1440 |
1440 |
1441 def GetChoiceCallBackFunction(self, choicectrl, plugin, path): |
1441 def GetChoiceCallBackFunction(self, choicectrl, confnode, path): |
1442 def OnChoiceChanged(event): |
1442 def OnChoiceChanged(event): |
1443 res = self.SetPluginParamsAttribute(plugin, path, choicectrl.GetStringSelection()) |
1443 res = self.SetConfNodeParamsAttribute(confnode, path, choicectrl.GetStringSelection()) |
1444 choicectrl.SetStringSelection(res) |
1444 choicectrl.SetStringSelection(res) |
1445 event.Skip() |
1445 event.Skip() |
1446 return OnChoiceChanged |
1446 return OnChoiceChanged |
1447 |
1447 |
1448 def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, plugin, path): |
1448 def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, confnode, path): |
1449 def OnChoiceContentChanged(event): |
1449 def OnChoiceContentChanged(event): |
1450 res = self.SetPluginParamsAttribute(plugin, path, choicectrl.GetStringSelection()) |
1450 res = self.SetConfNodeParamsAttribute(confnode, path, choicectrl.GetStringSelection()) |
1451 if wx.VERSION < (2, 8, 0): |
1451 if wx.VERSION < (2, 8, 0): |
1452 self.ParamsPanel.Freeze() |
1452 self.ParamsPanel.Freeze() |
1453 choicectrl.SetStringSelection(res) |
1453 choicectrl.SetStringSelection(res) |
1454 infos = self.PluginRoot.GetParamsAttributes(path) |
1454 infos = self.CTR.GetParamsAttributes(path) |
1455 staticbox = staticboxsizer.GetStaticBox() |
1455 staticbox = staticboxsizer.GetStaticBox() |
1456 staticbox.SetLabel("%(name)s - %(value)s"%infos) |
1456 staticbox.SetLabel("%(name)s - %(value)s"%infos) |
1457 self.RefreshSizerElement(self.ParamsPanel, staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]), selected=selected) |
1457 self.RefreshSizerElement(self.ParamsPanel, staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]), selected=selected) |
1458 self.ParamsPanelMainSizer.Layout() |
1458 self.ParamsPanelMainSizer.Layout() |
1459 self.ParamsPanel.Thaw() |
1459 self.ParamsPanel.Thaw() |
1763 |
1763 |
1764 def OnAboutMenu(self, event): |
1764 def OnAboutMenu(self, event): |
1765 OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc","about.html"), wx.Size(550, 500)) |
1765 OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc","about.html"), wx.Size(550, 500)) |
1766 |
1766 |
1767 def OnPouSelectedChanged(self, event): |
1767 def OnPouSelectedChanged(self, event): |
1768 wx.CallAfter(self.RefreshPluginMenu) |
1768 wx.CallAfter(self.RefreshConfNodeMenu) |
1769 IDEFrame.OnPouSelectedChanged(self, event) |
1769 IDEFrame.OnPouSelectedChanged(self, event) |
1770 |
1770 |
1771 def OnPageClose(self, event): |
1771 def OnPageClose(self, event): |
1772 wx.CallAfter(self.RefreshPluginMenu) |
1772 wx.CallAfter(self.RefreshConfNodeMenu) |
1773 IDEFrame.OnPageClose(self, event) |
1773 IDEFrame.OnPageClose(self, event) |
1774 |
1774 |
1775 def GetAddButtonFunction(self, plugin, window): |
1775 def GetAddButtonFunction(self, confnode, window): |
1776 def AddButtonFunction(event): |
1776 def AddButtonFunction(event): |
1777 if plugin and len(plugin.PlugChildsTypes) > 0: |
1777 if confnode and len(confnode.PlugChildsTypes) > 0: |
1778 plugin_menu = wx.Menu(title='') |
1778 confnode_menu = wx.Menu(title='') |
1779 for name, XSDClass, help in plugin.PlugChildsTypes: |
1779 for name, XSDClass, help in confnode.PlugChildsTypes: |
1780 new_id = wx.NewId() |
1780 new_id = wx.NewId() |
1781 plugin_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=name) |
1781 confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=name) |
1782 self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id) |
1782 self.Bind(wx.EVT_MENU, self._GetAddConfNodeFunction(name, confnode), id=new_id) |
1783 window_pos = window.GetPosition() |
1783 window_pos = window.GetPosition() |
1784 wx.CallAfter(self.PLCConfig.PopupMenu, plugin_menu) |
1784 wx.CallAfter(self.PLCConfig.PopupMenu, confnode_menu) |
1785 event.Skip() |
1785 event.Skip() |
1786 return AddButtonFunction |
1786 return AddButtonFunction |
1787 |
1787 |
1788 def GetDeleteButtonFunction(self, plugin): |
1788 def GetDeleteButtonFunction(self, confnode): |
1789 def DeleteButtonFunction(event): |
1789 def DeleteButtonFunction(event): |
1790 wx.CallAfter(self.DeletePlugin, plugin) |
1790 wx.CallAfter(self.DeleteConfNode, confnode) |
1791 event.Skip() |
1791 event.Skip() |
1792 return DeleteButtonFunction |
1792 return DeleteButtonFunction |
1793 |
1793 |
1794 def AddPlugin(self, PluginType, plugin): |
1794 def AddConfNode(self, ConfNodeType, confnode): |
1795 if self.PluginRoot.CheckProjectPathPerm(): |
1795 if self.CTR.CheckProjectPathPerm(): |
1796 dialog = wx.TextEntryDialog(self, _("Please enter a name for plugin:"), _("Add Plugin"), "", wx.OK|wx.CANCEL) |
1796 dialog = wx.TextEntryDialog(self, _("Please enter a name for confnode:"), _("Add ConfNode"), "", wx.OK|wx.CANCEL) |
1797 if dialog.ShowModal() == wx.ID_OK: |
1797 if dialog.ShowModal() == wx.ID_OK: |
1798 PluginName = dialog.GetValue() |
1798 ConfNodeName = dialog.GetValue() |
1799 plugin.PlugAddChild(PluginName, PluginType) |
1799 confnode.PlugAddChild(ConfNodeName, ConfNodeType) |
1800 self.PluginRoot.RefreshPluginsBlockLists() |
1800 self.CTR.RefreshConfNodesBlockLists() |
1801 self._Refresh(TITLE, FILEMENU) |
1801 self._Refresh(TITLE, FILEMENU) |
1802 self.RefreshPluginTree() |
1802 self.RefreshConfNodeTree() |
1803 dialog.Destroy() |
1803 dialog.Destroy() |
1804 |
1804 |
1805 def DeletePlugin(self, plugin): |
1805 def DeleteConfNode(self, confnode): |
1806 if self.PluginRoot.CheckProjectPathPerm(): |
1806 if self.CTR.CheckProjectPathPerm(): |
1807 dialog = wx.MessageDialog(self, _("Really delete plugin ?"), _("Remove plugin"), wx.YES_NO|wx.NO_DEFAULT) |
1807 dialog = wx.MessageDialog(self, _("Really delete confnode ?"), _("Remove confnode"), wx.YES_NO|wx.NO_DEFAULT) |
1808 if dialog.ShowModal() == wx.ID_YES: |
1808 if dialog.ShowModal() == wx.ID_YES: |
1809 self.PluginInfos.pop(plugin) |
1809 self.ConfNodeInfos.pop(confnode) |
1810 plugin.PlugRemove() |
1810 confnode.PlugRemove() |
1811 del plugin |
1811 del confnode |
1812 self.PluginRoot.RefreshPluginsBlockLists() |
1812 self.CTR.RefreshConfNodesBlockLists() |
1813 self._Refresh(TITLE, FILEMENU) |
1813 self._Refresh(TITLE, FILEMENU) |
1814 self.RefreshPluginTree() |
1814 self.RefreshConfNodeTree() |
1815 dialog.Destroy() |
1815 dialog.Destroy() |
1816 |
1816 |
1817 #------------------------------------------------------------------------------- |
1817 #------------------------------------------------------------------------------- |
1818 # Exception Handler |
1818 # Exception Handler |
1819 #------------------------------------------------------------------------------- |
1819 #------------------------------------------------------------------------------- |