[gjc]commit better analogy for colors in contact row

This commit is contained in:
Nikos Kouremenos 2005-11-08 14:09:56 +00:00
parent 58ae3ed63f
commit 99636d5ccf
3 changed files with 38 additions and 14 deletions

View File

@ -23,6 +23,7 @@
<signal name="delete_event" handler="on_roster_window_delete_event" last_modification_time="Mon, 21 Mar 2005 12:34:59 GMT"/>
<signal name="focus_in_event" handler="on_roster_window_focus_in_event" last_modification_time="Sun, 04 Sep 2005 16:33:35 GMT"/>
<signal name="key_press_event" handler="on_roster_window_key_press_event" last_modification_time="Tue, 20 Sep 2005 19:26:27 GMT"/>
<signal name="focus_out_event" handler="on_roster_window_focus_out_event" last_modification_time="Tue, 08 Nov 2005 14:01:01 GMT"/>
<child>
<widget class="GtkVBox" id="roster_vbox">
@ -376,6 +377,7 @@
<signal name="motion_notify_event" handler="on_roster_treeview_motion_notify_event" last_modification_time="Wed, 06 Jul 2005 14:38:58 GMT"/>
<signal name="leave_notify_event" handler="on_roster_treeview_leave_notify_event" last_modification_time="Wed, 06 Jul 2005 14:39:06 GMT"/>
<signal name="scroll_event" handler="on_roster_treeview_scroll_event" last_modification_time="Fri, 08 Jul 2005 22:09:03 GMT"/>
<signal name="style_set" handler="on_roster_treeview_style_set" last_modification_time="Tue, 08 Nov 2005 14:03:30 GMT"/>
</widget>
</child>
</widget>

View File

@ -384,20 +384,25 @@ def file_is_locked(path_to_file):
hfile.Close()
return False
def _get_fade_color(treeview, selected):
'''get a gdk color that is halfway between foreground and background
colors of the cell for the given treeview'''
def _get_fade_color(treeview, selected, focused):
'''get a gdk color that is between foreground and background in 0.3
0.7 respectively colors of the cell for the given treeview'''
style = treeview.style
if selected:
state = gtk.STATE_SELECTED
if focused: # is the window focused?
state = gtk.STATE_SELECTED
else: # is it not? NOTE: many gtk themes change bg on this
state = gtk.STATE_ACTIVE
else:
state = gtk.STATE_NORMAL
bg = style.base[state]
fg = style.text[state]
return gtk.gdk.Color((bg.red + fg.red)/2,
(bg.green + fg.green)/2,
(bg.blue + fg.blue)/2)
p = 0.3 # background
q = 0.7 # foreground # p + q should do 1.0
return gtk.gdk.Color(int(bg.red*p + fg.red*q),
int(bg.green*p + fg.green*q),
int(bg.blue*p + fg.blue*q))
def get_scaled_pixbuf(pixbuf, type):
'''returns scaled pixbuf, keeping ratio etc

View File

@ -237,7 +237,7 @@ class RosterWindow:
return self.transports_state_images[transport]
return self.jabber_state_images
def draw_contact(self, jid, account, selected=False):
def draw_contact(self, jid, account, selected=False, focus=False):
'''draw the correct state image and name'''
model = self.tree.get_model()
iters = self.get_contact_iter(jid, account)
@ -255,7 +255,7 @@ class RosterWindow:
status = contact.status.strip()
if status != '':
# escape markup entities and make them small italic and fg color
color = gtkgui_helpers._get_fade_color(self.tree, selected)
color = gtkgui_helpers._get_fade_color(self.tree, selected, focus)
colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue)
name += '\n<span size="small" style="italic" foreground="%s">%s</span>'\
% (colorstring, gtkgui_helpers.escape_for_pango_markup(status))
@ -1751,12 +1751,29 @@ _('If "%s" accepts this request you will know his status.') %jid)
return True # do NOT destory the window
def on_roster_window_focus_in_event(self, widget, event):
'''roster received focus, so if we had urgency REMOVE IT
NOTE: we do not have to read the message to remove urgency
so this functions does that'''
# roster received focus, so if we had urgency REMOVE IT
# NOTE: we do not have to read the message to remove urgency
# so this functions does that
if gtk.gtk_version >= (2, 8, 0) and gtk.pygtk_version >= (2, 8, 0):
if widget.props.urgency_hint:
widget.props.urgency_hint = False
# if a contact row is selected, update colors (eg. for status msg)
# because gtk engines may differ in bg when window is selected
# or not
if self._last_selected_contact is not None:
jid, account = self._last_selected_contact
self.draw_contact(jid, account, selected = True,
focus = True)
def on_roster_window_focus_out_event(self, widget, event):
# if a contact row is selected, update colors (eg. for status msg)
# because gtk engines may differ in bg when window is selected
# or not
if self._last_selected_contact is not None:
jid, account = self._last_selected_contact
self.draw_contact(jid, account, selected = True,
focus = False)
def on_roster_window_key_press_event(self, widget, event):
if event.keyval == gtk.keysyms.Escape:
@ -2378,7 +2395,7 @@ _('If "%s" accepts this request you will know his status.') %jid)
group_iter = model.iter_next(group_iter)
account_iter = model.iter_next(account_iter)
def _on_treeview_style_set(self, treeview, style):
def on_roster_treeview_style_set(self, treeview, style):
'''When style (theme) changes, redraw all contacts'''
for contact in self.iter_contact_rows():
self.draw_contact(contact[C_JID], contact[C_ACCOUNT])
@ -2404,7 +2421,7 @@ _('If "%s" accepts this request you will know his status.') %jid)
self.tree = self.xml.get_widget('roster_treeview')
self.tree.get_selection().connect('changed',
self._on_treeview_selection_changed)
self.tree.connect('style-set', self._on_treeview_style_set)
self._last_selected_contact = None # None or holds jid, account tupple
self.nb_unread = 0
self.last_save_dir = None