chiark / gitweb /
Move gcode formated text to own file.
authordaid <daid303@gmail.com>
Wed, 2 May 2012 15:54:29 +0000 (17:54 +0200)
committerdaid <daid303@gmail.com>
Wed, 2 May 2012 15:54:29 +0000 (17:54 +0200)
Cura/gui/alterationPanel.py
Cura/gui/gcodeTextArea.py [new file with mode: 0644]

index 2fa320c49e146de479d899f1e4776fc0093e9775..5f5098d63bf57134355dd0833850e4b937640bae 100644 (file)
@@ -1,6 +1,7 @@
-import wx, wx.stc\r
+import wx\r
 import sys,math,threading,os\r
 \r
+from gui import gcodeTextArea\r
 from util import profile\r
 \r
 class alterationPanel(wx.Panel):\r
@@ -12,19 +13,11 @@ class alterationPanel(wx.Panel):
 \r
                #self.textArea = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_PROCESS_TAB)\r
                #self.textArea.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))\r
-               self.textArea = wx.stc.StyledTextCtrl(self)\r
-               self.textArea.SetLexer(wx.stc.STC_LEX_CONTAINER)\r
+               self.textArea = gcodeTextArea.GcodeTextArea(self)\r
                self.list = wx.ListBox(self, choices=self.alterationFileList, style=wx.LB_SINGLE)\r
                self.list.SetSelection(0)\r
                self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list)\r
                self.textArea.Bind(wx.EVT_KILL_FOCUS, self.OnFocusLost, self.textArea)\r
-               self.textArea.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyle)\r
-               \r
-               fontSize = wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize()\r
-               fontName = wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL).GetFaceName()\r
-               self.textArea.SetStyleBits(5)\r
-               self.textArea.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT,    "face:%s,size:%d" % (fontName, fontSize))\r
-               self.textArea.StyleSetSpec(1,                           "fore:#008000,face:%s,size:%d" % (fontName, fontSize))\r
                \r
                sizer = wx.GridBagSizer()\r
                sizer.Add(self.list, (0,0), span=(1,1), flag=wx.EXPAND)\r
@@ -41,24 +34,9 @@ class alterationPanel(wx.Panel):
                self.currentFile = self.list.GetSelection()\r
 \r
        def loadFile(self, filename):\r
-               #self.textArea.SetValue(profile.getAlterationFile(filename))\r
-               self.textArea.SetText(profile.getAlterationFile(filename))\r
+               self.textArea.SetValue(profile.getAlterationFile(filename))\r
 \r
        def OnFocusLost(self, e):\r
                if self.currentFile == self.list.GetSelection():\r
-                       #profile.setAlterationFile(self.alterationFileList[self.list.GetSelection()], self.textArea.GetValue())\r
-                       profile.setAlterationFile(self.alterationFileList[self.list.GetSelection()], self.textArea.GetText())\r
-\r
-       def OnStyle(self, e):\r
-               #for lineNr in xrange(0, \r
-               lineNr = self.textArea.LineFromPosition(self.textArea.GetEndStyled())\r
-               while self.textArea.PositionFromLine(lineNr) > -1:\r
-                       line = self.textArea.GetLine(lineNr)\r
-                       self.textArea.StartStyling(self.textArea.PositionFromLine(lineNr), 31)\r
-                       self.textArea.SetStyling(self.textArea.LineLength(lineNr), wx.stc.STC_STYLE_DEFAULT)\r
-                       if ';' in line:\r
-                               pos = line.index(';')\r
-                               self.textArea.StartStyling(self.textArea.PositionFromLine(lineNr) + pos, 31)\r
-                               self.textArea.SetStyling(self.textArea.LineLength(lineNr) - pos, 1)\r
-                       lineNr += 1\r
+                       profile.setAlterationFile(self.alterationFileList[self.list.GetSelection()], self.textArea.GetValue())\r
 \r
diff --git a/Cura/gui/gcodeTextArea.py b/Cura/gui/gcodeTextArea.py
new file mode 100644 (file)
index 0000000..e6d8565
--- /dev/null
@@ -0,0 +1,36 @@
+import wx, wx.stc
+import sys,math,os
+
+from util import profile
+
+class GcodeTextArea(wx.stc.StyledTextCtrl):
+       def __init__(self, parent):
+               super(GcodeTextArea, self).__init__(parent)
+
+               self.SetLexer(wx.stc.STC_LEX_CONTAINER)
+               self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyle)
+               
+               fontSize = wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize()
+               fontName = wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL).GetFaceName()
+               self.SetStyleBits(5)
+               self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT,    "face:%s,size:%d" % (fontName, fontSize))
+               self.StyleSetSpec(1,                           "fore:#008000,face:%s,size:%d" % (fontName, fontSize))
+               
+       def OnStyle(self, e):
+               lineNr = self.LineFromPosition(self.GetEndStyled())
+               while self.PositionFromLine(lineNr) > -1:
+                       line = self.GetLine(lineNr)
+                       self.StartStyling(self.PositionFromLine(lineNr), 31)
+                       self.SetStyling(self.LineLength(lineNr), wx.stc.STC_STYLE_DEFAULT)
+                       if ';' in line:
+                               pos = line.index(';')
+                               self.StartStyling(self.PositionFromLine(lineNr) + pos, 31)
+                               self.SetStyling(self.LineLength(lineNr) - pos, 1)
+                       lineNr += 1
+
+       def GetValue(self):
+               return self.GetText()
+       
+       def SetValue(self, s):
+               self.SetText(s)
+