chiark / gitweb /
The new GCode text editor with syntax highlight is very cool, but is causing problems...
authordaid <daid303@gmail.com>
Mon, 7 May 2012 15:26:40 +0000 (17:26 +0200)
committerdaid <daid303@gmail.com>
Mon, 7 May 2012 15:26:40 +0000 (17:26 +0200)
Cura/gui/configBase.py
Cura/gui/gcodeTextArea.py
Cura/gui/toolbarUtil.py

index 40026d1e895b493a71c1953c5d87d5766199a304..79a7d24875a4b050fb64c2c8fafe8488bf54e6aa 100644 (file)
@@ -64,7 +64,7 @@ class configWindowBase(wx.Frame):
                                self.popup.text.SetLabel(setting.helpText)
                        self.popup.text.Wrap(350)
                        self.popup.Fit()
-                       if os.name == 'darwin':
+                       if sys.platform == 'darwin':
                                x, y = self.ClientToScreenXY(0, 0)
                                sx, sy = self.GetClientSizeTuple()
                        else:
index 68d05249ecb2999515664efbde49e7220884729b..5487241f009779d68b85671c005a9e0fca05aabb 100644 (file)
@@ -3,101 +3,109 @@ import sys,math,os
 
 from util import profile
 
-class GcodeTextArea(wx.stc.StyledTextCtrl):
-       def __init__(self, parent):
-               super(GcodeTextArea, self).__init__(parent)
+if sys.platform == 'darwin':
+       class GcodeTextArea(wx.TextCtrl):
+               def __init__(self, parent):
+                       super(GcodeTextArea, self).__init__(parent, style=wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_PROCESS_TAB)
+                       
+                       self.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
+
+else:
+       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)
+                       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(0, "face:%s,size:%d" % (fontName, fontSize))
-               self.StyleSetSpec(1, "fore:#006000,face:%s,size:%d" % (fontName, fontSize))
-               self.IndicatorSetStyle(0, wx.stc.STC_INDIC_TT)
-               self.IndicatorSetForeground(0, "#0000FF")
-               self.IndicatorSetStyle(1, wx.stc.STC_INDIC_SQUIGGLE)
-               self.IndicatorSetForeground(1, "#FF0000")
-               self.SetWrapMode(wx.stc.STC_WRAP_NONE)
-               self.SetScrollWidth(1000)
+                       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(0, "face:%s,size:%d" % (fontName, fontSize))
+                       self.StyleSetSpec(1, "fore:#006000,face:%s,size:%d" % (fontName, fontSize))
+                       self.IndicatorSetStyle(0, wx.stc.STC_INDIC_TT)
+                       self.IndicatorSetForeground(0, "#0000FF")
+                       self.IndicatorSetStyle(1, wx.stc.STC_INDIC_SQUIGGLE)
+                       self.IndicatorSetForeground(1, "#FF0000")
+                       self.SetWrapMode(wx.stc.STC_WRAP_NONE)
+                       self.SetScrollWidth(1000)
                
-               #GCodes and MCodes as supported by Marlin
-               #GCode 21 is not really supported by Marlin, but we still do not report it as error as it's often used.
-               self.supportedGCodes = [0,1,2,3,4,21,28,90,91,92]
-               self.supportedMCodes = [17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,42,80,81,82,83,84,85,92,104,105,106,107,109,114,115,117,119,140,190,201,202,203,204,205,206,220,221,240,301,302,303,400,500,501,502,503,999]
+                       #GCodes and MCodes as supported by Marlin
+                       #GCode 21 is not really supported by Marlin, but we still do not report it as error as it's often used.
+                       self.supportedGCodes = [0,1,2,3,4,21,28,90,91,92]
+                       self.supportedMCodes = [17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,42,80,81,82,83,84,85,92,104,105,106,107,109,114,115,117,119,140,190,201,202,203,204,205,206,220,221,240,301,302,303,400,500,501,502,503,999]
                
-       def OnStyle(self, e):
-               lineNr = self.LineFromPosition(self.GetEndStyled())
-               while self.PositionFromLine(lineNr) > -1:
-                       line = self.GetLine(lineNr)
-                       start = self.PositionFromLine(lineNr)
-                       length = self.LineLength(lineNr)
-                       self.StartStyling(start, 255)
-                       self.SetStyling(length, 0)
-                       if ';' in line:
-                               pos = line.index(';')
-                               self.StartStyling(start + pos, 31)
-                               self.SetStyling(length - pos, 1)
-                               length = pos
+               def OnStyle(self, e):
+                       lineNr = self.LineFromPosition(self.GetEndStyled())
+                       while self.PositionFromLine(lineNr) > -1:
+                               line = self.GetLine(lineNr)
+                               start = self.PositionFromLine(lineNr)
+                               length = self.LineLength(lineNr)
+                               self.StartStyling(start, 255)
+                               self.SetStyling(length, 0)
+                               if ';' in line:
+                                       pos = line.index(';')
+                                       self.StartStyling(start + pos, 31)
+                                       self.SetStyling(length - pos, 1)
+                                       length = pos
                        
