Python wx.Point() Examples

The following are 30 code examples of wx.Point(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: mining.py    From nuxhash with GNU General Public License v3.0 7 votes vote down vote up
def Render(self, cell, dc, state):
        position = cell.GetPosition()
        for device in self._Devices:
            box = self.GetTextExtent(device['name'])
            RADIUS = DeviceListRenderer.CORNER_RADIUS

            if device['vendor'] == 'nvidia':
                color = self._ColorDb.Find('LIME GREEN')
            else:
                color = self._ColorDb.Find('LIGHT GREY')
            dc.SetBrush(wx.Brush(color))
            dc.SetPen(wx.TRANSPARENT_PEN)
            shadeRect = wx.Rect(
                    position,
                    wx.Size(box.GetWidth() + RADIUS*2, box.GetHeight() + RADIUS*2))
            dc.DrawRoundedRectangle(shadeRect, RADIUS)

            textRect = wx.Rect(
                    wx.Point(position.x + RADIUS, position.y + RADIUS), box)
            self.RenderText(device['name'], 0, textRect, dc, state)

            position = wx.Point(
                    position.x, (position.y + box.GetHeight() + RADIUS*2 + RADIUS))
        return True 
Example #2
Source File: objdictedit.py    From CANFestivino with GNU Lesser General Public License v2.1 6 votes vote down vote up
def _init_ctrls(self, prnt):
        wx.Frame.__init__(self, id=ID_OBJDICTEDIT, name='objdictedit',
              parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
              style=wx.DEFAULT_FRAME_STYLE, title=_('Objdictedit'))
        self._init_utils()
        self.SetClientSize(wx.Size(1000, 700))
        self.SetMenuBar(self.MenuBar)
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
        if not self.ModeSolo:
            self.Bind(wx.EVT_MENU, self.OnSaveMenu, id=wx.ID_SAVE)
            accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)])
            self.SetAcceleratorTable(accel)

        self.FileOpened = wx.Notebook(id=ID_OBJDICTEDITFILEOPENED,
              name='FileOpened', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(0, 0), style=0)
        self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
              self.OnFileSelectedChanged, id=ID_OBJDICTEDITFILEOPENED)

        self.HelpBar = wx.StatusBar(id=ID_OBJDICTEDITHELPBAR, name='HelpBar',
              parent=self, style=wx.ST_SIZEGRIP)
        self._init_coll_HelpBar_Fields(self.HelpBar)
        self.SetStatusBar(self.HelpBar) 
Example #3
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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((self.Pos.x + horizontal_pos) / scaling[0]) * scaling[0] - self.Pos.x
            vertical_pos = round((self.Pos.y + vertical_pos) / 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 
Example #4
Source File: LD_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #5
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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)
        points = [wx.Point(int(round((self.Pos.x - 2) * scalex)) - 3,
                           int(round((self.Pos.y - 2) * scaley)) - 2),
                  wx.Point(int(round((self.Pos.x + self.Size[0] + 2) * scalex)) + 4,
                           int(round((self.Pos.y - 2) * scaley)) - 2),
                  wx.Point(int(round((self.Pos.x + self.Size[0] / 2) * scalex)),
                           int(round((self.Pos.y + self.Size[1] + 3) * scaley)) + 4)]
        dc.DrawPolygon(points)
        dc.SetLogicalFunction(wx.COPY)
        dc.SetUserScale(scalex, scaley)

    # Draws divergence 
Example #6
Source File: LD_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
def RefreshConnectors(self):
        scaling = self.Parent.GetScaling()
        height = self.Size[1] - self.Extensions[0] - self.Extensions[1]
        interval = height / max(len(self.Connectors) - 1, 1)
        for i, connector in enumerate(self.Connectors):
            if self.RealConnectors:
                position = self.Extensions[0] + int(round(self.RealConnectors[i] * height))
            else:
                position = self.Extensions[0] + int(round(i * interval))
            if scaling is not None:
                position = round((self.Pos.y + position) / scaling[1]) * scaling[1] - self.Pos.y
            if self.Type == LEFTRAIL:
                connector.SetPosition(wx.Point(self.Size[0], position))
            elif self.Type == RIGHTRAIL:
                connector.SetPosition(wx.Point(0, position))
        self.RefreshConnected()

    # Refresh the position of wires connected to power rail 
