コード例 #1
0
	def __update_ui_state(self):
		subdir_name = self.__patient.subdir_name
		path = self._LBL_directory.Label.strip().rstrip(os.sep).rstrip('/')
		if self._CHBOX_use_subdirectory.IsChecked():
			# add subdir if needed
			if not path.endswith(subdir_name):
				path = os.path.join(path, subdir_name)
				self._LBL_directory.Label = path + os.sep
		else:
			# remove subdir if there
			if path.endswith(subdir_name):
				path = path[:-len(subdir_name)].rstrip(os.sep).rstrip('/')
				self._LBL_directory.Label = path + os.sep

		is_empty = gmTools.dir_is_empty(directory = path)
		if is_empty is True:
			self._LBL_dir_is_empty.Label = ''
			self._BTN_open_directory.Disable()
			self._BTN_clear_directory.Disable()
			self._BTN_save_files.Enable()
			self._BTN_save_archive.Enable()
		elif is_empty is False:
			self._LBL_dir_is_empty.Label = _('directory contains data')
			self._BTN_open_directory.Enable()
			self._BTN_clear_directory.Enable()
			self._BTN_save_files.Disable()
			self._BTN_save_archive.Disable()
		else:	# we don't know, say, use_subdir and subdir does not yet exist
			self._LBL_dir_is_empty.Label = ''
			self._BTN_open_directory.Disable()
			self._BTN_clear_directory.Disable()
			self._BTN_save_files.Enable()
			self._BTN_save_archive.Enable()

		self.Layout()
コード例 #2
0
    def __refresh_include_or_remove_existing_data(self):
        if self._CHBOX_use_subdirectory.IsChecked():
            self._RBTN_include_data.Disable()
            self._RBTN_remove_data.Disable()
            return

        path = self._LBL_directory.Label.strip()
        if path == '':
            self._RBTN_include_data.Disable()
            self._RBTN_remove_data.Disable()
            return

        is_empty = gmTools.dir_is_empty(directory=path)
        if is_empty is None:
            self._RBTN_include_data.Disable()
            self._RBTN_remove_data.Disable()
            return

        if is_empty is True:
            self._RBTN_include_data.Disable()
            self._RBTN_remove_data.Disable()
            return

        self._RBTN_include_data.Enable()
        self._RBTN_remove_data.Enable()
コード例 #3
0
    def __refresh_dir_is_empty(self):
        path = self._LBL_directory.Label.strip()
        if path == '':
            self._LBL_dir_is_empty.Label = ''
            self._BTN_browse_directory.Disable()
            self._CHBOX_include_directory.Disable()
            return
        is_empty = gmTools.dir_is_empty(directory=path)
        if is_empty is None:
            self._LBL_dir_is_empty.Label = _('(cannot check directory)')
            self._BTN_browse_directory.Disable()
            self._CHBOX_include_directory.Disable()
            return
        if is_empty is True:
            self._LBL_dir_is_empty.Label = _('(directory appears empty)')
            self._BTN_browse_directory.Disable()
            self._CHBOX_include_directory.Disable()
            return

        msg = _('directory already contains data')
        self._BTN_browse_directory.Enable()
        self._CHBOX_include_directory.Enable()

        if os.path.isfile(os.path.join(path, 'DICOMDIR')):
            msg = _('%s\n- DICOM data') % msg

        if os.path.isdir(os.path.join(path, 'documents')):
            if len(os.listdir(os.path.join(path, 'documents'))) > 0:
                msg = _('%s\n- additional documents') % msg

        self._LBL_dir_is_empty.Label = msg
        self.Layout()
コード例 #4
0
	def __update_ui_state(self):

		media = self._LCTRL_removable_media.get_selected_item_data(only_one = True)
		if media is None:
			self._BTN_save2media.Disable()
			self._BTN_open_directory.Disable()
			self._BTN_clear_directory.Disable()
			self._CHBOX_encrypt.Disable()
			self._CHBOX_use_subdirectory.Disable()
			self._LBL_directory.Label = ''
			self._LBL_dir_is_empty.Label = ''
			return

		if media['type'] == 'cd':
			self._BTN_open_directory.Disable()
			self._BTN_clear_directory.Disable()
			self._LBL_directory.Label = ''
			if self.__burn_script is None:
				self._BTN_save2media.Disable()
				self._CHBOX_use_subdirectory.Disable()
				self._CHBOX_encrypt.Disable()
				self._LBL_dir_is_empty.Label = _('helper <gm-burn_doc(.bat)> not found')
			else:
				self._BTN_save2media.Enable()
				self._CHBOX_use_subdirectory.Enable()
				self._CHBOX_encrypt.Enable()
				self._LBL_dir_is_empty.Label = ''
			return

		if media['is_mounted'] is False:
			self._BTN_save2media.Disable()
			self._BTN_open_directory.Disable()
			self._BTN_clear_directory.Disable()
			self._CHBOX_use_subdirectory.Disable()
			self._CHBOX_encrypt.Disable()
			self._LBL_directory.Label = ''
			self._LBL_dir_is_empty.Label = _('media not mounted')
			return

		self._BTN_save2media.Enable()
		self._CHBOX_use_subdirectory.Enable()
		self._CHBOX_encrypt.Enable()

		path = self.__calc_path()
		self._LBL_directory.Label = path + os.sep
		is_empty = gmTools.dir_is_empty(directory = path)
		if is_empty is True:
			self._LBL_dir_is_empty.Label = ''
			self._BTN_open_directory.Enable()
			self._BTN_clear_directory.Disable()
		elif is_empty is False:
			self._LBL_dir_is_empty.Label = _('directory contains data')
			self._BTN_open_directory.Enable()
			self._BTN_clear_directory.Enable()
		else:	# we don't know, say, use_subdir and subdir does not yet exist
			self._LBL_dir_is_empty.Label = ''
			self._BTN_open_directory.Disable()
			self._BTN_clear_directory.Disable()
コード例 #5
0
    def _on_burn_items_button_pressed(self, event):
        event.Skip()

        found, external_cmd = gmShellAPI.detect_external_binary('gm-burn_doc')
        if not found:
            return False

        items = self._LCTRL_items.get_selected_item_data(only_one=False)
        if len(items) == 0:
            items = self._LCTRL_items.get_item_data()

        base_dir = None
        dlg = wx.DirDialog(
            self,
            message=_(
                'If you wish to include an existing directory select it here:'
            ),
            defaultPath=os.path.join(gmTools.gmPaths().home_dir, 'gnumed'),
            style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
        choice = dlg.ShowModal()
        path2include = dlg.GetPath()
        if choice == wx.ID_OK:
            if not gmTools.dir_is_empty(path2include):
                base_dir = path2include

        export_dir = gmPerson.gmCurrentPatient().export_area.export(
            base_dir=base_dir, items=items, with_metadata=True)
        if export_dir is None:
            return False

        cmd = u'%s %s' % (external_cmd, export_dir)
        if os.name == 'nt':
            blocking = True
        else:
            blocking = False
        success = gmShellAPI.run_command_in_shell(command=cmd,
                                                  blocking=blocking)
        if not success:
            gmGuiHelpers.gm_show_error(
                aMessage=_('Error burning documents to CD/DVD.'),
                aTitle=_('Burning documents'))
            return False

        self.save_soap_note(soap=_('Burned onto CD/DVD:\n - %s') %
                            u'\n - '.join([i['description'] for i in items]))

        browse_index = gmGuiHelpers.gm_show_question(
            title=title,
            question=_('Browse patient data pack ?'),
            cancel_button=False)
        if browse_index:
            gmNetworkTools.open_url_in_browser(
                url=u'file://%s' % os.path.join(export_dir, u'index.html'))

        return True
コード例 #6
0
    def _on_save_button_pressed(self, event):
        event.Skip()

        print("Is modal ? ->", self.IsModal())

        if self.__burn2cd:
            print("EndModal on burn2cd=True")
            self.EndModal(wx.ID_SAVE)

        if self._CHBOX_use_subdirectory.IsChecked() is True:
            print("EndModal on use_subdir=True")
            self.EndModal(wx.ID_SAVE)
            print("after EndModal !!")

        path = self._LBL_directory.Label

        if gmTools.dir_is_empty(path) is True:
            print("EndModal on dir_is_empty=True")
            self.EndModal(wx.ID_SAVE)

        if self._RBTN_remove_data.Value is True:
            really_remove_existing_data = gmGuiHelpers.gm_show_question(
                title=_('Creating patient media'),
                question=_('Really delete any existing data under\n'
                           '\n'
                           ' [%s]\n'
                           '\n'
                           'from disk ?\n'
                           '\n'
                           '(this operation is generally not reversible)') %
                path)
            if really_remove_existing_data is False:
                return

        print("Is modal ? ->", self.IsModal())
        print("now calling EndModal(wx.ID_SAVE)")
        self.EndModal(wx.ID_SAVE)
コード例 #7
0
    def _on_burn_items_button_pressed(self, event):
        event.Skip()

        # anything to do ?
        found, external_cmd = gmShellAPI.detect_external_binary('gm-burn_doc')
        if not found:
            return
        items = self._LCTRL_items.get_selected_item_data(only_one=False)
        if len(items) == 0:
            items = self._LCTRL_items.get_item_data()
        if len(items) == 0:
            return

        pat = gmPerson.gmCurrentPatient()
        dlg = cCreatePatientMediaDlg(self,
                                     -1,
                                     burn2cd=True,
                                     patient=pat,
                                     item_count=len(items))
        choice = dlg.ShowModal()
        if choice != wx.ID_SAVE:
            return
        path2include = dlg._LBL_directory.Label.strip()
        include_selected_dir = dlg._CHBOX_include_directory.IsChecked()
        dlg.Destroy()

        # do the export
        base_dir = None
        if include_selected_dir:
            if gmTools.dir_is_empty(path2include) is False:
                base_dir = gmTools.get_unique_filename(suffix='.iso')
                try:
                    shutil.copytree(path2include, base_dir)
                except shutil.Error:
                    _log.exception(
                        'cannot copy include directory [%s] -> [%s]',
                        path2include, base_dir)
                    return

        export_dir = gmPerson.gmCurrentPatient().export_area.export(
            base_dir=base_dir, items=items, with_metadata=True)
        if export_dir is None:
            return

        # burn onto media
        cmd = '%s %s' % (external_cmd, export_dir)
        if os.name == 'nt':
            blocking = True
        else:
            blocking = False
        success = gmShellAPI.run_command_in_shell(command=cmd,
                                                  blocking=blocking)
        if not success:
            gmGuiHelpers.gm_show_error(
                aMessage=_('Error burning documents to CD/DVD.'),
                aTitle=_('Burning documents'))
            return

        self.save_soap_note(soap=_('Burned onto CD/DVD:\n - %s') %
                            '\n - '.join([i['description'] for i in items]))

        browse_index = gmGuiHelpers.gm_show_question(
            title=_('Creating patient media'),
            question=_('Browse patient data pack ?'),
            cancel_button=False)
        if browse_index:
            gmNetworkTools.open_url_in_browser(
                url='file://%s' % os.path.join(export_dir, 'index.html'))

        return True
コード例 #8
0
    def _on_save_items_button_pressed(self, event):
        event.Skip()

        items = self._LCTRL_items.get_selected_item_data(only_one=False)
        if len(items) == 0:
            items = self._LCTRL_items.get_item_data()

        dlg = wx.DirDialog(
            self,
            message=_(
                'Select the directory into which to export the documents.'),
            defaultPath=os.path.join(gmTools.gmPaths().home_dir, 'gnumed'))
        choice = dlg.ShowModal()
        path = dlg.GetPath()
        if choice != wx.ID_OK:
            return True

        if not gmTools.dir_is_empty(path):
            reuse_nonempty_dir = gmGuiHelpers.gm_show_question(
                title=_(u'Saving export area documents'),
                question=_(
                    u'The chosen export directory\n'
                    u'\n'
                    u' [%s]\n'
                    u'\n'
                    u'already contains files. Do you still want to save the\n'
                    u'selected export area documents into that directory ?\n'
                    u'\n'
                    u'(this is useful for including the external documents\n'
                    u' already stored in or below this directory)\n'
                    u'\n'
                    u'[NO] will create a subdirectory for you and use that.') %
                path,
                cancel_button=True)
            if reuse_nonempty_dir is None:
                return True
            if reuse_nonempty_dir is False:
                path = gmTools.mk_sandbox_dir(
                    prefix=u'export-%s-' % gmPerson.gmCurrentPatient().dirname,
                    base_dir=path)

        include_metadata = gmGuiHelpers.gm_show_question(
            title=_(u'Saving export area documents'),
            question=_(u'Create descriptive metadata files\n'
                       u'and save them alongside the\n'
                       u'selected export area documents ?'),
            cancel_button=True)
        if include_metadata is None:
            return True

        export_dir = gmPerson.gmCurrentPatient().export_area.export(
            base_dir=path, items=items, with_metadata=include_metadata)

        self.save_soap_note(
            soap=_('Saved to [%s]:\n - %s') %
            (export_dir, u'\n - '.join([i['description'] for i in items])))

        title = _('Saving export area documents')
        msg = _('Saved documents into directory:\n\n %s') % export_dir
        if include_metadata:
            browse_index = gmGuiHelpers.gm_show_question(
                title=title,
                question=msg + u'\n\n' + _('Browse patient data pack ?'),
                cancel_button=False)
            if browse_index:
                gmNetworkTools.open_url_in_browser(
                    url=u'file://%s' % os.path.join(export_dir, u'index.html'))
        else:
            gmGuiHelpers.gm_show_info(title=title, info=msg)

        return True