Adding Font support in Dialog
authorlbessard
Wed, 30 Jan 2008 18:48:05 +0100
changeset 165 e464a4e4e06d
parent 164 0fb64076d3f5
child 166 de1845119cdd
Adding Font support in Dialog
Adding centered resizing for graphics
Dialogs.py
LDViewer.py
SFCViewer.py
Viewer.py
graphics/FBD_Objects.py
graphics/GraphicCommons.py
graphics/LD_Objects.py
graphics/SFC_Objects.py
--- a/Dialogs.py	Wed Jan 30 09:52:57 2008 +0100
+++ b/Dialogs.py	Wed Jan 30 18:48:05 2008 +0100
@@ -185,6 +185,9 @@
         self.PouNames = []
         self.PouElementNames = []
     
+    def SetPreviewFont(self, font):
+        self.Preview.SetFont(font)
+    
     def FindTreeItem(self, root, name, inputs = None):
         if root.IsOk():
             pydata = self.TypeTree.GetPyData(root)
@@ -338,6 +341,7 @@
         
     def RefreshPreview(self):
         dc = wx.ClientDC(self.Preview)
+        dc.SetFont(self.Preview.GetFont())
         dc.Clear()
         item = self.TypeTree.GetSelection()
         if item.IsOk():
@@ -525,6 +529,9 @@
             self.Class.Append(choice)
         self.Class.SetStringSelection("Input")
 
+    def SetPreviewFont(self, font):
+        self.Preview.SetFont(font)
+
     def RefreshNameList(self):
         selected = self.VariableName.GetStringSelection()
         self.VariableName.Clear()
@@ -626,6 +633,7 @@
     
     def RefreshPreview(self):
         dc = wx.ClientDC(self.Preview)
+        dc.SetFont(self.Preview.GetFont())
         dc.Clear()
         expression = self.Expression.GetValue()
         if self.Expression.IsEnabled() and expression != "":
@@ -785,7 +793,10 @@
         self._init_ctrls(parent)
         self.Connection = None
         self.MinConnectionSize = None
-            
+    
+    def SetPreviewFont(self, font):
+        self.Preview.SetFont(font)
+    
     def SetMinConnectionSize(self, size):
         self.MinConnectionSize = size
     
@@ -820,6 +831,7 @@
         
     def RefreshPreview(self):
         dc = wx.ClientDC(self.Preview)
+        dc.SetFont(self.Preview.GetFont())
         dc.Clear()
         if self.radioButton1.GetValue():
             self.Connection = FBD_Connector(self.Preview, CONNECTOR, self.ConnectionName.GetValue())
@@ -984,7 +996,10 @@
         elif type == "coil":
             self._init_ctrls(parent, "Edit Coil Values", ['Normal','Negate','Set','Reset'])
             self.Element = LD_Coil(self.Preview, COIL_NORMAL, "")
-        
+    
+    def SetPreviewFont(self, font):
+        self.Preview.SetFont(font)
+    
     def SetElementSize(self, size):
         min_width, min_height = self.Element.GetMinSize()
         width, height = max(min_width, size[0]), max(min_height, size[1])
@@ -1058,6 +1073,7 @@
 
     def RefreshPreview(self):
         dc = wx.ClientDC(self.Preview)
+        dc.SetFont(self.Preview.GetFont())
         dc.Clear()
         clientsize = self.Preview.GetClientSize()
         width, height = self.Element.GetSize()
@@ -1205,6 +1221,9 @@
         self.PowerRailMinSize = (0, 0)
         self.PowerRail = None
 
+    def SetPreviewFont(self, font):
+        self.Preview.SetFont(font)
+
     def SetMinSize(self, size):
         self.PowerRailMinSize = size
         self.RefreshPreview()    
@@ -1230,6 +1249,7 @@
 
     def RefreshPreview(self):
         dc = wx.ClientDC(self.Preview)
+        dc.SetFont(self.Preview.GetFont())
         dc.Clear()
         self.PowerRail = LD_PowerRail(self.Preview, self.Type, connectors = [True for i in xrange(self.PinNumber.GetValue())])
         min_width, min_height = 2, LD_LINE_SIZE * self.PinNumber.GetValue()
@@ -1384,6 +1404,9 @@
         self.Variables = []
         self.StepNames = []
     
+    def SetPreviewFont(self, font):
+        self.Preview.SetFont(font)
+    
     def OnOK(self, event):
         step_name = self.StepName.GetValue()
         if step_name == "":
@@ -1455,6 +1478,7 @@
     
     def RefreshPreview(self):
         dc = wx.ClientDC(self.Preview)
+        dc.SetFont(self.Preview.GetFont())
         dc.Clear()
         self.Step = SFC_Step(self.Preview, self.StepName.GetValue(), self.Initial)
         if self.checkBox1.IsChecked():
@@ -1639,7 +1663,10 @@
         self.MinTransitionSize = None
         
         self.Element = SFC_Transition(self.Preview)
-        
+    
+    def SetPreviewFont(self, font):
+        self.Preview.SetFont(font)
+    
     def SetElementSize(self, size):
         min_width, min_height = self.Element.GetMinSize()
         width, height = max(min_width, size[0]), max(min_height, size[1])
@@ -1745,6 +1772,7 @@
 
     def RefreshPreview(self):
         dc = wx.ClientDC(self.Preview)
+        dc.SetFont(self.Preview.GetFont())
         dc.Clear()
         clientsize = self.Preview.GetClientSize()
         posx, posy = self.Element.GetPosition()
@@ -1900,7 +1928,10 @@
         
         self.Divergence = None
         self.MinSize = (0, 0)
-        
+    
+    def SetPreviewFont(self, font):
+        self.Preview.SetFont(font)
+    
     def GetValues(self):
         values = {}
         if self.radioButton1.GetValue():
@@ -1927,6 +1958,7 @@
         
     def RefreshPreview(self):
         dc = wx.ClientDC(self.Preview)
+        dc.SetFont(self.Preview.GetFont())
         dc.Clear()
         if self.radioButton1.GetValue():
             self.Divergence = SFC_Divergence(self.Preview, SELECTION_DIVERGENCE, self.Sequences.GetValue())
--- a/LDViewer.py	Wed Jan 30 09:52:57 2008 +0100
+++ b/LDViewer.py	Wed Jan 30 18:48:05 2008 +0100
@@ -465,6 +465,7 @@
 
     def AddLadderRung(self):
         dialog = LDElementDialog(self.ParentWindow, "coil")
+        dialog.SetPreviewFont(self.GetFont())
         varlist = []
         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
         if vars:
@@ -554,6 +555,7 @@
                     wires.append(element)
         if len(wires) > 0:
             dialog = LDElementDialog(self.ParentWindow, "contact")
+            dialog.SetPreviewFont(self.GetFont())
             varlist = []
             vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
             if vars:
@@ -775,6 +777,7 @@
                         right_elements.reverse()
                     elif right_powerrail:
                         dialog = LDElementDialog(self.ParentWindow, "coil")
+                        dialog.SetPreviewFont(self.GetFont())
                         varlist = []
                         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
                         if vars:
@@ -1196,6 +1199,7 @@
             Viewer.EditContactContent(self, contact)
         else:
             dialog = LDElementDialog(self.ParentWindow, "contact")
+            dialog.SetPreviewFont(self.GetFont())
             varlist = []
             vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
             if vars:
@@ -1219,6 +1223,7 @@
             Viewer.EditCoilContent(self, coil)
         else:
             dialog = LDElementDialog(self.ParentWindow, "coil")
+            dialog.SetPreviewFont(self.GetFont())
             varlist = []
             vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
             if vars:
--- a/SFCViewer.py	Wed Jan 30 09:52:57 2008 +0100
+++ b/SFCViewer.py	Wed Jan 30 18:48:05 2008 +0100
@@ -479,6 +479,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.ParentWindow)
+            dialog.SetPreviewFont(self.GetFont())
             if dialog.ShowModal() == wx.ID_OK:
                 value = dialog.GetValues()
                 if value["type"] == SELECTION_DIVERGENCE:
--- a/Viewer.py	Wed Jan 30 09:52:57 2008 +0100
+++ b/Viewer.py	Wed Jan 30 18:48:05 2008 +0100
@@ -315,14 +315,15 @@
         self.SetDropTarget(ViewerDropTarget(self))
         
         dc = wx.ClientDC(self)
-        self.Font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
-        dc.SetFont(self.Font)
+        font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
+        dc.SetFont(font)
         width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
         while width > 260:
             faces["size"] -= 1
-            self.Font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
-            dc.SetFont(self.Font)
+            font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
+            dc.SetFont(font)
             width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+        self.SetFont(font)
         
         # Link Viewer event to corresponding methods
         self.Bind(wx.EVT_PAINT, self.OnPaint)
@@ -367,7 +368,7 @@
             dc = wx.BufferedPaintDC(self)
         else:
             dc = wx.ClientDC(self)
-        dc.SetFont(self.Font)
+        dc.SetFont(self.GetFont())
         if wx.VERSION >= (2, 6, 0):
             self.DoPrepareDC(dc)
         else:
@@ -1105,7 +1106,7 @@
                         wire = Wire(self, [wx.Point(pos.x, pos.y), WEST], [wx.Point(pos.x, pos.y), EAST])
                     wire.oldPos = pos
                     wire.Handle = (HANDLE_POINT, 0)
-                    wire.ProcessDragging(0, 0, self.Scaling)
+                    wire.ProcessDragging(0, 0, False, self.Scaling)
                     wire.Handle = (HANDLE_POINT, 1)
                     self.AddWire(wire)
                     if self.SelectedElement:
@@ -1381,6 +1382,7 @@
 
     def AddNewBlock(self, bbox):
         dialog = BlockPropertiesDialog(self.ParentWindow)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName))
         dialog.SetPouNames(self.Controler.GetProjectPouNames())
         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName))
@@ -1405,6 +1407,7 @@
     
     def AddNewVariable(self, bbox):
         dialog = VariablePropertiesDialog(self.ParentWindow)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetMinVariableSize((bbox.width, bbox.height))
         varlist = []
         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
@@ -1432,6 +1435,7 @@
 
     def AddNewConnection(self, bbox):
         dialog = ConnectionPropertiesDialog(self.ParentWindow)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetMinConnectionSize((bbox.width, bbox.height))
         if dialog.ShowModal() == wx.ID_OK:
             id = self.GetNewId()
@@ -1469,6 +1473,7 @@
 
     def AddNewContact(self, bbox):
         dialog = LDElementDialog(self.ParentWindow, "contact")
+        dialog.SetPreviewFont(self.GetFont())
         varlist = []
         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
         if vars:
@@ -1494,6 +1499,7 @@
 
     def AddNewCoil(self, bbox):
         dialog = LDElementDialog(self.ParentWindow, "coil")
+        dialog.SetPreviewFont(self.GetFont())
         varlist = []
         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
         if vars:
@@ -1522,6 +1528,7 @@
 
     def AddNewPowerRail(self, bbox):
         dialog = LDPowerRailDialog(self.ParentWindow)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetMinSize((bbox.width, bbox.height))
         if dialog.ShowModal() == wx.ID_OK:
             id = self.GetNewId()
@@ -1539,6 +1546,7 @@
 
     def AddNewStep(self, bbox, initial = False):
         dialog = StepContentDialog(self.ParentWindow, initial)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetPouNames(self.Controler.GetProjectPouNames())
         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName))
         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
@@ -1572,6 +1580,7 @@
 
     def AddNewTransition(self, bbox):
         dialog = TransitionContentDialog(self.ParentWindow, self.GetDrawingMode() == FREEDRAWING_MODE)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName))
         if dialog.ShowModal() == wx.ID_OK:
             id = self.GetNewId()
@@ -1590,6 +1599,7 @@
 
     def AddNewDivergence(self, bbox):
         dialog = DivergenceCreateDialog(self.ParentWindow)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetMinSize((bbox.width, bbox.height))
         if dialog.ShowModal() == wx.ID_OK:
             id = self.GetNewId()
@@ -1653,6 +1663,7 @@
 
     def EditBlockContent(self, block):
         dialog = BlockPropertiesDialog(self.ParentWindow)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName))
         dialog.SetPouNames(self.Controler.GetProjectPouNames())
         variable_names = self.Controler.GetEditedElementVariables(self.TagName)
@@ -1685,6 +1696,7 @@
 
     def EditVariableContent(self, variable):
         dialog = VariablePropertiesDialog(self.ParentWindow)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetMinVariableSize(variable.GetSize())
         varlist = []
         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
@@ -1721,6 +1733,7 @@
 
     def EditConnectionContent(self, connection):
         dialog = ConnectionPropertiesDialog(self.ParentWindow)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetMinConnectionSize(connection.GetSize())
         values = {"name" : connection.GetName(), "type" : connection.GetType()}
         dialog.SetValues(values)
@@ -1744,6 +1757,7 @@
 
     def EditContactContent(self, contact):
         dialog = LDElementDialog(self.ParentWindow, "contact")
+        dialog.SetPreviewFont(self.GetFont())
         varlist = []
         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
         if vars:
@@ -1769,6 +1783,7 @@
 
     def EditCoilContent(self, coil):
         dialog = LDElementDialog(self.ParentWindow, "coil")
+        dialog.SetPreviewFont(self.GetFont())
         varlist = []
         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
         if vars:
@@ -1797,6 +1812,7 @@
 
     def EditPowerRailContent(self, powerrail):
         dialog = LDPowerRailDialog(self.ParentWindow, powerrail.GetType(), len(powerrail.GetConnectors()))
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetMinSize(powerrail.GetSize())
         if dialog.ShowModal() == wx.ID_OK:
             old_type = powerrail.GetType()
@@ -1817,6 +1833,7 @@
 
     def EditStepContent(self, step):
         dialog = StepContentDialog(self.ParentWindow, step.GetInitial())
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetPouNames(self.Controler.GetProjectPouNames())
         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName))
         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
@@ -1852,6 +1869,7 @@
         
     def EditTransitionContent(self, transition):
         dialog = TransitionContentDialog(self.ParentWindow, self.GetDrawingMode() == FREEDRAWING_MODE)
+        dialog.SetPreviewFont(self.GetFont())
         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName))
         dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()})
         dialog.SetElementSize(transition.GetSize())
--- a/graphics/FBD_Objects.py	Wed Jan 30 09:52:57 2008 +0100
+++ b/graphics/FBD_Objects.py	Wed Jan 30 18:48:05 2008 +0100
@@ -94,13 +94,11 @@
     
     # Refresh the size of text for name
     def RefreshNameSize(self):
-        dc = wx.ClientDC(self.Parent)
-        self.NameSize = dc.GetTextExtent(self.Name)
+        self.NameSize = self.Parent.GetTextExtent(self.Name)
     
     # Refresh the size of text for execution order
     def RefreshExecutionOrderSize(self):
-        dc = wx.ClientDC(self.Parent)
-        self.ExecutionOrderSize = dc.GetTextExtent(str(self.ExecutionOrder))
+        self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
     
     # Refresh the block bounding box
     def RefreshBoundingBox(self):
@@ -216,8 +214,7 @@
         if type != self.Type or self.Extension != extension: 
             if type != self.Type:
                 self.Type = type
-                dc = wx.ClientDC(self.Parent)
-                self.TypeSize = dc.GetTextExtent(self.Type)
+                self.TypeSize = self.Parent.GetTextExtent(self.Type)
             self.Extension = extension
             # Find the block definition from type given and create the corresponding
             # inputs and outputs
@@ -440,13 +437,11 @@
     
     # Refresh the size of text for name
     def RefreshNameSize(self):
-        dc = wx.ClientDC(self.Parent)
-        self.NameSize = dc.GetTextExtent(self.Name)
+        self.NameSize = self.Parent.GetTextExtent(self.Name)
     
     # Refresh the size of text for execution order
     def RefreshExecutionOrderSize(self):
-        dc = wx.ClientDC(self.Parent)
-        self.ExecutionOrderSize = dc.GetTextExtent(str(self.ExecutionOrder))
+        self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
     
     # Refresh the variable bounding box
     def RefreshBoundingBox(self):
@@ -668,8 +663,7 @@
     
     # Refresh the size of text for name
     def RefreshNameSize(self):
-        dc = wx.ClientDC(self.Parent)
-        self.NameSize = dc.GetTextExtent(self.Name)
+        self.NameSize = self.Parent.GetTextExtent(self.Name)
     
     # Refresh the connection bounding box
     def RefreshBoundingBox(self):
--- a/graphics/GraphicCommons.py	Wed Jan 30 09:52:57 2008 +0100
+++ b/graphics/GraphicCommons.py	Wed Jan 30 18:48:05 2008 +0100
@@ -488,7 +488,7 @@
                 self.Dragging = True
             # If a dragging have been initiated, refreshes the element state
             if self.Dragging:
-                dragx, dragy = self.ProcessDragging(movex, movey, scaling)
+                dragx, dragy = self.ProcessDragging(movex, movey, event.ShiftDown(), scaling)
                 self.oldPos.x += dragx
                 self.oldPos.y += dragy
                 return dragx, dragy
@@ -518,7 +518,7 @@
         self.SetSize(width, height)
     
     # Refreshes the element state according to move defined and handle selected
-    def ProcessDragging(self, movex, movey, scaling):
+    def ProcessDragging(self, movex, movey, centered, scaling):
         handle_type, handle = self.Handle
         # If it is a resize handle, calculate the values from resizing
         if handle_type == HANDLE_RESIZE:
@@ -529,21 +529,35 @@
                 if scaling is not None:
                     movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
                 x = movex
-                width -= movex
+                if centered:
+                    width -= 2 * movex
+                else:
+                    width -= movex
             elif handle[0] == 3:
                 if scaling is not None:
                     movex = round(float(self.Pos.x + width + movex) / float(scaling[0])) * scaling[0] - self.Pos.x - width
-                width += movex
+                if centered:
+                    x = -movex
+                    width += 2 * movex
+                else:
+                    width += movex
             if handle[1] == 1:
                 movey = max(-self.BoundingBox.y, movey)
                 if scaling is not None:
                     movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y
                 y = movey
-                height -= movey
+                if centered:
+                    height -= 2 * movey
+                else:
+                    height -= movey
             elif handle[1] == 3:
                 if scaling is not None:
                     movey = round(float(self.Pos.y + height + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - height
-                height += movey
+                if centered:
+                    y = -movey
+                    height += 2 * movey
+                else:
+                    height += movey
             # Verify that new size is not lesser than minimum
             min_width, min_height = self.GetMinSize()
             if handle[0] != 2 and (width >= min_width or width > self.Size[0]):
@@ -1912,7 +1926,7 @@
             return Graphic_Element.OnMotion(self, event, dc, scaling)
     
     # Refreshes the wire state according to move defined and handle selected
-    def ProcessDragging(self, movex, movey, scaling):
+    def ProcessDragging(self, movex, movey, centered, scaling):
         handle_type, handle = self.Handle
         # A point has been handled
         if handle_type == HANDLE_POINT:
@@ -1964,7 +1978,7 @@
             return self.MoveSegment(handle[0], movex, movey, scaling)
         # Execute the default method for a graphic element
         else:
-            return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
+            return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
     
     # Refreshes the wire model
     def RefreshModel(self, move=True):
--- a/graphics/LD_Objects.py	Wed Jan 30 09:52:57 2008 +0100
+++ b/graphics/LD_Objects.py	Wed Jan 30 18:48:05 2008 +0100
@@ -109,7 +109,6 @@
                 
     # Refresh the power rail bounding box
     def RefreshBoundingBox(self):
-        dc = wx.ClientDC(self.Parent)
         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
     
     # Refresh the power rail size
@@ -313,7 +312,7 @@
             self.Parent.PopupDefaultMenu()
     
     # Refreshes the powerrail state according to move defined and handle selected
-    def ProcessDragging(self, movex, movey, scaling):
+    def ProcessDragging(self, movex, movey, centered, scaling):
         handle_type, handle = self.Handle
         # A connector has been handled
         if handle_type == HANDLE_CONNECTOR:
@@ -324,7 +323,7 @@
             self.MoveConnector(handle, movey)
             return 0, movey
         else:
-            return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
+            return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
     
     # Refreshes the power rail model
     def RefreshModel(self, move=True):
@@ -416,15 +415,13 @@
     
     # Refresh the size of text for name
     def RefreshNameSize(self):
-        dc = wx.ClientDC(self.Parent)
         if self.Name != "":
-            self.NameSize = dc.GetTextExtent(self.Name)
+            self.NameSize = self.Parent.GetTextExtent(self.Name)
         else:
             self.NameSize = 0, 0
     
     # Refresh the size of text for type
     def RefreshTypeSize(self):
-        dc = wx.ClientDC(self.Parent)
         typetext = ""
         if self.Type == CONTACT_REVERSE:
             typetext = "/"
@@ -433,15 +430,14 @@
         elif self.Type == CONTACT_FALLING:
             typetext = "N"
         if typetext != "":
-            self.TypeSize = dc.GetTextExtent(typetext)
+            self.TypeSize = self.Parent.GetTextExtent(typetext)
         else:
             self.TypeSize = 0, 0
     
     # Refresh the contact bounding box
     def RefreshBoundingBox(self):
-        dc = wx.ClientDC(self.Parent)
         # Calculate the size of the name outside the contact
-        text_width, text_height = dc.GetTextExtent(self.Name)
+        text_width, text_height = self.Parent.GetTextExtent(self.Name)
         # Calculate the bounding box size
         if self.Name != "":
             bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2)
@@ -646,15 +642,13 @@
                 
     # Refresh the size of text for name
     def RefreshNameSize(self):
-        dc = wx.ClientDC(self.Parent)
         if self.Name != "":
-            self.NameSize = dc.GetTextExtent(self.Name)
+            self.NameSize = self.Parent.GetTextExtent(self.Name)
         else:
             self.NameSize = 0, 0
     
     # Refresh the size of text for type
     def RefreshTypeSize(self):
-        dc = wx.ClientDC(self.Parent)
         typetext = ""
         if self.Type == COIL_REVERSE:
             typetext = "/"
@@ -663,15 +657,14 @@
         elif self.Type == COIL_RESET:
             typetext = "R"
         if typetext != "":
-            self.TypeSize = dc.GetTextExtent(typetext)
+            self.TypeSize = self.Parent.GetTextExtent(typetext)
         else:
             self.TypeSize = 0, 0
     
     # Refresh the coil bounding box
     def RefreshBoundingBox(self):
-        dc = wx.ClientDC(self.Parent)
         # Calculate the size of the name outside the coil
-        text_width, text_height = dc.GetTextExtent(self.Name)
+        text_width, text_height = self.Parent.GetTextExtent(self.Name)
         # Calculate the bounding box size
         if self.Name != "":
             bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2)
--- a/graphics/SFC_Objects.py	Wed Jan 30 09:52:57 2008 +0100
+++ b/graphics/SFC_Objects.py	Wed Jan 30 18:48:05 2008 +0100
@@ -150,7 +150,6 @@
     
     # Refresh the step bounding box
     def RefreshBoundingBox(self):
-        dc = wx.ClientDC(self.Parent)
         # Calculate the bounding box size
         if self.Action:
             bbx_width = self.Size[0] + CONNECTOR_SIZE
@@ -290,8 +289,7 @@
     
     # Returns the step minimum size
     def GetMinSize(self):
-        dc = wx.ClientDC(self.Parent)
-        text_width, text_height = dc.GetTextExtent(self.Name)
+        text_width, text_height = self.Parent.GetTextExtent(self.Name)
         if self.Initial:
             return text_width + 14, text_height + 14
         else:
@@ -393,7 +391,7 @@
         self.Parent.PopupDefaultMenu()
     
     # Refreshes the step state according to move defined and handle selected
-    def ProcessDragging(self, movex, movey, scaling):
+    def ProcessDragging(self, movex, movey, centered, scaling):
         handle_type, handle = self.Handle
         if handle_type == HANDLE_MOVE:
             movex = max(-self.BoundingBox.x, movex)
@@ -418,7 +416,7 @@
                 self.RefreshOutputPosition()
                 return movex, 0
         else:
-            return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
+            return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
     
     # Refresh input element model
     def RefreshInputModel(self):
@@ -543,17 +541,15 @@
     # Refresh the size of text for name
     def RefreshConditionSize(self):
         if self.Type != "connection":
-            dc = wx.ClientDC(self.Parent)
             if self.Condition != "":
-                self.ConditionSize = dc.GetTextExtent(self.Condition)
+                self.ConditionSize = self.Parent.GetTextExtent(self.Condition)
             else:
-                self.ConditionSize = dc.GetTextExtent("Transition")
+                self.ConditionSize = self.Parent.GetTextExtent("Transition")
     
     # Refresh the size of text for name
     def RefreshPrioritySize(self):
         if self.Priority != "":
-            dc = wx.ClientDC(self.Parent)
-            self.PrioritySize = dc.GetTextExtent(str(self.Priority))
+            self.PrioritySize = self.Parent.GetTextExtent(str(self.Priority))
         else:
             self.PrioritySize = None
 
@@ -570,7 +566,6 @@
     
     # Refresh the transition bounding box
     def RefreshBoundingBox(self):
