Beremiz.py
changeset 703 2f7b3d1de278
parent 702 01f5e6356859
child 704 5993b16fe2d0
child 706 64a9b509973b
equal deleted inserted replaced
702:01f5e6356859 703:2f7b3d1de278
   142 sys.path.append(base_folder)
   142 sys.path.append(base_folder)
   143 sys.path.append(os.path.join(base_folder, "plcopeneditor"))
   143 sys.path.append(os.path.join(base_folder, "plcopeneditor"))
   144 
   144 
   145 import wx.lib.buttons, wx.lib.statbmp
   145 import wx.lib.buttons, wx.lib.statbmp
   146 import TextCtrlAutoComplete, cPickle
   146 import TextCtrlAutoComplete, cPickle
       
   147 from BrowseValuesLibraryDialog import BrowseValuesLibraryDialog
   147 import types, time, re, platform, time, traceback, commands
   148 import types, time, re, platform, time, traceback, commands
   148 from plugger import PluginsRoot, MATIEC_ERROR_MODEL
   149 from plugger import PluginsRoot, MATIEC_ERROR_MODEL
   149 from wxPopen import ProcessLogger
   150 from wxPopen import ProcessLogger
   150 
   151 
   151 from docutils import *
   152 from docutils import *
   931         rightwindowsizer.AddSizer(rightparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT)
   932         rightwindowsizer.AddSizer(rightparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT)
   932         
   933         
   933         paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1))
   934         paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1))
   934         paramswindow.SetBackgroundColour(bkgdclr)
   935         paramswindow.SetBackgroundColour(bkgdclr)
   935         
   936         
   936         psizer = wx.BoxSizer(wx.HORIZONTAL)
   937         psizer = wx.BoxSizer(wx.VERTICAL)
   937         paramswindow.SetSizer(psizer)
   938         paramswindow.SetSizer(psizer)
   938         self.PluginInfos[plugin]["params"] = paramswindow
   939         self.PluginInfos[plugin]["params"] = paramswindow
   939         
   940         
   940         rightparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL)
   941         rightparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL)
   941         
   942         
  1002 
  1003 
  1003     def ExpandPlugin(self, plugin, force = False):
  1004     def ExpandPlugin(self, plugin, force = False):
  1004         for child in self.PluginInfos[plugin]["children"]:
  1005         for child in self.PluginInfos[plugin]["children"]:
  1005             self.PluginInfos[child]["left"].Show()
  1006             self.PluginInfos[child]["left"].Show()
  1006             self.PluginInfos[child]["right"].Show()
  1007             self.PluginInfos[child]["right"].Show()
  1007             if force or not self.PluginInfos[child]["expanded"]:
  1008             if force or self.PluginInfos[child]["expanded"]:
  1008                 self.ExpandPlugin(child, force)
  1009                 self.ExpandPlugin(child, force)
  1009                 if force:
  1010                 if force:
  1010                     self.PluginInfos[child]["expanded"] = True
  1011                     self.PluginInfos[child]["expanded"] = True
  1011         locations_infos = self.PluginInfos[plugin].get("locations_infos", None)
  1012         locations_infos = self.PluginInfos[plugin].get("locations_infos", None)
  1012         if locations_infos is not None:
  1013         if locations_infos is not None:
  1403         def OnCheckBoxChanged(event):
  1404         def OnCheckBoxChanged(event):
  1404             res = self.SetPluginParamsAttribute(plugin, path, chkbx.IsChecked())
  1405             res = self.SetPluginParamsAttribute(plugin, path, chkbx.IsChecked())
  1405             chkbx.SetValue(res)
  1406             chkbx.SetValue(res)
  1406             event.Skip()
  1407             event.Skip()
  1407         return OnCheckBoxChanged
  1408         return OnCheckBoxChanged
       
  1409     
       
  1410     def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, plugin, path):
       
  1411         infos = [value_infos]
       
  1412         def OnBrowseButton(event):
       
  1413             dialog = BrowseValuesLibraryDialog(self, name, library, infos[0])
       
  1414             if dialog.ShowModal() == wx.ID_OK:
       
  1415                 value, value_infos = self.SetPluginParamsAttribute(plugin, path, dialog.GetValueInfos())
       
  1416                 textctrl.ChangeValue(value)
       
  1417                 infos[0] = value_infos
       
  1418             dialog.Destroy()
       
  1419             event.Skip()
       
  1420         return OnBrowseButton
  1408     
  1421     
  1409     def ClearSizer(self, sizer):
  1422     def ClearSizer(self, sizer):
  1410         staticboxes = []
  1423         staticboxes = []
  1411         for item in sizer.GetChildren():
  1424         for item in sizer.GetChildren():
  1412             if item.IsSizer():
  1425             if item.IsSizer():
  1457                     name="%s_label"%element_infos["name"], parent=parent, 
  1470                     name="%s_label"%element_infos["name"], parent=parent, 
  1458                     pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
  1471                     pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
  1459                 boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT)
  1472                 boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT)
  1460                 id = wx.NewId()
  1473                 id = wx.NewId()
  1461                 if isinstance(element_infos["type"], types.ListType):
  1474                 if isinstance(element_infos["type"], types.ListType):
  1462                     combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent, 
  1475                     if isinstance(element_infos["value"], types.TupleType):
  1463                         pos=wx.Point(0, 0), size=wx.Size(300, 28), style=wx.CB_READONLY)
  1476                         browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
  1464                     boxsizer.AddWindow(combobox, 0, border=0, flag=0)
  1477                         boxsizer.AddSizer(browse_boxsizer, 0, border=0, flag=0)
  1465                     if element_infos["use"] == "optional":
  1478                         
  1466                         combobox.Append("")
  1479                         textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=parent, 
  1467                     if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
  1480                             pos=wx.Point(0, 0), size=wx.Size(275, 25), style=wx.TE_READONLY)
  1468                         for choice, xsdclass in element_infos["type"]:
  1481                         if element_infos["value"] is not None:
  1469                             combobox.Append(choice)
  1482                             textctrl.SetValue(element_infos["value"][0])
  1470                         name = element_infos["name"]
  1483                             value_infos = element_infos["value"][1]
  1471                         value = element_infos["value"]
  1484                         else:
  1472                         staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), 
  1485                             value_infos = None
  1473                             name='%s_staticbox'%element_infos["name"], parent=parent,
  1486                         browse_boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
  1474                             pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
  1487                         button_id = wx.NewId()
  1475                         staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
  1488                         button = wx.Button(id=button_id, name="browse_%s" % element_infos["name"], parent=parent, 
  1476                         sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
  1489                             label="...", pos=wx.Point(0, 0), size=wx.Size(25, 25))
  1477                         self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
  1490                         browse_boxsizer.AddWindow(button, 0, border=0, flag=0)
  1478                         callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, plugin, element_path)
  1491                         button.Bind(wx.EVT_BUTTON, 
       
  1492                                     self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], 
       
  1493                                                                    value_infos, plugin, element_path), 
       
  1494                                     id=button_id)
  1479                     else:
  1495                     else:
  1480                         for choice in element_infos["type"]:
  1496                         combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent, 
  1481                             combobox.Append(choice)
  1497                             pos=wx.Point(0, 0), size=wx.Size(300, 28), style=wx.CB_READONLY)
  1482                         callback = self.GetChoiceCallBackFunction(combobox, plugin, element_path)
  1498                         boxsizer.AddWindow(combobox, 0, border=0, flag=0)
  1483                     if element_infos["value"] is None:
  1499                         if element_infos["use"] == "optional":
  1484                         combobox.SetStringSelection("")
  1500                             combobox.Append("")
  1485                     else:
  1501                         if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
  1486                         combobox.SetStringSelection(element_infos["value"])
  1502                             for choice, xsdclass in element_infos["type"]:
  1487                     combobox.Bind(wx.EVT_COMBOBOX, callback, id=id)
  1503                                 combobox.Append(choice)
       
  1504                             name = element_infos["name"]
       
  1505                             value = element_infos["value"]
       
  1506                             staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), 
       
  1507                                 name='%s_staticbox'%element_infos["name"], parent=parent,
       
  1508                                 pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
       
  1509                             staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
       
  1510                             sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
       
  1511                             self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
       
  1512                             callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, plugin, element_path)
       
  1513                         else:
       
  1514                             for choice in element_infos["type"]:
       
  1515                                 combobox.Append(choice)
       
  1516                             callback = self.GetChoiceCallBackFunction(combobox, plugin, element_path)
       
  1517                         if element_infos["value"] is None:
       
  1518                             combobox.SetStringSelection("")
       
  1519                         else:
       
  1520                             combobox.SetStringSelection(element_infos["value"])
       
  1521                         combobox.Bind(wx.EVT_COMBOBOX, callback, id=id)
  1488                 elif isinstance(element_infos["type"], types.DictType):
  1522                 elif isinstance(element_infos["type"], types.DictType):
  1489                     scmin = -(2**31)
  1523                     scmin = -(2**31)
  1490                     scmax = 2**31-1
  1524                     scmax = 2**31-1
  1491                     if "min" in element_infos["type"]:
  1525                     if "min" in element_infos["type"]:
  1492                         scmin = element_infos["type"]["min"]
  1526                         scmin = element_infos["type"]["min"]
  1494                         scmax = element_infos["type"]["max"]
  1528                         scmax = element_infos["type"]["max"]
  1495                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
  1529                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
  1496                         pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
  1530                         pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
  1497                     spinctrl.SetRange(scmin,scmax)
  1531                     spinctrl.SetRange(scmin,scmax)
  1498                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
  1532                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
  1499                     spinctrl.SetValue(element_infos["value"])
  1533                     if element_infos["value"] is not None:
       
  1534                         spinctrl.SetValue(element_infos["value"])
  1500                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
  1535                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
  1501                 else:
  1536                 else:
  1502                     if element_infos["type"] == "boolean":
  1537                     if element_infos["type"] == "boolean":
  1503                         checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, 
  1538                         checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, 
  1504                             pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
  1539                             pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
  1505                         boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
  1540                         boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
  1506                         checkbox.SetValue(element_infos["value"])
  1541                         if element_infos["value"] is not None:
       
  1542                             checkbox.SetValue(element_infos["value"])
  1507                         checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id)
  1543                         checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id)
  1508                     elif element_infos["type"] in ["unsignedLong", "long","integer"]:
  1544                     elif element_infos["type"] in ["unsignedLong", "long","integer"]:
  1509                         if element_infos["type"].startswith("unsigned"):
  1545                         if element_infos["type"].startswith("unsigned"):
  1510                             scmin = 0
  1546                             scmin = 0
  1511                         else:
  1547                         else:
  1513                         scmax = 2**31-1
  1549                         scmax = 2**31-1
  1514                         spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
  1550                         spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
  1515                             pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
  1551                             pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
  1516                         spinctrl.SetRange(scmin, scmax)
  1552                         spinctrl.SetRange(scmin, scmax)
  1517                         boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
  1553                         boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
  1518                         spinctrl.SetValue(element_infos["value"])
  1554                         if element_infos["value"] is not None:
       
  1555                             spinctrl.SetValue(element_infos["value"])
  1519                         spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
  1556                         spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
  1520                     else:
  1557                     else:
  1521                         choices = cPickle.loads(str(self.Config.Read(element_path, cPickle.dumps([""]))))
  1558                         choices = cPickle.loads(str(self.Config.Read(element_path, cPickle.dumps([""]))))
  1522                         textctrl = TextCtrlAutoComplete.TextCtrlAutoComplete(id=id, 
  1559                         textctrl = TextCtrlAutoComplete.TextCtrlAutoComplete(id=id, 
  1523                                                                      name=element_infos["name"], 
  1560                                                                      name=element_infos["name"], 
  1528                                                                      pos=wx.Point(0, 0), 
  1565                                                                      pos=wx.Point(0, 0), 
  1529                                                                      size=wx.Size(300, 25), 
  1566                                                                      size=wx.Size(300, 25), 
  1530                                                                      style=0)
  1567                                                                      style=0)
  1531                         
  1568                         
  1532                         boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
  1569                         boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
  1533                         textctrl.ChangeValue(str(element_infos["value"]))
  1570                         if element_infos["value"] is not None:
       
  1571                             textctrl.ChangeValue(str(element_infos["value"]))
  1534                         textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path))
  1572                         textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path))
  1535             first = False
  1573             first = False
  1536     
  1574     
  1537     def ResetView(self):
  1575     def ResetView(self):
  1538         IDEFrame.ResetView(self)
  1576         IDEFrame.ResetView(self)