Commit df051e60 authored by Kliment's avatar Kliment

Add horrifyingly simple gcode editor

parent ed20b692
...@@ -264,6 +264,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -264,6 +264,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.menustrip = wx.MenuBar() self.menustrip = wx.MenuBar()
m = wx.Menu() m = wx.Menu()
self.Bind(wx.EVT_MENU, self.loadfile, m.Append(-1,"&Open..."," Opens file")) self.Bind(wx.EVT_MENU, self.loadfile, m.Append(-1,"&Open..."," Opens file"))
self.Bind(wx.EVT_MENU, self.do_editgcode, m.Append(-1,"&Edit..."," Edit open file"))
if sys.platform != 'darwin': if sys.platform != 'darwin':
self.Bind(wx.EVT_MENU, lambda x:threading.Thread(target=lambda :self.do_skein("set")).start(), m.Append(-1,"SFACT Settings"," Adjust SFACT settings")) self.Bind(wx.EVT_MENU, lambda x:threading.Thread(target=lambda :self.do_skein("set")).start(), m.Append(-1,"SFACT Settings"," Adjust SFACT settings"))
try: try:
...@@ -283,6 +284,17 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -283,6 +284,17 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.update_macros_menu() self.update_macros_menu()
self.SetMenuBar(self.menustrip) self.SetMenuBar(self.menustrip)
def doneediting(self,gcode):
f=open(self.filename,"w")
f.write("\n".join(gcode))
f.close()
wx.CallAfter(self.loadfile,None,self.filename)
def do_editgcode(self,e=None):
if(self.filename is not None):
macroed(self.filename,self.f,self.doneediting,1)
def new_macro(self,e=None): def new_macro(self,e=None):
dialog = wx.Dialog(self,-1,"Enter macro name",size=(200,100)) dialog = wx.Dialog(self,-1,"Enter macro name",size=(200,100))
panel = wx.Panel(dialog,-1) panel = wx.Panel(dialog,-1)
...@@ -956,7 +968,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -956,7 +968,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
thread(target=self.skein_func).start() thread(target=self.skein_func).start()
thread(target=self.skein_monitor).start() thread(target=self.skein_monitor).start()
def loadfile(self,event): def loadfile(self,event,filename=None):
basedir=self.settings.last_file_path basedir=self.settings.last_file_path
if not os.path.exists(basedir): if not os.path.exists(basedir):
basedir = "." basedir = "."
...@@ -966,7 +978,10 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -966,7 +978,10 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
pass pass
dlg=wx.FileDialog(self,"Open file to print",basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST) dlg=wx.FileDialog(self,"Open file to print",basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
dlg.SetWildcard("STL and GCODE files (;*.gcode;*.g;*.stl;*.STL;)") dlg.SetWildcard("STL and GCODE files (;*.gcode;*.g;*.stl;*.STL;)")
if(dlg.ShowModal() == wx.ID_OK): if(filename is not None or dlg.ShowModal() == wx.ID_OK):
if filename is not None:
name=filename
else:
name=dlg.GetPath() name=dlg.GetPath()
if not(os.path.exists(name)): if not(os.path.exists(name)):
self.status.SetStatusText("File not found!") self.status.SetStatusText("File not found!")
...@@ -1136,13 +1151,17 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1136,13 +1151,17 @@ 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): def __init__(self,macro_name,definition,callback,gcode=False):
self.indent_chars = " " self.indent_chars = " "
wx.Dialog.__init__(self,None,title="macro %s" % macro_name,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) title=" macro %s"
if gcode:
title=" %s"
self.gcode=gcode
wx.Dialog.__init__(self,None,title=title % macro_name,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
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," macro %s: "%macro_name) title = 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(title,1)
self.okb = wx.Button(self.panel,-1,"Save") self.okb = wx.Button(self.panel,-1,"Save")
...@@ -1154,7 +1173,10 @@ class macroed(wx.Dialog): ...@@ -1154,7 +1173,10 @@ class macroed(wx.Dialog):
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=(200,200))
if not self.gcode:
self.e.SetValue(self.unindent(definition)) self.e.SetValue(self.unindent(definition))
else:
self.e.SetValue("\n".join(definition))
topsizer.Add(self.e,1,wx.ALL+wx.EXPAND) topsizer.Add(self.e,1,wx.ALL+wx.EXPAND)
self.panel.SetSizer(topsizer) self.panel.SetSizer(topsizer)
topsizer.Layout() topsizer.Layout()
...@@ -1163,7 +1185,10 @@ class macroed(wx.Dialog): ...@@ -1163,7 +1185,10 @@ class macroed(wx.Dialog):
self.e.SetFocus() self.e.SetFocus()
def save(self,ev): def save(self,ev):
self.Destroy() self.Destroy()
if not self.gcode:
self.callback(self.reindent(self.e.GetValue())) self.callback(self.reindent(self.e.GetValue()))
else:
self.callback(self.e.GetValue().split("\n"))
def close(self,ev): def close(self,ev):
self.Destroy() self.Destroy()
def unindent(self,text): def unindent(self,text):
......
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