From e7ff7da1da45b74b5978bf380e0501e2ba6fbcf0 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 13 Jun 2005 22:11:09 +0000 Subject: [PATCH] themes are back (TODO: manage themes) --- src/chat.py | 20 +++++++++++---- src/common/config.py | 37 ++++++++++++++++++++------- src/config.py | 53 +-------------------------------------- src/gajim.py | 15 +++++++++-- src/groupchat_window.py | 8 +----- src/roster_window.py | 29 ++++++++++++--------- src/tabbed_chat_window.py | 12 +-------- 7 files changed, 76 insertions(+), 98 deletions(-) diff --git a/src/chat.py b/src/chat.py index 3a4177c4a..1163b58dc 100644 --- a/src/chat.py +++ b/src/chat.py @@ -810,12 +810,22 @@ class Chat: self.sent_history_pos[jid] = self.sent_history_pos[jid] + 1 conv_buf.set_text(self.sent_history[jid][self.sent_history_pos[jid]]) + def paint_banner(self, jid): + theme = gajim.config.get('roster_theme') + bgcolor = gajim.config.get_per('themes', theme, 'bannerbgcolor') + textcolor = gajim.config.get_per('themes', theme, 'bannertextcolor') + # the backgrounds are colored by using eventboxes and + # setting the bg color of the eventboxes. There is a + # separate event box for each component (name label and + # status icon). The avatar has one too in the glade file. + self.xmls[jid].get_widget('banner_eventbox').modify_bg( + gtk.STATE_NORMAL, gtk.gdk.color_parse(bgcolor)) + banner_name_label = self.xmls[jid].get_widget('banner_name_label') + banner_name_label.modify_fg(gtk.STATE_NORMAL, + gtk.gdk.color_parse(textcolor)) + def repaint_colored_widgets(self): """Repaint widgets (banner) in the window/tab with theme color""" - # get the bg color of the bar from the current theme colors - bgcolor = gajim.config.get('accountbgcolor') #FIXME: use uniq color - # iterate through tabs/windows and repaint for jid in self.xmls: - self.xmls[jid].get_widget('banner_eventbox').modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse(bgcolor)) + self.paint_banner(jid) diff --git a/src/common/config.py b/src/common/config.py index 9fa63960a..a5ad60a52 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -61,15 +61,6 @@ class Config: 'statusmsgcolor': [ opt_color, '#1eaa1e' ], 'collapsed_rows': [ opt_str, '' ], 'roster_theme': [ opt_str, 'green' ], - 'accounttextcolor': [ opt_color, '#ffffff' ], - 'accountbgcolor': [ opt_color, '#94aa8c' ], - 'accountfont': [ opt_str, 'Sans Bold 10' ], - 'grouptextcolor': [ opt_color, '#0000ff' ], - 'groupbgcolor': [ opt_color, '#eff3e7' ], - 'groupfont': [ opt_str, 'Sans Italic 10' ], - 'contacttextcolor': [ opt_color, '#000000' ], - 'contactbgcolor': [ opt_color, '#ffffff' ], - 'userfont': [ opt_str, 'Sans 10' ], 'saveposition': [ opt_bool, True ], 'mergeaccounts': [ opt_bool, False ], 'sort_by_show': [ opt_bool, True ], @@ -152,6 +143,19 @@ class Config: 'user': [ opt_str, '' ], 'pass': [ opt_str, '' ], }, {}), + 'themes': ({ + 'accounttextcolor': [ opt_color, '' ], + 'accountbgcolor': [ opt_color, '' ], + 'accountfont': [ opt_str, '' ], + 'grouptextcolor': [ opt_color, '' ], + 'groupbgcolor': [ opt_color, '' ], + 'groupfont': [ opt_str, '' ], + 'contacttextcolor': [ opt_color, '' ], + 'contactbgcolor': [ opt_color, '' ], + 'contactfont': [ opt_str, '' ], + 'bannertextcolor': [ opt_color, '' ], + 'bannerbgcolor': [ opt_color, '' ], + }, {}), } emoticons_default = { @@ -233,6 +237,21 @@ class Config: 'message_sent': [ True, '../data/sounds/sent.wav' ], } + themes_default = { + 'green': [ '#ffffff', '#94aa8c', 'Sans Bold 10', '#0000ff', '#eff3e7', + 'Sans Italic 10', '#000000', '#ffffff', 'Sans 10', '#ffffff', + '#94aa8c' ], + 'cyan': [ '#ff0000', '#9fdfff', 'Sans Bold 10', '#0000ff', '#ffffff', + 'Sans Italic 10', '#000000', '#ffffff', 'Sans 10', '#ffffff', + '#9fdfff' ], + 'marine': [ '#ffffff', '#918caa', 'Sans Bold 10', '#0000ff', '#e9e7f3', + 'Sans Italic 10', '#000000', '#ffffff', 'Sans 10', '#ffffff', + '#918caa' ], + 'human': [ '#ffffff', '#996442', 'Sans Bold 10', '#ab5920', '#e3ca94', + 'Sans Italic 10', '#000000', '#ffffff', 'Sans 10', '#ffffff', + '#996442' ], + } + def foreach(self, cb, data = None): for opt in self.__options: cb(data, opt, None, self.__options[opt]) diff --git a/src/config.py b/src/config.py index e6b61fda5..60086e214 100644 --- a/src/config.py +++ b/src/config.py @@ -148,54 +148,6 @@ class PreferencesWindow: st = gajim.config.get('use_transports_iconsets') self.xml.get_widget('transports_iconsets_checkbutton').set_active(st) - # Roster colors / font - self.theme_default = { - 'green': { - 'accounttextcolor': '#ffffff', - 'grouptextcolor': '#0000ff', - 'contacttextcolor': '#000000', - 'accountbgcolor': '#94aa8c', - 'groupbgcolor': '#eff3e7', - 'contactbgcolor': '#ffffff', - 'accountfont': 'Sans Bold 10', - 'groupfont': 'Sans Italic 10', - 'userfont': 'Sans 10', - }, - 'cyan': { - 'accounttextcolor': '#ff0000', - 'grouptextcolor': '#0000ff', - 'contacttextcolor': '#000000', - 'accountbgcolor': '#9fdfff', - 'groupbgcolor': '#ffffff', - 'contactbgcolor': '#ffffff', - 'accountfont': 'Sans Bold 10', - 'groupfont': 'Sans Italic 10', - 'userfont': 'Sans 10' - }, - 'marine': { - 'accounttextcolor': '#ffffff', - 'grouptextcolor': '#0000ff', - 'contacttextcolor': '#000000', - 'accountbgcolor': '#918caa', - 'groupbgcolor': '#e9e7f3', - 'contactbgcolor': '#ffffff', - 'accountfont': 'Sans Bold 10', - 'groupfont': 'Sans Italic 10', - 'userfont': 'Sans 10' - }, - 'human': { - 'accounttextcolor': '#ffffff', - 'grouptextcolor': '#ab5920', - 'contacttextcolor': '#000000', - 'accountbgcolor': '#996442', - 'groupbgcolor': '#e3ca94', - 'contactbgcolor': '#ffffff', - 'accountfont': 'Sans Bold 10', - 'groupfont': 'Sans Italic 10', - 'userfont': 'Sans 10' - }, - } - theme_combobox = self.xml.get_widget('theme_combobox') cell = gtk.CellRendererText() theme_combobox.pack_start(cell, True) @@ -203,14 +155,11 @@ class PreferencesWindow: model = gtk.ListStore(gobject.TYPE_STRING) theme_combobox.set_model(model) i = 0 - for t in self.theme_default: + for t in gajim.config.get_per('themes'): model.append([t]) if gajim.config.get('roster_theme') == t: theme_combobox.set_active(i) i += 1 - model.append(['custom']) - if gajim.config.get('roster_theme') == 'custom': - theme_combobox.set_active(i) self.on_theme_combobox_changed(theme_combobox) #use tabbed chat window diff --git a/src/gajim.py b/src/gajim.py index 4140274be..c0856b68a 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -790,16 +790,27 @@ class Interface: # Do not set gajim.verbose to False if -v option was given if gajim.config.get('verbose'): gajim.verbose = True - #add default emoticons is there is not in the config file + #add default emoticons if there is not in the config file if len(gajim.config.get_per('emoticons')) == 0: for emot in gajim.config.emoticons_default: gajim.config.add_per('emoticons', emot) gajim.config.set_per('emoticons', emot, 'path', gajim.config.emoticons_default[emot]) - #add default status messages is there is not in the config file + #add default status messages if there is not in the config file if len(gajim.config.get_per('statusmsg')) == 0: for msg in gajim.config.statusmsg_default: gajim.config.add_per('statusmsg', msg) gajim.config.set_per('statusmsg', msg, 'message', gajim.config.statusmsg_default[msg]) + #add default themes if there is not in the config file + if len(gajim.config.get_per('themes')) == 0: + d = ['accounttextcolor', 'accountbgcolor', 'accountfont', + 'grouptextcolor', 'groupbgcolor', 'groupfont', 'contacttextcolor', + 'contactbgcolor', 'contactfont', 'bannertextcolor', 'bannerbgcolor'] + default = gajim.config.themes_default + for theme in default: + gajim.config.add_per('themes', theme) + for o in d: + gajim.config.set_per('themes', theme, o, + default[theme][d.index(o)]) if gajim.verbose: gajim.log.setLevel(gajim.logging.DEBUG) diff --git a/src/groupchat_window.py b/src/groupchat_window.py index 21f9bf339..ee81b2204 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -669,14 +669,8 @@ class GroupchatWindow(chat.Chat): 'conversation_textview') self.name_labels[room_jid] = self.xmls[room_jid].get_widget( 'banner_name_label') - # set the fg colour of the label to white - self.name_labels[room_jid].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('white')) + self.paint_banner(room_jid) - banner_eventbox = self.xmls[room_jid].get_widget('banner_eventbox') - # get the background color from the current theme - bgcolor = gajim.config.get('accountbgcolor') - banner_eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(bgcolor)) - # connect the menuitems to their respective functions xm = gtk.glade.XML(GTKGUI_GLADE, 'gc_actions_menu', APP) xm.signal_autoconnect(self) diff --git a/src/roster_window.py b/src/roster_window.py index 9b63a9e3d..82e174bdc 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1387,13 +1387,14 @@ class RosterWindow: def iconCellDataFunc(self, column, renderer, model, iter, data = None): '''When a row is added, set properties for icon renderer''' + theme = gajim.config.get('roster_theme') if model.get_value(iter, 2) == 'account': renderer.set_property('cell-background', - gajim.config.get('accountbgcolor')) + gajim.config.get_per('themes', theme, 'accountbgcolor')) renderer.set_property('xalign', 0) elif model.get_value(iter, 2) == 'group': renderer.set_property('cell-background', - gajim.config.get('groupbgcolor')) + gajim.config.get_per('themes', theme, 'groupbgcolor')) renderer.set_property('xalign', 0.5) else: jid = model.get_value(iter, 3) @@ -1404,39 +1405,43 @@ class RosterWindow: renderer.set_property('cell-background', '#ab6161') else: renderer.set_property('cell-background', - gajim.config.get('userbgcolor')) + gajim.config.get_per('themes', theme, 'contactbgcolor')) renderer.set_property('xalign', 1) renderer.set_property('width', 20) def nameCellDataFunc(self, column, renderer, model, iter, data = None): '''When a row is added, set properties for name renderer''' + theme = gajim.config.get('roster_theme') if model.get_value(iter, 2) == 'account': renderer.set_property('foreground', - gajim.config.get('accounttextcolor')) + gajim.config.get_per('themes', theme, 'accounttextcolor')) renderer.set_property('cell-background', - gajim.config.get('accountbgcolor')) - renderer.set_property('font', gajim.config.get('accountfont')) + gajim.config.get_per('themes', theme, 'accountbgcolor')) + renderer.set_property('font', + gajim.config.get_per('themes', theme, 'accountfont')) renderer.set_property('xpad', 0) elif model.get_value(iter, 2) == 'group': renderer.set_property('foreground', - gajim.config.get('grouptextcolor')) + gajim.config.get_per('themes', theme, 'grouptextcolor')) renderer.set_property('cell-background', - gajim.config.get('groupbgcolor')) - renderer.set_property('font', gajim.config.get('groupfont')) + gajim.config.get_per('themes', theme, 'groupbgcolor')) + renderer.set_property('font', + gajim.config.get_per('themes', theme, 'groupfont')) renderer.set_property('xpad', 4) else: jid = model.get_value(iter, 3) account = model.get_value(iter, 4) renderer.set_property('foreground', - gajim.config.get('usertextcolor')) + gajim.config.get_per('themes', theme, 'contacttextcolor')) if jid in self.newly_added[account]: renderer.set_property('cell-background', '#adc3c6') elif jid in self.to_be_removed[account]: renderer.set_property('cell-background', '#ab6161') else: renderer.set_property('cell-background', - gajim.config.get('userbgcolor')) - renderer.set_property('font', gajim.config.get('userfont')) + gajim.config.get_per('themes', theme, 'contactbgcolor')) + renderer.set_property('font', + gajim.config.get_per('themes', theme, 'contactfont')) renderer.set_property('xpad', 8) def get_show(self, luser): diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index 40fa01126..d075e5c05 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -97,24 +97,14 @@ class TabbedChatWindow(chat.Chat): def draw_name_banner(self, name, jid): '''Draw the fat line at the top of the window that houses the status icon, name, jid, and avatar''' - # this is the text for the big brown bar label_text = '%s\n%s' \ % (name, jid) - # get the bg color of the bar from the current theme colors - bgcolor = gajim.config.get('accountbgcolor') - - # the backgrounds are colored by using eventboxes and - # setting the bg color of the eventboxes. There is a - # separate event box for each component (name label and - # status icon). The avatar has one too in the glade file. - self.xmls[jid].get_widget('banner_eventbox').modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse(bgcolor)) # setup the label that holds name and jid banner_name_label = self.xmls[jid].get_widget('banner_name_label') - banner_name_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('white')) banner_name_label.set_markup(label_text) + self.paint_banner(jid) def set_avatar(self, vcard): if not vcard.has_key('PHOTO'):