Example #1
0
    def on_dclick(self, e):
        key = e.GetText()
        from util.primitives.funcs import get
        mysentinel = Sentinel()  #@UndefinedVariable
        defval = get(self.defaults, key, mysentinel)
        val = self.prefs.setdefault(key, defval)

        preftype = defval.__class__ if defval is not mysentinel else val.__class__

        if issubclass(preftype, bool):
            val = not val

        elif isinstance(val, list):
            if is_all(val, (str, unicode))[0]:
                from gui.toolbox import edit_string_list
                ok, new_list = edit_string_list(self, val, 'Editing ' + key)
                if ok and new_list: val = new_list
                elif ok: val = defval
            elif is_all(val)[0]:
                from gui.toolbox import edit_list
                ok, new_list = edit_list(self, val, 'Editing ' + key)
                if ok and new_list: val = new_list
                elif ok: val = defval
            else:
                print is_all(val)
                raise AssertionError, key + \
                    ' is not a homogenous list :( tell Kevin to make this more gooder'

            if val == defval and defval is mysentinel:
                delpref(str(key))
                return

        elif isinstance(defval,
                        (str, unicode, int, float)) or defval is mysentinel:
            t = type(val) if defval is mysentinel else type(defval)

            print 'editing pref of type', t

            diag = wx.TextEntryDialog(self,
                                      key, 'Enter %s' % nice_type_names[t],
                                      str(val))

            if diag.ShowModal() == wx.ID_OK:
                val = diag.GetValue()

                if t is bool:
                    val = bool_from_string(val)
                if val != '':
                    val = t(val)
                elif defval is not mysentinel:
                    val = defval
                else:
                    delpref(str(key))
                    return

        self.prefs[str(key)] = val
        self.on_filter_txt()
        self._did_change_pref = True
Example #2
0
    def on_dclick(self, e):
        key = e.GetText()
        from util.primitives.funcs import get
        mysentinel = Sentinel() #@UndefinedVariable
        defval = get(self.defaults, key, mysentinel)
        val    = self.prefs.setdefault(key, defval)

        preftype = defval.__class__ if defval is not mysentinel else val.__class__

        if issubclass(preftype, bool):
            val = not val

        elif isinstance(val, list):
            if is_all(val, (str, unicode))[0]:
                from gui.toolbox import edit_string_list
                ok, new_list = edit_string_list(self, val, 'Editing ' + key)
                if ok and new_list: val = new_list
                elif ok: val = defval
            elif is_all(val)[0]:
                from gui.toolbox import edit_list
                ok, new_list = edit_list(self, val, 'Editing ' + key)
                if ok and new_list: val = new_list
                elif ok: val = defval
            else:
                print is_all(val)
                raise AssertionError, key + \
                    ' is not a homogenous list :( tell Kevin to make this more gooder'

            if val == defval and defval is mysentinel:
                delpref(str(key))
                return

        elif isinstance(defval, (str,unicode,int,float)) or defval is mysentinel:
            t = type(val) if defval is mysentinel else type(defval)

            print 'editing pref of type',t

            diag = wx.TextEntryDialog(self, key, 'Enter %s' % nice_type_names[t], str(val))

            if diag.ShowModal() == wx.ID_OK:
                val = diag.GetValue()

                if t is bool:
                    val = bool_from_string(val)
                if val != '':
                    val = t(val)
                elif defval is not mysentinel:
                    val = defval
                else:
                    delpref(str(key))
                    return

        self.prefs[str(key)] = val
        self.on_filter_txt()
        self._did_change_pref = True
Example #3
0
    def add_new_pref(self, e):
        key = str(wx.GetTextFromUser('Please enter the name for the pref', 'Add pref', self.filter_txt.Value))
        if not key: return
        typ = str(wx.GetSingleChoice('Please choose the type for the pref', 'Add pref', nice_type_names.values()))
        if not typ: return
        typ = nice_name_types[typ]

        if typ is list:
            from gui.toolbox import edit_list
            ok, val = edit_list(self, [], 'Editing %s' % key)
            if not ok: return
        else:
            val = str(wx.GetTextFromUser('Please enter the value for the pref','Add pref'))
            val = bool_from_string(val) if typ is bool else typ(val)
            if val == '': return

        self.prefs[key] = val
Example #4
0
    def add_new_pref(self, e):
        key = str(
            wx.GetTextFromUser('Please enter the name for the pref',
                               'Add pref', self.filter_txt.Value))
        if not key: return
        typ = str(
            wx.GetSingleChoice('Please choose the type for the pref',
                               'Add pref', nice_type_names.values()))
        if not typ: return
        typ = nice_name_types[typ]

        if typ is list:
            from gui.toolbox import edit_list
            ok, val = edit_list(self, [], 'Editing %s' % key)
            if not ok: return
        else:
            val = str(
                wx.GetTextFromUser('Please enter the value for the pref',
                                   'Add pref'))
            val = bool_from_string(val) if typ is bool else typ(val)
            if val == '': return

        self.prefs[key] = val