In tweaks, use the first variable name in the tweak block as the unique identifier for the tweak. You can find a tweak by searching for characters in this unique ID.

This commit is contained in:
Charles Haley 2012-07-06 10:32:28 +02:00
parent 0dadd6534e
commit 921ff8cf64

View File

@ -39,13 +39,15 @@ class Delegate(QStyledItemDelegate): # {{{
class Tweak(object): # {{{ class Tweak(object): # {{{
def __init__(self, name, doc, var_names, defaults, custom, tweak_num): def __init__(self, name, doc, var_names, defaults, custom):
translate = _ translate = _
self.name = translate(name) self.name = translate(name)
self.doc = doc.strip() self.doc = doc.strip()
if self.doc: if self.doc:
self.doc = translate(self.doc) self.doc = translate(self.doc)
self.var_names = var_names self.var_names = var_names
if len(self.var_names) > 0:
self.doc = "%s: %s\n\n%s"%(_('ID'), self.var_names[-1], self.doc)
self.default_values = {} self.default_values = {}
for x in var_names: for x in var_names:
self.default_values[x] = defaults[x] self.default_values[x] = defaults[x]
@ -53,7 +55,6 @@ class Tweak(object): # {{{
for x in var_names: for x in var_names:
if x in custom: if x in custom:
self.custom_values[x] = custom[x] self.custom_values[x] = custom[x]
self.tweak_num = tweak_num
def __str__(self): def __str__(self):
ans = ['#: ' + self.name] ans = ['#: ' + self.name]
@ -94,8 +95,10 @@ class Tweak(object): # {{{
self.custom_values.update(varmap) self.custom_values.update(varmap)
@property @property
def name_with_position_number(self): def name_with_first_var(self):
return "%d: %s"%(self.tweak_num, self.name) if len(self.var_names) > 0:
return "%s (%s:%s)"%(self.name, _('ID'), self.var_names[-1])
return self.name
# }}} # }}}
@ -118,7 +121,7 @@ class Tweaks(QAbstractListModel, SearchQueryParser): # {{{
except: except:
return NONE return NONE
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
return textwrap.fill(tweak.name_with_position_number, 40) return textwrap.fill(tweak.name_with_first_var, 40)
if role == Qt.FontRole and tweak.is_customized: if role == Qt.FontRole and tweak.is_customized:
ans = QFont() ans = QFont()
ans.setBold(True) ans.setBold(True)
@ -187,7 +190,7 @@ class Tweaks(QAbstractListModel, SearchQueryParser): # {{{
pos += 1 pos += 1
if not var_names: if not var_names:
raise ValueError('Failed to find any variables for %r'%name) raise ValueError('Failed to find any variables for %r'%name)
self.tweaks.append(Tweak(name, doc, var_names, defaults, custom, len(self.tweaks)+1)) self.tweaks.append(Tweak(name, doc, var_names, defaults, custom))
#print '\n\n', self.tweaks[-1] #print '\n\n', self.tweaks[-1]
return pos return pos