simple small GUI editor for macros in pronterface

master
Keegi 2011-07-07 00:19:45 +03:00
parent 8ca085a728
commit d08bc641c0
2 changed files with 58 additions and 7 deletions

View File

@ -182,6 +182,15 @@ class pronsole(cmd.Cmd):
print "Empty macro - cancelled"
del self.cur_macro,self.cur_macro_name,self.cur_macro_def
def start_macro(self,macro_name,prev_definition=""):
if not self.processing_rc:
print "Enter macro using indented lines, end with empty line"
self.cur_macro_name = macro_name
self.cur_macro_def = ""
self.cur_macro = "def macro(self,*arg):\n"
self.onecmd = self.hook_macro # override onecmd temporarily
self.prompt="..>"
def do_macro(self,args):
if args.strip()=="":
self.print_topics("User-defined macros",self.macros.keys(),15,80)
@ -214,13 +223,10 @@ class pronsole(cmd.Cmd):
self.cur_macro = "def macro(self,*arg):\n self.onecmd('"+macro_def+"'.format(*arg))\n"
self.end_macro()
return
if not self.processing_rc:
print "Enter macro using indented lines, end with empty line"
self.cur_macro_name = macro_name
self.cur_macro_def = ""
self.cur_macro = "def macro(self,*arg):\n"
self.onecmd = self.hook_macro # override onecmd temporarily
self.prompt="..>"
if self.macros.has_key(macro_name):
self.start_macro(macro_name,self.macros[macro_name])
else:
self.start_macro(macro_name)
def help_macro(self):
print "Define single-line macro: macro <name> <definition>"

View File

@ -172,6 +172,19 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
except:
print "You must enter a temperature."
def start_macro(self,macro_name,old_macro_definition=""):
if not self.processing_rc:
import macroed
def cb(definition):
pronsole.pronsole.start_macro(self,macro_name)
for line in definition.split("\n"):
if hasattr(self,"cur_macro_def"):
self.hook_macro(line)
if hasattr(self,"cur_macro_def"):
self.end_macro()
macroed.macroed(macro_name,old_macro_definition,cb)
else:
pronsole.pronsole.start_macro(self,macro_name,old_macro_definition)
def catchprint(self,l):
wx.CallAfter(self.logbox.AppendText,l)
@ -786,6 +799,38 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.printbtn.SetLabel("Print")
self.paused=0
class macroed(wx.Frame):
"""Really simple editor to edit macro definitions"""
def __init__(self,macro_name,definition,callback):
# TBD: remove top-level indent from the definition (if any)
wx.Frame.__init__(self,None,title="macro %s" % macro_name)
self.callback = callback
self.panel=wx.Panel(self,-1)
titlesizer=wx.BoxSizer(wx.HORIZONTAL)
title = wx.StaticText(self.panel,-1," macro %s: "%macro_name)
title.SetFont(wx.Font(11,wx.NORMAL,wx.NORMAL,wx.BOLD))
titlesizer.Add(title,1)
self.okb = wx.Button(self.panel,-1,"Save")
self.okb.Bind(wx.EVT_BUTTON,self.save)
titlesizer.Add(self.okb)
self.cancelb = wx.Button(self.panel,-1,"Cancel")
self.cancelb.Bind(wx.EVT_BUTTON,self.close)
titlesizer.Add(self.cancelb)
topsizer=wx.BoxSizer(wx.VERTICAL)
topsizer.Add(titlesizer,0,wx.EXPAND)
self.e=wx.TextCtrl(self.panel,style=wx.TE_MULTILINE+wx.HSCROLL,size=(200,200))
self.e.SetValue(definition)
topsizer.Add(self.e,1,wx.ALL+wx.EXPAND)
self.panel.SetSizer(topsizer)
topsizer.Layout()
topsizer.Fit(self)
self.Show()
def save(self,ev):
self.Close()
# TBD: add back top-level indent unless single line.
self.callback(self.e.GetValue())
def close(self,ev):
self.Close()
if __name__ == '__main__':