diff --git a/anon_gui.py b/anon_gui.py index 2c51226..6fa0cc7 100644 --- a/anon_gui.py +++ b/anon_gui.py @@ -79,6 +79,9 @@ import contextlib # import watchdog.observers +__VERSION__ = 0.1 +__APP_NAME__ = "Uploader" + anonymizer = dicognito.anonymizer.Anonymizer() # determine if application is a script file or frozen exe @@ -154,6 +157,7 @@ def annonymise( run_gui: bool = True, file_list: bool = False, dev: bool = False, + remove_files_on_annonymisation: bool = True, ): logger.debug(locals()) if run_gui: # Let the GUI handle it all @@ -164,6 +168,7 @@ def annonymise( clear_files=False, clear_files_on_close=True, dev=dev, + remove_files_on_annonymisation=remove_files_on_annonymisation, ) return if path.is_dir(): @@ -312,8 +317,13 @@ class LoginDialog(wx.Dialog): self.main_sizer.Add(self.error_text) + self.Bind(wx.EVT_CLOSE, self.on_close) + self.SetSizer(main_sizer) + def on_close(self, event): + self.Destroy() + # ---------------------------------------------------------------------- def on_login(self, event): """ @@ -555,11 +565,13 @@ class AnonGui(wx.App): self.frame = wx.Frame( None, wx.ID_ANY, - title="Uploader", + title=__APP_NAME__, style=wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP, - size=(300, 300), + size=(300, 400), ) + self.frame.SetIcon(wx.Icon("icon/icon1.ico")) + self.panel = wx.Panel(self.frame, wx.ID_ANY) self.file_detail_map = {} @@ -576,26 +588,26 @@ class AnonGui(wx.App): self.panel.sizer = wx.BoxSizer(wx.VERTICAL) - self.link_rapid_upload = hl.HyperLinkCtrl( - self.panel, - wx.ID_ANY, - "Rapid", - URL=f"{self.base_site_url}/rapids/create/", - ) - # self.panel.sizer.Add(self.link_rapid_upload, 0, wx.ALL, 10) + #self.link_rapid_upload = hl.HyperLinkCtrl( + # self.panel, + # wx.ID_ANY, + # "Rapid", + # URL=f"{self.base_site_url}/rapids/create/", + #) + ## self.panel.sizer.Add(self.link_rapid_upload, 0, wx.ALL, 10) - self.link_long_upload = hl.HyperLinkCtrl( - self.panel, - wx.ID_ANY, - "Long Series", - URL=f"{self.base_site_url}/longs/create/series", - ) - self.link_atlas_case = hl.HyperLinkCtrl( - self.panel, - wx.ID_ANY, - "Atlas Case", - URL=f"{self.base_site_url}/atlas/case/create/", - ) + #self.link_long_upload = hl.HyperLinkCtrl( + # self.panel, + # wx.ID_ANY, + # "Long Series", + # URL=f"{self.base_site_url}/longs/create/series", + #) + #self.link_atlas_case = hl.HyperLinkCtrl( + # self.panel, + # wx.ID_ANY, + # "Atlas Case", + # URL=f"{self.base_site_url}/atlas/case/create/", + #) # self.panel.sizer.Add(self.link_long_upload, 0, wx.ALL, 10) # Create menu bar @@ -616,6 +628,8 @@ class AnonGui(wx.App): #file_menu.Append(wx.ID_SAVE, "&Save") #file_menu.AppendSeparator() file_menu.Append(wx.ID_EXIT, "&Exit") + self.Bind(wx.EVT_MENU, lambda evt: wx.Exit(), id=wx.ID_EXIT) + self.menu_bar.Append(file_menu, "&File") @@ -683,11 +697,11 @@ class AnonGui(wx.App): # Set menu bar self.frame.SetMenuBar(self.menu_bar) - hoz_links = wx.BoxSizer(wx.HORIZONTAL) - hoz_links.Add(self.link_rapid_upload, 1, wx.EXPAND) - hoz_links.Add(self.link_long_upload, 1, wx.EXPAND) - hoz_links.Add(self.link_atlas_case, 1, wx.EXPAND) - self.panel.sizer.Add(hoz_links, 1, wx.EXPAND) + #hoz_links = wx.BoxSizer(wx.HORIZONTAL) + #hoz_links.Add(self.link_rapid_upload, 1, wx.EXPAND) + #hoz_links.Add(self.link_long_upload, 1, wx.EXPAND) + #hoz_links.Add(self.link_atlas_case, 1, wx.EXPAND) + #self.panel.sizer.Add(hoz_links, 1, wx.EXPAND) # self.dirctrl = wx.GenericDirCtrl(self.panel, wx.ID_ANY, # dir=dir, @@ -695,7 +709,7 @@ class AnonGui(wx.App): # wx.DIRCTRL_3D_INTERNAL | # wx.DIRCTRL_MULTIPLE, # filter="Dicom files (*.dcm)|*.dcm") - upload_drag_sizer = wx.BoxSizer(wx.HORIZONTAL) + bottom_button_sizer = wx.BoxSizer(wx.HORIZONTAL) self.drag_button = wx.Button( self.panel, id=wx.ID_ANY, label="Drag" ) @@ -705,8 +719,8 @@ class AnonGui(wx.App): ) self.upload_button.SetToolTip("Upload files to the server. You must be logged in.") self.upload_button.Disable() - upload_drag_sizer.Add(self.upload_button, 4, wx.EXPAND) - upload_drag_sizer.Add(self.drag_button, 1, wx.EXPAND) + bottom_button_sizer.Add(self.upload_button, 4, wx.EXPAND) + bottom_button_sizer.Add(self.drag_button, 1, wx.EXPAND) # Use some sizers to see layout options # self.panel.sizer.Add(self.dirctrl, 1, wx.EXPAND) @@ -755,7 +769,7 @@ class AnonGui(wx.App): self.panel.sizer.Add(self.list_ctrl, 8, wx.EXPAND) #self.panel.sizer.Add(self.drag_button, 2, wx.EXPAND) #self.panel.sizer.Add(self.upload_button, 2, wx.EXPAND) - self.panel.sizer.Add(upload_drag_sizer, 2, wx.EXPAND) + self.panel.sizer.Add(bottom_button_sizer, 1, wx.EXPAND) self.progress_sizer = wx.BoxSizer(wx.VERTICAL) self.progress_bar = wx.Gauge( @@ -807,13 +821,13 @@ class AnonGui(wx.App): def import_from_dir(self, event): default_path = str(self.input_dir.resolve()) with wx.DirDialog( - self.frame, "Choose a directory", style=wx.DD_DIR_MUST_EXIST, defaultPath=default_path + self.frame, "Choose a directory to import dicom files from.", style=wx.DD_DIR_MUST_EXIST, defaultPath=default_path ) as dlg: if dlg.ShowModal() == wx.ID_OK: load_path = Path(dlg.GetPath()) - self.AnnonymiseFilesInDir(load_path, self.dir) + self.AnnonymiseFilesInDir(load_path, self.dir, remove_original=False) - def AnnonymiseFilesInDir(self, input_dir, output_dir): + def AnnonymiseFilesInDir(self, input_dir, output_dir, remove_original: bool | None=None): logger.debug("AnnonymiseFilesInDir") logger.debug(f"input: {input_dir} / output {output_dir}") if input_dir.is_dir(): @@ -829,6 +843,10 @@ class AnonGui(wx.App): logger.debug(files) + + if remove_original is None: + remove_original = self.remove_files_on_annonymisation + # files = order_files_by_dicom_attribute(files) # progress_dialog = wx.ProgressDialog( @@ -852,7 +870,7 @@ class AnonGui(wx.App): i += 1 # new_filepath = Path(output_dir).joinpath(f"IMG_{i:03}.dcm") - dataset, filepath = anonymize_file(file, new_filepath, remove_original=self.remove_files_on_annonymisation) + dataset, filepath = anonymize_file(file, new_filepath, remove_original=remove_original) self.add_datails_to_file_detail_map(dataset, filepath) # progress_dialog.Destroy() @@ -864,8 +882,8 @@ class AnonGui(wx.App): self.progress_text.SetLabelText(text) self.progress_bar.SetRange(total) self.progress_sizer.ShowItems(show=True) - self.panel.Layout() self.panel.sizer.Fit(self.panel) + self.frame.Layout() try: class P: @@ -877,6 +895,7 @@ class AnonGui(wx.App): def update(self, n: int): self.gui.progress_bar.SetValue(n) self.gui.progress_text.SetLabelText(f"{self.text} : {n}") + self.gui.frame.Refresh() yield P(self, total, text) finally: @@ -900,12 +919,18 @@ class AnonGui(wx.App): def on_about_box(self, event=None): description = f""" - An upload/export tool +A dicom export/upload tool - Settings - -------- - Watch/import dir: {self.input_dir} - Annonymised files dir: {self.dir} +Settings +-------- +Watch/import dir: {self.input_dir} +Annonymised files dir: {self.dir} + +clear files on start: {self.clear_files_on_start} +clear files on close: {self.clear_files_on_close} +remove files on annonymisations: {self.remove_files_on_annonymisation} + +base site url: {self.base_site_url} """ licence = """GPL""" @@ -913,15 +938,17 @@ class AnonGui(wx.App): info = wx.adv.AboutDialogInfo() # info.SetIcon(wx.Icon('hunter.png', wx.BITMAP_TYPE_PNG)) - info.SetName("RadUploader") - info.SetVersioe("0.1") + info.SetName(__APP_NAME__) + info.SetVersion(__VERSION__) info.SetDescription(description) + info.SetIcon(wx.Icon("icon/icon1.png", desiredWidth=100)) info.SetLicence(licence) wx.adv.AboutBox(info) - def OnExit(self): + def OnExit(self, event=None): + print("on exit") if self.clear_files_on_close: self.ClearFiles(load_dir=False) @@ -1242,6 +1269,9 @@ class AnonGui(wx.App): self.list_ctrl.UpdateData(DATA) self.populate_series_grid() + self.frame.Refresh() + self.frame.Layout() + # progress_dialog.Destroy() # if hashes: diff --git a/anon_gui.spec b/anon_gui.spec index d0eda3f..39f0c07 100644 --- a/anon_gui.spec +++ b/anon_gui.spec @@ -34,4 +34,5 @@ exe = EXE( target_arch=None, codesign_identity=None, entitlements_file=None, + icon='icon\\icon1.ico' ) diff --git a/icon/icon1.ico b/icon/icon1.ico new file mode 100644 index 0000000..aa55511 Binary files /dev/null and b/icon/icon1.ico differ diff --git a/icon/icon1.jfif b/icon/icon1.jfif new file mode 100644 index 0000000..5ae2b9c Binary files /dev/null and b/icon/icon1.jfif differ diff --git a/icon/icon1.png b/icon/icon1.png new file mode 100644 index 0000000..44adf9f Binary files /dev/null and b/icon/icon1.png differ diff --git a/icon/icon2.jfif b/icon/icon2.jfif new file mode 100644 index 0000000..0faa291 Binary files /dev/null and b/icon/icon2.jfif differ