Beremiz.py
changeset 188 e152b46cd9b0
parent 176 d8cacbf276b5
child 193 ca6ad333aa80
equal deleted inserted replaced
187:b147a2b0a163 188:e152b46cd9b0
   431         window_size = self.PLCConfig.GetClientSize()
   431         window_size = self.PLCConfig.GetClientSize()
   432         sizer = self.PLCConfig.GetSizer()
   432         sizer = self.PLCConfig.GetSizer()
   433         if sizer:
   433         if sizer:
   434             maxx, maxy = sizer.GetMinSize()
   434             maxx, maxy = sizer.GetMinSize()
   435             self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   435             self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   436                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, xstart, ystart)
   436                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, 
       
   437                 max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)), 
       
   438                 max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)))
   437 
   439 
   438     def RefreshPLCParams(self):
   440     def RefreshPLCParams(self):
   439         self.Freeze()
   441         self.Freeze()
   440         self.ClearSizer(self.PLCParamsSizer)
   442         self.ClearSizer(self.PLCParamsSizer)
   441         
   443         
   972         for element_infos in elements:
   974         for element_infos in elements:
   973             if path:
   975             if path:
   974                 element_path = "%s.%s"%(path, element_infos["name"])
   976                 element_path = "%s.%s"%(path, element_infos["name"])
   975             else:
   977             else:
   976                 element_path = element_infos["name"]
   978                 element_path = element_infos["name"]
   977             if isinstance(element_infos["type"], types.ListType):
   979             if element_infos["type"] == "element":
   978                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   980                 staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
       
   981                     name='%s_staticbox'%element_infos["name"], parent=parent,
       
   982                     pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
       
   983                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
       
   984                 if first:
       
   985                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
       
   986                 else:
       
   987                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
       
   988                 self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
       
   989             else:
       
   990                 boxsizer = wx.FlexGridSizer(cols=3, rows=1)
       
   991                 boxsizer.AddGrowableCol(1)
   979                 if first:
   992                 if first:
   980                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
   993                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
   981                 else:
   994                 else:
   982                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
   995                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
   983                 staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
   996                 staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
   987                 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
  1000                 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
   988                     name="%s_label"%element_infos["name"], parent=parent, 
  1001                     name="%s_label"%element_infos["name"], parent=parent, 
   989                     pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
  1002                     pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
   990                 boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
  1003                 boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
   991                 id = wx.NewId()
  1004                 id = wx.NewId()
   992                 choicectrl = wx.Choice(id=id, name=element_infos["name"], parent=parent, 
  1005                 if isinstance(element_infos["type"], types.ListType):
   993                     pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0)
  1006                     choicectrl = wx.Choice(id=id, name=element_infos["name"], parent=parent, 
   994                 boxsizer.AddWindow(choicectrl, 0, border=0, flag=0)
  1007                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0)
   995                 choicectrl.Append("")
  1008                     boxsizer.AddWindow(choicectrl, 0, border=0, flag=0)
   996                 if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
  1009                     if element_infos["use"] == "optional":
   997                     for choice, xsdclass in element_infos["type"]:
  1010                         choicectrl.Append("")
   998                         choicectrl.Append(choice)
  1011                     if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
   999                     staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, 
  1012                         for choice, xsdclass in element_infos["type"]:
  1000                         name='%s_staticbox'%element_infos["name"], parent=parent,
  1013                             choicectrl.Append(choice)
  1001                         pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
  1014                         staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, 
  1002                     staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
  1015                             name='%s_staticbox'%element_infos["name"], parent=parent,
  1003                     sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
  1016                             pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
  1004                     self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
  1017                         staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
  1005                     callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, plugin, element_path)
  1018                         sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
  1006                 else:
  1019                         self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
  1007                     for choice in element_infos["type"]:
  1020                         callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, plugin, element_path)
  1008                         choicectrl.Append(choice)
       
  1009                     callback = self.GetChoiceCallBackFunction(choicectrl, plugin, element_path)
       
  1010                 if element_infos["value"]:
       
  1011                     choicectrl.SetStringSelection(element_infos["value"])
       
  1012                 choicectrl.Bind(wx.EVT_CHOICE, callback, id=id)
       
  1013             elif isinstance(element_infos["type"], types.DictType):
       
  1014                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
       
  1015                 if first:
       
  1016                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
       
  1017                 else:
       
  1018                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
       
  1019                 staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
       
  1020                     name="%s_bitmap"%element_infos["name"], parent=parent,
       
  1021                     pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
       
  1022                 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
       
  1023                 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
       
  1024                     name="%s_label"%element_infos["name"], parent=parent, 
       
  1025                     pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
       
  1026                 boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
       
  1027                 id = wx.NewId()
       
  1028                 scmin = -(2**31)
       
  1029                 scmax = 2**31-1
       
  1030                 if "min" in element_infos["type"]:
       
  1031                     scmin = element_infos["type"]["min"]
       
  1032                 if "max" in element_infos["type"]:
       
  1033                     scmax = element_infos["type"]["max"]
       
  1034                 spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
       
  1035                     pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
       
  1036                 spinctrl.SetRange(scmin,scmax)
       
  1037                 boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
       
  1038                 spinctrl.SetValue(element_infos["value"])
       
  1039                 spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
       
  1040             elif element_infos["type"] == "element":
       
  1041                 staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
       
  1042                     name='%s_staticbox'%element_infos["name"], parent=parent,
       
  1043                     pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
       
  1044                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
       
  1045                 if first:
       
  1046                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
       
  1047                 else:
       
  1048                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
       
  1049                 self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
       
  1050             else:
       
  1051                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
       
  1052                 if first:
       
  1053                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
       
  1054                 else:
       
  1055                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
       
  1056                 staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
       
  1057                     name="%s_bitmap"%element_infos["name"], parent=parent,
       
  1058                     pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
       
  1059                 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
       
  1060 
       
  1061                 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
       
  1062                     name="%s_label"%element_infos["name"], parent=parent, 
       
  1063                     pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
       
  1064                 boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
       
  1065                 id = wx.NewId()
       
  1066                 if element_infos["type"] == "boolean":
       
  1067                     checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, 
       
  1068                         pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
       
  1069                     boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
       
  1070                     checkbox.SetValue(element_infos["value"])
       
  1071                     checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id)
       
  1072                 elif element_infos["type"] in ["unsignedLong", "long","integer"]:
       
  1073                     if element_infos["type"].startswith("unsigned"):
       
  1074                         scmin = 0
       
  1075                     else:
  1021                     else:
  1076                         scmin = -(2**31)
  1022                         for choice in element_infos["type"]:
       
  1023                             choicectrl.Append(choice)
       
  1024                         callback = self.GetChoiceCallBackFunction(choicectrl, plugin, element_path)
       
  1025                     if element_infos["value"] is None:
       
  1026                         choicectrl.SetStringSelection("")
       
  1027                     else:
       
  1028                         choicectrl.SetStringSelection(element_infos["value"])
       
  1029                     choicectrl.Bind(wx.EVT_CHOICE, callback, id=id)
       
  1030                 elif isinstance(element_infos["type"], types.DictType):
       
  1031                     scmin = -(2**31)
  1077                     scmax = 2**31-1
  1032                     scmax = 2**31-1
       
  1033                     if "min" in element_infos["type"]:
       
  1034                         scmin = element_infos["type"]["min"]
       
  1035                     if "max" in element_infos["type"]:
       
  1036                         scmax = element_infos["type"]["max"]
  1078                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
  1037                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
  1079                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
  1038                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
  1080                     spinctrl.SetRange(scmin, scmax)
  1039                     spinctrl.SetRange(scmin,scmax)
  1081                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
  1040                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
  1082                     spinctrl.SetValue(element_infos["value"])
  1041                     spinctrl.SetValue(element_infos["value"])
  1083                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
  1042                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
  1084                 else:
  1043                 else:
  1085                     textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=parent, 
  1044                     if element_infos["type"] == "boolean":
  1086                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0)#wx.TE_PROCESS_ENTER)
  1045                         checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, 
  1087                     boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
  1046                             pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
  1088                     textctrl.SetValue(str(element_infos["value"]))
  1047                         boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
  1089                     textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path))
  1048                         checkbox.SetValue(element_infos["value"])
       
  1049                         checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id)
       
  1050                     elif element_infos["type"] in ["unsignedLong", "long","integer"]:
       
  1051                         if element_infos["type"].startswith("unsigned"):
       
  1052                             scmin = 0
       
  1053                         else:
       
  1054                             scmin = -(2**31)
       
  1055                         scmax = 2**31-1
       
  1056                         spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
       
  1057                             pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
       
  1058                         spinctrl.SetRange(scmin, scmax)
       
  1059                         boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
       
  1060                         spinctrl.SetValue(element_infos["value"])
       
  1061                         spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
       
  1062                     else:
       
  1063                         textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=parent, 
       
  1064                             pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0)#wx.TE_PROCESS_ENTER)
       
  1065                         boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
       
  1066                         textctrl.SetValue(str(element_infos["value"]))
       
  1067                         textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path))
  1090             first = False
  1068             first = False
  1091     
  1069     
  1092     def OnNewProjectMenu(self, event):
  1070     def OnNewProjectMenu(self, event):
  1093         defaultpath = self.PluginRoot.GetProjectPath()
  1071         defaultpath = self.PluginRoot.GetProjectPath()
  1094         if not defaultpath:
  1072         if not defaultpath: