def pick_indications(parent=None, msg=None, right_column=None, picks=None): if parent is None: parent = wx.GetApp().GetTopWindow() if msg is None: msg = _('Pick the relevant indications.') if right_column is None: right_columns = ['This vaccine'] else: right_columns = [right_column] picker = gmListWidgets.cItemPickerDlg(parent, -1, msg = msg) picker.set_columns(columns = [_('Known indications')], columns_right = right_columns) inds = gmVaccination.get_indications(order_by = 'l10n_description') picker.set_choices ( choices = [ i['l10n_description'] for i in inds ], data = inds ) picker.set_picks ( picks = [ p['l10n_description'] for p in picks ], data = picks ) result = picker.ShowModal() if result == wx.ID_CANCEL: picker.Destroy() return None picks = picker.picks picker.Destroy() return picks
def edit(workplace=None): dbcfg = gmCfg.cCfgSQL() if workplace is None: dlg = wx.TextEntryDialog( parent=parent, message=_('Enter a descriptive name for the new workplace:'), caption=_('Configuring GNUmed workplaces ...'), defaultValue=u'', style=wx.OK | wx.CENTRE) dlg.ShowModal() workplace = dlg.GetValue().strip() if workplace == u'': gmGuiHelpers.gm_show_error( _('Cannot save a new workplace without a name.'), _('Configuring GNUmed workplaces ...')) return False curr_plugins = [] else: curr_plugins = gmTools.coalesce( dbcfg.get2(option=u'horstspace.notebook.plugin_load_order', workplace=workplace, bias='workplace'), []) msg = _( 'Pick the plugin(s) to be loaded the next time the client is restarted under the workplace:\n' '\n' ' [%s]\n') % workplace picker = gmListWidgets.cItemPickerDlg( parent, -1, title=_('Configuring workplace plugins ...'), msg=msg) picker.set_columns(['Available plugins'], ['Active plugins']) available_plugins = gmPlugin.get_installed_plugins(plugin_dir='gui') picker.set_choices(available_plugins) picker.set_picks(picks=curr_plugins[:]) btn_pressed = picker.ShowModal() if btn_pressed != wx.ID_OK: picker.Destroy() return False new_plugins = picker.get_picks() picker.Destroy() if new_plugins == curr_plugins: return True if new_plugins is None: return True dbcfg.set(option=u'horstspace.notebook.plugin_load_order', value=new_plugins, workplace=workplace) return True
def configure_list_from_list_option(parent=None, message=None, option=None, bias='user', default_value=None, choices=None, columns=None, data=None, caption=None, picks=None): if default_value is None: default_value = [] dbcfg = gmCfg.cCfgSQL() current_value = dbcfg.get2( option=option, workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace, bias=bias, default=default_value) if parent is None: parent = wx.GetApp().GetTopWindow() if caption is None: caption = _('Configuration') # setup item picker picker = gmListWidgets.cItemPickerDlg(parent, -1, msg=message) picker.set_columns(columns) picker.set_choices(choices) picker.set_picks(picks) result = picker.ShowModal() if result == wx.ID_CANCEL: picker.DestroyLater() return picks = picker.get_picks() picker.DestroyLater() dbcfg.set(workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace, option=option, value=picks) return
def configure_list_from_list_option(parent=None, message=None, option=None, bias='user', default_value=None, choices=None, columns=None, data=None, caption=None, picks=None): if default_value is None: default_value = [] dbcfg = gmCfg.cCfgSQL() current_value = dbcfg.get2 ( option = option, workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace, bias = bias, default = default_value ) if parent is None: parent = wx.GetApp().GetTopWindow() if caption is None: caption = _('Configuration') # setup item picker picker = gmListWidgets.cItemPickerDlg(parent, -1, msg = message) picker.set_columns(columns) picker.set_choices(choices) picker.set_picks(picks) result = picker.ShowModal() if result == wx.ID_CANCEL: picker.DestroyLater() return picks = picker.get_picks() picker.DestroyLater() dbcfg.set ( workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace, option = option, value = picks ) return
def manage_praxis_branches(parent=None): if parent is None: parent = wx.GetApp().GetTopWindow() #--------------------------- def get_unit_tooltip(unit): if unit is None: return None return u'\n'.join( unit.format(with_address=True, with_org=True, with_comms=True)) #--------------------------- def manage_orgs(): gmOrganizationWidgets.manage_orgs(parent=parent) #--------------------------- branches = gmPraxis.get_praxis_branches() org = branches[0].organization praxis = branches[0]['praxis'] msg = _('Pick those units of "%s" which are branches of your praxis !\n' '\n' 'Note that no other client should be connected at this time.\n' '\n' 'If you want to select another organization entirely\n' 'first remove all existing branches.\n') % praxis picker = gmListWidgets.cItemPickerDlg(parent, -1, msg=msg) picker.extra_button = (_('Manage units'), _('Manage organizations and their units'), manage_orgs) picker.left_item_tooltip_callback = get_unit_tooltip picker.right_item_tooltip_callback = get_unit_tooltip picker.set_columns(columns=[_('Units of "%s"') % praxis], columns_right=[_('Branches of your praxis')]) units = org.units branch_unit_pks = [b['pk_org_unit'] for b in branches] branch_units = [] for unit in units: if unit['pk_org_unit'] in branch_unit_pks: branch_units.append(unit) items = [ u'%s%s' % (u['unit'], gmTools.coalesce(u['l10n_unit_category'], u'', u' (%s)')) for u in units ] picker.set_choices(choices=items, data=units) items = [ u'%s%s' % (u['unit'], gmTools.coalesce(u['l10n_unit_category'], u'', u' (%s)')) for u in branch_units ] picker.set_picks(picks=items, data=branch_units) del units del branch_unit_pks del branch_units del items result = picker.ShowModal() if result == wx.ID_CANCEL: picker.Destroy() return None picks = picker.picks picker.Destroy() failed_delete_msg = _('Cannot delete praxis branch(es).\n' '\n' 'There are probably clients logged in\n' 'from other locations. You need to log out\n' 'all but this client before the praxis can\n' 'be reconfigured.') if len(picks) == 0: if not gmPraxis.delete_praxis_branches(): gmGuiHelpers.gm_show_error(error=failed_delete_msg, title=_('Configuring praxis ...')) return False while not set_active_praxis_branch(parent=parent): pass return pk_picked_units = [p['pk_org_unit'] for p in picks] pk_branches_to_keep = [ b['pk_praxis_branch'] for b in gmPraxis.get_praxis_branches() if b['pk_org_unit'] in pk_picked_units ] if len(pk_branches_to_keep) == 0: if not gmPraxis.delete_praxis_branches(): gmGuiHelpers.gm_show_error(error=failed_delete_msg, title=_('Configuring praxis ...')) return False else: if not gmPraxis.delete_praxis_branches( except_pk_praxis_branches=pk_branches_to_keep): gmGuiHelpers.gm_show_error(error=failed_delete_msg, title=_('Configuring praxis ...')) return False gmPraxis.create_praxis_branches(pk_org_units=pk_picked_units) # detect whether active branch in kept branches if gmPraxis.gmCurrentPraxisBranch( )['pk_praxis_branch'] in pk_branches_to_keep: return while not set_active_praxis_branch(parent=parent): pass
def manage_praxis_branches(parent=None): if parent is None: parent = wx.GetApp().GetTopWindow() #--------------------------- def get_unit_tooltip(unit): if unit is None: return None return u'\n'.join(unit.format(with_address = True, with_org = True, with_comms = True)) #--------------------------- def manage_orgs(): gmOrganizationWidgets.manage_orgs(parent = parent) #--------------------------- branches = gmPraxis.get_praxis_branches() org = branches[0].organization praxis = branches[0]['praxis'] msg = _( 'Pick those units of "%s" which are branches of your praxis !\n' '\n' 'Note that no other client should be connected at this time.\n' '\n' 'If you want to select another organization entirely\n' 'first remove all existing branches.\n' ) % praxis picker = gmListWidgets.cItemPickerDlg(parent, -1, msg = msg) picker.extra_button = ( _('Manage units'), _('Manage organizations and their units'), manage_orgs ) picker.left_item_tooltip_callback = get_unit_tooltip picker.right_item_tooltip_callback = get_unit_tooltip picker.set_columns(columns = [_('Units of "%s"') % praxis], columns_right = [_('Branches of your praxis')]) units = org.units branch_unit_pks = [b['pk_org_unit'] for b in branches] branch_units = [] for unit in units: if unit['pk_org_unit'] in branch_unit_pks: branch_units.append(unit) items = [ u'%s%s' % (u['unit'], gmTools.coalesce(u['l10n_unit_category'], u'', u' (%s)')) for u in units ] picker.set_choices(choices = items, data = units) items = [ u'%s%s' % (u['unit'], gmTools.coalesce(u['l10n_unit_category'], u'', u' (%s)')) for u in branch_units ] picker.set_picks(picks = items, data = branch_units) del units del branch_unit_pks del branch_units del items result = picker.ShowModal() if result == wx.ID_CANCEL: picker.Destroy() return None picks = picker.picks picker.Destroy() failed_delete_msg = _( 'Cannot delete praxis branch(es).\n' '\n' 'There are probably clients logged in\n' 'from other locations. You need to log out\n' 'all but this client before the praxis can\n' 'be reconfigured.' ) if len(picks) == 0: if not gmPraxis.delete_praxis_branches(): gmGuiHelpers.gm_show_error ( error = failed_delete_msg, title = _('Configuring praxis ...') ) return False while not set_active_praxis_branch(parent = parent): pass return pk_picked_units = [p['pk_org_unit'] for p in picks] pk_branches_to_keep = [ b['pk_praxis_branch'] for b in gmPraxis.get_praxis_branches() if b['pk_org_unit'] in pk_picked_units ] if len(pk_branches_to_keep) == 0: if not gmPraxis.delete_praxis_branches(): gmGuiHelpers.gm_show_error ( error = failed_delete_msg, title = _('Configuring praxis ...') ) return False else: if not gmPraxis.delete_praxis_branches(except_pk_praxis_branches = pk_branches_to_keep): gmGuiHelpers.gm_show_error ( error = failed_delete_msg, title = _('Configuring praxis ...') ) return False gmPraxis.create_praxis_branches(pk_org_units = pk_picked_units) # detect whether active branch in kept branches if gmPraxis.gmCurrentPraxisBranch()['pk_praxis_branch'] in pk_branches_to_keep: return while not set_active_praxis_branch(parent = parent): pass
def edit(workplace=None): dbcfg = gmCfg.cCfgSQL() if workplace is None: dlg = wx.TextEntryDialog ( parent = parent, message = _('Enter a descriptive name for the new workplace:'), caption = _('Configuring GNUmed workplaces ...'), defaultValue = u'', style = wx.OK | wx.CENTRE ) dlg.ShowModal() workplace = dlg.GetValue().strip() if workplace == u'': gmGuiHelpers.gm_show_error(_('Cannot save a new workplace without a name.'), _('Configuring GNUmed workplaces ...')) return False curr_plugins = [] else: curr_plugins = gmTools.coalesce(dbcfg.get2 ( option = u'horstspace.notebook.plugin_load_order', workplace = workplace, bias = 'workplace' ), [] ) msg = _( 'Pick the plugin(s) to be loaded the next time the client is restarted under the workplace:\n' '\n' ' [%s]\n' ) % workplace picker = gmListWidgets.cItemPickerDlg ( parent, -1, title = _('Configuring workplace plugins ...'), msg = msg ) picker.set_columns(['Available plugins'], ['Active plugins']) available_plugins = gmPlugin.get_installed_plugins(plugin_dir = 'gui') picker.set_choices(available_plugins) picker.set_picks(picks = curr_plugins[:]) btn_pressed = picker.ShowModal() if btn_pressed != wx.ID_OK: picker.Destroy() return False new_plugins = picker.get_picks() picker.Destroy() if new_plugins == curr_plugins: return True if new_plugins is None: return True dbcfg.set ( option = u'horstspace.notebook.plugin_load_order', value = new_plugins, workplace = workplace ) return True