-        dc = wx.ClientDC(self.Parent)
         bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]
         if self.Priority != 0:
             bbx_y = self.Pos.y - self.PrioritySize[1] - 2
@@ -769,7 +764,7 @@
         self.Parent.PopupDefaultMenu()
     
     # Refreshes the transition state according to move defined and handle selected
-    def ProcessDragging(self, movex, movey, scaling):
+    def ProcessDragging(self, movex, movey, centered, scaling):
         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
             movex = max(-self.BoundingBox.x, movex)
             if scaling is not None:
@@ -779,7 +774,7 @@
             self.RefreshOutputPosition()
             return movex, 0
         else:
-            return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
+            return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
     
     # Refresh input element model
     def RefreshInputModel(self):
@@ -1196,7 +1191,7 @@
                 self.Parent.PopupDivergenceMenu(False)
     
     # Refreshes the divergence state according to move defined and handle selected
-    def ProcessDragging(self, movex, movey, scaling):
+    def ProcessDragging(self, movex, movey, centered, scaling):
         handle_type, handle = self.Handle
         # A connector has been handled
         if handle_type == HANDLE_CONNECTOR:
@@ -1208,7 +1203,7 @@
                 self.RefreshConnectedPosition(handle)
             return movex, 0
         elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
-            return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
+            return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
         return 0, 0
     
     # Refresh output element model
@@ -1329,8 +1324,7 @@
     
     # Refresh the jump bounding box
     def RefreshBoundingBox(self):
-        dc = wx.ClientDC(self.Parent)
-        text_width, text_height = dc.GetTextExtent(self.Target)
+        text_width, text_height = self.Parent.GetTextExtent(self.Target)
         # Calculate the bounding box size
         bbx_width = self.Size[0] + 2 + text_width
         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, 
@@ -1413,7 +1407,7 @@
         self.Parent.PopupDefaultMenu()
     
     # Refreshes the jump state according to move defined and handle selected
-    def ProcessDragging(self, movex, movey, scaling):
+    def ProcessDragging(self, movex, movey, centered, scaling):
         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
             movex = max(-self.BoundingBox.x, movex)
             if scaling is not None:
@@ -1422,7 +1416,7 @@
             self.RefreshInputPosition()
             return movex, 0
         else:
-            return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
+            return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
     
     # Refresh input element model
     def RefreshInputModel(self):
@@ -1575,23 +1569,22 @@
     
     # Changes the action block actions
     def SetActions(self, actions):
-        dc = wx.ClientDC(self.Parent)
         self.Actions = actions
         self.ColSize = [0, 0, 0]
         min_height = 0
         for action in self.Actions:
-            width, height = dc.GetTextExtent(action["qualifier"])
+            width, height = self.Parent.GetTextExtent(action["qualifier"])
             self.ColSize[0] = max(self.ColSize[0], width + 10)
             row_height = height
             if "duration" in action:
-                width, height = dc.GetTextExtent(action["duration"])
+                width, height = self.Parent.GetTextExtent(action["duration"])
                 row_height = max(row_height, height)
                 self.ColSize[0] = max(self.ColSize[0], width + 10)
-            width, height = dc.GetTextExtent(action["value"])
+            width, height = self.Parent.GetTextExtent(action["value"])
             row_height = max(row_height, height)
             self.ColSize[1] = max(self.ColSize[1], width + 10)
             if "indicator" in action and action["indicator"] != "":
-                width, height = dc.GetTextExtent(action["indicator"])
+                width, height = self.Parent.GetTextExtent(action["indicator"])
                 row_height = max(row_height, height)
                 self.ColSize[2] = max(self.ColSize[2], width + 10)
             min_height += row_height + 5
@@ -1632,7 +1625,7 @@
         self.Parent.PopupDefaultMenu()
     
     # Refreshes the action block state according to move defined and handle selected
-    def ProcessDragging(self, movex, movey, scaling):
+    def ProcessDragging(self, movex, movey, centered, scaling):
         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
             handle_type, handle = self.Handle
             if handle_type == HANDLE_MOVE:
@@ -1647,9 +1640,9 @@
                         return movex, 0
                 return 0, 0
             else:
-                return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
-        else:
-            return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
+                return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
+        else:
+            return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
 
     
    # Refreshes the action block model