Example #7
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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(position.x*width / 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(position.x*width / self.Size[0])), height))
            output.MoveConnected()
        self.Size = wx.Size(width, height)
        self.RefreshBoundingBox()

    # Returns the divergence minimum size 
Example #8
Source File: NetworkEditor.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #9
Source File: FBD_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #10
Source File: networkedit.py    From CANFestivino with GNU Lesser General Public License v2.1 6 votes vote down vote up
def _init_ctrls(self, prnt):
        wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit',
              parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
              style=wx.DEFAULT_FRAME_STYLE, title=_('Networkedit'))
        self._init_utils()
        self.SetClientSize(wx.Size(1000, 700))
        self.SetMenuBar(self.MenuBar)
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
        if not self.ModeSolo:
            self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
            accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)])
            self.SetAcceleratorTable(accel)

        NetworkEditorTemplate._init_ctrls(self, self)

        self.HelpBar = wx.StatusBar(id=ID_NETWORKEDITHELPBAR, name='HelpBar',
              parent=self, style=wx.ST_SIZEGRIP)
        self._init_coll_HelpBar_Fields(self.HelpBar)
        self.SetStatusBar(self.HelpBar) 
Example #11
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #12
Source File: FBD_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #13
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent, type, number=2, id=None):
        Graphic_Element.__init__(self, parent)
        self.Type = type
        self.Id = id
        self.RealConnectors = None
        number = max(2, number)
        self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1])
        # Create an input and output connector
        if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
            self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True)]
            self.Outputs = []
            for i in xrange(number):
                self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True))
        elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
            self.Inputs = []
            for i in xrange(number):
                self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True))
            self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True)]
        self.Value = None
        self.PreviousValue = None 
Example #14
Source File: Viewer.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #15
Source File: GraphicCommons.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
def OnLeftDown(self, event, dc, scaling):
        # Test if an handle have been clicked
        handle = self.TestHandle(event)
        # Find which type of handle have been clicked,
        # Save a resize event and change the cursor
        cursor = HANDLE_CURSORS.get(handle, 1)
        wx.CallAfter(self.Parent.SetCurrentCursor, cursor)
        if cursor > 1:
            self.Handle = (HANDLE_RESIZE, handle)
        else:
            self.Handle = (HANDLE_MOVE, None)
            self.SetSelected(False)
        # Initializes the last position
        self.oldPos = GetScaledEventPosition(event, dc, scaling)
        self.StartPos = wx.Point(self.Pos.x, self.Pos.y)
        self.CurrentDrag = wx.Point(0, 0)

    # Method called when a LeftUp event have been generated 
Example #16
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #17
Source File: GraphicCommons.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #18
Source File: SearchResultPanel.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
def _init_ctrls(self, prnt):
        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() 
Example #19
Source File: SFCViewer.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #20
Source File: SFCViewer.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #21
Source File: SFCViewer.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #22
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #23
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #24
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #25
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def AddAction(self):
        if not self.Action:
            self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] // 2), EAST, onlyone=True)
            self.RefreshBoundingBox()

    # Remove action connector from step 
Example #26
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #27
Source File: SFC_Objects.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #28
Source File: GraphicCommons.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def DrawHighlightment(self, dc):
        scalex, scaley = dc.GetUserScale()
        dc.SetUserScale(1, 1)
        # If user trying to connect wire with wrong input, highlight will become red.
        if self.ErrHighlight and not self.EndConnected:
            highlightcolor = wx.RED
        else:
            highlightcolor = HIGHLIGHTCOLOR
        dc.SetPen(MiterPen(highlightcolor, (2 * scalex + 5)))
        dc.SetBrush(wx.Brush(highlightcolor))
        dc.SetLogicalFunction(wx.AND)
        # Draw the start and end points if they are not connected or the mouse is over them
        if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
            dc.DrawCircle(round(self.Points[0].x * scalex),
                          round(self.Points[0].y * scaley),
                          (POINT_RADIUS + 1) * scalex + 2)
        if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd):
            dc.DrawCircle(self.Points[-1].x * scalex, self.Points[-1].y * scaley, (POINT_RADIUS + 1) * scalex + 2)
        # Draw the wire lines and the last point (it seems that DrawLines stop before the last point)
        if len(self.Points) > 1:
            points = [wx.Point(round((self.Points[0].x - self.Segments[0][0]) * scalex),
                               round((self.Points[0].y - self.Segments[0][1]) * scaley))]
            points.extend([wx.Point(round(point.x * scalex), round(point.y * scaley)) for point in self.Points[1:-1]])
            points.append(wx.Point(round((self.Points[-1].x + self.Segments[-1][0]) * scalex),
                                   round((self.Points[-1].y + self.Segments[-1][1]) * scaley)))
        else:
            points = []
        dc.DrawLines(points)
        dc.SetLogicalFunction(wx.COPY)
        dc.SetUserScale(scalex, scaley)

        if self.StartConnected is not None:
            self.StartConnected.DrawHighlightment(dc)
            self.StartConnected.Draw(dc)
        if self.EndConnected is not None:
            self.EndConnected.DrawHighlightment(dc)
            self.EndConnected.Draw(dc)

    # Draws the wire lines and points 
