this feature is inspired by Bernhard Kubicek's work on a similar
feature.  Any number of filters may be listed in the inifile as
[FILTER]PROGRAM=.  These work similarly to extension-based filters,
except that the user chooses them explicitly from the menu to apply
them to the already-loaded file.
---
This seems like a good idea.  What do you think of this approach?

 share/axis/tcl/axis.tcl               |    8 +++++-
 src/emc/usr_intf/axis/scripts/axis.py |   41 +++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/share/axis/tcl/axis.tcl b/share/axis/tcl/axis.tcl
index 24f0174..89caac6 100644
--- a/share/axis/tcl/axis.tcl
+++ b/share/axis/tcl/axis.tcl
@@ -26,6 +26,8 @@ menu .menu.file \
        -tearoff 0
 menu .menu.file.recent \
        -tearoff 0
+menu .menu.file.filters \
+       -tearoff 0
 menu .menu.machine \
        -tearoff 0
 menu .menu.machine.home \
@@ -54,6 +56,10 @@ setup_menu_accel .menu.file end [_ "Recent _Files"]
     -command edit_program
 setup_menu_accel .menu.file end [_ "_Edit..."]
 
+.menu.file add cascade \
+    -menu .menu.file.filters
+setup_menu_accel .menu.file end [_ "F_ilter"]
+
 .menu.file add command \
        -accelerator [_ "Ctrl-R"] \
        -command reload_file
@@ -1880,7 +1886,7 @@ proc update_state {args} {
     relief {$task_state == $STATE_ON}    .toolbar.machine_power 
 
     state  {$interp_state == $INTERP_IDLE && $taskfile != ""} \
-        .toolbar.reload {.menu.file "_Reload"}
+        .toolbar.reload {.menu.file "_Reload"} {.menu.file "F_ilter"}
     state  {$taskfile != ""} \
         .toolbar.reload {.menu.file "_Save gcode as..."}
     state  {$interp_state == $INTERP_IDLE && $taskfile != "" && $::has_editor} 
\
diff --git a/src/emc/usr_intf/axis/scripts/axis.py 
b/src/emc/usr_intf/axis/scripts/axis.py
index 702307f..da97406 100755
--- a/src/emc/usr_intf/axis/scripts/axis.py
+++ b/src/emc/usr_intf/axis/scripts/axis.py
@@ -1203,6 +1203,7 @@ widgets = nf.Widgets(root_window,
 
     ("menu_view", Menu, ".menu.view"),
     ("menu_file", Menu, ".menu.file"),
+    ("menu_filters", Menu, ".menu.file.filters"),
     ("menu_machine", Menu, ".menu.machine"),
     ("menu_touchoff", Menu, ".menu.machine.touchoff"),
 
@@ -2407,6 +2408,28 @@ class TclCommands(nf.TclCommands):
         else:
             add_recent_file(f)
 
+    def filter_gcode(program):
+        global loaded_file
+        if not loaded_file: return
+        if get_filter(loaded_file):
+            srcfile = os.path.join(tempdir, os.path.basename(loaded_file))
+        else:
+            srcfile = loaded_file
+        outfile = tempfile.NamedTemporaryFile(
+            suffix="ngc", dir=tempdir, delete=False)
+        exitcode, stderr = filter_program(program, srcfile, outfile.name)
+        if exitcode:
+            root_window.tk.call("nf_dialog", (".error", "-ext", stderr),
+                    _("Filter failed"),
+                    _("The program %(program)r exited with code %(code)d.  "
+                    "Any error messages it produced are shown below:")
+                        % {'program': program, 'code': exitcode},
+                    "error",0,_("OK"))
+            return 
+        dest = os.path.join(tempdir, os.path.basename(loaded_file))
+        os.rename(outfile.name, dest)
+        open_file_guts(dest, True, False)
+
 commands = TclCommands(root_window)
 
 vars = nf.Variables(root_window, 
@@ -2778,6 +2801,23 @@ update_ms = int(1000 * 
float(inifile.find("DISPLAY","CYCLE_TIME") or 0.020))
 widgets.unhomemenu.add_command(command=commands.unhome_all_axes)
 root_window.tk.call("setup_menu_accel", widgets.unhomemenu, "end", _("Unhome 
All Axes"))
 
+filters = inifile.findall("FILTER", "PROGRAM")
+for f in filters:
+    if ";" in f:
+        p, t = f.split(";", 1)
+    else:
+        p = t = f
+    p = p.strip()
+    t = t.strip()
+    widgets.menu_filters.add_command(command=("filter_gcode", p), label=t)
+    try:
+        root_window.tk.call("setup_menu_accel", ".menu.file.filters", "end", t)
+    except Tkinter.TclError:
+        # The inifile has an invalid string, such as "Bogus_".  Rather than
+        # punishing the user by refusing to start, skip the accelerator
+        # set-up logic
+        pass
+
 s = emc.stat();
 s.poll()
 statfail=0
-- 
1.6.3.3

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to