Commit 685590e4 authored by sumpfralle's avatar sumpfralle

r706@erker: lars | 2010-02-22 01:26:28 +0100

 implement non-interactive mode for GTK interface
 renamed function "save" in SimpleGui.py to "save_toolpath"
 small cleanups


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@158 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 8daedfe4
...@@ -37,33 +37,38 @@ if __name__ == "__main__": ...@@ -37,33 +37,38 @@ if __name__ == "__main__":
if options.gtk_gui: if options.gtk_gui:
try: try:
from pycam.Gui.Project import ProjectGui from pycam.Gui.Project import ProjectGui
gui = ProjectGui() gui_class = ProjectGui
except ImportError, err_msg: except ImportError, err_msg:
print >> sys.stderr, "Failed to load GTK bindings for python. Please install the package 'python-gtk2'." print >> sys.stderr, "Failed to load GTK bindings for python. Please install the package 'python-gtk2'."
print >> sys.stderr, "Details: %s" % str(err_msg) print >> sys.stderr, "Details: %s" % str(err_msg)
print >> sys.stderr, "I will try to use the alternative Tk interface now ..." print >> sys.stderr, "I will try to use the alternative Tk interface now ..."
try: try:
from pycam.Gui.SimpleGui import SimpleGui from pycam.Gui.SimpleGui import SimpleGui
gui = SimpleGui() gui_class = SimpleGui()
except ImportError: except ImportError:
gui = None gui_class = None
else: else:
try: try:
from pycam.Gui.SimpleGui import SimpleGui from pycam.Gui.SimpleGui import SimpleGui
gui = SimpleGui() gui_class = SimpleGui
except ImportError, err_msg: except ImportError, err_msg:
print >> sys.stderr, "Failed to load TkInter bindings for python. Please install the package 'python-tk'." print >> sys.stderr, "Failed to load TkInter bindings for python. Please install the package 'python-tk'."
print >> sys.stderr, "Details: %s" % str(err_msg) print >> sys.stderr, "Details: %s" % str(err_msg)
print >> sys.stderr, "I will try to use the alternative GTK interface now ..." print >> sys.stderr, "I will try to use the alternative GTK interface now ..."
try: try:
from pycam.Gui.Project import ProjectGui from pycam.Gui.Project import ProjectGui
gui = ProjectGui() gui_class = ProjectGui
except ImportError: except ImportError:
gui = None gui_class = None
# exit if no interface is found # exit if no interface is found
if gui is None: if gui_class is None:
print >> sys.stderr, "Neither the GTK nor the Tk interface is available. Please install the corresponding packages!" print >> sys.stderr, "Neither the GTK nor the Tk interface is available. Please install the corresponding packages!"
sys.exit(1) sys.exit(1)
else:
if outputfile:
gui = gui_class(no_dialog=True)
else:
gui = gui_class()
if not inputfile: if not inputfile:
from pycam.Importers.TestModel import TestModel from pycam.Importers.TestModel import TestModel
...@@ -81,7 +86,7 @@ if __name__ == "__main__": ...@@ -81,7 +86,7 @@ if __name__ == "__main__":
# an output filename is given and no gui is explicitly requested # an output filename is given and no gui is explicitly requested
gui.generateToolpath() gui.generateToolpath()
if outputfile: if outputfile:
gui.save(outputfile) gui.save_toolpath(outputfile)
else: else:
# the gui should be shown # the gui should be shown
if outputfile: if outputfile:
......
...@@ -247,10 +247,12 @@ class GLView: ...@@ -247,10 +247,12 @@ class GLView:
class ProjectGui: class ProjectGui:
def __init__(self, master=None): def __init__(self, master=None, no_dialog=False):
""" TODO: remove "master" above when the Tk interface is abandoned"""
self.settings = pycam.Gui.Settings.Settings() self.settings = pycam.Gui.Settings.Settings()
self.gui_is_active = False self.gui_is_active = False
self.view3d = None self.view3d = None
self.no_dialog = no_dialog
self._batch_queue = [] self._batch_queue = []
self.gui = gtk.Builder() self.gui = gtk.Builder()
self.gui.add_from_file(GTKBUILD_FILE) self.gui.add_from_file(GTKBUILD_FILE)
...@@ -274,7 +276,6 @@ class ProjectGui: ...@@ -274,7 +276,6 @@ class ProjectGui:
filter.add_pattern("*.stl") filter.add_pattern("*.stl")
model_file_chooser.add_filter(filter) model_file_chooser.add_filter(filter)
model_file_chooser.set_filter(filter) model_file_chooser.set_filter(filter)
self.window.show()
self.model = None self.model = None
self.toolpath = None self.toolpath = None
self.physics = None self.physics = None
...@@ -420,6 +421,8 @@ class ProjectGui: ...@@ -420,6 +421,8 @@ class ProjectGui:
self.processing_file_selector.set_filter(filter) self.processing_file_selector.set_filter(filter)
# make sure that the toolpath settings are consistent # make sure that the toolpath settings are consistent
self.disable_invalid_toolpath_settings() self.disable_invalid_toolpath_settings()
if not self.no_dialog:
self.window.show()
def gui_activity_guard(func): def gui_activity_guard(func):
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
...@@ -435,7 +438,7 @@ class ProjectGui: ...@@ -435,7 +438,7 @@ class ProjectGui:
return wrapper return wrapper
def update_view(self, widget=None, data=None): def update_view(self, widget=None, data=None):
if self.view3d: if self.view3d and self.view3d.is_visible and not self.no_dialog:
self.view3d.paint() self.view3d.paint()
def update_physics(self): def update_physics(self):
...@@ -472,6 +475,9 @@ class ProjectGui: ...@@ -472,6 +475,9 @@ class ProjectGui:
@gui_activity_guard @gui_activity_guard
def toggle_3d_view(self, widget=None, value=None): def toggle_3d_view(self, widget=None, value=None):
# no interactive mode
if self.no_dialog:
return
if self.view3d and not self.view3d.enabled: if self.view3d and not self.view3d.enabled:
# initialization failed - don't do anything # initialization failed - don't do anything
return return
...@@ -688,7 +694,7 @@ class ProjectGui: ...@@ -688,7 +694,7 @@ class ProjectGui:
show_error_dialog(self.window, "Failed to save processing settings file") show_error_dialog(self.window, "Failed to save processing settings file")
@gui_activity_guard @gui_activity_guard
def generate_toolpath(self, widget, data=None): def generate_toolpath(self, widget=None, data=None):
start_time = time.time() start_time = time.time()
class UpdateView: class UpdateView:
def __init__(self, func, max_fps=1): def __init__(self, func, max_fps=1):
...@@ -780,6 +786,10 @@ class ProjectGui: ...@@ -780,6 +786,10 @@ class ProjectGui:
print "Time elapsed: %f" % (time.time() - start_time) print "Time elapsed: %f" % (time.time() - start_time)
self.update_view() self.update_view()
# for compatibility with old pycam GUI (see pycam.py)
# TODO: remove it in v0.2
generateToolpath = generate_toolpath
def get_save_filename(self, title, type_filter=None): def get_save_filename(self, title, type_filter=None):
# we open a dialog # we open a dialog
dialog = gtk.FileChooserDialog(title=title, dialog = gtk.FileChooserDialog(title=title,
...@@ -824,7 +834,7 @@ class ProjectGui: ...@@ -824,7 +834,7 @@ class ProjectGui:
return filename return filename
@gui_activity_guard @gui_activity_guard
def save_toolpath(self, widget, data=None): def save_toolpath(self, widget=None, data=None):
if not self.toolpath: if not self.toolpath:
return return
offset = float(self.gui.get_object("ToolRadiusControl").get_value())/2 offset = float(self.gui.get_object("ToolRadiusControl").get_value())/2
...@@ -852,6 +862,8 @@ class ProjectGui: ...@@ -852,6 +862,8 @@ class ProjectGui:
self.gui.get_object("FeedrateControl").get_value(), self.gui.get_object("FeedrateControl").get_value(),
self.gui.get_object("SpeedControl").get_value()) self.gui.get_object("SpeedControl").get_value())
fi.close() fi.close()
if self.no_dialog:
print "GCode file successfully written: %s" % str(filename)
except IOError, err_msg: except IOError, err_msg:
if not no_dialog: if not no_dialog:
show_error_dialog(self.window, "Failed to save toolpath file") show_error_dialog(self.window, "Failed to save toolpath file")
......
...@@ -325,13 +325,13 @@ class SimpleGui(Tk.Frame): ...@@ -325,13 +325,13 @@ class SimpleGui(Tk.Frame):
def browseSaveAs(self): def browseSaveAs(self):
filename = tkFileDialog.SaveAs(self, filetypes=[("GCODE files", ".nc .gc .ngc")]).show() filename = tkFileDialog.SaveAs(self, filetypes=[("GCODE files", ".nc .gc .ngc")]).show()
if filename: if filename:
self.save(filename) self.save_toolpath(filename)
def setOutputFilename(self, filename): def setOutputFilename(self, filename):
if filename: if filename:
self.OutputFileName.set(filename) self.OutputFileName.set(filename)
def save(self, filename): def save_toolpath(self, filename):
self.OutputFileName.set(filename) self.OutputFileName.set(filename)
if self.toolpath: if self.toolpath:
offset = float(self.ToolRadius.get())/2 offset = float(self.ToolRadius.get())/2
...@@ -498,7 +498,7 @@ class SimpleGui(Tk.Frame): ...@@ -498,7 +498,7 @@ class SimpleGui(Tk.Frame):
self.ogl.redraw = self.Redraw self.ogl.redraw = self.Redraw
self.pack(expand=1, fill=Tk.BOTH) self.pack(expand=1, fill=Tk.BOTH)
def __init__(self, master=None): def __init__(self, master=None, no_dialog=False):
Tk.Frame.__init__(self, master) Tk.Frame.__init__(self, master)
self.model = None self.model = None
self.toolpath = None self.toolpath = None
......
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