From 287f50b657f30a7e5a8571c56f6910e6f9d69343 Mon Sep 17 00:00:00 2001 From: "Saara Saaninkoski (TAU)" <saara.saaninkoski@tuni.fi> Date: Tue, 21 Jan 2020 15:10:47 +0200 Subject: [PATCH] Release 1.0.1 --- CHANGES.rst | 4 ++++ kvalikirstu2/gui.py | 32 +++++++++++++++++--------------- kvalikirstu2/gui_model.py | 7 +------ kvalikirstu2/header_scanner.py | 11 ++++++----- kvalikirstu2/kvali_interface.py | 4 +++- setup.py | 2 +- tests/test_gui.py | 1 + 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 46dced9..f8b74c5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,10 @@ Kvalikirstu2 Changelog ====================== +1.0.1 - 2020/01/21 +------------------- +- Bug fix in a file conversion dialog + 1.0.0 - 2019/12/19 ------------------- - First public release \ No newline at end of file diff --git a/kvalikirstu2/gui.py b/kvalikirstu2/gui.py index 73981c1..aaf0410 100644 --- a/kvalikirstu2/gui.py +++ b/kvalikirstu2/gui.py @@ -51,7 +51,6 @@ class MainWindow(wx.Frame): pub.subscribe(self._study_exists_updated, gui_model.Messages.STUDY_EXISTS) pub.subscribe(self._index_exists_updated, gui_model.Messages.INDEX_EXISTS) pub.subscribe(self._temp_exists_updated, gui_model.Messages.TEMP_EXISTS) - pub.subscribe(self._convertable_files_found, gui_model.Messages.CONVERTABLE_FILES) pub.subscribe(self._update_title, gui_model.Messages.STUDY_EXISTS) pub.subscribe(self._update_index_button, gui_model.Messages.INDEX_EXISTS) self.model.broadcast_initial_messages() @@ -88,19 +87,18 @@ class MainWindow(wx.Frame): for button_bar, button_id in self.exists_listeners[gui_model.Messages.TEMP_EXISTS]: button_bar.EnableButton(button_id, exists) - def _convertable_files_found(self, found, formats=None): - if found: - formats = [] if not format else formats - msg = _( - "{}{} files found\n\n" - "These files must be converted for Kvalikirstu2.\n" - "Convert files to odt?").format( - ", ".join(formats[:-1]), _(" or ") + formats[-1] if len(formats) > 1 else "") + def _ask_to_convert(self): + formats = utils.CONVERTABLE_FORMATS + msg = _( + "{}{} files found\n\n" + "These files must be converted for Kvalikirstu2.\n" + "Convert files to odt?").format( + ", ".join(formats[:-1]), _(" or ") + formats[-1] if len(formats) > 1 else "") - with wx.MessageDialog(self, msg, style=wx.YES_NO, caption=_("Convert?")) as dlg: - dlg_return = dlg.ShowModal() - if dlg_return == wx.ID_YES: - self._convert(_("Convert to ODT"), self.model.convert_to_odt) + with wx.MessageDialog(self, msg, style=wx.YES_NO, caption=_("Convert?")) as dlg: + dlg_return = dlg.ShowModal() + if dlg_return == wx.ID_YES: + self._convert(_("Convert to ODT"), self.model.convert_to_odt) def _init_ui(self): """Inits the UI components of the main frame. @@ -425,6 +423,7 @@ class MainWindow(wx.Frame): if tempfiles_generated: dlg.run_function(self.model.generate_output, initial_msg=_("Generating index...")) + def generate_tempfiles(self, dlg): """Generates tempfiles for the index. Runs in a loop so that the user can resolve any error that comes up. @@ -491,7 +490,7 @@ class MainWindow(wx.Frame): title=_("Citation requirements"), message=_("Writing citation requirements to all text files..."), parent=self - ) as dlg: + ) as dlg: dlg.run_function( self.model.generate_citation_requirement, initial_msg=_("Generating citation requirements")) @@ -535,7 +534,10 @@ class MainWindow(wx.Frame): path = dlg.GetPath() with progress_dialog.Dialog(_("Read study"), _("Reading study files..."), parent=self) as dlg: - dlg.run_function(self.model.set_study_path, path, initial_msg=_("Parsing study files...")) + convert = dlg.run_function(self.model.set_study_path, path, initial_msg=_("Parsing study files...")) + + if convert: + self._ask_to_convert() def _init_help(self): self.html_window = html.HtmlHelpController(self, style=wx.html.HF_TOOLBAR | diff --git a/kvalikirstu2/gui_model.py b/kvalikirstu2/gui_model.py index 7a6d7ba..de7038c 100644 --- a/kvalikirstu2/gui_model.py +++ b/kvalikirstu2/gui_model.py @@ -25,7 +25,6 @@ class Messages: HEADER_CHANGED = "header_changed" # A single header changed UNDO_REDO_CHANGED = "undo_redo_changed" # Can program undo/redo? HEADER_TYPE_SHOW = "header_type_shown" # Updates what header types are shown in the GUI - CONVERTABLE_FILES = "convertable_files_found" # Does the data set contain convertable (non-txt) files? TASK_PROGRESS = "task_progress" # A task made progress, sends an info message TASK_FINISHED = "task_finished" # A task finished, sends an info message @@ -65,7 +64,6 @@ class GUIModel: pub.sendMessage(Messages.STUDY_EXISTS, exists=False) pub.sendMessage(Messages.TEMP_EXISTS, exists=False) pub.sendMessage(Messages.UNDO_REDO_CHANGED, redo=False, undo=False) - pub.sendMessage(Messages.CONVERTABLE_FILES, found=False) kvali_interface.check_archive_interface() # Header stuff @@ -304,10 +302,8 @@ class GUIModel: kvali_interface.set_study_path(path) self._read_headers() self._set_unsaved_changes(False) - pub.sendMessage( - Messages.CONVERTABLE_FILES, - found=kvali_interface.convertable_files_exist(), formats=utils.CONVERTABLE_FORMATS) self._broadcast_study() + return kvali_interface.convertable_files_exist() def add_text_to_dafs(self, text): """Adds text to data files. @@ -611,7 +607,6 @@ class GUIModel: kvali_interface.set_header_info(self.header_info) self._set_unsaved_changes(True) - def _set_unsaved_changes(self, changes): """Sets self.unsaved_changes to True/False. diff --git a/kvalikirstu2/header_scanner.py b/kvalikirstu2/header_scanner.py index bb5239c..502ccf1 100644 --- a/kvalikirstu2/header_scanner.py +++ b/kvalikirstu2/header_scanner.py @@ -26,12 +26,13 @@ def get_header_info_for_study(path: str): value_map_key = str((header, value)) header_info.value_mapping[value_map_key] = value if not headers: - logger.warning(_("No headers detected for the selected data!\n\n"\ - "If the data is not in textual form, you need to create a header list.\n" \ - "Rename data files (if required) before creating the header list.\n\n" \ + logger.warning(_("No headers detected for the selected data!\n\n" + "If the data is not in textual form, you need to create a header list.\n" + "Rename data files (if required) before creating the header list.\n\n" "If the data is in textual form, try converting the files.")) - except UnicodeDecodeError as ex: - logger.warning(_('Encoding error while reading file %s') % ex.filepath) + + except UnicodeDecodeError as decode_ex: + logger.warning(_('Encoding error while reading file %s'), decode_ex.filepath) header_info.init_builtin_headers() return header_info diff --git a/kvalikirstu2/kvali_interface.py b/kvalikirstu2/kvali_interface.py index 9f5747b..73e2866 100644 --- a/kvalikirstu2/kvali_interface.py +++ b/kvalikirstu2/kvali_interface.py @@ -448,6 +448,7 @@ def convert_to_txt(): yield from converter.convert_files_with_libreoffice_to_txt(_DATA['data_path'], args.timeout) yield from converter.convert_file_encoding_in_folder(_DATA['data_path'], args.encoding, ".txt") + def convert_txt_encoding(): """ Converts data files to txt. """ @@ -464,7 +465,6 @@ def convert_to_odt(): raise InvalidProgramStateException(_("A study has not been chosen.")) convert_odt = _convert_to_odt() - set_study_and_header_info() return convert_odt @@ -575,12 +575,14 @@ def _add_headers_for_external_study(headers): header_info.init_builtin_headers() save_header_info(header_info) + def get_daf_container_path(): """Forms and returns the path of the daf container file. """ daf_container_file = os.path.join(_DATA['data_path'], _DATA['interface'].get_study_data_filename(_DATA['metadata'])) return daf_container_file + def setup_external_file_study(headers): """ Transforms the study into one that contains external files that are linked to from the index. Any text in readable files is marked as data so it won't be read. diff --git a/setup.py b/setup.py index 5212d47..22f0575 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ from setuptools import setup, find_packages setup( name='kvalikirstu2', - version='1.0.0', + version='1.0.1', url='', description='A tool for analyzing qualitative studies', author='Jukka Lipsanen and Saara Saaninkoski', diff --git a/tests/test_gui.py b/tests/test_gui.py index e9ca8ac..2c2cac6 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -25,6 +25,7 @@ from kvalikirstu2 import progress_dialog test_files_path = os.path.join(os.path.dirname(__file__), "test files") +@mock.patch('kvalikirstu2.gui.MainWindow._ask_to_convert', mock.Mock()) @mock.patch('wx.MessageBox', mock.Mock(return_value=wx.ID_OK)) @mock.patch('wx.Dialog.ShowModal', mock.Mock(return_value=wx.ID_CANCEL)) class TestGUI(unittest.TestCase): -- GitLab