def text_ctrl_input_on_kill_focus(self, event): """Get the path for STL input file from user typing into TextCtrl element. :param event: :return: """ prev_text = self.stl_path_text self.stl_path_text = self.stl_path_input.GetValue() self.stl_path_input.SetValue(MetadataPanel.reduce_text_path(self.stl_path_input.GetValue())) if prev_text != self.stl_path_text: # Check file path validity if Util.is_file(self.stl_path_text): if self.stl_path_text.endswith('.stl'): # Check if this .stl is valid mesh = ModelShipper.load_stl_model(self.stl_path_text) if mesh: # Load in LDraw object to input model ModelShipper.input_model = LDrawModel(mesh) self.stl_dir = Util.get_parent(self.stl_path_text) # Only the dir SettingsManager.save_settings("stl_dir", self.stl_dir) self.stl_path_isvalid = True UIDriver.fire_event( UserEvent(UserEventType.INPUT_MODEL_READY, LogMessage(LogType.INFORMATION, "Input file loaded from: '" + self.stl_path_text + "'."))) else: self.stl_path_isvalid = False UIDriver.fire_event( UserEvent(UserEventType.LOG_INFO, LogMessage(LogType.ERROR, "The input file '" + self.stl_path_text + "' is not a valid STL file."))) else: self.stl_path_isvalid = False UIDriver.fire_event( UserEvent(UserEventType.LOG_INFO, LogMessage(LogType.ERROR, "Input file must have .stl extension."))) else: self.stl_path_isvalid = False if len(self.stl_path_text) <=0: log_msg = "Input filepath cannot be blank." else: log_msg = "The path '" + self.stl_path_text + "' could not be found." UIDriver.fire_event( UserEvent(UserEventType.LOG_INFO, LogMessage(LogType.ERROR, log_msg))) self.check_input() event.Skip()
def load_settings(self): """Load settings values into memory on startup. """ # If settings file doesnt exist if not Util.is_file(SettingsManager.file_path): # If directory doesnt exist if not Util.is_dir(SettingsManager.settings_path): Util.mkdir(SettingsManager.settings_path) # Create user settings with default SettingsManager.create_settings(SettingsManager.filename) with open(SettingsManager.file_path, "r") as file: file_settings = json.load(file) self.stl_dir = file_settings["stl_dir"] self.part_name = file_settings["part_name"] self.part_dir = file_settings["part_dir"] self.author_default = file_settings["author"] self.license_default = file_settings["license"]
def test_is_file(self): self.assertTrue(Util.is_file(self.valid_file)) self.assertFalse(Util.is_file(self.invalid_file))