Beremiz.py
changeset 662 037d2beecfb9
parent 650 26236e691330
child 666 5056f17a0c6b
equal deleted inserted replaced
661:5d3da49e8029 662:037d2beecfb9
   647         xstart, ystart = self.PLCConfig.GetViewStart()
   647         xstart, ystart = self.PLCConfig.GetViewStart()
   648         window_size = self.PLCConfig.GetClientSize()
   648         window_size = self.PLCConfig.GetClientSize()
   649         sizer = self.PLCConfig.GetSizer()
   649         sizer = self.PLCConfig.GetSizer()
   650         if sizer:
   650         if sizer:
   651             maxx, maxy = sizer.GetMinSize()
   651             maxx, maxy = sizer.GetMinSize()
       
   652             posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
       
   653             posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
       
   654             self.PLCConfig.Scroll(posx, posy)
   652             self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   655             self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   653                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, 
   656                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
   654                 max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)), 
       
   655                 max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)))
       
   656 
   657 
   657     def RefreshPLCParams(self):
   658     def RefreshPLCParams(self):
   658         self.Freeze()
   659         self.Freeze()
   659         self.ClearSizer(self.PLCParamsSizer)
   660         self.ClearSizer(self.PLCParamsSizer)
   660         
   661         
   813         if locations_infos is not None:
   814         if locations_infos is not None:
   814             if force or locations_infos["root"]["expanded"]:
   815             if force or locations_infos["root"]["expanded"]:
   815                 self.ExpandLocation(locations_infos, "root", force)
   816                 self.ExpandLocation(locations_infos, "root", force)
   816                 if force:
   817                 if force:
   817                     locations_infos["root"]["expanded"] = True
   818                     locations_infos["root"]["expanded"] = True
   818                 
       
   819     
   819     
   820     def CollapsePlugin(self, plugin, force = False):
   820     def CollapsePlugin(self, plugin, force = False):
   821         for child in self.PluginInfos[plugin]["children"]:
   821         for child in self.PluginInfos[plugin]["children"]:
   822             self.PluginInfos[child]["left"].Hide()
   822             self.PluginInfos[child]["left"].Hide()
   823             self.PluginInfos[child]["right"].Hide()
   823             self.PluginInfos[child]["right"].Hide()
  1083                                    style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT)
  1083                                    style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT)
  1084             treectrl.SetImageList(self.LocationImageList)
  1084             treectrl.SetImageList(self.LocationImageList)
  1085             treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos))
  1085             treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos))
  1086             treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True))
  1086             treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True))
  1087             treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False))
  1087             treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False))
       
  1088             treectrl.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelTreeCtrl)
  1088             
  1089             
  1089             treectrl.AddRoot("")
  1090             treectrl.AddRoot("")
  1090             self.PluginTreeSizer.AddWindow(treectrl, 0, border=0, flag=0)
  1091             self.PluginTreeSizer.AddWindow(treectrl, 0, border=0, flag=0)
  1091             
  1092             
  1092             rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
  1093             rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
  1098             for location in plugin_locations:
  1099             for location in plugin_locations:
  1099                 locations_infos["root"]["children"].append("root.%s" % location["name"])
  1100                 locations_infos["root"]["children"].append("root.%s" % location["name"])
  1100                 self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location)
  1101                 self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location)
  1101                 treectrl.Expand(treectrl.GetRootItem())
  1102                 treectrl.Expand(treectrl.GetRootItem())
  1102             if locations_infos["root"]["expanded"]:
  1103             if locations_infos["root"]["expanded"]:
       
  1104                 self.PluginTreeSizer.Layout()
  1103                 self.ExpandLocation(locations_infos, "root")
  1105                 self.ExpandLocation(locations_infos, "root")
  1104             else:
  1106             else:
  1105                 self.RefreshTreeCtrlSize(treectrl)
  1107                 self.RefreshTreeCtrlSize(treectrl)
  1106     
  1108     
  1107     def GenerateLocationTreeBranch(self, treectrl, root, locations_infos, parent, location):
  1109     def GenerateLocationTreeBranch(self, treectrl, root, locations_infos, parent, location):
  1136             item = event.GetItem()
  1138             item = event.GetItem()
  1137             location_name = locations_infos["root"]["left"].GetPyData(item)
  1139             location_name = locations_infos["root"]["left"].GetPyData(item)
  1138             if location_name is not None:
  1140             if location_name is not None:
  1139                 infos = locations_infos[location_name]["infos"]
  1141                 infos = locations_infos[location_name]["infos"]
  1140                 if infos["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
  1142                 if infos["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
  1141                     data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["name"], infos["description"])))
  1143                     data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["var_name"], infos["description"])))
  1142                     dragSource = wx.DropSource(self)
  1144                     dragSource = wx.DropSource(self)
  1143                     dragSource.SetData(data)
  1145                     dragSource.SetData(data)
  1144                     dragSource.DoDragDrop()
  1146                     dragSource.DoDragDrop()
  1145         return OnLocationBeginDragFunction
  1147         return OnLocationBeginDragFunction
  1146     
  1148     
  1147     def RefreshTreeCtrlSize(self, treectrl):
  1149     def RefreshTreeCtrlSize(self, treectrl):
  1148         rect = self.GetTreeCtrlItemRect(treectrl, treectrl.GetRootItem())
  1150         rect = self.GetTreeCtrlItemRect(treectrl, treectrl.GetRootItem())
  1149         treectrl.SetMinSize(wx.Size(max(rect.width, rect.x + rect.width) + 20, max(rect.height, rect.y + rect.height) + 10))
  1151         treectrl.SetMinSize(wx.Size(max(rect.width, rect.x + rect.width) + 20, max(rect.height, rect.y + rect.height) + 20))
  1150         self.PLCConfigMainSizer.Layout()
  1152         self.PLCConfigMainSizer.Layout()
  1151         self.PLCConfig.Refresh()
  1153         self.PLCConfig.Refresh()
       
  1154         wx.CallAfter(self.RefreshScrollBars)
       
  1155     
       
  1156     def OnMouseWheelTreeCtrl(self, event):
       
  1157         x, y = self.PLCConfig.GetViewStart()
       
  1158         rotation = - (event.GetWheelRotation() / event.GetWheelDelta()) * 3
       
  1159         if event.ShiftDown():
       
  1160             self.PLCConfig.Scroll(x + rotation, y)
       
  1161         else:
       
  1162             self.PLCConfig.Scroll(x, y + rotation)
  1152     
  1163     
  1153     def GetTreeCtrlItemRect(self, treectrl, item):
  1164     def GetTreeCtrlItemRect(self, treectrl, item):
  1154         item_rect = treectrl.GetBoundingRect(item, True)
  1165         item_rect = treectrl.GetBoundingRect(item, True)
  1155         if item_rect is not None:
  1166         if item_rect is not None:
  1156             minx, miny = item_rect.x, item_rect.y
  1167             minx, miny = item_rect.x, item_rect.y