Commit 46242acf authored by sumpfralle's avatar sumpfralle

fixed handling of RecentChooserMenu patterns

added GUI "callback" to DXFImporter


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@861 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 87901b7c
...@@ -154,21 +154,17 @@ def report_exception(): ...@@ -154,21 +154,17 @@ def report_exception():
+ "text below to the developers of PyCAM. Thanks a lot!\n" \ + "text below to the developers of PyCAM. Thanks a lot!\n" \
+ traceback.format_exc()) + traceback.format_exc())
def get_filters_from_list(filter_list, file_filter=True): def get_filters_from_list(filter_list):
if file_filter:
return_class = gtk.FileFilter
else:
return_class = gtk.RecentFilter
result = [] result = []
for one_filter in filter_list: for one_filter in filter_list:
file_filter = return_class() current_filter = gtk.FileFilter()
file_filter.set_name(one_filter[0]) current_filter.set_name(one_filter[0])
file_extensions = one_filter[1] file_extensions = one_filter[1]
if not isinstance(file_extensions, (list, tuple)): if not isinstance(file_extensions, (list, tuple)):
file_extensions = [file_extensions] file_extensions = [file_extensions]
for ext in file_extensions: for ext in file_extensions:
file_filter.add_pattern(ext) current_filter.add_pattern(ext)
result.append(file_filter) result.append(current_filter)
return result return result
def get_font_dir(): def get_font_dir():
...@@ -883,9 +879,13 @@ class ProjectGui: ...@@ -883,9 +879,13 @@ class ProjectGui:
if not self.recent_manager is None: if not self.recent_manager is None:
recent_files_menu = gtk.RecentChooserMenu(self.recent_manager) recent_files_menu = gtk.RecentChooserMenu(self.recent_manager)
recent_files_menu.set_name("RecentFilesMenu") recent_files_menu.set_name("RecentFilesMenu")
for file_filter in get_filters_from_list(FILTER_MODEL, recent_menu_filter = gtk.RecentFilter()
file_filter=False): for filter_name, filter_patterns in FILTER_MODEL:
recent_files_menu.add_filter(file_filter) if not isinstance(filter_patterns, (list, set, tuple)):
filter_patterns = [filter_patterns]
for pattern in filter_patterns:
recent_menu_filter.add_pattern(pattern)
recent_files_menu.add_filter(recent_menu_filter)
recent_files_menu.set_show_numbers(True) recent_files_menu.set_show_numbers(True)
# non-local files (without "file://") are not supported. yet # non-local files (without "file://") are not supported. yet
recent_files_menu.set_local_only(True) recent_files_menu.set_local_only(True)
...@@ -2510,9 +2510,7 @@ class ProjectGui: ...@@ -2510,9 +2510,7 @@ class ProjectGui:
def load_model_file(self, widget=None, filename=None): def load_model_file(self, widget=None, filename=None):
if callable(filename): if callable(filename):
filename = filename() filename = filename()
if filename: if not filename:
self.add_to_recent_file_list(filename)
else:
filename = self.get_filename_via_dialog("Loading model ...", filename = self.get_filename_via_dialog("Loading model ...",
mode_load=True, type_filter=FILTER_MODEL) mode_load=True, type_filter=FILTER_MODEL)
if filename: if filename:
...@@ -2527,11 +2525,12 @@ class ProjectGui: ...@@ -2527,11 +2525,12 @@ class ProjectGui:
self.update_progress_bar(text="Loading model file ...") self.update_progress_bar(text="Loading model file ...")
# "cancel" is not allowed # "cancel" is not allowed
self.disable_progress_cancel_button() self.disable_progress_cancel_button()
self.load_model(importer(filename, if self.load_model(importer(filename,
program_locations=program_locations, program_locations=program_locations,
unit=self.settings.get("unit"), unit=self.settings.get("unit"),
callback=self.update_progress_bar)) callback=self.update_progress_bar)):
self.set_model_filename(filename) self.set_model_filename(filename)
self.add_to_recent_file_list(filename)
else: else:
log.error("Failed to detect filetype!") log.error("Failed to detect filetype!")
...@@ -2539,9 +2538,7 @@ class ProjectGui: ...@@ -2539,9 +2538,7 @@ class ProjectGui:
def export_emc_tools(self, widget=None, filename=None): def export_emc_tools(self, widget=None, filename=None):
if callable(filename): if callable(filename):
filename = filename() filename = filename()
if filename: if not filename:
self.add_to_recent_file_list(filename)
else:
filename = self.get_filename_via_dialog("Exporting EMC tool definition ...", filename = self.get_filename_via_dialog("Exporting EMC tool definition ...",
mode_load=False, type_filter=FILTER_EMC_TOOL, mode_load=False, type_filter=FILTER_EMC_TOOL,
filename_templates=(self.last_model_filename,)) filename_templates=(self.last_model_filename,))
...@@ -2567,16 +2564,16 @@ class ProjectGui: ...@@ -2567,16 +2564,16 @@ class ProjectGui:
def load_task_settings_file(self, widget=None, filename=None): def load_task_settings_file(self, widget=None, filename=None):
if callable(filename): if callable(filename):
filename = filename() filename = filename()
if filename: if not filename:
self.add_to_recent_file_list(filename)
else:
filename = self.get_filename_via_dialog("Loading settings ...", filename = self.get_filename_via_dialog("Loading settings ...",
mode_load=True, type_filter=FILTER_CONFIG) mode_load=True, type_filter=FILTER_CONFIG)
if filename: # Only update the last_task_settings attribute if the task file was
# loaded interactively. E.g. ignore the initial task file loading.
self.last_task_settings_file = filename self.last_task_settings_file = filename
self.update_save_actions()
if filename: if filename:
self.load_task_settings(filename) self.load_task_settings(filename)
self.add_to_recent_file_list(filename)
self.update_save_actions()
def load_model(self, model): def load_model(self, model):
# load the new model only if the import worked # load the new model only if the import worked
...@@ -2588,6 +2585,9 @@ class ProjectGui: ...@@ -2588,6 +2585,9 @@ class ProjectGui:
self.append_to_queue(self.update_support_grid_controls) self.append_to_queue(self.update_support_grid_controls)
self.append_to_queue(self.toggle_3d_view, value=True) self.append_to_queue(self.toggle_3d_view, value=True)
self.append_to_queue(self.update_view) self.append_to_queue(self.update_view)
return True
else:
return False
def load_task_settings(self, filename=None): def load_task_settings(self, filename=None):
settings = pycam.Gui.Settings.ProcessSettings() settings = pycam.Gui.Settings.ProcessSettings()
...@@ -3417,7 +3417,6 @@ class ProjectGui: ...@@ -3417,7 +3417,6 @@ class ProjectGui:
widget = widget() widget = widget()
if isinstance(widget, basestring): if isinstance(widget, basestring):
filename = widget filename = widget
self.add_to_recent_file_list(filename)
else: else:
# we open a dialog # we open a dialog
filename = self.get_filename_via_dialog("Save toolpath to ...", filename = self.get_filename_via_dialog("Save toolpath to ...",
......
...@@ -237,7 +237,7 @@ def import_model(filename, program_locations=None, unit=None, callback=None): ...@@ -237,7 +237,7 @@ def import_model(filename, program_locations=None, unit=None, callback=None):
if unit == "mm": if unit == "mm":
# pstoedit uses inch internally - we need to scale # pstoedit uses inch internally - we need to scale
log.info("DXFImporter: scaling model from inch to mm") log.info("DXFImporter: scaling model from inch to mm")
model.scale(25.4) model.scale(25.4, callback=callback)
log.info("DXFImporter: Imported DXF model: %d lines / %d polygons" \ log.info("DXFImporter: Imported DXF model: %d lines / %d polygons" \
% (len(lines), len(model.get_polygons()))) % (len(lines), len(model.get_polygons())))
return model return model
......
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