# HG changeset patch # User Laurent Bessard # Date 1361966676 -3600 # Node ID 77b6f3c5f1ba5b2bf2cc1be54dde1972959631d9 # Parent 735464c8616a3192fae2e3bea6ad142cd909f71d Fixed topology panel in order to avoid node buttons to move right when a locations tree is expanded diff -r 735464c8616a -r 77b6f3c5f1ba LPCManager.py --- a/LPCManager.py Fri Feb 22 11:54:26 2013 +0100 +++ b/LPCManager.py Wed Feb 27 13:04:36 2013 +0100 @@ -1302,9 +1302,8 @@ self.PLCConfigMainSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) self.PLCParamsSizer = wx.BoxSizer(wx.VERTICAL) - self.ConfNodeTreeSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=0, vgap=2) + self.ConfNodeTreeSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=0, vgap=2) self.ConfNodeTreeSizer.AddGrowableCol(0) - self.ConfNodeTreeSizer.AddGrowableCol(1) self.PLCConfigMainSizer.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) self.PLCConfigMainSizer.AddSizer(self.ConfNodeTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT) @@ -1413,9 +1412,6 @@ else: bkgdclr = TITLE_COLOUR - if self.CTR not in self.ConfNodeInfos: - self.ConfNodeInfos[self.CTR] = {"right_visible" : False} - plcwindow.SetBackgroundColour(TITLE_COLOUR) plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) @@ -1434,20 +1430,17 @@ plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) - msizer = self.GenerateMethodButtonSizer(self.CTR, plcwindow, not self.ConfNodeInfos[self.CTR]["right_visible"]) + msizer = self.GenerateMethodButtonSizer(self.CTR, plcwindow) plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) self.PLCConfigMainSizer.Layout() self.RefreshScrollBars() self.Thaw() - def GenerateMethodButtonSizer(self, confnode, parent, horizontal = True): + def GenerateMethodButtonSizer(self, confnode, parent): normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) - if horizontal: - msizer = wx.FlexGridSizer(cols=len(confnode.ConfNodeMethods)) - else: - msizer = wx.FlexGridSizer(cols=1) + msizer = wx.FlexGridSizer(cols=len(confnode.ConfNodeMethods)) for confnode_method in confnode.ConfNodeMethods: if "method" in confnode_method and confnode_method.get("shown",True): id = wx.NewId() @@ -1505,16 +1498,16 @@ self.Thaw() def GenerateTreeBranch(self, confnode): - leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) + nodewindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) if confnode.CTNTestModified(): bkgdclr=CHANGED_WINDOW_COLOUR else: bkgdclr=WINDOW_COLOUR - leftwindow.SetBackgroundColour(bkgdclr) + nodewindow.SetBackgroundColour(bkgdclr) if confnode not in self.ConfNodeInfos: - self.ConfNodeInfos[confnode] = {"expanded" : False, "left_visible" : False, "right_visible" : False} + self.ConfNodeInfos[confnode] = {"expanded" : False, "visible" : False} self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChildren() confnode_infos = confnode.GetVariableLocationTree() @@ -1524,28 +1517,27 @@ if not self.ConfNodeInfos[confnode].has_key("locations_infos"): self.ConfNodeInfos[confnode]["locations_infos"] = {"root": {"expanded" : False}} - self.ConfNodeInfos[confnode]["locations_infos"]["root"]["left"] = None - self.ConfNodeInfos[confnode]["locations_infos"]["root"]["right"] = None + self.ConfNodeInfos[confnode]["locations_infos"]["root"]["window"] = None self.ConfNodeInfos[confnode]["locations_infos"]["root"]["children"] = [] - self.ConfNodeTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) - - leftwindowvsizer = wx.BoxSizer(wx.VERTICAL) - leftwindow.SetSizer(leftwindowvsizer) - - leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) - leftwindowvsizer.AddSizer(leftwindowsizer, 0, border=0, flag=0) - - #self.GenerateEnableButton(leftwindow, leftwindowsizer, confnode) - - st = wx.StaticText(leftwindow, -1) + self.ConfNodeTreeSizer.AddWindow(nodewindow, 0, border=0, flag=wx.GROW) + + nodewindowvsizer = wx.BoxSizer(wx.VERTICAL) + nodewindow.SetSizer(nodewindowvsizer) + + nodewindowsizer = wx.BoxSizer(wx.HORIZONTAL) + nodewindowvsizer.AddSizer(nodewindowsizer, 0, border=0, flag=0) + + #self.GenerateEnableButton(nodewindow, nodewindowsizer, confnode) + + st = wx.StaticText(nodewindow, -1) st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) st.SetLabel(confnode.GetFullIEC_Channel()) - leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.LEFT|wx.RIGHT) + nodewindowsizer.AddWindow(st, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) expandbutton_id = wx.NewId() expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')), - name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0), + name='ExpandButton', parent=nodewindow, pos=wx.Point(0, 0), size=wx.Size(13, 13), style=wx.NO_BORDER) expandbutton.labelDelta = 0 expandbutton.SetBezelWidth(0) @@ -1580,31 +1572,27 @@ expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) else: expandbutton.Enable(False) - leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) - - sb = wx.StaticBitmap(leftwindow, -1) + nodewindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) + + sb = wx.StaticBitmap(nodewindow, -1) icon = confnode_infos.get("icon", None) if icon is None: icon_bitmap = self.LocationImageList.GetBitmap(self.LocationImageDict[confnode_infos["type"]]) else: icon_bitmap = wx.Bitmap(icon) sb.SetBitmap(icon_bitmap) - leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) + nodewindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) st_id = wx.NewId() - st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) + st = wx.StaticText(nodewindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) st.SetLabel(confnode.MandatoryParams[1].getName()) - leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) - - rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) - rightwindow.SetBackgroundColour(bkgdclr) - rightwindowsizer = self.GenerateMethodButtonSizer(confnode, rightwindow, not self.ConfNodeInfos[confnode]["right_visible"]) - rightwindow.SetSizer(rightwindowsizer) - self.ConfNodeTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) - - self.ConfNodeInfos[confnode]["left"] = leftwindow - self.ConfNodeInfos[confnode]["right"] = rightwindow + nodewindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) + + buttons_sizer = self.GenerateMethodButtonSizer(confnode, nodewindow) + nodewindowsizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER_VERTICAL) + + self.ConfNodeInfos[confnode]["window"] = nodewindow for child in self.ConfNodeInfos[confnode]["children"]: self.GenerateTreeBranch(child) if not self.ConfNodeInfos[child]["expanded"]: @@ -1622,12 +1610,7 @@ treectrl.AddRoot("") self.ConfNodeTreeSizer.AddWindow(treectrl, 0, border=0, flag=0) - rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) - rightwindow.SetBackgroundColour(wx.WHITE) - self.ConfNodeTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) - - locations_infos["root"]["left"] = treectrl - locations_infos["root"]["right"] = rightwindow + locations_infos["root"]["window"] = treectrl for location in confnode_locations: locations_infos["root"]["children"].append("root.%s" % location["name"]) self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location) @@ -1636,8 +1619,7 @@ def ExpandConfNode(self, confnode, force = False): for child in self.ConfNodeInfos[confnode]["children"]: - self.ConfNodeInfos[child]["left"].Show() - self.ConfNodeInfos[child]["right"].Show() + self.ConfNodeInfos[child]["window"].Show() if force or self.ConfNodeInfos[child]["expanded"]: self.ExpandConfNode(child, force) if force: @@ -1651,8 +1633,7 @@ def CollapseConfNode(self, confnode, force = False): for child in self.ConfNodeInfos[confnode]["children"]: - self.ConfNodeInfos[child]["left"].Hide() - self.ConfNodeInfos[child]["right"].Hide() + self.ConfNodeInfos[child]["window"].Hide() self.CollapseConfNode(child, force) if force: self.ConfNodeInfos[child]["expanded"] = False @@ -1665,32 +1646,28 @@ def ExpandLocation(self, locations_infos, group, force = False, refresh_size=True): locations_infos[group]["expanded"] = True if group == "root": - if locations_infos[group]["left"] is not None: - locations_infos[group]["left"].Show() - if locations_infos[group]["right"] is not None: - locations_infos[group]["right"].Show() - elif locations_infos["root"]["left"] is not None: - locations_infos["root"]["left"].Expand(locations_infos[group]["item"]) + if locations_infos[group]["window"] is not None: + locations_infos[group]["window"].Show() + elif locations_infos["root"]["window"] is not None: + locations_infos["root"]["window"].Expand(locations_infos[group]["item"]) if force: for child in locations_infos[group]["children"]: self.ExpandLocation(locations_infos, child, force, False) - if locations_infos["root"]["left"] is not None and refresh_size: - self.RefreshTreeCtrlSize(locations_infos["root"]["left"]) + if locations_infos["root"]["window"] is not None and refresh_size: + self.RefreshTreeCtrlSize(locations_infos["root"]["window"]) def CollapseLocation(self, locations_infos, group, force = False, refresh_size=True): locations_infos[group]["expanded"] = False if group == "root": - if locations_infos[group]["left"] is not None: - locations_infos[group]["left"].Hide() - if locations_infos[group]["right"] is not None: - locations_infos[group]["right"].Hide() - elif locations_infos["root"]["left"] is not None: - locations_infos["root"]["left"].Collapse(locations_infos[group]["item"]) + if locations_infos[group]["window"] is not None: + locations_infos[group]["window"].Hide() + elif locations_infos["root"]["window"] is not None: + locations_infos["root"]["window"].Collapse(locations_infos[group]["item"]) if force: for child in locations_infos[group]["children"]: self.CollapseLocation(locations_infos, child, force, False) - if locations_infos["root"]["left"] is not None and refresh_size: - self.RefreshTreeCtrlSize(locations_infos["root"]["left"]) + if locations_infos["root"]["window"] is not None and refresh_size: + self.RefreshTreeCtrlSize(locations_infos["root"]["window"]) def GenerateLocationTreeBranch(self, treectrl, root, locations_infos, parent, location): location_name = "%s.%s" % (parent, location["name"]) @@ -1722,7 +1699,7 @@ def GenerateLocationBeginDragFunction(self, locations_infos): def OnLocationBeginDragFunction(event): item = event.GetItem() - location_name = locations_infos["root"]["left"].GetPyData(item) + location_name = locations_infos["root"]["window"].GetPyData(item) if location_name is not None: infos = locations_infos[location_name]["infos"] if infos["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]: @@ -1765,10 +1742,10 @@ def GenerateLocationExpandCollapseFunction(self, locations_infos, expand): def OnLocationExpandedFunction(event): item = event.GetItem() - location_name = locations_infos["root"]["left"].GetPyData(item) + location_name = locations_infos["root"]["window"].GetPyData(item) if location_name is not None: locations_infos[location_name]["expanded"] = expand - self.RefreshTreeCtrlSize(locations_infos["root"]["left"]) + self.RefreshTreeCtrlSize(locations_infos["root"]["window"]) event.Skip() return OnLocationExpandedFunction