Commit 120740f0 authored by Kliment Yanev's avatar Kliment Yanev

Added search functionality to gcode editor.

Merge branch 'experimental' of https://github.com/jezmy/Printrun into experimental

Conflicts:
	gviz.py
parents 2d0d71f9 92cba52d
...@@ -13,12 +13,13 @@ ...@@ -13,12 +13,13 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>. # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import wx,time import wx,time
ID_ABOUT = 101
ID_EXIT = 110
class window(wx.Frame): class window(wx.Frame):
def __init__(self,f,size=(600,600),build_dimensions=[200,200,100,0,0,0],grid=(10,50),extrusion_width=0.5): def __init__(self,f,size=(600,600),build_dimensions=[200,200,100,0,0,0],grid=(10,50),extrusion_width=0.5):
wx.Frame.__init__(self,None,title="Gcode view, shift to move view, mousewheel to set layer",size=(size[0],size[1])) wx.Frame.__init__(self,None,title="Gcode view, shift to move view, mousewheel to set layer",size=(size[0],size[1]))
self.p=gviz(self,size=size,build_dimensions=build_dimensions,grid=grid,extrusion_width=extrusion_width) self.p=gviz(self,size=size,build_dimensions=build_dimensions,grid=grid,extrusion_width=extrusion_width)
# Set up a status bar for displaying info (Jezmy) # Set up a status bar for displaying info (Jezmy)
self.CreateStatusBar(1); self.CreateStatusBar(1);
self.SetStatusText("Layer number and Z position show here when you scroll"); self.SetStatusText("Layer number and Z position show here when you scroll");
...@@ -32,7 +33,7 @@ class window(wx.Frame): ...@@ -32,7 +33,7 @@ class window(wx.Frame):
self.Bind(wx.EVT_MOUSEWHEEL,self.zoom) self.Bind(wx.EVT_MOUSEWHEEL,self.zoom)
self.p.Bind(wx.EVT_MOUSE_EVENTS,self.mouse) self.p.Bind(wx.EVT_MOUSE_EVENTS,self.mouse)
self.Bind(wx.EVT_MOUSE_EVENTS,self.mouse) self.Bind(wx.EVT_MOUSE_EVENTS,self.mouse)
def mouse(self,event): def mouse(self,event):
if event.ButtonUp(wx.MOUSE_BTN_LEFT): if event.ButtonUp(wx.MOUSE_BTN_LEFT):
if(self.initpos is not None): if(self.initpos is not None):
......
...@@ -38,6 +38,7 @@ StringIO=cStringIO ...@@ -38,6 +38,7 @@ StringIO=cStringIO
thread=threading.Thread thread=threading.Thread
winsize=(800,500) winsize=(800,500)
layerindex=0
if os.name=="nt": if os.name=="nt":
winsize=(800,530) winsize=(800,530)
try: try:
...@@ -916,18 +917,6 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -916,18 +917,6 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
def cbutton_edit(self,e,button=None): def cbutton_edit(self,e,button=None):
bedit=ButtonEdit(self) bedit=ButtonEdit(self)
def okhandler(event):
if event.GetId()==wx.ID_OK:
if n==len(self.custombuttons):
self.custombuttons+=[None]
self.custombuttons[n]=[bedit.name.GetValue().strip(),bedit.command.GetValue().strip()]
if bedit.color.GetValue().strip()!="":
self.custombuttons[n]+=[bedit.color.GetValue()]
self.cbutton_save(n,self.custombuttons[n])
bedit.Destroy()
self.cbuttons_reload()
bedit.Bind(wx.EVT_BUTTON,okhandler)
if button is not None: if button is not None:
n = button.custombutton n = button.custombutton
bedit.name.SetValue(button.properties[0]) bedit.name.SetValue(button.properties[0])
...@@ -946,9 +935,16 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -946,9 +935,16 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
n = len(self.custombuttons) n = len(self.custombuttons)
while n>0 and self.custombuttons[n-1] is None: while n>0 and self.custombuttons[n-1] is None:
n -= 1 n -= 1
bedit.Show() if bedit.ShowModal()==wx.ID_OK:
if n==len(self.custombuttons):
self.custombuttons+=[None]
self.custombuttons[n]=[bedit.name.GetValue().strip(),bedit.command.GetValue().strip()]
if bedit.color.GetValue().strip()!="":
self.custombuttons[n]+=[bedit.color.GetValue()]
self.cbutton_save(n,self.custombuttons[n])
bedit.Destroy()
self.cbuttons_reload()
def cbutton_remove(self,e,button): def cbutton_remove(self,e,button):
n = button.custombutton n = button.custombutton
self.custombuttons[n]=None self.custombuttons[n]=None
...@@ -1441,8 +1437,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1441,8 +1437,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
if self.p.online: if self.p.online:
wx.CallAfter(self.printbtn.Enable) wx.CallAfter(self.printbtn.Enable)
threading.Thread(target=self.loadviz).start() threading.Thread(target=self.loadviz).start()
dlg.Destroy()
def loadviz(self): def loadviz(self):
Xtot,Ytot,Ztot,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax = pronsole.measurements(self.f) Xtot,Ytot,Ztot,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax = pronsole.measurements(self.f)
print pronsole.totalelength(self.f), _("mm of filament used in this print\n") print pronsole.totalelength(self.f), _("mm of filament used in this print\n")
...@@ -1635,6 +1630,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1635,6 +1630,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
class macroed(wx.Dialog): class macroed(wx.Dialog):
"""Really simple editor to edit macro definitions""" """Really simple editor to edit macro definitions"""
def __init__(self,macro_name,definition,callback,gcode=False): def __init__(self,macro_name,definition,callback,gcode=False):
self.indent_chars = " " self.indent_chars = " "
title=" macro %s" title=" macro %s"
...@@ -1645,19 +1641,22 @@ class macroed(wx.Dialog): ...@@ -1645,19 +1641,22 @@ class macroed(wx.Dialog):
self.callback = callback self.callback = callback
self.panel=wx.Panel(self,-1) self.panel=wx.Panel(self,-1)
titlesizer=wx.BoxSizer(wx.HORIZONTAL) titlesizer=wx.BoxSizer(wx.HORIZONTAL)
title = wx.StaticText(self.panel,-1,title%macro_name) titletext = wx.StaticText(self.panel,-1," _") #title%macro_name)
#title.SetFont(wx.Font(11,wx.NORMAL,wx.NORMAL,wx.BOLD)) #title.SetFont(wx.Font(11,wx.NORMAL,wx.NORMAL,wx.BOLD))
titlesizer.Add(title,1) titlesizer.Add(titletext,1)
self.findb = wx.Button(self.panel, -1, _("Find")) #New button for "Find" (Jezmy)
self.findb.Bind(wx.EVT_BUTTON, self.find)
self.okb = wx.Button(self.panel, -1, _("Save")) self.okb = wx.Button(self.panel, -1, _("Save"))
self.okb.Bind(wx.EVT_BUTTON, self.save) self.okb.Bind(wx.EVT_BUTTON, self.save)
self.Bind(wx.EVT_CLOSE, self.close) self.Bind(wx.EVT_CLOSE, self.close)
titlesizer.Add(self.findb)
titlesizer.Add(self.okb) titlesizer.Add(self.okb)
self.cancelb = wx.Button(self.panel, -1, _("Cancel")) self.cancelb = wx.Button(self.panel, -1, _("Cancel"))
self.cancelb.Bind(wx.EVT_BUTTON, self.close) self.cancelb.Bind(wx.EVT_BUTTON, self.close)
titlesizer.Add(self.cancelb) titlesizer.Add(self.cancelb)
topsizer=wx.BoxSizer(wx.VERTICAL) topsizer=wx.BoxSizer(wx.VERTICAL)
topsizer.Add(titlesizer,0,wx.EXPAND) topsizer.Add(titlesizer,0,wx.EXPAND)
self.e=wx.TextCtrl(self.panel,style=wx.TE_MULTILINE+wx.HSCROLL,size=(200,200)) self.e=wx.TextCtrl(self.panel,style=wx.TE_MULTILINE+wx.HSCROLL,size=(400,400))
if not self.gcode: if not self.gcode:
self.e.SetValue(self.unindent(definition)) self.e.SetValue(self.unindent(definition))
else: else:
...@@ -1669,6 +1668,37 @@ class macroed(wx.Dialog): ...@@ -1669,6 +1668,37 @@ class macroed(wx.Dialog):
self.Show() self.Show()
self.e.SetFocus() self.e.SetFocus()
def find(self,ev):
# Ask user what to look for, find it and point at it ... (Jezmy)
S = self.e.GetStringSelection()
if not S :
S = "Z"
FindValue = wx.GetTextFromUser('Please enter a search string:', caption="Search", default_value=S, parent=None)
somecode = self.e.GetValue()
numLines = len(somecode)
position = somecode.find(FindValue, self.e.GetInsertionPoint())
if position == -1 :
# ShowMessage(self,-1, "Not found!")
titletext = wx.TextCtrl(self.panel,-1,"Not Found!")
else:
# self.title.SetValue("Position : "+str(position))
titletext = wx.TextCtrl(self.panel,-1,str(position))
# ananswer = wx.MessageBox(str(numLines)+" Lines detected in file\n"+str(position), "OK")
self.e.SetFocus()
self.e.SetInsertionPoint(position)
self.e.SetSelection(position, position + len(FindValue))
self.e.ShowPosition(position)
def ShowMessage(self, ev , message):
dlg = wxMessageDialog(self, message,
"Info!", wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def save(self,ev): def save(self,ev):
self.Destroy() self.Destroy()
if not self.gcode: if not self.gcode:
...@@ -1760,8 +1790,6 @@ class ButtonEdit(wx.Dialog): ...@@ -1760,8 +1790,6 @@ class ButtonEdit(wx.Dialog):
topsizer.Add( (0,0),1) topsizer.Add( (0,0),1)
topsizer.Add(self.CreateStdDialogButtonSizer(wx.OK|wx.CANCEL),0,wx.ALIGN_CENTER) topsizer.Add(self.CreateStdDialogButtonSizer(wx.OK|wx.CANCEL),0,wx.ALIGN_CENTER)
self.SetSizer(topsizer) self.SetSizer(topsizer)
self.handler=None
def macrob_enabler(self,e): def macrob_enabler(self,e):
macro = self.command.GetValue() macro = self.command.GetValue()
valid = False valid = False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment