SFCViewer.py
changeset 64 dd6f693e46a1
parent 58 39cd981ff242
child 67 3a1b0afdaf84
--- a/SFCViewer.py	Tue Aug 07 17:37:38 2007 +0200
+++ b/SFCViewer.py	Tue Aug 07 17:38:48 2007 +0200
@@ -22,7 +22,6 @@
 #License along with this library; if not, write to the Free Software
 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from wxPython.wx import *
 import wx
 from types import *
 
@@ -56,7 +55,7 @@
             previous.RefreshConnectedPosition(connector)
         else:
             previous.RefreshOutputPosition()
-        wire.SetPoints([wxPoint(pos.x, pos.y + GetWireSize(previous)), wxPoint(pos.x, pos.y)])
+        wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)])
         self.AddBlock(transition)
         self.Controler.AddCurrentElementEditingTransition(id)
         self.RefreshTransitionModel(transition)
@@ -66,7 +65,7 @@
             next_block = next.GetParentBlock()
             next_pos = next.GetPosition(False)
             transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
-            wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, 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)
@@ -110,7 +109,7 @@
             previous.RefreshConnectedPosition(connector)
         else:
             previous.RefreshOutputPosition()
-        wire.SetPoints([wxPoint(pos.x, pos.y + GetWireSize(previous)), wxPoint(pos.x, pos.y)])
+        wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)])
         self.AddBlock(step)
         self.Controler.AddCurrentElementEditingStep(id)
         self.RefreshStepModel(step)
@@ -120,7 +119,7 @@
             next_block = next.GetParentBlock()
             next_pos = next.GetPosition(False)
             step.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
-            wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, 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()
             step.RefreshOutputModel(True)
@@ -207,7 +206,7 @@
             self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
         elif self.Mode == MODE_WIRE:
             pos = GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)
-            wire = Wire(self, [wxPoint(pos.x, pos.y), SOUTH], [wxPoint(pos.x, pos.y), NORTH])
+            wire = Wire(self, [wx.Point(pos.x, pos.y), SOUTH], [wx.Point(pos.x, pos.y), NORTH])
             wire.oldPos = pos
             wire.Handle = (HANDLE_POINT, 0)
             wire.ProcessDragging(0, 0)
@@ -234,15 +233,15 @@
             elif self.Mode == MODE_COMMENT:
                 bbox = self.rubberBand.GetCurrentExtent()
                 self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
-                wxCallAfter(self.AddComment, bbox)
+                wx.CallAfter(self.AddComment, bbox)
         elif self.Mode == MODE_INITIALSTEP:
-            wxCallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling))
+            wx.CallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling))
         elif self.Mode == MODE_SELECTION and self.SelectedElement:
             if self.IsWire(self.SelectedElement):
                 self.SelectedElement.SetSelectedSegment(0)
             else:
                 self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
-            wxCallAfter(self.SetCursor, wxNullCursor)
+            wx.CallAfter(self.SetCursor, wx.NullCursor)
             self.ReleaseMouse()
             self.Refresh()
         elif self.Mode == MODE_WIRE and self.SelectedElement:
@@ -270,7 +269,7 @@
                 else:
                     self.SelectedElement.SetSelected(True)
                     self.SelectedElement.OnRightUp(event, dc, self.Scaling)
-                wxCallAfter(self.SetCursor, wxNullCursor)
+                wx.CallAfter(self.SetCursor, wx.NullCursor)
                 self.ReleaseMouse()
                 self.Refresh()
         event.Skip()
@@ -305,18 +304,21 @@
 #-------------------------------------------------------------------------------
 
     def OnChar(self, event):
+        xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
+        xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
+        ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
         keycode = event.GetKeyCode()
         if self.Scaling:
             scaling = self.Scaling
         else:
             scaling = (8, 8)
-        if keycode == WXK_DELETE and self.SelectedElement:
+        if keycode == wx.WXK_DELETE and self.SelectedElement:
             self.SelectedElement.Delete()
             self.SelectedElement = None
             self.RefreshBuffer()
             self.RefreshScrollBars()
             self.Refresh()
-        elif keycode == WXK_LEFT:
+        elif keycode == wx.WXK_LEFT:
             if event.ControlDown() and event.ShiftDown():
                 self.Scroll(0, ypos)
             elif event.ControlDown():
@@ -326,7 +328,7 @@
                 self.RefreshBuffer()
                 self.RefreshScrollBars()
                 self.Refresh()
-        elif keycode == WXK_RIGHT:
+        elif keycode == wx.WXK_RIGHT:
             if event.ControlDown() and event.ShiftDown():
                 self.Scroll(xmax, ypos)
             elif event.ControlDown():
@@ -336,7 +338,7 @@
                 self.RefreshBuffer()
                 self.RefreshScrollBars()
                 self.Refresh()
-        elif keycode == WXK_UP:
+        elif keycode == wx.WXK_UP:
             if event.ControlDown() and event.ShiftDown():
                 self.Scroll(xpos, 0)
             elif event.ControlDown():
@@ -346,7 +348,7 @@
                 self.RefreshBuffer()
                 self.RefreshScrollBars()
                 self.Refresh()
-        elif keycode == WXK_DOWN:
+        elif keycode == wx.WXK_DOWN:
             if event.ControlDown() and event.ShiftDown():
                 self.Scroll(xpos, ymax)
             elif event.ControlDown():
@@ -362,11 +364,11 @@
 #-------------------------------------------------------------------------------
 
     def AddInitialStep(self, pos):
-        dialog = StepNameDialog(self.Parent, "Add a new initial step", "Please enter step name", "", wxOK|wxCANCEL)
+        dialog = StepNameDialog(self.Parent, "Add a new initial step", "Please enter step name", "", wx.OK|wx.CANCEL)
         dialog.SetPouNames(self.Controler.GetProjectPouNames())
         dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
-        if dialog.ShowModal() == wxID_OK:
+        if dialog.ShowModal() == wx.ID_OK:
             id = self.GetNewId()
             name = dialog.GetValue()
             step = SFC_Step(self, name, True, id)
@@ -385,11 +387,11 @@
 
     def AddStep(self):
         if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step):
-            dialog = StepNameDialog(self.Parent, "Add a new step", "Please enter step name", "", wxOK|wxCANCEL)
+            dialog = StepNameDialog(self.Parent, "Add a new step", "Please enter step name", "", wx.OK|wx.CANCEL)
             dialog.SetPouNames(self.Controler.GetProjectPouNames())
             dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
             dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
-            if dialog.ShowModal() == wxID_OK:
+            if dialog.ShowModal() == wx.ID_OK:
                 name = dialog.GetValue()
                 if self.IsWire(self.SelectedElement):
                     self.SelectedElement.SetSelectedSegment(None)
@@ -446,7 +448,7 @@
                 dialog.SetQualifierList(self.Controler.GetQualifierTypes())
                 dialog.SetActionList(self.Controler.GetCurrentElementEditingActions())
                 dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars())
-                if dialog.ShowModal() == wxID_OK:
+                if dialog.ShowModal() == wx.ID_OK:
                     actions = dialog.GetValues()
                     self.SelectedElement.AddAction()
                     self.RefreshStepModel(self.SelectedElement)
@@ -457,7 +459,7 @@
                     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([wxPoint(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wxPoint(pos.x, pos.y)])
+                    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.AddCurrentElementEditingActionBlock(id)
@@ -470,7 +472,7 @@
     def AddDivergence(self):
         if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, Graphic_Group) or isinstance(self.SelectedElement, SFC_Step):        
             dialog = DivergenceCreateDialog(self.Parent)
-            if dialog.ShowModal() == wxID_OK:
+            if dialog.ShowModal() == wx.ID_OK:
                 value = dialog.GetValues()
                 if value["type"] == SELECTION_DIVERGENCE:
                     if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step):
@@ -508,7 +510,7 @@
                     divergence_connectors = divergence.GetConnectors()
                     wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
                     previous_block.RefreshOutputPosition()
-                    wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)])
+                    wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
                     self.AddBlock(divergence)
                     self.Controler.AddCurrentElementEditingDivergence(id, value["type"])
                     self.RefreshDivergenceModel(divergence)
@@ -520,7 +522,7 @@
                             next_block = next.GetParentBlock()
                             divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
                             divergence.RefreshConnectedPosition(connector)
-                            wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
+                            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
                             next_block.RefreshModel()
                             next = None
                         else:
@@ -566,7 +568,7 @@
                     divergence_connectors = divergence.GetConnectors()
                     wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
                     previous_block.RefreshOutputPosition()
-                    wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)])
+                    wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
                     self.AddBlock(divergence)
                     self.Controler.AddCurrentElementEditingDivergence(id, value["type"])
                     self.RefreshDivergenceModel(divergence)
@@ -578,7 +580,7 @@
                             next_block = next.GetParentBlock()
                             divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
                             divergence.RefreshConnectedPosition(connector)
-                            wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
+                            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
                             next_block.RefreshModel()
                             next = None
                         else:
@@ -632,7 +634,7 @@
                         pos = input.GetPosition(False)
                         wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input)
                         wire_size = GetWireSize(input)
-                        wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)])
+                        wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
                         input_block = input.GetParentBlock()
                         input_block.RefreshOutputPosition()
                     divergence.RefreshPosition()
@@ -648,7 +650,7 @@
                         next_block = next.GetParentBlock()
                         divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
                         divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0])
-                        wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
+                        wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
                         next_block.RefreshModel()
                     else:
                         if value["type"] == SELECTION_CONVERGENCE:
@@ -686,8 +688,8 @@
             for block in self.Blocks:
                 if isinstance(block, SFC_Step):
                     choices.append(block.GetName())
-            dialog = wxSingleChoiceDialog(self.Parent, "Add a new jump", "Please choose a target", choices, wxOK|wxCANCEL)
-            if dialog.ShowModal() == wxID_OK:
+            dialog = wx.SingleChoiceDialog(self.Parent, "Add a new jump", "Please choose a target", choices, wx.OK|wx.CANCEL)
+            if dialog.ShowModal() == wx.ID_OK:
                 value = dialog.GetStringSelection()
                 self.SelectedElement.AddOutput()
                 self.RefreshStepModel(self.SelectedElement)
@@ -703,7 +705,7 @@
                 jump_connector = jump.GetConnector()
                 wire = self.ConnectConnectors(jump_connector, transition_connectors["output"])
                 transition.RefreshOutputPosition()
-                wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
+                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()
@@ -711,11 +713,11 @@
             dialog.Destroy()
 
     def EditStepContent(self, step):
-        dialog = StepNameDialog(self.Parent, "Edit step name", "Please enter step name", step.GetName(), wxOK|wxCANCEL)
+        dialog = StepNameDialog(self.Parent, "Edit step name", "Please enter step name", step.GetName(), wx.OK|wx.CANCEL)
         dialog.SetPouNames(self.Controler.GetProjectPouNames())
         dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
-        if dialog.ShowModal() == wxID_OK:
+        if dialog.ShowModal() == wx.ID_OK:
             value = dialog.GetValue()
             step.SetName(value)
             min_size = step.GetMinSize()
@@ -727,52 +729,6 @@
             self.Refresh()
         dialog.Destroy()
 
-    def EditTransitionContent(self, transition):
-        dialog = TransitionContentDialog(self.Parent)
-        dialog.SetTransitions(self.Controler.GetCurrentElementEditingTransitions())
-        dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition()})
-        if dialog.ShowModal() == wxID_OK:
-            values = dialog.GetValues()
-            transition.SetType(values["type"])
-            transition.SetCondition(values["value"])
-            transition.RefreshModel()
-            self.RefreshBuffer()
-            self.RefreshScrollBars()
-            self.Refresh()
-        dialog.Destroy()
-
-    def EditJumpContent(self, jump):
-        choices = []
-        for block in self.Blocks:
-            if isinstance(block, SFC_Step):
-                choices.append(block.GetName())
-        dialog = wxSingleChoiceDialog(self.Parent, "Edit jump target", "Please choose a target", choices, wxOK|wxCANCEL)
-        dialog.SetSelection(choices.index(jump.GetTarget()))
-        if dialog.ShowModal() == wxID_OK:
-            value = dialog.GetStringSelection()
-            jump.SetTarget(value)
-            jump.RefreshModel()
-            self.RefreshBuffer()
-            self.RefreshScrollBars()
-            self.Refresh()
-        dialog.Destroy()
-
-    def EditActionBlockContent(self, actionblock):
-        dialog = ActionBlockDialog(self.Parent)
-        dialog.SetQualifierList(self.Controler.GetQualifierTypes())
-        dialog.SetActionList(self.Controler.GetCurrentElementEditingActions())
-        dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars())
-        dialog.SetValues(actionblock.GetActions())
-        if dialog.ShowModal() == wxID_OK:
-            actions = dialog.GetValues()
-            actionblock.SetActions(actions)
-            actionblock.RefreshModel()
-            self.RefreshBuffer()
-            self.RefreshScrollBars()
-            self.Refresh()
-        dialog.Destroy()
-        
-
 #-------------------------------------------------------------------------------
 #                          Delete element functions
 #-------------------------------------------------------------------------------
@@ -828,7 +784,7 @@
                         next_pos = next.GetPosition(False)
                         wire_size = GetWireSize(previous_block)
                         previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y))
-                        wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)])
+                        wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
                         if isinstance(next_block, SFC_Divergence):
                             next_block.RefreshPosition()
                         previous_block.RefreshOutputModel(True)
@@ -941,8 +897,8 @@
                     next_pos = next.GetPosition(False)
                     wire_size = GetWireSize(previous_block)
                     previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y))
-                    wire.SetPoints([wxPoint(previous_pos.x, previous_pos.y + wire_size), 
-                        wxPoint(previous_pos.x, previous_pos.y)])
+                    wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), 
+                        wx.Point(previous_pos.x, previous_pos.y)])
                     if isinstance(next_block, SFC_Divergence):
                         next_block.RefreshPosition()
                     previous_block.RefreshOutputModel(True)
@@ -971,8 +927,8 @@
                 next_pos = next.GetPosition(False)
                 wire_size = GetWireSize(previous_block)
                 previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y))
-                wire.SetPoints([wxPoint(previous_pos.x, previous_pos.y + wire_size), 
-                    wxPoint(previous_pos.x, previous_pos.y)])
+                wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), 
+                    wx.Point(previous_pos.x, previous_pos.y)])
                 if isinstance(next_block, SFC_Divergence):
                     next_block.RefreshPosition()
                 previous_block.RefreshOutputModel(True)