Added "runtime.py", a file that is executed in python thread in runtime, before handling python_eval FBs requests. Added small python editor taken from wxPython demo, and appropriate icon and button to launch it.
authoretisserant
Tue, 30 Dec 2008 22:43:48 +0100
changeset 283 d0e6fc0701fb
parent 282 2221e99d2f8f
child 284 3fecc96090c8
Added "runtime.py", a file that is executed in python thread in runtime, before handling python_eval FBs requests. Added small python editor taken from wxPython demo, and appropriate icon and button to launch it.
PythonSTC.py
images/editPYTHONcode.png
images/icons.svg
plugger.py
runtime/PLCObject.py
tests/python/plc.xml
tests/python/runtime.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PythonSTC.py	Tue Dec 30 22:43:48 2008 +0100
@@ -0,0 +1,595 @@
+import  keyword
+import  os
+import  wx
+import  wx.stc  as  stc
+
+#----------------------------------------------------------------------
+
+"""
+This Python editor class comes from the wxPython demo, a bit tweaked
+"""
+
+#----------------------------------------------------------------------
+
+
+if wx.Platform == '__WXMSW__':
+    faces = { 'times': 'Times New Roman',
+              'mono' : 'Courier New',
+              'helv' : 'Arial',
+              'other': 'Comic Sans MS',
+              'size' : 10,
+              'size2': 8,
+             }
+elif wx.Platform == '__WXMAC__':
+    faces = { 'times': 'Times New Roman',
+              'mono' : 'Monaco',
+              'helv' : 'Arial',
+              'other': 'Comic Sans MS',
+              'size' : 12,
+              'size2': 10,
+             }
+else:
+    faces = { 'times': 'Times',
+              'mono' : 'Courier',
+              'helv' : 'Helvetica',
+              'other': 'new century schoolbook',
+              'size' : 12,
+              'size2': 10,
+             }
+
+
+#----------------------------------------------------------------------
+
+class PythonSTC(stc.StyledTextCtrl):
+
+    fold_symbols = 2
+    
+    def __init__(self, parent, ID,
+                 pos=wx.DefaultPosition, size=wx.DefaultSize,
+                 style=0):
+        stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
+
+        self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
+        self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
+
+        self.SetLexer(stc.STC_LEX_PYTHON)
+        self.SetKeyWords(0, " ".join(keyword.kwlist))
+
+        self.SetProperty("fold", "1")
+        self.SetProperty("tab.timmy.whinge.level", "1")
+        self.SetMargins(0,0)
+
+        self.SetViewWhiteSpace(False)
+        #self.SetBufferedDraw(False)
+        #self.SetViewEOL(True)
+        #self.SetEOLMode(stc.STC_EOL_CRLF)
+        #self.SetUseAntiAliasing(True)
+        
+        self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
+        self.SetEdgeColumn(78)
+
+        # Setup a margin to hold fold markers
+        #self.SetFoldFlags(16)  ###  WHAT IS THIS VALUE?  WHAT ARE THE OTHER FLAGS?  DOES IT MATTER?
+        self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
+        self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
+        self.SetMarginSensitive(2, True)
+        self.SetMarginWidth(2, 12)
+
+        if self.fold_symbols == 0:
+            # Arrow pointing right for contracted folders, arrow pointing down for expanded
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_ARROWDOWN, "black", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_ARROW, "black", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "black", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "black", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY,     "white", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY,     "white", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY,     "white", "black")
+            
+        elif self.fold_symbols == 1:
+            # Plus for contracted folders, minus for expanded
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_MINUS, "white", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_PLUS,  "white", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "white", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "white", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY, "white", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
+
+        elif self.fold_symbols == 2:
+            # Like a flattened tree control using circular headers and curved joins
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_CIRCLEMINUS,          "white", "#404040")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_CIRCLEPLUS,           "white", "#404040")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,                "white", "#404040")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNERCURVE,         "white", "#404040")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_CIRCLEPLUSCONNECTED,  "white", "#404040")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE,         "white", "#404040")
+
+        elif self.fold_symbols == 3:
+            # Like a flattened tree control using square headers
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS,          "white", "#808080")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,           "white", "#808080")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,             "white", "#808080")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,           "white", "#808080")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
+            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,           "white", "#808080")
+
+
+        self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
+        self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
+        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
+
+        # Make some styles,  The lexer defines what each style is used for, we
+        # just have to define what each style looks like.  This set is adapted from
+        # Scintilla sample property files.
+
+        # Global default styles for all languages
+        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d" % faces)
+        self.StyleClearAll()  # Reset all to be like the default
+
+        # Global default styles for all languages
+        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d" % faces)
+        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
+        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
+        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
+        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")
+
+        # Python styles
+        # Default 
+        self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
+        # Comments
+        self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
+        # Number
+        self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
+        # String
+        self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
+        # Single quoted string
+        self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
+        # Keyword
+        self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
+        # Triple quotes
+        self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
+        # Triple double quotes
+        self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
+        # Class name definition
+        self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
+        # Function or method name definition
+        self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
+        # Operators
+        self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
+        # Identifiers
+        self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
+        # Comment-blocks
+        self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
+        # End of line where string is not closed
+        self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
+
+        self.SetCaretForeground("BLUE")
+
+    def OnKeyPressed(self, event):
+        if self.CallTipActive():
+            self.CallTipCancel()
+
+        event.Skip()
+## For later use
+#        key = event.GetKeyCode()
+#        if key == 32 and event.ControlDown():
+#            pos = self.GetCurrentPos()
+#
+#            # Tips
+#            if event.ShiftDown():
+#                self.CallTipSetBackground("yellow")
+#                self.CallTipShow(pos, 'lots of of text: blah, blah, blah\n\n'
+#                                 'show some suff, maybe parameters..\n\n'
+#                                 'fubar(param1, param2)')
+#            # Code completion
+#            else:
+#                #lst = []
+#                #for x in range(50000):
+#                #    lst.append('%05d' % x)
+#                #st = " ".join(lst)
+#                #print len(st)
+#                #self.AutoCompShow(0, st)
+#
+#                kw = keyword.kwlist[:]
+#                kw.append("zzzzzz?2")
+#                kw.append("aaaaa?2")
+#                kw.append("__init__?3")
+#                kw.append("zzaaaaa?2")
+#                kw.append("zzbaaaa?2")
+#                kw.append("this_is_a_longer_value")
+#                #kw.append("this_is_a_much_much_much_much_much_much_much_longer_value")
+#
+#                kw.sort()  # Python sorts are case sensitive
+#                self.AutoCompSetIgnoreCase(False)  # so this needs to match
+#
+#                # Images are specified with a appended "?type"
+#                for i in range(len(kw)):
+#                    if kw[i] in keyword.kwlist:
+#                        kw[i] = kw[i] + "?1"
+#
+#                self.AutoCompShow(0, " ".join(kw))
+#        else:
+#            event.Skip()
+
+
+    def OnUpdateUI(self, evt):
+        # check for matching braces
+        braceAtCaret = -1
+        braceOpposite = -1
+        charBefore = None
+        caretPos = self.GetCurrentPos()
+
+        if caretPos > 0:
+            charBefore = self.GetCharAt(caretPos - 1)
+            styleBefore = self.GetStyleAt(caretPos - 1)
+
+        # check before
+        if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
+            braceAtCaret = caretPos - 1
+
+        # check after
+        if braceAtCaret < 0:
+            charAfter = self.GetCharAt(caretPos)
+            styleAfter = self.GetStyleAt(caretPos)
+
+            if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
+                braceAtCaret = caretPos
+
+        if braceAtCaret >= 0:
+            braceOpposite = self.BraceMatch(braceAtCaret)
+
+        if braceAtCaret != -1  and braceOpposite == -1:
+            self.BraceBadLight(braceAtCaret)
+        else:
+            self.BraceHighlight(braceAtCaret, braceOpposite)
+            #pt = self.PointFromPosition(braceOpposite)
+            #self.Refresh(True, wxRect(pt.x, pt.y, 5,5))
+            #print pt
+            #self.Refresh(False)
+
+
+    def OnMarginClick(self, evt):
+        # fold and unfold as needed
+        if evt.GetMargin() == 2:
+            if evt.GetShift() and evt.GetControl():
+                self.FoldAll()
+            else:
+                lineClicked = self.LineFromPosition(evt.GetPosition())
+
+                if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
+                    if evt.GetShift():
+                        self.SetFoldExpanded(lineClicked, True)
+                        self.Expand(lineClicked, True, True, 1)
+                    elif evt.GetControl():
+                        if self.GetFoldExpanded(lineClicked):
+                            self.SetFoldExpanded(lineClicked, False)
+                            self.Expand(lineClicked, False, True, 0)
+                        else:
+                            self.SetFoldExpanded(lineClicked, True)
+                            self.Expand(lineClicked, True, True, 100)
+                    else:
+                        self.ToggleFold(lineClicked)
+
+
+    def FoldAll(self):
+        lineCount = self.GetLineCount()
+        expanding = True
+
+        # find out if we are folding or unfolding
+        for lineNum in range(lineCount):
+            if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
+                expanding = not self.GetFoldExpanded(lineNum)
+                break
+
+        lineNum = 0
+
+        while lineNum < lineCount:
+            level = self.GetFoldLevel(lineNum)
+            if level & stc.STC_FOLDLEVELHEADERFLAG and \
+               (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
+
+                if expanding:
+                    self.SetFoldExpanded(lineNum, True)
+                    lineNum = self.Expand(lineNum, True)
+                    lineNum = lineNum - 1
+                else:
+                    lastChild = self.GetLastChild(lineNum, -1)
+                    self.SetFoldExpanded(lineNum, False)
+
+                    if lastChild > lineNum:
+                        self.HideLines(lineNum+1, lastChild)
+
+            lineNum = lineNum + 1
+
+
+
+    def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
+        lastChild = self.GetLastChild(line, level)
+        line = line + 1
+
+        while line <= lastChild:
+            if force:
+                if visLevels > 0:
+                    self.ShowLines(line, line)
+                else:
+                    self.HideLines(line, line)
+            else:
+                if doExpand:
+                    self.ShowLines(line, line)
+
+            if level == -1:
+                level = self.GetFoldLevel(line)
+
+            if level & stc.STC_FOLDLEVELHEADERFLAG:
+                if force:
+                    if visLevels > 1:
+                        self.SetFoldExpanded(line, True)
+                    else:
+                        self.SetFoldExpanded(line, False)
+
+                    line = self.Expand(line, doExpand, force, visLevels-1)
+
+                else:
+                    if doExpand and self.GetFoldExpanded(line):
+                        line = self.Expand(line, True, force, visLevels-1)
+                    else:
+                        line = self.Expand(line, False, force, visLevels-1)
+            else:
+                line = line + 1
+
+        return line
+
+
+#----------------------------------------------------------------------
+class PythonCodeEditor(PythonSTC):
+    def __init__(self, parent):
+        PythonSTC.__init__(self, parent, -1, style=wx.BORDER_NONE)
+        self.SetUpEditor()
+
+    # Some methods to make it compatible with how the wxTextCtrl is used
+    def SetValue(self, value):
+        if wx.USE_UNICODE:
+            value = value.decode('iso8859_1')
+        self.SetText(value)
+        self.EmptyUndoBuffer()
+        self.SetSavePoint()
+
+    def IsModified(self):
+        return self.GetModify()
+
+    def Clear(self):
+        self.ClearAll()
+
+    def SetInsertionPoint(self, pos):
+        self.SetCurrentPos(pos)
+        self.SetAnchor(pos)
+
+    def ShowPosition(self, pos):
+        line = self.LineFromPosition(pos)
+        #self.EnsureVisible(line)
+        self.GotoLine(line)
+
+    def GetLastPosition(self):
+        return self.GetLength()
+
+    def GetPositionFromLine(self, line):
+        return self.PositionFromLine(line)
+
+    def GetRange(self, start, end):
+        return self.GetTextRange(start, end)
+
+    def GetSelection(self):
+        return self.GetAnchor(), self.GetCurrentPos()
+
+    def SetSelection(self, start, end):
+        self.SetSelectionStart(start)
+        self.SetSelectionEnd(end)
+
+    def SelectLine(self, line):
+        start = self.PositionFromLine(line)
+        end = self.GetLineEndPosition(line)
+        self.SetSelection(start, end)
+        
+    def SetUpEditor(self):
+        """
+        This method carries out the work of setting up the demo editor.            
+        It's seperate so as not to clutter up the init code.
+        """
+        import keyword
+        
+        self.SetLexer(stc.STC_LEX_PYTHON)
+        self.SetKeyWords(0, " ".join(keyword.kwlist))
+
+        # Enable folding
+        self.SetProperty("fold", "1" ) 
+
+        # Highlight tab/space mixing (shouldn't be any)
+        self.SetProperty("tab.timmy.whinge.level", "1")
+
+        # Set left and right margins
+        self.SetMargins(2,2)
+
+        # Set up the numbers in the margin for margin #1
+        self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
+        # Reasonable value for, say, 4-5 digits using a mono font (40 pix)
+        self.SetMarginWidth(1, 40)
+
+        # Indentation and tab stuff
+        self.SetIndent(4)               # Proscribed indent size for wx
+        self.SetIndentationGuides(True) # Show indent guides
+        self.SetBackSpaceUnIndents(True)# Backspace unindents rather than delete 1 space
+        self.SetTabIndents(True)        # Tab key indents
+        self.SetTabWidth(4)             # Proscribed tab size for wx
+        self.SetUseTabs(False)          # Use spaces rather than tabs, or
+                                        # TabTimmy will complain!    
+        # White space
+        self.SetViewWhiteSpace(False)   # Don't view white space
+
+        # EOL: Since we are loading/saving ourselves, and the
+        # strings will always have \n's in them, set the STC to
+        # edit them that way.            
+        self.SetEOLMode(wx.stc.STC_EOL_LF)
+        self.SetViewEOL(False)
+        
+        # No right-edge mode indicator
+        self.SetEdgeMode(stc.STC_EDGE_NONE)
+
+        # Setup a margin to hold fold markers
+        self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
+        self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
+        self.SetMarginSensitive(2, True)
+        self.SetMarginWidth(2, 12)
+
+        # and now set up the fold markers
+        self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "black")
+        self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "black")
+        self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,  "white", "black")
+        self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,  "white", "black")
+        self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,    "white", "black")
+        self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,  "white", "black")
+        self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS, "white", "black")
+
+        # Global default style
+        if wx.Platform == '__WXMSW__':
+            self.StyleSetSpec(stc.STC_STYLE_DEFAULT, 
+                              'fore:#000000,back:#FFFFFF,face:Courier New')
+        elif wx.Platform == '__WXMAC__':
+            # TODO: if this looks fine on Linux too, remove the Mac-specific case 
+            # and use this whenever OS != MSW.
+            self.StyleSetSpec(stc.STC_STYLE_DEFAULT, 
+                              'fore:#000000,back:#FFFFFF,face:Monaco')
+        else:
+            defsize = wx.SystemSettings.GetFont(wx.SYS_ANSI_FIXED_FONT).GetPointSize()
+            self.StyleSetSpec(stc.STC_STYLE_DEFAULT, 
+                              'fore:#000000,back:#FFFFFF,face:Courier,size:%d'%defsize)
+
+        # Clear styles and revert to default.
+        self.StyleClearAll()
+
+        # Following style specs only indicate differences from default.
+        # The rest remains unchanged.
+
+        # Line numbers in margin
+        self.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,'fore:#000000,back:#99A9C2')    
+        # Highlighted brace
+        self.StyleSetSpec(wx.stc.STC_STYLE_BRACELIGHT,'fore:#00009D,back:#FFFF00')
+        # Unmatched brace
+        self.StyleSetSpec(wx.stc.STC_STYLE_BRACEBAD,'fore:#00009D,back:#FF0000')
+        # Indentation guide
+        self.StyleSetSpec(wx.stc.STC_STYLE_INDENTGUIDE, "fore:#CDCDCD")
+
+        # Python styles
+        self.StyleSetSpec(wx.stc.STC_P_DEFAULT, 'fore:#000000')
+        # Comments
+        self.StyleSetSpec(wx.stc.STC_P_COMMENTLINE,  'fore:#008000,back:#F0FFF0')
+        self.StyleSetSpec(wx.stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0')
+        # Numbers
+        self.StyleSetSpec(wx.stc.STC_P_NUMBER, 'fore:#008080')
+        # Strings and characters
+        self.StyleSetSpec(wx.stc.STC_P_STRING, 'fore:#800080')
+        self.StyleSetSpec(wx.stc.STC_P_CHARACTER, 'fore:#800080')
+        # Keywords
+        self.StyleSetSpec(wx.stc.STC_P_WORD, 'fore:#000080,bold')
+        # Triple quotes
+        self.StyleSetSpec(wx.stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA')
+        self.StyleSetSpec(wx.stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA')
+        # Class names
+        self.StyleSetSpec(wx.stc.STC_P_CLASSNAME, 'fore:#0000FF,bold')
+        # Function names
+        self.StyleSetSpec(wx.stc.STC_P_DEFNAME, 'fore:#008080,bold')
+        # Operators
+        self.StyleSetSpec(wx.stc.STC_P_OPERATOR, 'fore:#800000,bold')
+        # Identifiers. I leave this as not bold because everything seems
+        # to be an identifier if it doesn't match the above criterae
+        self.StyleSetSpec(wx.stc.STC_P_IDENTIFIER, 'fore:#000000')
+
+        # Caret color
+        self.SetCaretForeground("BLUE")
+        # Selection background
+        self.SetSelBackground(1, '#66CCFF')
+
+        self.SetSelBackground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT))
+        self.SetSelForeground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT))
+
+    def RegisterModifiedEvent(self, eventHandler):
+        self.Bind(wx.stc.EVT_STC_CHANGE, eventHandler)
+
+
+class PythonCodePanel(wx.Panel):
+    """Panel for the 'Demo Code' tab"""
+    def __init__(self, parent, mainFrame):
+        wx.Panel.__init__(self, parent, size=(1,1))
+        if 'wxMSW' in wx.PlatformInfo:
+            self.Hide()
+        self.mainFrame = mainFrame
+        self.editor = PythonCodeEditor(self)
+        self.editor.RegisterModifiedEvent(self.OnCodeModified)
+
+        self.btnSave = wx.Button(self, -1, "Save")
+        self.btnRestore = wx.Button(self, -1, "Restore")
+        self.btnSave.Enable(False)
+        self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
+        self.btnRestore.Bind(wx.EVT_BUTTON, self.OnRestore)
+
+        self.controlBox = wx.BoxSizer(wx.HORIZONTAL)
+        self.controlBox.Add(self.btnSave, 0, wx.RIGHT, 5)
+        self.controlBox.Add(self.btnRestore, 0)
+
+        self.box = wx.BoxSizer(wx.VERTICAL)
+        self.box.Add(self.controlBox, 0, wx.EXPAND)
+        self.box.Add(wx.StaticLine(self), 0, wx.EXPAND)
+        self.box.Add(self.editor, 1, wx.EXPAND)
+        
+        self.box.Fit(self)
+        self.SetSizer(self.box)
+        
+        self.sourceFile = None
+
+
+    # Loads from a file object
+    def LoadSourceFile(self, filename):
+        self.sourceFile = filename
+        if os.path.exists(filename):
+            self.LoadSource(file(filename).read())
+
+    def LoadSource(self, source):
+        self.editor.Clear()
+        self.editor.SetValue(source)
+        self.JumpToLine(0)
+        self.btnSave.Enable(False)
+
+    def JumpToLine(self, line, highlight=False):
+        self.editor.GotoLine(line)
+        self.editor.SetFocus()
+        if highlight:
+            self.editor.SelectLine(line)
+                    
+    def OnCodeModified(self, event):
+        self.btnSave.Enable(self.editor.IsModified())
+        # TODO : add callback
+        
+    def OnSave(self, event):
+        overwriteMsg = "You are about to overwrite that file\n" + \
+                       "Do you want to continue?"
+        dlg = wx.MessageDialog(self, overwriteMsg, "wxPython Demo",
+                               wx.YES_NO | wx.NO_DEFAULT| wx.ICON_EXCLAMATION)
+        result = dlg.ShowModal()
+        if result == wx.ID_NO:
+            return
+        dlg.Destroy()
+
+        source = self.editor.GetText()
+
+        f = file(self.sourceFile, "w")
+        f.write(source)
+        f.close()
+         
+        # TODO
+        #self.mainFrame.SetTreeModified(True)
+
+
+    def OnRestore(self, event):
+        self.LoadSourceFile(self.sourceFile)
+        self.btnSave.Enable(self.editor.IsModified())
Binary file images/editPYTHONcode.png has changed
--- a/images/icons.svg	Wed Dec 24 00:02:12 2008 +0100
+++ b/images/icons.svg	Tue Dec 30 22:43:48 2008 +0100
@@ -29,8 +29,8 @@
     </rdf:RDF>
   </metadata>
   <sodipodi:namedview
