def open_and_display_file(self, fpath): try: self.model_file = ModelFile(fpath) if self.scene is None: self.scene = Scene() self.glarea = GLArea(self.scene) self.add_file_to_scene(self.model_file) if self.panel is None or not self.panel_matches_file(): self.panel = self.create_panel() # update panel to reflect new model properties self.panel.set_initial_values() self.panel.connect_handlers() # always start with the same view on the scene self.scene.reset_view(True) self.scene.mode_2d = False self.window.set_file_widgets(self.glarea, self.panel) self.window.filename = self.model_file.basename except IOError, e: dialog = OpenErrorAlert(self.window, fpath, e.strerror) dialog.run() dialog.destroy()
def open_and_display_file(self, fpath): progress_dialog = ProgressDialog('Loading', self.window) self.window.set_cursor(gtk.gdk.WATCH) success = True try: self.model_file = ModelFile(fpath) if self.scene is None: self.scene = Scene() self.glarea = SceneArea(self.scene) progress_dialog.set_text('Reading file...') progress_dialog.show() model, model_data = self.model_file.read(progress_dialog.step) progress_dialog.set_text('Loading model...') model.load_data(model_data, progress_dialog.step) self.scene.clear() model.offset_x = self.config.read('machine.platform_offset_x', int) model.offset_y = self.config.read('machine.platform_offset_y', int) self.scene.add_model(model) # platform needs to be added last to be translucent platform_w = self.config.read('machine.platform_w', int) platform_d = self.config.read('machine.platform_d', int) platform = Platform(platform_w, platform_d) self.scene.add_supporting_actor(platform) if self.panel is None or not self.panel_matches_file(): self.panel = self.create_panel() # update panel to reflect new model properties self.panel.set_initial_values() self.panel.connect_handlers() # always start with the same view on the scene self.scene.reset_view(True) if self.model_file.filetype == 'gcode': self.scene.mode_2d = self.config.read('ui.gcode_2d', bool) else: self.scene.mode_2d = False if hasattr(self.panel, 'set_3d_view'): self.panel.set_3d_view(not self.scene.mode_2d) self.window.set_file_widgets(self.glarea, self.panel) self.window.filename = self.model_file.basename self.menu_enable_file_items(self.model_file.filetype != 'gcode') except IOError, e: self.window.window.set_cursor(None) progress_dialog.hide() error_dialog = OpenErrorAlert(self.window, fpath, e.strerror) error_dialog.run() error_dialog.destroy() success = False