我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用wx.Point()。
def __init__(self, strCaption="", imageIndex=-1, enabled=True): """ Default class constructor. :param `strCaption`: the tab caption; :param `imageIndex`: the tab image index based on the assigned (set) :class:`ImageList` (if any); :param `enabled`: sets the tab as enabled or disabled. """ self._pos = wx.Point() self._size = wx.Size() self._strCaption = strCaption self._ImageIndex = imageIndex self._captionRect = wx.Rect() self._bEnabled = enabled
def _init_ctrls(self, prnt): wx.Panel.__init__(self, id=ID_SEARCHRESULTPANEL, name='SearchResultPanel', parent=prnt, pos=wx.Point(0, 0), size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) self.HeaderLabel = wx.StaticText(id=ID_SEARCHRESULTPANELHEADERLABEL, name='HeaderLabel', parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) search_results_tree_style = CT.TR_HAS_BUTTONS | CT.TR_NO_LINES | CT.TR_HAS_VARIABLE_ROW_HEIGHT self.SearchResultsTree = CT.CustomTreeCtrl(id=ID_SEARCHRESULTPANELSEARCHRESULTSTREE, name="SearchResultsTree", parent=self, pos=wx.Point(0, 0), style=search_results_tree_style) if wx.VERSION >= (2, 8, 11): self.SearchResultsTree.SetAGWWindowStyleFlag(search_results_tree_style) self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnSearchResultsTreeItemActivated, id=ID_SEARCHRESULTPANELSEARCHRESULTSTREE) self.ResetButton = wx.lib.buttons.GenBitmapButton( self, bitmap=GetBitmap("reset"), size=wx.Size(28, 28), style=wx.NO_BORDER) self.ResetButton.SetToolTipString(_("Reset search result")) self.Bind(wx.EVT_BUTTON, self.OnResetButton, self.ResetButton) self._init_sizers()
def UpdateScrollPos(self, event): if (event.Dragging() and self.SelectedElement is not None) or self.rubberBand.IsShown(): position = event.GetPosition() move_window = wx.Point() window_size = self.Editor.GetClientSize() xstart, ystart = self.GetViewStart() if position.x < SCROLL_ZONE and xstart > 0: move_window.x = -1 elif position.x > window_size[0] - SCROLL_ZONE: move_window.x = 1 if position.y < SCROLL_ZONE and ystart > 0: move_window.y = -1 elif position.y > window_size[1] - SCROLL_ZONE: move_window.y = 1 if move_window.x != 0 or move_window.y != 0: self.RefreshVisibleElements(xp=xstart + move_window.x, yp=ystart + move_window.y) self.Scroll(xstart + move_window.x, ystart + move_window.y) self.RefreshScrollBars(move_window.x, move_window.y)
def _create_NetworkEditor(self, prnt): self.NetworkEditor = wx.Panel( id=-1, parent=prnt, pos=wx.Point(0, 0), size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) NetworkEditorTemplate._init_ctrls(self, self.NetworkEditor) main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) main_sizer.AddGrowableCol(0) main_sizer.AddGrowableRow(0) main_sizer.AddWindow(self.NetworkNodes, 0, border=5, flag=wx.GROW | wx.ALL) self.NetworkEditor.SetSizer(main_sizer) return self.NetworkEditor
def __init__(self, parent, name, initial=False, id=None): Graphic_Element.__init__(self, parent) DebugDataConsumer.__init__(self) self.SetName(name) self.Initial = initial self.Id = id self.Highlights = [] self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) # Create an input and output connector if not self.Initial: self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) else: self.Input = None self.Output = None self.Action = None self.PreviousValue = None self.PreviousSpreading = False
def RefreshConnectors(self): scaling = self.Parent.GetScaling() horizontal_pos = self.Size[0] / 2 vertical_pos = self.Size[1] / 2 if scaling is not None: horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y # Update input position if it exists if self.Input: self.Input.SetPosition(wx.Point(horizontal_pos, 0)) # Update output position if self.Output: self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1])) # Update action position if it exists if self.Action: self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos)) self.RefreshConnected() # Refresh the position of wires connected to step
def RefreshConnectors(self): scaling = self.Parent.GetScaling() horizontal_pos = self.Size[0] / 2 vertical_pos = self.Size[1] / 2 if scaling is not None: horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y # Update input position self.Input.SetPosition(wx.Point(horizontal_pos, 0)) # Update output position self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1])) if self.Type == "connection": self.Condition.SetPosition(wx.Point(0, vertical_pos)) self.RefreshConnected() # Refresh the position of the wires connected to transition
def SetType(self, type, condition=None): if self.Type != type: if self.Type == "connection": self.Condition.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE) self.Type = type if type == "connection": self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST) else: if condition is None: condition = "" self.Condition = condition self.RefreshConditionSize() elif self.Type != "connection": if condition is None: condition = "" self.Condition = condition self.RefreshConditionSize() self.RefreshBoundingBox() # Returns the transition type
def AddBranch(self): if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: maxx = 0 for output in self.Outputs: pos = output.GetRelPosition() maxx = max(maxx, pos.x) connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True) self.Outputs.append(connector) self.MoveConnector(connector, 0) elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: maxx = 0 for input in self.Inputs: pos = input.GetRelPosition() maxx = max(maxx, pos.x) connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True) self.Inputs.append(connector) self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL) # Remove a branch from the divergence
def SetSize(self, width, height): height = self.GetMinSize()[1] for i, input in enumerate(self.Inputs): position = input.GetRelPosition() if self.RealConnectors: input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0)) else: input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0)) input.MoveConnected() for i, output in enumerate(self.Outputs): position = output.GetRelPosition() if self.RealConnectors: output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), height)) else: output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), height)) output.MoveConnected() self.Size = wx.Size(width, height) self.RefreshBoundingBox() # Returns the divergence minimum size
def RefreshBoundingBox(self): if len(self.Elements) > 0: bbox = self.Elements[0].GetBoundingBox() minx, miny = bbox.x, bbox.y maxx = bbox.x + bbox.width maxy = bbox.y + bbox.height for element in self.Elements[1:]: bbox = element.GetBoundingBox() minx = min(minx, bbox.x) miny = min(miny, bbox.y) maxx = max(maxx, bbox.x + bbox.width) maxy = max(maxy, bbox.y + bbox.height) self.BoundingBox = wx.Rect(minx, miny, maxx - minx, maxy - miny) else: self.BoundingBox = wx.Rect(0, 0, 0, 0) self.Pos = wx.Point(self.BoundingBox.x, self.BoundingBox.y) self.Size = wx.Size(self.BoundingBox.width, self.BoundingBox.height) # Forbids to change the group position
def DrawHighlightment(self, dc): scalex, scaley = dc.GetUserScale() dc.SetUserScale(1, 1) dc.SetPen(MiterPen(HIGHLIGHTCOLOR)) dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) dc.SetLogicalFunction(wx.AND) left = (self.Pos.x - 1) * scalex - 2 right = (self.Pos.x + self.Size[0] + 1) * scalex + 2 top = (self.Pos.y - 1) * scaley - 2 bottom = (self.Pos.y + self.Size[1] + 1) * scaley + 2 angle_top = (self.Pos.x + self.Size[0] - 9) * scalex + 2 angle_right = (self.Pos.y + 9) * scaley - 2 polygon = [wx.Point(left, top), wx.Point(angle_top, top), wx.Point(right, angle_right), wx.Point(right, bottom), wx.Point(left, bottom)] dc.DrawPolygon(polygon) dc.SetLogicalFunction(wx.COPY) dc.SetUserScale(scalex, scaley) # Draws the comment and its content
def MoveConnector(self, connector, movey): position = connector.GetRelPosition() connector.SetPosition(wx.Point(position.x, position.y + movey)) miny = self.Size[1] maxy = 0 for connect in self.Connectors: connect_pos = connect.GetRelPosition() miny = min(miny, connect_pos.y - self.Extensions[0]) maxy = max(maxy, connect_pos.y - self.Extensions[0]) min_pos = self.Pos.y + miny self.Pos.y = min(min_pos, self.Pos.y) if min_pos == self.Pos.y: for connect in self.Connectors: connect_pos = connect.GetRelPosition() connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny)) self.Connectors.sort(lambda x, y: cmp(x.Pos.y, y.Pos.y)) maxy = 0 for connect in self.Connectors: connect_pos = connect.GetRelPosition() maxy = max(maxy, connect_pos.y) self.Size[1] = max(maxy + self.Extensions[1], self.Size[1]) connector.MoveConnected() self.RefreshBoundingBox() # Returns the index in connectors list for the connector given
def RefreshConnectors(self): scaling = self.Parent.GetScaling() # Calculate the size for the connector lines lines = max(len(self.Inputs), len(self.Outputs)) if lines > 0: linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE) # Update inputs and outputs positions position = BLOCK_LINE_SIZE + linesize / 2 for i in xrange(lines): if scaling is not None: ypos = round_scaling(self.Pos.y + position, scaling[1]) - self.Pos.y else: ypos = position if i < len(self.Inputs): self.Inputs[i].SetPosition(wx.Point(0, ypos)) if i < len(self.Outputs): self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos)) position += linesize self.RefreshConnected() # Refresh the positions of wires connected to inputs and outputs
def SetType(self, type, value_type): if type != self.Type: self.Type = type # Create an input or output connector according to variable type if self.Type != INPUT: if self.Input is None: self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone=True) elif self.Input: self.Input.UnConnect(delete=True) self.Input = None if self.Type != OUTPUT: if self.Output is None: self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST) elif self.Output: self.Output.UnConnect(delete=True) self.Output = None self.RefreshConnectors() self.RefreshBoundingBox() elif value_type != self.ValueType: if self.Input: self.Input.SetType(value_type) if self.Output: self.Output.SetType(value_type) # Returns the variable type
def OnRightClick(self, event): menu = wx.Menu() tPopupID0 = wx.NewId() tPopupID1 = wx.NewId() tPopupID2 = wx.NewId() tPopupID3 = wx.NewId() tPopupID4 = wx.NewId() tPopupID5 = wx.NewId() menu.Append(tPopupID2, "Edit") menu.Append(tPopupID0, "New") menu.Append(tPopupID1, "Copy") menu.AppendSeparator() menu.Append(tPopupID3, "Delete") menu.Append(tPopupID4, "Delete All") wx.EVT_MENU(self, tPopupID2, self.OnPopupEdit) wx.EVT_MENU(self, tPopupID0, self.OnPopupNew) wx.EVT_MENU(self, tPopupID1, self.OnPopupCopy) wx.EVT_MENU(self, tPopupID3, self.OnPopupDelete) wx.EVT_MENU(self, tPopupID4, self.OnPopupDeleteAll) if len(self.itemDataMap) == 0: for m in menu.GetMenuItems(): m.Enable(False) m = menu.FindItemById(tPopupID0) m.Enable(True) self.PopupMenu(menu, wx.Point(self.x, self.y)) menu.Destroy() event.Skip()
def __init__(self, parent, name): wxskinDialog.__init__(self, parent, -1, "Phonebook import") self.SetAutoLayout(True) self.function = 0 # Main window resizer object border = wx.BoxSizer(wx.VERTICAL) label = wx.StaticText(self, -1, "Name '%s' already exists in SIM phonebook.\n\nDo you want to overwrite exisiting, duplicate or skip!?" % (name)) border.Add(label, 1, wx.ALL, 10) buttons = wx.BoxSizer(wx.HORIZONTAL) buttons.Add(wx.Button(self, ID_BUTTON_OVERWRITE, "Overwrite"), 1, wx.ALIGN_LEFT | wx.ALL, 20) buttons.Add(wx.Button(self, ID_BUTTON_COPY, "Duplicate"), 1, wx.ALIGN_RIGHT | wx.ALL, 20) buttons.Add(wx.Button(self, ID_BUTTON_SKIP, "Skip"), 1, wx.ALIGN_RIGHT | wx.ALL, 20) buttons.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.ALIGN_RIGHT | wx.ALL, 20) border.Add(buttons, 1, wx.ALL) self.applyAll = wx.CheckBox(self, ID_CHECKBOX_APPLY_ALL, " Apply to all", wx.Point(65, 40), wx.Size(150, 20), wx.NO_BORDER) border.Add(self.applyAll, 1, wx.ALIGN_CENTER | wx.ALL) wx.EVT_BUTTON(self, ID_BUTTON_OVERWRITE, self.onOverwrite) wx.EVT_BUTTON(self, ID_BUTTON_COPY, self.onDuplicate) wx.EVT_BUTTON(self, ID_BUTTON_SKIP, self.onSkip) self.SetAutoLayout(1); self.SetSizer(border) border.Fit(self) self.Layout()
def OnRightClick(self, event): tsubPopupID1 = 10 tsubPopupID2 = 11 tsubPopupID3 = 12 submenu = wx.Menu() submenu.Append(tsubPopupID1, "Read") submenu.Append(tsubPopupID2, "Unread") submenu.Append(tsubPopupID3, "Deleted") wx.EVT_MENU(self, tsubPopupID1, self.OnPopupMarkRead) wx.EVT_MENU(self, tsubPopupID2, self.OnPopupMarkUnread) wx.EVT_MENU(self, tsubPopupID3, self.OnPopupMarkDeleted) menu = wx.Menu() tPopupID0 = wx.NewId() tPopupID1 = wx.NewId() tPopupID2 = wx.NewId() tPopupID3 = wx.NewId() tPopupID4 = wx.NewId() tPopupID5 = wx.NewId() menu.AppendMenu(tPopupID1, "Mark as", submenu) menu.AppendSeparator() menu.Append(tPopupID2, "Edit") menu.Append(tPopupID0, "New") menu.Append(tPopupID1, "Copy") menu.AppendSeparator() menu.Append(tPopupID3, "Delete") menu.Append(tPopupID4, "Delete All") wx.EVT_MENU(self, tPopupID2, self.OnPopupEdit) wx.EVT_MENU(self, tPopupID0, self.OnPopupNew) wx.EVT_MENU(self, tPopupID1, self.OnPopupCopy) wx.EVT_MENU(self, tPopupID3, self.OnPopupDelete) wx.EVT_MENU(self, tPopupID4, self.OnPopupDeleteAll) self.PopupMenu(menu, wx.Point(self.x, self.y)) menu.Destroy() event.Skip()
def SetPosition(self, value): """ Sets the tab position. :param `value`: the new tab position, an instance of :class:`Point`. """ self._pos = value
def HitTest(self, pt): """ Returns the index of the tab at the specified position or ``wx.NOT_FOUND`` if ``None``, plus the flag style of :meth:`~ImageContainerBase.HitTest`. :param `pt`: an instance of :class:`Point`, to test for hits. :return: The index of the tab at the specified position plus the hit test flag, which can be one of the following bits: ====================== ======= ================================ HitTest Flags Value Description ====================== ======= ================================ ``IMG_OVER_IMG`` 0 The mouse is over the tab icon ``IMG_OVER_PIN`` 1 The mouse is over the pin button ``IMG_OVER_EW_BORDER`` 2 The mouse is over the east-west book border ``IMG_NONE`` 3 Nowhere ====================== ======= ================================ """ style = self.GetParent().GetAGWWindowStyleFlag() for i in reversed( xrange(len(self._pagesInfoVec)) ) : if self._pagesInfoVec[i].GetPosition() == wx.Point(-1, -1): break # For Web Hover style, we test the TextRect if not self.HasAGWFlag(INB_WEB_HILITE): buttonRect = wx.RectPS(self._pagesInfoVec[i].GetPosition(), self._pagesInfoVec[i].GetSize()) else: buttonRect = self._pagesInfoVec[i].GetTextRect() if buttonRect.Contains(pt): return i, IMG_OVER_IMG return -1, IMG_NONE
def set_xy_limits(self, center=wx.Point(-9999, -9999)): self.axes.set_xlim([center[0] - self.size_npix_xy[0]/2.0, center[0] + self.size_npix_xy[0]/2.0]) self.axes.set_ylim([center[1] - self.size_npix_xy[1]/2.0, center[1] + self.size_npix_xy[1]/2.0]) if getattr(self, "crosshair", None) is None: self.crosshair = self.axes.plot([center[0]], [center[1]], 'gx', zorder=100, markersize=7) else: self.crosshair[0].set_data([center[0]], [center[1]]) self.figure.canvas.draw()
def _init_ctrls(self, prnt): wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), style=wx.DEFAULT_FRAME_STYLE, title='') self.SetIcon(prnt.icon) self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, name='HtmlContent', parent=self, pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO | wx.html.HW_NO_SELECTION) self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick)
def __init__(self, parent, name, library, default=None): wx.Dialog.__init__(self, name='BrowseValueDialog', parent=parent, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, title=_('Browse %s values library') % name) self.staticText1 = wx.StaticText( label=_('Choose a value for %s:') % name, name='staticText1', parent=self, pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) self.ValuesLibrary = wx.TreeCtrl( name='ValuesLibrary', parent=self, pos=wx.Point(0, 0), size=wx.Size(400, 200), style=wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.SUNKEN_BORDER | wx.TR_HIDE_ROOT | wx.TR_LINES_AT_ROOT) self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) self.flexGridSizer1.AddWindow(self.staticText1, 0, border=20, flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) self.flexGridSizer1.AddWindow(self.ValuesLibrary, 0, border=20, flag=wx.GROW | wx.LEFT | wx.RIGHT) self.flexGridSizer1.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) self.flexGridSizer1.AddGrowableCol(0) self.flexGridSizer1.AddGrowableRow(1) self.SetSizer(self.flexGridSizer1) self.Fit() root = self.ValuesLibrary.AddRoot("") self.GenerateValuesLibraryBranch(root, library, default)
def OnProjectTreeMotion(self, event): if not event.Dragging(): pt = wx.Point(event.GetX(), event.GetY()) item, flags = self.ProjectTree.HitTest(pt) if item is not None and item.IsOk() and flags & wx.TREE_HITTEST_ONITEMLABEL: item_infos = self.ProjectTree.GetPyData(item) if item != self.LastToolTipItem and self.LastToolTipItem is not None: self.ProjectTree.SetToolTip(None) self.LastToolTipItem = None if self.LastToolTipItem != item and \ item_infos["type"] in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: bodytype = self.Controler.GetEditedElementBodyType( item_infos["tagname"]) if item_infos["type"] == ITEM_POU: block_type = { "program": _("Program"), "functionBlock": _("Function Block"), "function": _("Function") }[self.Controler.GetPouType(item_infos["name"])] elif item_infos["type"] == ITEM_TRANSITION: block_type = "Transition" else: block_type = "Action" self.LastToolTipItem = item wx.CallAfter(self.ProjectTree.SetToolTipString, "%s : %s : %s" % ( block_type, bodytype, item_infos["name"])) elif self.LastToolTipItem is not None: self.ProjectTree.SetToolTip(None) self.LastToolTipItem = None event.Skip()
def ArrowPoints(direction, width, height, xoffset, yoffset): if direction == wx.TOP: return [wx.Point(xoffset + 1, yoffset + height - 2), wx.Point(xoffset + width / 2, yoffset + 1), wx.Point(xoffset + width - 1, yoffset + height - 2)] else: return [wx.Point(xoffset + 1, yoffset - height + 1), wx.Point(xoffset + width / 2, yoffset - 2), wx.Point(xoffset + width - 1, yoffset - height + 1)]
def __init__(self, label, callback): self.Position = wx.Point(0, 0) self.Size = wx.Size(*BUTTON_SIZE) self.Label = label self.Shown = True self.Callback = callback
def SetPosition(self, x, y): self.Position = wx.Point(x, y)
def SetToolTipPosition(self, pos): """ Set tool tip position @param pos: New tool tip position """ # Get screen size to prevent tool tip to go out of the screen screen_width, screen_height = wx.GetDisplaySize() # Calculate position of tool tip to stay in screen limits tip_width, tip_height = self.GetToolTipSize() self.SetPosition(wx.Point( max(0, min(pos.x, screen_width - tip_width)), max(0, min(pos.y, screen_height - tip_height))))
def GetDraggingAxesPosition(self, panel): x, y = panel.GetPosition() return wx.Point(self.DraggingAxesBoundingBox.x - x, self.DraggingAxesBoundingBox.y - y)
def SetPosition(self, x, y): """ Set button position @param x: X coordinate of Button in Graphic Viewer @param y: Y coordinate of Button in Graphic Viewer """ self.Position = wx.Point(x, y)
def OnLeftDown(self, event): selected = self.ListBox.HitTest(wx.Point(event.GetX(), event.GetY())) parent_size = self.Parent.GetSize() parent_rect = wx.Rect(0, -parent_size[1], parent_size[0], parent_size[1]) if selected != wx.NOT_FOUND: wx.CallAfter(self.Parent.SetValueFromSelected, self.ListBox.GetString(selected)) elif parent_rect.InsideXY(event.GetX(), event.GetY()): result, x, y = self.Parent.HitTest(wx.Point(event.GetX(), event.GetY() + parent_size[1])) if result != wx.TE_HT_UNKNOWN: self.Parent.SetInsertionPoint(self.Parent.XYToPosition(x, y)) else: wx.CallAfter(self.Parent.DismissListBox) event.Skip()
def OnMotion(self, event): self.ListBox.SetSelection( self.ListBox.HitTest(wx.Point(event.GetX(), event.GetY()))) event.Skip()
def CreateTransition(self, connector, next=None): previous = connector.GetParentBlock() id = self.GetNewId() transition = SFC_Transition(self, "reference", "", 0, id) pos = connector.GetPosition(False) transition.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) transition_connectors = transition.GetConnectors() wire = self.ConnectConnectors(transition_connectors["input"], connector) if isinstance(previous, SFC_Divergence): previous.RefreshConnectedPosition(connector) else: previous.RefreshOutputPosition() wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) self.AddBlock(transition) self.Controler.AddEditedElementTransition(self.TagName, id) self.RefreshTransitionModel(transition) if next: wire = self.ConnectConnectors(next, transition_connectors["output"]) pos = transition_connectors["output"].GetPosition(False) next_block = next.GetParentBlock() next_pos = next.GetPosition(False) transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) if isinstance(next_block, SFC_Divergence): next_block.RefreshPosition() transition.RefreshOutputModel(True) return transition
def AddStepAction(self): if isinstance(self.SelectedElement, SFC_Step): connectors = self.SelectedElement.GetConnectors() if not connectors["action"]: dialog = ActionBlockDialog(self.ParentWindow) dialog.SetQualifierList(self.Controler.GetQualifierTypes()) dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug)) dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) if dialog.ShowModal() == wx.ID_OK: actions = dialog.GetValues() self.SelectedElement.AddAction() self.RefreshStepModel(self.SelectedElement) connectors = self.SelectedElement.GetConnectors() pos = connectors["action"].GetPosition(False) id = self.GetNewId() actionblock = SFC_ActionBlock(self, [], id) actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] / 2) actionblock_connector = actionblock.GetConnector() wire = self.ConnectConnectors(actionblock_connector, connectors["action"]) wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)]) actionblock.SetActions(actions) self.AddBlock(actionblock) self.Controler.AddEditedElementActionBlock(self.TagName, id) self.RefreshActionBlockModel(actionblock) self.RefreshBuffer() self.RefreshScrollBars() self.Refresh(False) dialog.Destroy()
def AddJump(self): if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output: choices = [] for block in self.Blocks: if isinstance(block, SFC_Step): choices.append(block.GetName()) dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Add a new jump"), _("Please choose a target"), choices, wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL) if dialog.ShowModal() == wx.ID_OK: value = dialog.GetStringSelection() self.SelectedElement.AddOutput() self.RefreshStepModel(self.SelectedElement) step_connectors = self.SelectedElement.GetConnectors() transition = self.CreateTransition(step_connectors["output"]) transition_connectors = transition.GetConnectors() id = self.GetNewId() jump = SFC_Jump(self, value, id) pos = transition_connectors["output"].GetPosition(False) jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) self.AddBlock(jump) self.Controler.AddEditedElementJump(self.TagName, id) jump_connector = jump.GetConnector() wire = self.ConnectConnectors(jump_connector, transition_connectors["output"]) transition.RefreshOutputPosition() wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) self.RefreshJumpModel(jump) self.RefreshBuffer() self.RefreshScrollBars() self.Refresh(False) dialog.Destroy()
def stepCreationFunction(viewer, id, specific_values): step = SFC_Step(viewer, specific_values.name, specific_values.initial, id) if specific_values.action is not None: step.AddAction() connector = step.GetActionConnector() connector.SetPosition(wx.Point(*specific_values.action.position)) return step
def _init_Editor(self, prnt): self.Editor = wx.ScrolledWindow(prnt, name="Viewer", pos=wx.Point(0, 0), size=wx.Size(0, 0), style=wx.HSCROLL | wx.VSCROLL) self.Editor.ParentWindow = self # Create a new Viewer
def SetScale(self, scale_number, refresh=True, mouse_event=None): new_scale = max(0, min(scale_number, len(ZOOM_FACTORS) - 1)) if self.CurrentScale != new_scale: if refresh: dc = self.GetLogicalDC() self.CurrentScale = new_scale self.ViewScale = (ZOOM_FACTORS[self.CurrentScale], ZOOM_FACTORS[self.CurrentScale]) if refresh: self.Editor.Freeze() if mouse_event is None: client_size = self.Editor.GetClientSize() mouse_pos = wx.Point(client_size[0] / 2, client_size[1] / 2) mouse_event = wx.MouseEvent(wx.EVT_MOUSEWHEEL.typeId) mouse_event.x = mouse_pos.x mouse_event.y = mouse_pos.y else: mouse_pos = mouse_event.GetPosition() pos = mouse_event.GetLogicalPosition(dc) xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) scrollx = max(0, round(pos.x * self.ViewScale[0] - mouse_pos.x) / SCROLLBAR_UNIT) scrolly = max(0, round(pos.y * self.ViewScale[1] - mouse_pos.y) / SCROLLBAR_UNIT) if scrollx > xmax or scrolly > ymax: self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax)) self.Scroll(scrollx, scrolly) else: self.Scroll(scrollx, scrolly) self.RefreshScrollBars() self.RefreshScaling(refresh) self.Editor.Thaw()
def AddInput(self): if not self.Input: self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) self.RefreshBoundingBox() # Remove output connector from step
def AddOutput(self): if not self.Output: self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True) self.RefreshBoundingBox() # Remove output connector from step
def RefreshOutputPosition(self, move=None): if self.Output: wires = self.Output.GetWires() if len(wires) != 1: return current_pos = self.Output.GetPosition(False) output = wires[0][0].GetOtherConnected(self.Output) output_pos = output.GetPosition(False) diffx = current_pos.x - output_pos.x output_block = output.GetParentBlock() wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] diffy = wire_size - output_pos.y + current_pos.y if diffy != 0: if isinstance(output_block, SFC_Step): output_block.MoveActionBlock((diffx, diffy)) wires[0][0].SetPoints([wx.Point(current_pos.x, current_pos.y + wire_size), wx.Point(current_pos.x, current_pos.y)]) if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: output_block.Move(diffx, diffy, self.Parent.Wires) output_block.RefreshOutputPosition((diffx, diffy)) else: output_block.RefreshPosition() elif move: if isinstance(output_block, SFC_Step): output_block.MoveActionBlock(move) wires[0][0].Move(move[0], move[1], True) if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: output_block.Move(move[0], move[1], self.Parent.Wires) output_block.RefreshOutputPosition(move) else: output_block.RefreshPosition() elif isinstance(output_block, SFC_Divergence): output_block.MoveConnector(output, diffx) else: if isinstance(output_block, SFC_Step): output_block.MoveActionBlock((diffx, 0)) output_block.Move(diffx, 0) output_block.RefreshOutputPosition() # Refresh action element with this step
def __init__(self, parent, type="reference", condition=None, priority=0, id=None): Graphic_Element.__init__(self, parent) DebugDataConsumer.__init__(self) self.Type = None self.Id = id self.Priority = 0 self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) # Create an input and output connector self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True) self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True) self.SetType(type, condition) self.SetPriority(priority) self.Highlights = {} self.PreviousValue = None self.PreviousSpreading = False
def MoveConnector(self, connector, movex): position = connector.GetRelPosition() connector.SetPosition(wx.Point(position.x + movex, position.y)) minx = self.Size[0] maxx = 0 for input in self.Inputs: input_pos = input.GetRelPosition() minx = min(minx, input_pos.x) maxx = max(maxx, input_pos.x) for output in self.Outputs: output_pos = output.GetRelPosition() minx = min(minx, output_pos.x) maxx = max(maxx, output_pos.x) if minx != 0: for input in self.Inputs: input_pos = input.GetRelPosition() input.SetPosition(wx.Point(input_pos.x - minx, input_pos.y)) for output in self.Outputs: output_pos = output.GetRelPosition() output.SetPosition(wx.Point(output_pos.x - minx, output_pos.y)) self.Inputs.sort(lambda x, y: cmp(x.Pos.x, y.Pos.x)) self.Outputs.sort(lambda x, y: cmp(x.Pos.x, y.Pos.x)) self.Pos.x += minx self.Size[0] = maxx - minx connector.MoveConnected() self.RefreshBoundingBox() # Returns the divergence connector that starts with the point given if it exists
def __init__(self, parent, target, id=None): Graphic_Element.__init__(self, parent) self.SetTarget(target) self.Id = id self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) self.Highlights = [] # Create an input and output connector self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True) self.Value = None self.PreviousValue = None
def RefreshConnectors(self): scaling = self.Parent.GetScaling() horizontal_pos = self.Size[0] / 2 if scaling is not None: horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x self.Input.SetPosition(wx.Point(horizontal_pos, 0)) self.RefreshConnected() # Refresh the position of wires connected to jump
def Draw(self, dc): Graphic_Element.Draw(self, dc) if self.Value: dc.SetPen(MiterPen(wx.GREEN)) dc.SetBrush(wx.GREEN_BRUSH) else: dc.SetPen(MiterPen(wx.BLACK)) dc.SetBrush(wx.BLACK_BRUSH) if getattr(dc, "printing", False): target_size = dc.GetTextExtent(self.Target) else: target_size = self.TargetSize # Draw plain rectangle for representing the divergence dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1]) points = [wx.Point(self.Pos.x, self.Pos.y), wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), wx.Point(self.Pos.x + self.Size[0], self.Pos.y), wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] dc.DrawPolygon(points) target_pos = (self.Pos.x + self.Size[0] + 2, self.Pos.y + (self.Size[1] - target_size[1]) / 2) dc.DrawText(self.Target, target_pos[0], target_pos[1]) # Draw input connector if self.Input: self.Input.Draw(dc) if not getattr(dc, "printing", False): DrawHighlightedText(dc, self.Target, self.Highlights, target_pos[0], target_pos[1]) # ------------------------------------------------------------------------------- # Sequencial Function Chart Action Block # -------------------------------------------------------------------------------
def __init__(self, parent, actions=[], id=None): Graphic_Element.__init__(self, parent) self.Id = id self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) self.Highlights = {} # Create an input and output connector self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone=True) self.SetActions(actions) self.Value = None self.PreviousValue = None