Esempio n. 1
0
    def edit_old(workplace=None):

        available_plugins = gmPlugin.get_installed_plugins(plugin_dir='gui')
        if workplace is None:
            dlg = wx.TextEntryDialog(
                parent,
                _('Enter a descriptive name for the new workplace:'),
                caption=_('Configuring GNUmed workplaces ...'),
                value='',
                style=wx.OK | wx.CENTRE)
            dlg.ShowModal()
            workplace = dlg.GetValue().strip()
            if workplace == '':
                gmGuiHelpers.gm_show_error(
                    _('Cannot save a new workplace without a name.'),
                    _('Configuring GNUmed workplaces ...'))
                return False
            curr_plugins = []
            choices = available_plugins
        else:
            curr_plugins = gmTools.coalesce(
                gmCfgDB.get4workplace(
                    option='horstspace.notebook.plugin_load_order',
                    workplace=workplace), [])
            choices = curr_plugins[:]
            for p in available_plugins:
                if p not in choices:
                    choices.append(p)

        sels = range(len(curr_plugins))
        new_plugins = gmListWidgets.get_choices_from_list(
            parent=parent,
            msg=_('\n'
                  'Select the plugin(s) to be loaded the next time\n'
                  'the client is restarted under the workplace:\n'
                  '\n'
                  ' [%s]'
                  '\n') % workplace,
            caption=_('Configuring GNUmed workplaces ...'),
            choices=choices,
            selections=sels,
            columns=[_('Plugins')],
            single_selection=False)

        if new_plugins == curr_plugins:
            return True

        if new_plugins is None:
            return True

        gmCfgDB.set(option='horstspace.notebook.plugin_load_order',
                    value=new_plugins,
                    workplace=workplace)

        return True