-                       pos = 0
-                       while pos < length:
-                               if line[pos] in " \t\n\r":
-                                       while pos < length and line[pos] in " \t\n\r":
-                                               pos += 1
-                               else:
-                                       end = pos
-                                       while end < length and not line[end] in " \t\n\r":
-                                               end += 1
-                                       if self.checkGCodePart(line[pos:end], start + pos):
-                                               self.StartStyling(start + pos, 0x20)
-                                               self.SetStyling(end - pos, 0x20)
-                                       pos = end
-                       lineNr += 1
+                               pos = 0
+                               while pos < length:
+                                       if line[pos] in " \t\n\r":
+                                               while pos < length and line[pos] in " \t\n\r":
+                                                       pos += 1
+                                       else:
+                                               end = pos
+                                               while end < length and not line[end] in " \t\n\r":
+                                                       end += 1
+                                               if self.checkGCodePart(line[pos:end], start + pos):
+                                                       self.StartStyling(start + pos, 0x20)
+                                                       self.SetStyling(end - pos, 0x20)
+                                               pos = end
+                               lineNr += 1
 
-       def checkGCodePart(self, part, pos):
-               if len(part) < 2:
-                       self.StartStyling(pos, 0x40)
-                       self.SetStyling(1, 0x40)
-                       return True
-               if not part[0] in "GMXYZFESTBPIDCJ":
-                       self.StartStyling(pos, 0x40)
-                       self.SetStyling(1, 0x40)
-                       return True
-               if part[1] == '{':
-                       if part[-1] != '}':
-                               return True
-                       tag = part[2:-1]
-                       if not profile.isProfileSetting(tag) and not profile.isPreference(tag):
-                               self.StartStyling(pos + 2, 0x40)
-                               self.SetStyling(len(tag), 0x40)
+               def checkGCodePart(self, part, pos):
+                       if len(part) < 2:
+                               self.StartStyling(pos, 0x40)
+                               self.SetStyling(1, 0x40)
                                return True
-               elif part[0] in "GM":
-                       try:
-                               code = int(part[1:])
-                       except (ValueError):
-                               self.StartStyling(pos + 1, 0x40)
-                               self.SetStyling(len(part) - 1, 0x40)
+                       if not part[0] in "GMXYZFESTBPIDCJ":
+                               self.StartStyling(pos, 0x40)
+                               self.SetStyling(1, 0x40)
                                return True
-                       if part[0] == 'G':
-                               if not code in self.supportedGCodes:
+                       if part[1] == '{':
+                               if part[-1] != '}':
                                        return True
-                       if part[0] == 'M':
-                               if not code in self.supportedMCodes:
+                               tag = part[2:-1]
+                               if not profile.isProfileSetting(tag) and not profile.isPreference(tag):
+                                       self.StartStyling(pos + 2, 0x40)
+                                       self.SetStyling(len(tag), 0x40)
                                        return True
-               else:
-                       try:
-                               float(part[1:])
-                       except (ValueError):
-                               self.StartStyling(pos + 1, 0x40)
-                               self.SetStyling(len(part) - 1, 0x40)
-                               return True
-               return False
+                       elif part[0] in "GM":
+                               try:
+                                       code = int(part[1:])
+                               except (ValueError):
+                                       self.StartStyling(pos + 1, 0x40)
+                                       self.SetStyling(len(part) - 1, 0x40)
+                                       return True
+                               if part[0] == 'G':
+                                       if not code in self.supportedGCodes:
+                                               return True
+                               if part[0] == 'M':
+                                       if not code in self.supportedMCodes:
+                                               return True
+                       else:
+                               try:
+                                       float(part[1:])
+                               except (ValueError):
+                                       self.StartStyling(pos + 1, 0x40)
+                                       self.SetStyling(len(part) - 1, 0x40)
+                                       return True
+                       return False
 
-       def GetValue(self):
-               return self.GetText()
+               def GetValue(self):
+                       return self.GetText()
        
-       def SetValue(self, s):
-               self.SetText(s)
+               def SetValue(self, s):
+                       self.SetText(s)
 
index 1ec088efae8920e0d061cac672e59a4524fc2700..5914a30810728f638713ac67880267a214a71a89 100644 (file)
@@ -41,7 +41,7 @@ class Toolbar(wx.ToolBar):
                popup.text.SetLabel(control.helpText)
                popup.text.Wrap(350)
                popup.Fit();
-               if os.name == 'darwin':
+               if sys.platform == 'darwin':
                        x, y = self.GetParent().ClientToScreenXY(0, 0)
                        sx, sy = self.GetParent().GetClientSizeTuple()
                else: