lpcmanager

Removing topology tree.

2016-12-12, dgaberscek
7569023737b8
Parents a65acdffded1
Children b60723fcb4a3
Removing topology tree.
  • +0 -398
    LPCManager.py
  • --- a/LPCManager.py Wed Dec 07 09:22:30 2016 +0100
    +++ b/LPCManager.py Mon Dec 12 08:39:26 2016 +0100
    @@ -1346,406 +1346,8 @@
    self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
    maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
    - def RefreshPLCParams(self):
    - self.Freeze()
    - self.ClearSizer(self.PLCParamsSizer)
    -
    - if self.CTR is not None:
    - plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
    - if self.CTR.CTNTestModified():
    - bkgdclr = CHANGED_TITLE_COLOUR
    - else:
    - bkgdclr = TITLE_COLOUR
    -
    - plcwindow.SetBackgroundColour(TITLE_COLOUR)
    - plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
    - self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
    -
    - plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
    - plcwindow.SetSizer(plcwindowsizer)
    -
    - st = wx.StaticText(plcwindow, -1)
    - st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName=faces["helv"]))
    - st.SetLabel(self.CTR.GetProjectName())
    - plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL | wx.ALIGN_CENTER)
    -
    - plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
    - plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
    -
    - plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
    - plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
    -
    - 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):
    - 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"])
    - 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()
    - label = confnode_method["name"]
    - button = GenBitmapTextButton(id=id, parent=parent,
    - bitmap=wx.Bitmap(
    - Bpath("images", "%s.png" % confnode_method.get("bitmap", "Unknown"))),
    - label=label,
    - name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER)
    - button.SetFont(normal_bt_font)
    - button.SetToolTipString(confnode_method["tooltip"])
    - button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode, confnode_method["method"]), id=id)
    -
    - # a fancy underline on mouseover
    - def setFontStyle(b, s):
    - def fn(event):
    - b.SetFont(s)
    - b.Refresh()
    - event.Skip()
    -
    - return fn
    -
    - button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font))
    - button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font))
    - # hack to force size to mini
    - if not confnode_method.get("enabled", True):
    - button.Disable()
    - msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER)
    - return msizer
    -
    - def GenerateEnableButton(self, parent, sizer, confnode):
    - enabled = confnode.CTNEnabled()
    - if enabled is not None:
    - enablebutton_id = wx.NewId()
    - enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id,
    - bitmap=wx.Bitmap(Bpath('images', 'Disabled.png')),
    - name='EnableButton', parent=parent,
    - size=wx.Size(16, 16), pos=wx.Point(0, 0),
    - style=0) # wx.NO_BORDER)
    - enablebutton.SetToolTipString(_("Enable/Disable this confnode"))
    - make_genbitmaptogglebutton_flat(enablebutton)
    - enablebutton.SetBitmapSelected(wx.Bitmap(Bpath('images', 'Enabled.png')))
    - enablebutton.SetToggle(enabled)
    -
    - def toggleenablebutton(event):
    - res = self.SetConfNodeParamsAttribute(confnode, "BaseParams.Enabled", enablebutton.GetToggle())
    - enablebutton.SetToggle(res)
    - event.Skip()
    -
    - enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id)
    - sizer.AddWindow(enablebutton, 0, border=0, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
    - else:
    - sizer.AddSpacer(wx.Size(16, 16))
    -
    - def RefreshConfNodeTree(self):
    - self.Freeze()
    - self.ClearSizer(self.ConfNodeTreeSizer)
    - if self.CTR is not None:
    - for child in self.CTR.IECSortedChildren():
    - self.GenerateTreeBranch(child)
    - if not self.ConfNodeInfos[child]["expanded"]:
    - self.CollapseConfNode(child)
    - self.PLCConfigMainSizer.Layout()
    - self.RefreshScrollBars()
    - self.Thaw()
    -
    - def GenerateTreeBranch(self, confnode):
    - nodewindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
    - if confnode.CTNTestModified():
    - bkgdclr = CHANGED_WINDOW_COLOUR
    - else:
    - bkgdclr = WINDOW_COLOUR
    -
    - nodewindow.SetBackgroundColour(bkgdclr)
    -
    - if confnode not in self.ConfNodeInfos:
    - self.ConfNodeInfos[confnode] = {"expanded": False, "visible": False}
    -
    - self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChildren()
    - confnode_infos = confnode.GetVariableLocationTree()
    - confnode_locations = []
    - if len(self.ConfNodeInfos[confnode]["children"]) == 0:
    - confnode_locations = confnode_infos["children"]
    - if not self.ConfNodeInfos[confnode].has_key("locations_infos"):
    - self.ConfNodeInfos[confnode]["locations_infos"] = {"root": {"expanded": False}}
    -
    - self.ConfNodeInfos[confnode]["locations_infos"]["root"]["window"] = None
    - self.ConfNodeInfos[confnode]["locations_infos"]["root"]["children"] = []
    -
    - 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())
    - 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=nodewindow, pos=wx.Point(0, 0),
    - size=wx.Size(13, 13), style=wx.NO_BORDER)
    - expandbutton.labelDelta = 0
    - expandbutton.SetBezelWidth(0)
    - expandbutton.SetUseFocusIndicator(False)
    - expandbutton.SetBitmapSelected(wx.Bitmap(Bpath('images', 'minus.png')))
    -
    - if len(self.ConfNodeInfos[confnode]["children"]) > 0:
    - expandbutton.SetToggle(self.ConfNodeInfos[confnode]["expanded"])
    -
    - def togglebutton(event):
    - if expandbutton.GetToggle():
    - self.ExpandConfNode(confnode)
    - else:
    - self.CollapseConfNode(confnode)
    - self.ConfNodeInfos[confnode]["expanded"] = expandbutton.GetToggle()
    - self.PLCConfigMainSizer.Layout()
    - self.RefreshScrollBars()
    - event.Skip()
    -
    - expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
    - elif len(confnode_locations) > 0:
    - locations_infos = self.ConfNodeInfos[confnode]["locations_infos"]
    - expandbutton.SetToggle(locations_infos["root"]["expanded"])
    -
    - def togglebutton(event):
    - if expandbutton.GetToggle():
    - self.ExpandLocation(locations_infos, "root")
    - else:
    - self.CollapseLocation(locations_infos, "root")
    - self.ConfNodeInfos[confnode]["expanded"] = expandbutton.GetToggle()
    - locations_infos["root"]["expanded"] = expandbutton.GetToggle()
    - self.PLCConfigMainSizer.Layout()
    - self.RefreshScrollBars()
    - event.Skip()
    -
    - expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
    - else:
    - expandbutton.Enable(False)
    - 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)
    - nodewindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
    -
    - st_id = wx.NewId()
    - 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())
    - 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"]:
    - self.CollapseConfNode(child)
    -
    - if len(confnode_locations) > 0:
    - locations_infos = self.ConfNodeInfos[confnode]["locations_infos"]
    - treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize,
    - style=wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.NO_BORDER | wx.TR_HIDE_ROOT | wx.TR_NO_LINES | wx.TR_LINES_AT_ROOT)
    - treectrl.SetImageList(self.LocationImageList)
    - treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos))
    - treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True))
    - treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED,
    - self.GenerateLocationExpandCollapseFunction(locations_infos, False))
    -
    - treectrl.AddRoot("")
    - self.ConfNodeTreeSizer.AddWindow(treectrl, 0, border=0, flag=0)
    -
    - 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)
    - if locations_infos["root"]["expanded"]:
    - self.ExpandLocation(locations_infos, "root")
    -
    - def ExpandConfNode(self, confnode, force=False):
    - for child in self.ConfNodeInfos[confnode]["children"]:
    - self.ConfNodeInfos[child]["window"].Show()
    - if force or self.ConfNodeInfos[child]["expanded"]:
    - self.ExpandConfNode(child, force)
    - if force:
    - self.ConfNodeInfos[child]["expanded"] = True
    - locations_infos = self.ConfNodeInfos[confnode].get("locations_infos", None)
    - if locations_infos is not None:
    - if force or locations_infos["root"]["expanded"]:
    - self.ExpandLocation(locations_infos, "root", force)
    - if force:
    - locations_infos["root"]["expanded"] = True
    -
    - def CollapseConfNode(self, confnode, force=False):
    - for child in self.ConfNodeInfos[confnode]["children"]:
    - self.ConfNodeInfos[child]["window"].Hide()
    - self.CollapseConfNode(child, force)
    - if force:
    - self.ConfNodeInfos[child]["expanded"] = False
    - locations_infos = self.ConfNodeInfos[confnode].get("locations_infos", None)
    - if locations_infos is not None:
    - self.CollapseLocation(locations_infos, "root", force)
    - if force:
    - locations_infos["root"]["expanded"] = False
    -
    - def ExpandLocation(self, locations_infos, group, force=False, refresh_size=True):
    - locations_infos[group]["expanded"] = True
    - if group == "root":
    - 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"]["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]["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"]["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"])
    - if not locations_infos.has_key(location_name):
    - locations_infos[location_name] = {"expanded": False}
    -
    - if location["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
    - label = "%(name)s (%(location)s)" % location
    - elif location["location"] != "":
    - label = "%(location)s: %(name)s" % location
    - else:
    - label = location["name"]
    - item = treectrl.AppendItem(root, label)
    - treectrl.SetPyData(item, location_name)
    - treectrl.SetItemImage(item, self.LocationImageDict[location["type"]])
    -
    - locations_infos[location_name]["item"] = item
    - locations_infos[location_name]["children"] = []
    - infos = location.copy()
    - infos.pop("children")
    - locations_infos[location_name]["infos"] = infos
    - for child in location["children"]:
    - child_name = "%s.%s" % (location_name, child["name"])
    - locations_infos[location_name]["children"].append(child_name)
    - self.GenerateLocationTreeBranch(treectrl, item, locations_infos, location_name, child)
    - if locations_infos[location_name]["expanded"]:
    - self.ExpandLocation(locations_infos, location_name)
    -
    - def GenerateLocationBeginDragFunction(self, locations_infos):
    - def OnLocationBeginDragFunction(event):
    - item = event.GetItem()
    - 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]:
    - data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["var_name"],
    - infos["description"])))
    - dragSource = wx.DropSource(self)
    - dragSource.SetData(data)
    - dragSource.DoDragDrop()
    -
    - return OnLocationBeginDragFunction
    -
    - def RefreshTreeCtrlSize(self, treectrl):
    - rect = self.GetTreeCtrlItemRect(treectrl, treectrl.GetRootItem())
    - treectrl.SetMinSize(wx.Size(max(rect.width, rect.x + rect.width) + 20, max(rect.height, rect.y + rect.height)))
    - self.PLCConfigMainSizer.Layout()
    - self.PLCConfig.Refresh()
    - wx.CallAfter(self.RefreshScrollBars)
    -
    - def GetTreeCtrlItemRect(self, treectrl, item):
    - item_rect = treectrl.GetBoundingRect(item, True)
    - if item_rect is not None:
    - minx, miny = item_rect.x, item_rect.y
    - maxx, maxy = item_rect.x + item_rect.width, item_rect.y + item_rect.height
    - else:
    - minx = miny = maxx = maxy = 0
    -
    - if treectrl.ItemHasChildren(item) and (item == treectrl.GetRootItem() or treectrl.IsExpanded(item)):
    - if wx.VERSION >= (2, 6, 0):
    - child, item_cookie = treectrl.GetFirstChild(item)
    - else:
    - child, item_cookie = treectrl.GetFirstChild(item, 0)
    - while child.IsOk():
    - child_rect = self.GetTreeCtrlItemRect(treectrl, child)
    - minx = min(minx, child_rect.x)
    - miny = min(miny, child_rect.y)
    - maxx = max(maxx, child_rect.x + child_rect.width)
    - maxy = max(maxy, child_rect.y + child_rect.height)
    - child, item_cookie = treectrl.GetNextChild(item, item_cookie)
    -
    - return wx.Rect(minx, miny, maxx - minx, maxy - miny)
    -
    - def GenerateLocationExpandCollapseFunction(self, locations_infos, expand):
    - def OnLocationExpandedFunction(event):
    - item = event.GetItem()
    - 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"]["window"])
    - event.Skip()
    -
    - return OnLocationExpandedFunction
    -
    - def GetButtonCallBackFunction(self, confnode, method):
    - """ Generate the callbackfunc for a given confnode method"""
    -
    - def OnButtonClick(event):
    - # Disable button to prevent re-entrant call
    - event.GetEventObject().Disable()
    - # Call
    - getattr(confnode, method)()
    - # Re-enable button
    - event.GetEventObject().Enable()
    - # Trigger refresh on Idle
    - wx.CallAfter(self.RefreshAll)
    - event.Skip()
    -
    - return OnButtonClick
    -
    - def ClearSizer(self, sizer):
    - staticboxes = []
    - for item in sizer.GetChildren():
    - if item.IsSizer():
    - item_sizer = item.GetSizer()
    - self.ClearSizer(item_sizer)
    - if isinstance(item_sizer, wx.StaticBoxSizer):
    - staticboxes.append(item_sizer.GetStaticBox())
    - sizer.Clear(True)
    - for staticbox in staticboxes:
    - staticbox.Destroy()
    -
    def RefreshAll(self):
    Beremiz.RefreshAll(self)
    - self.RefreshPLCParams()
    - self.RefreshConfNodeTree()
    # Remove taskbar icon when simulating
    def StartLocalRuntime(self, taskbaricon=True):