Esempio n. 2
0
    def edit(workplace=None):
        if workplace is None:
            dlg = wx.TextEntryDialog(
                parent,
                _('Enter a descriptive name for the new workplace:'),
                caption=_('Configuring GNUmed workplaces ...'),
                value='',
                style=wx.OK | wx.CENTRE)
            dlg.ShowModal()
            workplace = dlg.GetValue().strip()
            if workplace == '':
                gmGuiHelpers.gm_show_error(
                    _('Cannot save a new workplace without a name.'),
                    _('Configuring GNUmed workplaces ...'))
                return False
            curr_plugins = []
        else:
            curr_plugins = gmTools.coalesce(
                gmCfgDB.get4workplace(
                    option='horstspace.notebook.plugin_load_order',
                    workplace=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.DestroyLater()
            return False

        new_plugins = picker.get_picks()
        picker.DestroyLater()
        if new_plugins == curr_plugins:
            return True

        if new_plugins is None:
            return True

        gmCfgDB.set(option='horstspace.notebook.plugin_load_order',
                    value=new_plugins,
                    workplace=workplace)

        return True
Esempio n. 3
0
def configure_string_from_list_option(parent=None,
                                      message=None,
                                      option=None,
                                      bias='user',
                                      default_value='',
                                      choices=None,
                                      columns=None,
                                      data=None,
                                      caption=None):

    current_value = gmCfgDB.get(
        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')

    selections = None
    if current_value is not None:
        try:
            selections = [choices.index(current_value)]
        except ValueError:
            pass

    choice = gmListWidgets.get_choices_from_list(parent=parent,
                                                 msg=message,
                                                 caption=caption,
                                                 choices=choices,
                                                 columns=columns,
                                                 data=data,
                                                 selections=selections,
                                                 single_selection=True,
                                                 can_return_empty=False)

    # aborted
    if choice is None:
        return

    # same value selected again
    if choice == current_value:
        return

    gmCfgDB.set(workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
                option=option,
                value=choice)
    return
Esempio n. 4
0
def configure_string_option(parent=None,
                            message=None,
                            option=None,
                            bias='user',
                            default_value='',
                            validator=None):
    current_value = gmCfgDB.get(
        option=option,
        workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
        bias=bias,
        default=default_value)

    if current_value is not None:
        current_value = '%s' % current_value

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    if validator is None:
        validator = lambda in_val: (True, in_val)

    while True:
        dlg = wx.TextEntryDialog(parent,
                                 message,
                                 caption=_('Configuration'),
                                 value=gmTools.coalesce(current_value, ''),
                                 style=wx.OK | wx.CANCEL | wx.CENTRE)
        result = dlg.ShowModal()
        if result == wx.ID_CANCEL:
            dlg.DestroyLater()
            return None

        user_val = dlg.GetValue().strip()
        dlg.DestroyLater()

        if user_val == current_value:
            return user_val

        validated, user_val = validator(user_val)
        if validated:
            break
        gmDispatcher.send(signal='statustext',
                          msg=_('Value [%s] not valid for option <%s>.') %
                          (user_val, option),
                          beep=True)
    gmCfgDB.set(workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
                option=option,
                value=user_val)
    return user_val
Esempio n. 5
0
    def clone(workplace=None):
        if workplace is None:
            return False

        new_name = wx.GetTextFromUser(
            message=_('Enter a name for the new workplace !'),
            caption=_('Cloning workplace'),
            default_value='%s-2' % workplace,
            parent=parent).strip()
        if new_name == '':
            return False

        opt = 'horstspace.notebook.plugin_load_order'
        plugins = gmCfgDB.get4workplace(option=opt, workplace=workplace)
        gmCfgDB.set(option=opt, value=plugins, workplace=new_name)
        # FIXME: clone cfg, too
        return True
Esempio n. 6
0
def configure_boolean_option(parent=None,
                             question=None,
                             option=None,
                             button_tooltips=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    tooltips = [
        _('Set "%s" to <True>.') % option,
        _('Set "%s" to <False>.') % option,
        _('Abort the dialog and do not change the current setting.')
    ]
    if button_tooltips is not None:
        for idx in range(len(button_tooltips)):
            tooltips[idx] = button_tooltips[idx]

    dlg = gmGuiHelpers.c3ButtonQuestionDlg(parent,
                                           -1,
                                           caption=_('Configuration'),
                                           question=question,
                                           button_defs=[{
                                               'label': _('Yes'),
                                               'tooltip': tooltips[0]
                                           }, {
                                               'label': _('No'),
                                               'tooltip': tooltips[1]
                                           }, {
                                               'label': _('Cancel'),
                                               'tooltip': tooltips[2],
                                               'default': True
                                           }])

    decision = dlg.ShowModal()
    if decision == wx.ID_YES:
        gmCfgDB.set(
            workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
            option=option,
            value=True)
    elif decision == wx.ID_NO:
        gmCfgDB.set(
            workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
            option=option,
            value=False)

    return
Esempio n. 7
0
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 = []
#	current_value = gmCfgDB.get (
#		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()
    gmCfgDB.set(workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
                option=option,
                value=picks)

    return
Esempio n. 8
0
def GetPluginLoadList(option, plugin_dir='', defaults=None, workplace=None):
    """Get a list of plugins to load.

	1) from database if option is not None
	2) from list of defaults
	3) if 2 is None, from source directory (then stored in database)

	FIXME: NOT from files in directories (important for py2exe)
	"""
    if workplace == 'System Fallback':
        return ['gmProviderInboxPlugin', 'gmDataMiningPlugin']

    if workplace is None:
        workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace

    p_list = None

    if option is not None:
        p_list = gmCfgDB.get4workplace(option=option,
                                       workplace=workplace,
                                       default=defaults)

    if p_list is not None:
        return p_list

    if defaults is None:
        p_list = get_installed_plugins(plugin_dir=plugin_dir)
        if (len(p_list) == 0):
            _log.error('cannot find plugins by scanning plugin directory ?!?')
            return defaults
    else:
        p_list = defaults
    # store for current user/current workplace
    gmCfgDB.set(option=option, value=p_list, workplace=workplace)
    _log.debug("plugin load list stored: %s" % str(p_list))
    return p_list