def browse_output(self, event): """Browse for a valid output file path :param event: :return: """ UIDriver.fire_event(UserEvent( UserEventType.RENDERING_CANVAS_DISABLE, LogMessage(LogType.IGNORE, ""))) dat_wildcard = "*.dat" dialog = wx.FileDialog(self, "Choose a location for the LDraw file", defaultDir=self.part_dir, style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, wildcard=dat_wildcard) dialog.SetFilename(self.part_name) if dialog.ShowModal() == wx.ID_OK: pathname = dialog.GetPath() if self.out_file != pathname: # Check if part name ends with .dat, if not append that if not pathname.endswith('.dat'): pathname = pathname + '.dat' self.out_file = pathname # Full path self.part_dir = Util.get_parent(pathname) # Only the dir self.part_name = Util.get_filename(pathname) # Only filename self.ldraw_name_isvalid = True SettingsManager.save_settings("part_dir", self.part_dir) SettingsManager.save_settings("part_name", self.part_name) self.ldraw_name_input.SetValue(self.out_file) self.ldraw_name_input.SetValue(MetadataPanel.reduce_text_path(self.ldraw_name_input.GetValue())) self.check_input() UIDriver.fire_event( UserEvent(UserEventType.LOG_INFO, LogMessage(LogType.INFORMATION, "Output file will be saved as: '" + self.out_file + "'."))) UIDriver.fire_event(UserEvent( UserEventType.RENDERING_CANVAS_ENABLE, LogMessage(LogType.IGNORE, ""))) dialog.Destroy()
def test_get_filename(self): self.assertEqual(Util.get_filename(self.valid_file), 'HELP.txt')