Fix style of some dicts

This commit is contained in:
Sébastien Helleu 2014-07-13 10:12:59 +02:00
parent ac53e98cd0
commit 890d4fa2e1
4 changed files with 58 additions and 35 deletions

View File

@ -190,9 +190,11 @@ class Buffer(QtCore.QObject):
'nicks': [] 'nicks': []
} }
else: else:
self.nicklist[parent]['nicks'].append({'prefix': prefix, self.nicklist[parent]['nicks'].append({
'name': name, 'prefix': prefix,
'visible': visible}) 'name': name,
'visible': visible,
})
def nicklist_remove_item(self, parent, group, name): def nicklist_remove_item(self, parent, group, name):
"""Remove a group/nick from nicklist.""" """Remove a group/nick from nicklist."""
@ -225,7 +227,11 @@ class Buffer(QtCore.QObject):
for group in sorted(self.nicklist): for group in sorted(self.nicklist):
for nick in sorted(self.nicklist[group]['nicks'], for nick in sorted(self.nicklist[group]['nicks'],
key=lambda n: n['name']): key=lambda n: n['name']):
prefix_color = {'': '', ' ': '', '+': 'yellow'} prefix_color = {
'': '',
' ': '',
'+': 'yellow',
}
color = prefix_color.get(nick['prefix'], 'green') color = prefix_color.get(nick['prefix'], 'green')
if color: if color:
icon = QtGui.QIcon( icon = QtGui.QIcon(

View File

@ -165,14 +165,20 @@ class Network(QtCore.QObject):
self.send_to_weechat('\n'.join(_PROTO_SYNC_CMDS)) self.send_to_weechat('\n'.join(_PROTO_SYNC_CMDS))
def status_icon(self, status): def status_icon(self, status):
icon = {self.status_disconnected: 'dialog-close.png', """Return the name of icon for a given status."""
self.status_connecting: 'dialog-close.png', icon = {
self.status_connected: 'dialog-ok-apply.png'} self.status_disconnected: 'dialog-close.png',
self.status_connecting: 'dialog-close.png',
self.status_connected: 'dialog-ok-apply.png',
}
return icon.get(status, '') return icon.get(status, '')
def get_options(self): def get_options(self):
return {'server': self._server, """Get connection options."""
'port': self._port, return {
'ssl': 'on' if self._ssl else 'off', 'server': self._server,
'password': self._password, 'port': self._port,
'lines': str(self._lines)} 'ssl': 'on' if self._ssl else 'off',
'password': self._password,
'lines': str(self._lines),
}

View File

@ -127,7 +127,12 @@ class Color():
return '' return ''
def _attrcode_to_char(self, code): def _attrcode_to_char(self, code):
codes = {'\x01': '*', '\x02': '!', '\x03': '/', '\x04': '_'} codes = {
'\x01': '*',
'\x02': '!',
'\x03': '/',
'\x04': '_',
}
return codes.get(code, '') return codes.get(code, '')
def _convert_color(self, match): def _convert_color(self, match):

View File

@ -88,9 +88,10 @@ class WeechatObject:
return self._str_value(self.value) return self._str_value(self.value)
def __str__(self): def __str__(self):
self._obj_cb = {'hda': self._str_value_hdata, self._obj_cb = {
'inl': self._str_value_infolist, 'hda': self._str_value_hdata,
} 'inl': self._str_value_infolist,
}
return '%s: %s' % (self.objtype, return '%s: %s' % (self.objtype,
self._obj_cb.get(self.objtype, self._obj_cb.get(self.objtype,
self._str_value_other)()) self._str_value_other)())
@ -130,19 +131,20 @@ class Protocol:
"""Decode binary message received from WeeChat/relay.""" """Decode binary message received from WeeChat/relay."""
def __init__(self): def __init__(self):
self._obj_cb = {'chr': self._obj_char, self._obj_cb = {
'int': self._obj_int, 'chr': self._obj_char,
'lon': self._obj_long, 'int': self._obj_int,
'str': self._obj_str, 'lon': self._obj_long,
'buf': self._obj_buffer, 'str': self._obj_str,
'ptr': self._obj_ptr, 'buf': self._obj_buffer,
'tim': self._obj_time, 'ptr': self._obj_ptr,
'htb': self._obj_hashtable, 'tim': self._obj_time,
'hda': self._obj_hdata, 'htb': self._obj_hashtable,
'inf': self._obj_info, 'hda': self._obj_hdata,
'inl': self._obj_infolist, 'inf': self._obj_info,
'arr': self._obj_array, 'inl': self._obj_infolist,
} 'arr': self._obj_array,
}
def _obj_type(self): def _obj_type(self):
"""Read type in data (3 chars).""" """Read type in data (3 chars)."""
@ -260,11 +262,12 @@ class Protocol:
item[key] = self._obj_cb[objtype]() item[key] = self._obj_cb[objtype]()
item['__path'] = pointers item['__path'] = pointers
items.append(item) items.append(item)
return {'path': list_path, return {
'keys': dict_keys, 'path': list_path,
'count': count, 'keys': dict_keys,
'items': items, 'count': count,
} 'items': items,
}
def _obj_info(self): def _obj_info(self):
"""Read an info in data.""" """Read an info in data."""
@ -286,7 +289,10 @@ class Protocol:
var_value = self._obj_cb[var_type]() var_value = self._obj_cb[var_type]()
variables[var_name] = var_value variables[var_name] = var_value
items.append(variables) items.append(variables)
return {'name': name, 'items': items} return {
'name': name,
'items': items
}
def _obj_array(self): def _obj_array(self):
"""Read an array of values in data.""" """Read an array of values in data."""