Example #29
Source File: GraphicCommons.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def AddSegment(self):
        handle_type, handle = self.Handle
        if handle_type == HANDLE_SEGMENT:
            segment, dir = handle
            if len(self.Segments) > 1:
                pointx = self.Points[segment].x
                pointy = self.Points[segment].y
                if dir[0] != 0:
                    pointx = (self.Points[segment].x + self.Points[segment + 1].x) // 2
                if dir[1] != 0:
                    pointy = (self.Points[segment].y + self.Points[segment + 1].y) // 2
                self.Points.insert(segment + 1, wx.Point(pointx, pointy))
                self.Segments.insert(segment + 1, (dir[1], dir[0]))
                self.Points.insert(segment + 2, wx.Point(pointx, pointy))
                self.Segments.insert(segment + 2, dir)
            else:
                p1x = p2x = self.Points[segment].x
                p1y = p2y = self.Points[segment].y
                if dir[0] != 0:
                    p1x = (2 * self.Points[segment].x + self.Points[segment + 1].x) // 3
                    p2x = (self.Points[segment].x + 2 * self.Points[segment + 1].x) // 3
                if dir[1] != 0:
                    p1y = (2 * self.Points[segment].y + self.Points[segment + 1].y) // 3
                    p2y = (self.Points[segment].y + 2 * self.Points[segment + 1].y) // 3
                self.Points.insert(segment + 1, wx.Point(p1x, p1y))
                self.Segments.insert(segment + 1, (dir[1], dir[0]))
                self.Points.insert(segment + 2, wx.Point(p1x, p1y))
                self.Segments.insert(segment + 2, dir)
                self.Points.insert(segment + 3, wx.Point(p2x, p2y))
                self.Segments.insert(segment + 3, (dir[1], dir[0]))
                self.Points.insert(segment + 4, wx.Point(p2x, p2y))
                self.Segments.insert(segment + 4, dir)
            self.GeneratePoints()

    # Delete the handled segment by removing the two segment points 
Example #30
Source File: GraphicCommons.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def SetPoints(self, points, verify=True):
        if len(points) > 1:
            self.Points = [wx.Point(x, y) for x, y in points]
            # Calculate the start and end directions
            self.StartPoint = [None, vector(self.Points[0], self.Points[1])]
            self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])]
            # Calculate the start and end points
            self.StartPoint[0] = wx.Point(self.Points[0].x + CONNECTOR_SIZE * self.StartPoint[1][0],
                                          self.Points[0].y + CONNECTOR_SIZE * self.StartPoint[1][1])
            self.EndPoint[0] = wx.Point(self.Points[-1].x + CONNECTOR_SIZE * self.EndPoint[1][0],
                                        self.Points[-1].y + CONNECTOR_SIZE * self.EndPoint[1][1])
            self.Points[0] = self.StartPoint[0]
            self.Points[-1] = self.EndPoint[0]
            # Calculate the segments directions
            self.Segments = []
            i = 0
            while i < len(self.Points) - 1:
                if verify and 0 < i < len(self.Points) - 2 and \
                   self.Points[i] == self.Points[i + 1] and \
                   self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]):
                    for dummy in xrange(2):
                        self.Points.pop(i)
                else:
                    segment = vector(self.Points[i], self.Points[i + 1])
                    if is_null_vector(segment) and i > 0:
                        segment = (self.Segments[-1][1], self.Segments[-1][0])
                    if i < len(self.Points) - 2:
                        next = vector(self.Points[i + 1], self.Points[i + 2])
                        if next == segment or is_null_vector(add_vectors(segment, next)):
                            self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y))
                    self.Segments.append(segment)
                    i += 1
            self.RefreshBoundingBox()
            self.RefreshRealPoints()

    # Returns the position of the point indicated