From 9385aa8c2513d5891ad47a72e94ccb0ac794b592 Mon Sep 17 00:00:00 2001 From: daid Date: Wed, 2 May 2012 17:54:29 +0200 Subject: [PATCH] Move gcode formated text to own file. --- Cura/gui/alterationPanel.py | 32 +++++--------------------------- Cura/gui/gcodeTextArea.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 Cura/gui/gcodeTextArea.py diff --git a/Cura/gui/alterationPanel.py b/Cura/gui/alterationPanel.py index 2fa320c4..5f5098d6 100644 --- a/Cura/gui/alterationPanel.py +++ b/Cura/gui/alterationPanel.py @@ -1,6 +1,7 @@ -import wx, wx.stc +import wx import sys,math,threading,os +from gui import gcodeTextArea from util import profile class alterationPanel(wx.Panel): @@ -12,19 +13,11 @@ class alterationPanel(wx.Panel): #self.textArea = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_PROCESS_TAB) #self.textArea.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) - self.textArea = wx.stc.StyledTextCtrl(self) - self.textArea.SetLexer(wx.stc.STC_LEX_CONTAINER) + self.textArea = gcodeTextArea.GcodeTextArea(self) self.list = wx.ListBox(self, choices=self.alterationFileList, style=wx.LB_SINGLE) self.list.SetSelection(0) self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list) self.textArea.Bind(wx.EVT_KILL_FOCUS, self.OnFocusLost, self.textArea) - self.textArea.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.textArea.SetStyleBits(5) - self.textArea.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%s,size:%d" % (fontName, fontSize)) - self.textArea.StyleSetSpec(1, "fore:#008000,face:%s,size:%d" % (fontName, fontSize)) sizer = wx.GridBagSizer() sizer.Add(self.list, (0,0), span=(1,1), flag=wx.EXPAND) @@ -41,24 +34,9 @@ class alterationPanel(wx.Panel): self.currentFile = self.list.GetSelection() def loadFile(self, filename): - #self.textArea.SetValue(profile.getAlterationFile(filename)) - self.textArea.SetText(profile.getAlterationFile(filename)) + self.textArea.SetValue(profile.getAlterationFile(filename)) def OnFocusLost(self, e): if self.currentFile == self.list.GetSelection(): - #profile.setAlterationFile(self.alterationFileList[self.list.GetSelection()], self.textArea.GetValue()) - profile.setAlterationFile(self.alterationFileList[self.list.GetSelection()], self.textArea.GetText()) - - def OnStyle(self, e): - #for lineNr in xrange(0, - lineNr = self.textArea.LineFromPosition(self.textArea.GetEndStyled()) - while self.textArea.PositionFromLine(lineNr) > -1: - line = self.textArea.GetLine(lineNr) - self.textArea.StartStyling(self.textArea.PositionFromLine(lineNr), 31) - self.textArea.SetStyling(self.textArea.LineLength(lineNr), wx.stc.STC_STYLE_DEFAULT) - if ';' in line: - pos = line.index(';') - self.textArea.StartStyling(self.textArea.PositionFromLine(lineNr) + pos, 31) - self.textArea.SetStyling(self.textArea.LineLength(lineNr) - pos, 1) - lineNr += 1 + profile.setAlterationFile(self.alterationFileList[self.list.GetSelection()], self.textArea.GetValue()) diff --git a/Cura/gui/gcodeTextArea.py b/Cura/gui/gcodeTextArea.py new file mode 100644 index 00000000..e6d85655 --- /dev/null +++ b/Cura/gui/gcodeTextArea.py @@ -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) + -- 2.30.2