-     inkscape:window-height="945"
-     inkscape:window-width="1270"
+     inkscape:window-height="975"
+     inkscape:window-width="1680"
      inkscape:pageshadow="2"
      inkscape:pageopacity="0.0"
      guidetolerance="10.0"
@@ -41,9 +41,9 @@
      pagecolor="#ffffff"
      id="base"
      showgrid="false"
-     inkscape:zoom="2.828427"
-     inkscape:cx="16.327355"
-     inkscape:cy="437.51409"
+     inkscape:zoom="5.656854"
+     inkscape:cx="241.82787"
+     inkscape:cy="888.09651"
      inkscape:window-x="0"
      inkscape:window-y="25"
      inkscape:current-layer="svg2"
@@ -82634,7 +82634,7 @@
        y2="144.96741"
        gradientUnits="userSpaceOnUse"
        spreadMethod="reflect"
-       gradientTransform="translate(60,0)" />
+       gradientTransform="translate(170,0)" />
     <linearGradient
        inkscape:collect="always"
        xlink:href="#linearGradient17526"
@@ -82645,7 +82645,7 @@
        y2="144.96741"
        gradientUnits="userSpaceOnUse"
        spreadMethod="reflect"
-       gradientTransform="translate(60,0)" />
+       gradientTransform="translate(170,0)" />
     <linearGradient
        inkscape:collect="always"
        xlink:href="#linearGradient17526"
@@ -82656,7 +82656,7 @@
        y2="144.96741"
        gradientUnits="userSpaceOnUse"
        spreadMethod="reflect"
-       gradientTransform="translate(60,0)" />
+       gradientTransform="translate(170,0)" />
     <linearGradient
        inkscape:collect="always"
        xlink:href="#linearGradient17526"
@@ -82666,7 +82666,8 @@
        x1="335"
        y1="137.36218"
        x2="335"
-       y2="144.96741" />
+       y2="144.96741"
+       gradientTransform="translate(110,0)" />
     <linearGradient
        inkscape:collect="always"
        xlink:href="#linearGradient17546"
@@ -82696,6 +82697,162 @@
        x2="349.32599"
        y2="86.359415"
        gradientUnits="userSpaceOnUse" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient34137"
+       id="linearGradient16525"
+       gradientUnits="userSpaceOnUse"
+       x1="-77.844841"
+       y1="5.1423945"
+       x2="-77.844841"
+       y2="14.276564" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient34137"
+       id="linearGradient16527"
+       gradientUnits="userSpaceOnUse"
+       x1="-77.844841"
+       y1="5.1423945"
+       x2="-77.844841"
+       y2="14.276564" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient1908"
+       id="linearGradient16529"
+       gradientUnits="userSpaceOnUse"
+       x1="-84.232422"
+       y1="10.337565"
+       x2="-71.603516"
+       y2="10.337565" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient34137"
+       id="linearGradient16531"
+       gradientUnits="userSpaceOnUse"
+       x1="-77.844841"
+       y1="5.1423945"
+       x2="-77.844841"
+       y2="14.276564" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient34137"
+       id="linearGradient16533"
+       gradientUnits="userSpaceOnUse"
+       x1="-77.844841"
+       y1="5.1423945"
+       x2="-77.844841"
+       y2="14.276564" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3256"
+       id="linearGradient16535"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="scale(1.044357,0.957527)"
+       x1="591.27606"
+       y1="330.16998"
+       x2="620.33301"
+       y2="382.54678" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient5083"
+       id="linearGradient16537"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(0.1929605,-4.2624229e-3,5.8523266e-3,0.1786386,680.44209,227.41631)"
+       x1="566.74347"
+       y1="415.15009"
+       x2="588.13922"
+       y2="458.04449" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2345"
+       id="linearGradient16539"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(-8.3139607e-2,-3.7222758e-2,-3.2434452e-2,9.3494299e-2,693.52705,270.28905)"
+       x1="100.76616"
+       y1="77.379333"
+       x2="125.25793"
+       y2="77.379333" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient1930"
+       id="linearGradient16541"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(-7.8190371e-2,-3.5007179e-2,-3.4487422e-2,9.9412027e-2,684.96091,272.7873)"
+       x1="10.145814"
+       y1="21.762129"
+       x2="19.678274"
+       y2="15.811033" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2355"
+       id="linearGradient16543"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(-9.5227098e-3,-1.5294307e-3,-0.8372982,1.5053504,699.75234,263.84813)"
+       x1="1270.3132"
+       y1="4.8765283"
+       x2="1247.6848"
+       y2="0.72310239" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3970"
+       id="linearGradient16545"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(0.2028254,-4.4803884e-3,5.5677069e-3,0.1699505,680.44209,227.41631)"
+       x1="-94.151642"
+       y1="379.97745"
+       x2="-100.40970"
+       y2="374.03232" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2560"
+       id="linearGradient16547"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(-0.1217387,-1.9552238e-2,-6.5495488e-2,0.1177522,699.8779,263.8683)"
+       spreadMethod="reflect"
+       x1="97.345161"
+       y1="112.84396"
+       x2="99.206970"
+       y2="115.81121" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2560"
+       id="linearGradient16549"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(0.1839072,-4.062449e-3,6.1404966e-3,0.1874324,680.55604,227.23529)"
+       x1="-13.150850"
+       y1="250.48668"
+       x2="-5.5906620"
+       y2="258.31036" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient1884"
+       id="linearGradient16551"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(-8.7438501e-2,-1.4043452e-2,-9.118816e-2,0.1639442,699.8779,263.8683)"
+       x1="240.97612"
+       y1="200.61511"
+       x2="231.89941"
+       y2="205.45764" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient1884"
+       id="linearGradient16553"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(0.2064601,-4.5604396e-3,5.0398802e-3,0.1538412,680.41644,232.74127)"
+       x1="7.1050277"
+       y1="221.98289"
+       x2="46.488174"
+       y2="259.94464" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient1884"
+       id="linearGradient16555"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(0.2064601,-4.5604396e-3,5.0398802e-3,0.1538412,682.71501,230.6378)"
+       x1="7.1050277"
+       y1="221.98289"
+       x2="46.488174"
+       y2="259.94464" />
   </defs>
   <g
      id="g19063"
@@ -85260,7 +85417,7 @@
        sodipodi:role="line"
        id="tspan16268"
        x="113.29593"
-       y="121.52582">%% editIECrawcode EditCfile Transfer Connect Disconnect Debug %%</tspan></text>
+       y="121.52582">%% editIECrawcode editPYTHONcode EditCfile Transfer Connect Disconnect Debug %%</tspan></text>
   <rect
      width="24"
      height="24"
@@ -85484,11 +85641,11 @@
      style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
      id="EditCfile"
      y="131.36218"
-     x="260"
+     x="370"
      height="24"
      width="24" />
   <g
-     transform="translate(-400.13257,-140)"
+     transform="translate(-290.13257,-140)"
      id="g20864">
     <flowRoot
        style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:url(#linearGradient20956);fill-opacity:1;stroke:#547c1b;stroke-width:0.1061436;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;font-family:Andale Mono"
@@ -85709,7 +85866,7 @@
   <rect
      width="24"
      height="24"
-     x="320"
+     x="430"
      y="131.36218"
      id="Transfer"
      style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
@@ -85719,32 +85876,32 @@
      style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
      id="Connect"
      y="131.36218"
-     x="380"
+     x="490"
      height="24"
      width="24" />
   <rect
      width="24"
      height="24"
-     x="440"
+     x="550"
      y="131.36218"
      id="Disconnect"
      style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
      inkscape:label="#rect16270" />
   <path
      style="opacity:1;fill:url(#linearGradient17534);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:8.59499931;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-     d="M 392,137.40625 C 388.95578,137.61016 386.40951,139.60837 385.4375,142.375 L 380,142.375 L 380,147.375 L 385.4375,147.375 C 386.41696,150.12787 388.96436,152.1385 392,152.34375 L 392,137.40625 z M 393,137.40625 L 393,152.34375 C 396.03564,152.1385 398.58304,150.12787 399.5625,147.375 L 404,147.375 L 404,142.375 L 399.5625,142.375 C 398.59049,139.60837 396.04422,137.61016 393,137.40625 z"
+     d="M 502,137.40625 C 498.95578,137.61016 496.40951,139.60837 495.4375,142.375 L 490,142.375 L 490,147.375 L 495.4375,147.375 C 496.41696,150.12787 498.96436,152.1385 502,152.34375 L 502,137.40625 z M 503,137.40625 L 503,152.34375 C 506.03564,152.1385 508.58304,150.12787 509.5625,147.375 L 514,147.375 L 514,142.375 L 509.5625,142.375 C 508.59049,139.60837 506.04422,137.61016 503,137.40625 z"
      id="path16742" />
   <path
      style="opacity:1;fill:url(#linearGradient17532);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:8.59499931;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-     d="M 448,137.40625 C 444.95578,137.61016 442.40951,139.60837 441.4375,142.375 L 436,142.375 L 436,147.375 L 441.4375,147.375 C 442.41696,150.12787 444.96436,152.1385 448,152.34375 L 448,137.40625 z"
+     d="M 558,137.40625 C 554.95578,137.61016 552.40951,139.60837 551.4375,142.375 L 546,142.375 L 546,147.375 L 551.4375,147.375 C 552.41696,150.12787 554.96436,152.1385 558,152.34375 L 558,137.40625 z"
      id="path16754" />
   <path
      style="opacity:1;fill:url(#linearGradient17536);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:8.59499931;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-     d="M 456,137.42468 L 456,152.36218 C 459.03564,152.15693 461.58304,150.1463 462.5625,147.39343 L 467,147.39343 L 467,142.39343 L 462.5625,142.39343 C 461.59049,139.6268 459.04422,137.62859 456,137.42468 z"
+     d="M 566,137.42468 L 566,152.36218 C 569.03564,152.15693 571.58304,150.1463 572.5625,147.39343 L 577,147.39343 L 577,142.39343 L 572.5625,142.39343 C 571.59049,139.6268 569.04422,137.62859 566,137.42468 z"
      id="path16750" />
   <path
      id="path17538"
-     d="M 332,137.40625 C 328.95578,137.61016 326.40951,139.60837 325.4375,142.375 L 320,142.375 L 320,147.375 L 325.4375,147.375 C 326.41696,150.12787 328.96436,152.1385 332,152.34375 L 332,137.40625 z M 333,137.40625 L 333,152.34375 C 336.03564,152.1385 338.58304,150.12787 339.5625,147.375 L 344,147.375 L 344,142.375 L 339.5625,142.375 C 338.59049,139.60837 336.04422,137.61016 333,137.40625 z"
+     d="M 442,137.40625 C 438.95578,137.61016 436.40951,139.60837 435.4375,142.375 L 430,142.375 L 430,147.375 L 435.4375,147.375 C 436.41696,150.12787 438.96436,152.1385 442,152.34375 L 442,137.40625 z M 443,137.40625 L 443,152.34375 C 446.03564,152.1385 448.58304,150.12787 449.5625,147.375 L 454,147.375 L 454,142.375 L 449.5625,142.375 C 448.59049,139.60837 446.04422,137.61016 443,137.40625 z"
      style="opacity:1;fill:url(#linearGradient17540);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:8.59499931;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
   <path
      sodipodi:type="star"
@@ -85761,18 +85918,18 @@
      inkscape:rounded="0"
      inkscape:randomized="0"
      d="M 332,150 L 327.11751,141.54327 L 336.88249,141.54327 L 332,150 z"
-     transform="matrix(1.1031299,0.6368924,-0.6368924,1.1031299,58.022874,-226.14748)" />
+     transform="matrix(1.1031299,0.6368924,-0.6368924,1.1031299,168.02287,-226.14748)" />
   <rect
      inkscape:label="#rect16270"
      style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
      id="Debug"
      y="131.36218"
-     x="500"
+     x="610"
      height="24"
      width="24" />
   <path
      style="opacity:1;fill:#160379;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-     d="M 514.14211,134.18201 L 513.44846,134.37119 L 514.09481,136.75167 C 513.55664,136.88976 513.034,137.15037 512.61293,137.57144 C 512.58031,137.60404 512.56503,137.64813 512.53409,137.68179 C 511.78169,137.61864 511.00589,137.70771 510.24821,137.94979 L 509.60186,135.53777 L 508.90819,135.72696 L 509.5861,138.20203 C 508.90904,138.50465 508.25523,138.92751 507.67856,139.47899 L 505.51876,138.13898 L 505.15618,138.7538 L 507.18983,139.99922 C 506.46851,140.85118 505.98679,141.84216 505.771,142.83687 L 503.56394,142.23781 L 503.37475,142.93146 L 505.67641,143.56206 C 505.54986,144.9582 505.92466,146.33767 506.82724,147.39291 L 514.37857,139.84157 L 514.88305,140.34605 L 507.33172,147.89738 C 508.2984,148.72357 509.54404,149.1165 510.81574,149.07974 L 511.28869,150.84539 L 511.98234,150.65621 L 511.54092,149.01668 C 512.59832,148.85042 513.66579,148.38127 514.58351,147.64515 L 515.46634,149.06397 L 516.08117,148.70138 L 515.13529,147.15642 C 515.82639,146.46532 516.32697,145.65819 516.64871,144.82323 L 518.49319,145.31195 L 518.68237,144.6183 L 516.86941,144.1296 C 517.03506,143.48333 517.09629,142.82751 517.04282,142.19052 C 517.07648,142.15959 517.12057,142.14431 517.15319,142.11171 C 517.57426,141.69063 517.83486,141.16798 517.97296,140.6298 L 520.35344,141.27617 L 520.54262,140.58251 L 518.08331,139.92038 C 518.10481,139.07152 517.80055,138.21881 517.15319,137.57144 C 516.50581,136.92407 515.6531,136.61982 514.80424,136.64131 L 514.14211,134.18201 z"
+     d="M 624.14211,134.18201 L 623.44846,134.37119 L 624.09481,136.75167 C 623.55664,136.88976 623.034,137.15037 622.61293,137.57144 C 622.58031,137.60404 622.56503,137.64813 622.53409,137.68179 C 621.78169,137.61864 621.00589,137.70771 620.24821,137.94979 L 619.60186,135.53777 L 618.90819,135.72696 L 619.5861,138.20203 C 618.90904,138.50465 618.25523,138.92751 617.67856,139.47899 L 615.51876,138.13898 L 615.15618,138.7538 L 617.18983,139.99922 C 616.46851,140.85118 615.98679,141.84216 615.771,142.83687 L 613.56394,142.23781 L 613.37475,142.93146 L 615.67641,143.56206 C 615.54986,144.9582 615.92466,146.33767 616.82724,147.39291 L 624.37857,139.84157 L 624.88305,140.34605 L 617.33172,147.89738 C 618.2984,148.72357 619.54404,149.1165 620.81574,149.07974 L 621.28869,150.84539 L 621.98234,150.65621 L 621.54092,149.01668 C 622.59832,148.85042 623.66579,148.38127 624.58351,147.64515 L 625.46634,149.06397 L 626.08117,148.70138 L 625.13529,147.15642 C 625.82639,146.46532 626.32697,145.65819 626.64871,144.82323 L 628.49319,145.31195 L 628.68237,144.6183 L 626.86941,144.1296 C 627.03506,143.48333 627.09629,142.82751 627.04282,142.19052 C 627.07648,142.15959 627.12057,142.14431 627.15319,142.11171 C 627.57426,141.69063 627.83486,141.16798 627.97296,140.6298 L 630.35344,141.27617 L 630.54262,140.58251 L 628.08331,139.92038 C 628.10481,139.07152 627.80055,138.21881 627.15319,137.57144 C 626.50581,136.92407 625.6531,136.61982 624.80424,136.64131 L 624.14211,134.18201 z"
      id="path16411" />
   <rect
      style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:10.43299961;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
@@ -85820,4 +85977,222 @@
      height="10.821424"
      x="125.33468"
      y="615.21997" />
+  <rect
+     inkscape:label="#rect16270"
+     style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="editPYTHONcode"
+     y="131.36218"
+     x="270"
+     height="24"
+     width="24" />
+  <g
+     transform="translate(-390.13257,-140)"
+     id="g16441">
+    <flowRoot
+       style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:url(#linearGradient16533);fill-opacity:1;stroke:#547c1b;stroke-width:0.1061436;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;font-family:Andale Mono"
+       xml:space="preserve"
+       id="flowRoot16443"
+       transform="matrix(1.6473499,0,0,1.6473499,800.92342,263.57576)"><flowRegion
+         style="fill:url(#linearGradient16527);fill-opacity:1;stroke:url(#linearGradient16529)"
+         id="flowRegion16445"><rect
+           style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:url(#linearGradient16525);fill-opacity:1;stroke:#547c1b;stroke-width:0.1061436;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;font-family:Andale Mono"
+           id="rect16447"
+           y="2.3818817"
+           x="-85.494621"
+           height="232.12506"
+           width="382.57648" /></flowRegion><flowPara
+         style="fill:url(#linearGradient16531);fill-opacity:1;stroke:#547c1b;stroke-width:0.1061436;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+         id="flowPara16449">Py</flowPara></flowRoot>    <g
+       style="fill:#7f755d;fill-opacity:1"
+       transform="matrix(0.181771,-4.0153553e-3,5.9117061e-3,0.1804431,680.18691,229.08403)"
+       id="g16451">
+      <path
+         sodipodi:nodetypes="ccccccc"
+         id="path16453"
+         d="M 1.4170205,261.85309 L 9.1864055,255.27395 C 9.9518515,254.21564 11.377875,252.55111 10.711989,250.47625 C 10.0461,248.4014 5.4846525,241.65013 3.1398275,240.697 C 1.7535525,239.78864 0.71840855,240.54988 -0.39798145,241.67613 L -8.3708247,248.81583 L 1.4170205,261.85309 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="cccccc"
+         id="path16455"
+         d="M 6.3306155,244.87972 C 6.3306155,244.87972 3.7145895,242.19726 2.5681985,241.86603 C 1.4218075,241.53479 -0.21785545,242.50228 -0.21785545,242.50228 L -9.1679878,250.90814 L -4.2239471,254.16031 L 6.3306155,244.87972 z"
+         style="fill-rule:evenodd;stroke:url(#linearGradient16535);stroke-width:0.12755789pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccccc"
+         id="path16457"
+         d="M 1.1712645,261.24893 L 9.7300545,253.87341 C 10.495502,252.8151 10.517969,252.27744 9.8520825,250.20259 C 9.1862035,248.12772 7.5403915,246.24034 6.6758715,245.16696 C 5.8113565,244.0936 5.7408825,244.27913 5.7408825,244.27913 L -4.2206337,252.95532 L 1.1712645,261.24893 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         transform="matrix(-0.538066,-9.955063e-2,-0.448862,0.758281,97.82153,199.2334)"
+         sodipodi:nodetypes="ccccccc"
+         id="path16459"
+         d="M 175.51025,216.82807 L 197.46364,233.74298 L 204.12164,231.58363 L 202.16407,207.12378 L 197.10375,199.73321 L 172.81106,211.0698 L 175.51025,216.82807 z"
+         style="fill-rule:evenodd;stroke:#7f755d;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="cccc"
+         id="path16461"
+         d="M -116.9537,358.31756 L -100.70034,336.46939 L -91.069768,343.09529 L -116.9537,358.31756 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         transform="matrix(-0.538066,-9.955063e-2,-0.448862,0.758281,97.82153,199.2334)"
+         sodipodi:nodetypes="ccccc"
+         id="path16463"
+         d="M 107.78757,107.46646 L 173.65809,214.67963 L 181.21581,210.00104 L 114.26562,101.7082 L 107.78757,107.46646 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccc"
+         id="path16465"
+         d="M -14.598686,260.57822 L -99.704366,337.78772 L -103.54647,335.69094 L -19.451374,259.12046 L -14.598686,260.57822 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         transform="matrix(-0.538066,-9.955063e-2,-0.448862,0.758281,97.82153,199.2334)"
+         sodipodi:nodetypes="ccccc"
+         id="path16467"
+         d="M 125.60221,97.389495 L 191.64176,204.28456 L 198.48463,201.62144 L 133.87972,96.129874 L 125.60221,97.389495 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccc"
+         id="path16469"
+         d="M -9.830588,265.49155 L -93.94093,340.37129 L -96.53602,334.59238 L -13.039235,260.2047 L -9.830588,265.49155 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         transform="matrix(-0.538066,-9.955063e-2,-0.448862,0.758281,97.82153,199.2334)"
+         sodipodi:nodetypes="ccccccccccc"
+         id="path16471"
+         d="M 110.00338,110.582 C 111.27578,110.83648 116.12154,105.36357 123.67926,102.84433 C 131.23699,100.32508 135.49923,99.188954 136.39896,97.929333 C 137.29869,96.669712 136.43925,93.695085 133.33988,93.430686 C 130.09271,93.15368 135.3148,88.032086 131.72037,87.852364 C 128.12145,87.672418 131.36048,82.453989 128.12145,82.81388 C 124.5267,83.213296 119.12416,83.893555 113.18594,86.412797 C 107.24773,88.932039 99.510061,93.970524 99.15017,94.690307 C 98.790278,95.410091 98.25044,98.46917 100.94963,99.548845 C 103.64882,100.62852 100.76968,102.78787 104.18865,104.58733 C 107.60763,106.38679 104.42506,111.48173 110.00338,110.582 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         transform="matrix(-0.538066,-9.955063e-2,-0.448862,0.758281,97.82153,199.2334)"
+         sodipodi:nodetypes="ccccccc"
+         id="path16473"
+         d="M 173.64877,214.66374 L 181.08857,209.83267 C 181.08857,209.83267 182.77556,212.86926 183.04548,215.20855 C 183.28072,217.24734 184.08017,219.45977 182.48315,220.29203 C 181.09241,221.01677 180.07638,220.60693 178.97421,219.75219 C 177.87204,218.89745 175.55524,217.053 175.12786,216.53566 C 174.70049,216.01831 173.64877,214.66374 173.64877,214.66374 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccccc"
+         id="path16475"
+         d="M -93.801751,340.32522 C -93.801751,340.32522 -97.897663,343.71564 -98.99638,344.28849 C -100.09509,344.86133 -102.91776,345.59134 -103.2362,344.8422 C -103.56274,344.07396 -102.24889,341.85896 -101.59629,340.7565 C -100.93948,339.64693 -98.769705,336.94388 -98.438557,336.57695 C -98.107409,336.21001 -96.443231,334.61775 -96.443231,334.61775 L -93.801751,340.32522 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccccc"
+         id="path16477"
+         d="M -96.344601,334.49624 C -97.169892,335.48224 -100.50622,339.12061 -102.33175,339.75455 C -103.19302,340.24788 -104.44501,340.99506 -105.15067,340.98956 C -105.85633,340.98405 -106.624,341.40064 -105.39353,339.47427 C -104.16306,337.54789 -103.63893,336.36627 -101.6981,334.46589 C -100.12383,332.67006 -97.928213,331.13259 -97.928213,331.13259 L -96.344601,334.49624 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         transform="matrix(-0.538066,-9.955063e-2,-0.448862,0.758281,97.82153,199.2334)"
+         sodipodi:nodetypes="cccccc"
+         id="path16479"
+         d="M 197.2837,233.653 L 205.02137,239.50124 L 204.12164,231.13376 C 204.12164,231.13376 202.27339,227.63345 201.87232,228.97441 C 201.06256,231.6736 200.61523,232.01892 198.2734,230.68389 C 195.89613,229.32869 197.2837,233.653 197.2837,233.653 z"
+         style="fill-rule:evenodd;stroke:#000000;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccc"
+         id="path16481"
+         d="M -20.117505,259.67677 C -15.463433,263.36921 -13.650268,263.31164 -10.473468,272.34499 C -5.0278431,265.96965 -1.9685818,264.70796 2.2270432,261.0599 C -0.5195352,255.66293 -2.6979317,251.97049 -8.2854192,249.07351 C -12.115812,253.63066 -14.923476,255.68781 -20.117505,259.67677 z"
+         style="opacity:0.66134183;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         transform="matrix(-0.538066,-9.955063e-2,-0.448862,0.758281,97.82153,199.2334)"
+         sodipodi:nodetypes="cccccc"
+         id="path16483"
+         d="M 197.2837,233.653 L 205.02137,239.50124 L 204.12164,231.13376 C 204.12164,231.13376 202.27339,227.63345 201.87232,228.97441 C 201.06256,231.6736 200.61523,232.01892 198.2734,230.68389 C 195.89613,229.32869 197.2837,233.653 197.2837,233.653 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccc"
+         id="path16485"
+         d="M -3.0784244,252.19014 L -16.418882,263.36268 L -19.013169,260.9776 L -5.9198974,250.37251 L -3.0784244,252.19014 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccc"
+         id="path16487"
+         d="M 9.6173564,249.29743 C 3.2420641,243.37924 0.56301192,248.71048 -3.7231012,252.27396 C -4.5878635,251.47893 -5.4526259,250.68391 -6.3173882,249.88888 C -3.0779069,246.19314 -1.4454866,244.26517 3.5617617,242.01579 C 4.5089194,242.62167 8.1880805,248.20943 9.6173564,249.29743 z"
+         style="fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    </g>
+    <path
+       sodipodi:nodetypes="ccccccc"
+       id="path16489"
+       d="M 682.29306,275.84865 L 683.70096,274.59964 C 683.83718,274.40072 684.09282,274.08695 683.95617,273.70587 C 683.81951,273.3248 682.9286,272.09472 682.48588,271.92805 C 682.22205,271.76573 682.03377,271.91081 681.83256,272.12374 L 680.39015,273.47727 L 682.29306,275.84865 z"
+       style="fill:#ff7556;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="cccccc"
+       id="path16491"
+       d="M 683.10581,272.68865 C 683.10581,272.68865 682.60207,272.20321 682.38644,272.14666 C 682.17081,272.0901 681.87114,272.27582 681.87114,272.27582 L 680.25428,273.8676 L 681.19528,274.44884 L 683.10581,272.68865 z"
+       style="fill:url(#linearGradient16537);fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient16539);stroke-width:0.02369117pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccccc"
+       id="path16493"
+       d="M 682.2436,275.7379 L 683.79378,274.33833 C 683.93,274.13941 683.93093,274.03986 683.79427,273.65879 C 683.65761,273.27772 683.33949,272.93536 683.17189,272.74036 C 683.00428,272.54537 682.99228,272.57998 682.99228,272.57998 L 681.18859,274.22592 L 682.2436,275.7379 z"
+       style="fill:url(#linearGradient16541);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccccc"
+       id="path16495"
+       d="M 665.03485,291.8397 L 661.48338,293.88793 L 660.98249,293.47319 L 663.11342,290.02876 L 664.20805,289.06043 L 665.76229,291.06509 L 665.03485,291.8397 z"
+       style="fill:url(#linearGradient16543);fill-opacity:1;fill-rule:evenodd;stroke:#7f755d;stroke-width:0.0312406pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="cccc"
+       id="path16497"
+       d="M 660.82006,294.1801 L 663.71636,290.07167 L 665.55111,291.2577 L 660.82006,294.1801 z"
+       style="fill:url(#linearGradient16545);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccc"
+       id="path16499"
+       d="M 680.51064,277.3948 L 665.39151,291.56438 L 664.999,290.77704 L 680.31238,276.47151 L 680.51064,277.3948 z"
+       style="fill:#d98100;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccc"
+       id="path16501"
+       d="M 679.30091,275.67874 L 663.90994,290.31144 L 663.18128,289.93939 L 678.38781,275.42906 L 679.30091,275.67874 z"
+       style="fill:#eb9a00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccc"
+       id="path16503"
+       d="M 679.51026,275.6741 L 664.39922,289.79573 L 663.9195,289.3064 L 678.77489,275.36099 L 679.51026,275.6741 z"
+       style="fill:#ffe07a;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccc"
+       id="path16505"
+       d="M 680.21919,276.56799 L 664.99958,290.76563 L 664.48097,289.70732 L 679.58924,275.60323 L 680.21919,276.56799 z"
+       style="fill:#f5a600;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccccccccc"
+       id="path16507"
+       d="M 680.04086,277.80167 C 679.8924,277.81722 679.83623,276.96093 679.27303,276.48047 C 678.70984,276.00001 678.36972,275.7695 678.37853,275.57591 C 678.38735,275.38232 678.70917,274.9735 679.0427,274.98614 C 679.39214,274.99938 679.27024,274.18692 679.64701,274.21961 C 680.02425,274.25234 680.11004,273.45824 680.4083,273.56186 C 680.73933,273.67686 681.2305,273.86106 681.63034,274.31528 C 682.03018,274.76951 682.41239,275.61091 682.3918,275.71903 C 682.3712,275.82716 682.18384,276.27065 681.82623,276.38036 C 681.46863,276.49007 681.58835,276.84359 681.10124,277.04393 C 680.61413,277.24428 680.53241,278.01991 680.04086,277.80167 z"
+       style="fill:url(#linearGradient16547);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccccc"
+       id="path16509"
+       d="M 665.3937,291.56227 L 665.02514,290.75517 C 665.02514,290.75517 664.61494,291.15939 664.4028,291.48747 C 664.21792,291.7734 663.96239,292.07487 664.05769,292.21902 C 664.14069,292.34455 664.27557,292.30276 664.45431,292.19915 C 664.63304,292.09553 665.01254,291.87094 665.09654,291.80434 C 665.18054,291.73774 665.3937,291.56227 665.3937,291.56227 z"
+       style="fill:#d98100;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccccc"
+       id="path16511"
+       d="M 665.02523,290.75654 C 665.02523,290.75654 664.28253,291.40056 664.08126,291.51105 C 663.88,291.62154 663.35844,291.7682 663.29456,291.63093 C 663.22905,291.49016 663.46046,291.07502 663.57538,290.8684 C 663.69105,290.66044 664.07899,290.1515 664.13848,290.08226 C 664.19796,290.01302 664.49842,289.71163 664.49842,289.71163 L 665.02523,290.75654 z"
+       style="fill:#f5a600;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccccc"
+       id="path16513"
+       d="M 664.51606,289.68875 C 664.36825,289.87453 663.7686,290.5613 663.43226,290.68608 C 663.27476,290.78089 663.04599,290.92425 662.91446,290.92614 C 662.78293,290.92803 662.64241,291.00825 662.86002,290.64684 C 663.07764,290.28543 663.16814,290.06469 663.51829,289.70517 C 663.80076,289.36649 664.20058,289.07305 664.20058,289.07305 L 664.51606,289.68875 z"
+       style="fill:#ffe07a;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="cccccc"
+       id="path16515"
+       d="M 661.50864,293.87805 L 660.26587,294.58383 L 661.01805,293.40925 C 661.01805,293.40925 661.48116,292.94175 661.41562,293.13881 C 661.28394,293.53553 661.30176,293.59185 661.64351,293.44006 C 661.99043,293.28598 661.50864,293.87805 661.50864,293.87805 z"
+       style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.0312406pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccc"
+       id="path16517"
+       d="M 678.26705,275.53471 C 679.15668,276.19859 679.49421,276.18047 680.14093,277.83841 C 681.11705,276.63667 681.67947,276.39068 682.43919,275.69859 C 681.89468,274.71155 681.46637,274.03748 680.40762,273.52459 C 679.72147,274.38335 679.21075,274.77544 678.26705,275.53471 z"
+       style="opacity:0.66134183;fill:url(#linearGradient16549);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="cccccc"
+       id="path16519"
+       d="M 661.50864,293.87805 L 660.26587,294.58383 L 661.01805,293.40925 C 661.01805,293.40925 661.48116,292.94175 661.41562,293.13881 C 661.28394,293.53553 661.30176,293.59185 661.64351,293.44006 C 661.99043,293.28598 661.50864,293.87805 661.50864,293.87805 z"
+       style="fill:url(#linearGradient16551);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccc"
+       id="path16521"
+       d="M 681.35307,274.03857 L 678.9786,276.20131 L 678.48072,275.77079 L 680.78933,273.65144 L 681.35307,274.03857 z"
+       style="fill:url(#linearGradient16553);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="ccccc"
+       id="path16523"
+       d="M 683.74504,273.49232 C 682.52118,272.4238 682.05427,273.42101 681.27718,274.09784 C 681.11122,273.95433 680.94525,273.81082 680.77929,273.66732 C 681.36055,272.97034 681.65306,272.60698 682.5725,272.17027 C 682.75266,272.27845 683.47211,273.29694 683.74504,273.49232 z"
+       style="fill:url(#linearGradient16555);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+  </g>
 </svg>
--- a/plugger.py	Wed Dec 24 00:02:12 2008 +0100
+++ b/plugger.py	Tue Dec 30 22:43:48 2008 +0100
@@ -850,6 +850,10 @@
         # define name for IEC raw code file
         return os.path.join(self.PlugPath(), "raw_plc.st")
     
+    def _getPYTHONcodepath(self):
+        # define name for IEC raw code file
+        return os.path.join(self.PlugPath(), "runtime.py")
+
     def GetLocations(self):
         locations = []
         filepath = os.path.join(self._getBuildPath(),"LOCATED_VARIABLES.h")
@@ -984,7 +988,18 @@
         @param locations: ignored
         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
         """
-        return [(C_file_name, self.plcCFLAGS) for C_file_name in self.PLCGeneratedCFiles ] , "", False
+
+        res = ([(C_file_name, self.plcCFLAGS) 
+                for C_file_name in self.PLCGeneratedCFiles ], 
+               "", # no ldflags
+               False) # do not expose retreive/publish calls
+        
+        pyfile=self._getPYTHONcodepath()
+        if os.path.exists(pyfile):
+            res += (("runtime.py", file(pyfile,"rb")),)
+
+        return res
+
     
     def ResetIECProgramsAndVariables(self):
         """
@@ -1263,6 +1278,17 @@
             
         new_dialog.Show()
 
+    def _editPYTHONcode(self):
+        from PythonSTC import PythonCodePanel
+        new_dialog = wx.Frame(self.AppFrame)
+        
+        PYTHON_viewer = PythonCodePanel(new_dialog, self.AppFrame)
+        #ST_viewer.Enable(False)
+        pyfile=self._getPYTHONcodepath()
+        PYTHON_viewer.LoadSourceFile(pyfile)
+            
+        new_dialog.Show()
+
     def _EditPLC(self):
         if self.PLCEditor is None:
             self.RefreshPluginsBlockLists()
@@ -1648,7 +1674,11 @@
          "tooltip" : "Show IEC code generated by PLCGenerator",
          "method" : "_showIECcode"},
         {"bitmap" : opjimg("editIECrawcode"),
-         "name" : "Append code",
+         "name" : "Raw IEC code",
          "tooltip" : "Edit raw IEC code added to code generated by PLCGenerator",
          "method" : "_editIECrawcode"},
+        {"bitmap" : opjimg("editPYTHONcode"),
+         "name" : "Python code",
+         "tooltip" : "Write Python runtime code, for use with python_eval FBs",
+         "method" : "_editPYTHONcode"},
     ]
--- a/runtime/PLCObject.py	Wed Dec 24 00:02:12 2008 +0100
+++ b/runtime/PLCObject.py	Tue Dec 30 22:43:48 2008 +0100
@@ -25,7 +25,6 @@
 import Pyro.core as pyro
 from threading import Timer, Thread
 import ctypes, os, commands
-import time
 
 if os.name in ("nt", "ce"):
     from _ctypes import LoadLibrary as dlopen
@@ -170,11 +169,15 @@
         return False
 
     def PythonThreadProc(self):
+        pyfile = os.path.join(self.workingdir, "runtime.py")
+        if os.path.exists(pyfile):
+            # TODO handle exceptions in runtime.py
+            execfile(pyfile)
         res = ""
         print "PythonThreadProc started"
         while self.PLCStatus == "Started":
             cmd = self._PythonIterator(res)
-            print "_PythonIterator(", res, ") -> ", cmd
+            #print "_PythonIterator(", res, ") -> ", cmd
             try :
                 res = eval(cmd)
             except Exception,e:
--- a/tests/python/plc.xml	Wed Dec 24 00:02:12 2008 +0100
+++ b/tests/python/plc.xml	Tue Dec 30 22:43:48 2008 +0100
@@ -8,7 +8,7 @@
               productVersion="0.0"
               creationDateTime="2008-12-14T16:21:19"/>
   <contentHeader name="Beremiz Python Support Tests"
-                 modificationDateTime="2008-12-24T00:54:43">
+                 modificationDateTime="2008-12-30T00:26:11">
     <coordinateInfo>
       <pageSize x="1024" y="1024"/>
       <fbd>
@@ -58,6 +58,11 @@
                 <derived name="python_eval"/>
               </type>
             </variable>
+            <variable name="pytest_var3">
+              <type>
+                <BOOL/>
+              </type>
+            </variable>
           </localVars>
         </interface>
         <body>
@@ -242,7 +247,7 @@
               <connectionPointOut>
                 <relPosition x="290" y="15"/>
               </connectionPointOut>
-              <expression>'sys.stdout.write("90AB\n")'</expression>
+              <expression>'myprintfunc("90AB\n")'</expression>
             </inVariable>
             <block localId="15" width="125" height="80" typeName="python_eval" instanceName="Block3">
               <position x="650" y="542"/>
@@ -288,6 +293,170 @@
 <![CDATA[This example test that, despite of 2T period clock stimulating TRIG pin of pyth_eval blocks, blocks keep executing one after the other, in respect of execution order.]]>
               </content>
             </comment>
+            <block localId="17" width="80" height="120" typeName="MUX">
+              <position x="1065" y="495"/>
+              <inputVariables>
+                <variable formalParameter="K">
+                  <connectionPointIn>
+                    <relPosition x="0" y="30"/>
+                    <connection refLocalId="18">
+                      <position x="1065" y="525"/>
+                      <position x="1030" y="525"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN0">
+                  <connectionPointIn>
+                    <relPosition x="0" y="50"/>
+                    <connection refLocalId="5" formalParameter="RESULT">
+                      <position x="1065" y="545"/>
+                      <position x="905" y="545"/>
+                      <position x="905" y="250"/>
+                      <position x="775" y="250"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN1">
+                  <connectionPointIn>
+                    <relPosition x="0" y="70"/>
+                    <connection refLocalId="8" formalParameter="RESULT">
+                      <position x="1065" y="565"/>
+                      <position x="890" y="565"/>
+                      <position x="890" y="360"/>
+                      <position x="775" y="360"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN2">
+                  <connectionPointIn>
+                    <relPosition x="0" y="90"/>
+                    <connection refLocalId="12" formalParameter="RESULT">
+                      <position x="1065" y="585"/>
+                      <position x="875" y="585"/>
+                      <position x="875" y="480"/>
+                      <position x="775" y="480"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN3">
+                  <connectionPointIn>
+                    <relPosition x="0" y="110"/>
+                    <connection refLocalId="15" formalParameter="RESULT">
+                      <position x="1065" y="605"/>
+                      <position x="775" y="605"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+              </inputVariables>
+              <inOutVariables/>
+              <outputVariables>
+                <variable formalParameter="OUT">
+                  <connectionPointOut>
+                    <relPosition x="80" y="30"/>
+                  </connectionPointOut>
+                </variable>
+              </outputVariables>
+            </block>
+            <inVariable localId="18" height="30" width="20">
+              <position x="1010" y="510"/>
+              <connectionPointOut>
+                <relPosition x="20" y="15"/>
+              </connectionPointOut>
+              <expression>3</expression>
+            </inVariable>
+            <outVariable localId="19" height="35" width="125">
+              <position x="1185" y="510"/>
+              <connectionPointIn>
+                <relPosition x="0" y="15"/>
+                <connection refLocalId="17" formalParameter="OUT">
+                  <position x="1185" y="525"/>
+                  <position x="1145" y="525"/>
+                </connection>
+              </connectionPointIn>
+              <expression>pytest_var1</expression>
+            </outVariable>
+            <block localId="21" width="80" height="120" typeName="MUX">
+              <position x="985" y="170"/>
+              <inputVariables>
+                <variable formalParameter="K">
+                  <connectionPointIn>
+                    <relPosition x="0" y="30"/>
+                    <connection refLocalId="22">
+                      <position x="985" y="200"/>
+                      <position x="950" y="200"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN0">
+                  <connectionPointIn>
+                    <relPosition x="0" y="50"/>
+                    <connection refLocalId="5" formalParameter="ACK">
+                      <position x="985" y="220"/>
+                      <position x="775" y="220"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN1">
+                  <connectionPointIn>
+                    <relPosition x="0" y="70"/>
+                    <connection refLocalId="8" formalParameter="ACK">
+                      <position x="985" y="240"/>
+                      <position x="805" y="240"/>
+                      <position x="805" y="330"/>
+                      <position x="775" y="330"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN2">
+                  <connectionPointIn>
+                    <relPosition x="0" y="90"/>
+                    <connection refLocalId="12" formalParameter="ACK">
+                      <position x="985" y="260"/>
+                      <position x="820" y="260"/>
+                      <position x="820" y="450"/>
+                      <position x="775" y="450"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN3">
+                  <connectionPointIn>
+                    <relPosition x="0" y="110"/>
+                    <connection refLocalId="15" formalParameter="ACK">
+                      <position x="985" y="280"/>
+                      <position x="835" y="280"/>
+                      <position x="835" y="575"/>
+                      <position x="775" y="575"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+              </inputVariables>
+              <inOutVariables/>
+              <outputVariables>
+                <variable formalParameter="OUT">
+                  <connectionPointOut>
+                    <relPosition x="80" y="30"/>
+                  </connectionPointOut>
+                </variable>
+              </outputVariables>
+            </block>
+            <inVariable localId="22" height="30" width="20">
+              <position x="930" y="185"/>
+              <connectionPointOut>
+                <relPosition x="20" y="15"/>
+              </connectionPointOut>
+              <expression>3</expression>
+            </inVariable>
+            <outVariable localId="23" height="35" width="125">
+              <position x="1150" y="185"/>
+              <connectionPointIn>
+                <relPosition x="0" y="15"/>
+                <connection refLocalId="21" formalParameter="OUT">
+                  <position x="1150" y="200"/>
+                  <position x="1065" y="200"/>
+                </connection>
+              </connectionPointIn>
+              <expression>pytest_var3</expression>
+            </outVariable>
           </FBD>
         </body>
       </pou>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/python/runtime.py	Tue Dec 30 22:43:48 2008 +0100
@@ -0,0 +1,4 @@
+import time
+def myprintfunc(arg):
+    print arg
+    return arg