From 9acd7749b9046cb794a57122feccd69163f3ae44 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Tue, 28 Apr 2009 10:06:35 +1000 Subject: [PATCH] Merge hacking-mitter --- mitterlib/ui/ui_pygtk.py | 179 +++++++++++++++------------------------ 1 file changed, 68 insertions(+), 111 deletions(-) diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index bea69db..cc88261 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -186,72 +186,72 @@ class _ThreadManager(object): # ---------------------------------------------------------------------- # Custom cell renderer # ---------------------------------------------------------------------- -class CellRendererNetworkData(gtk.GenericCellrenderer): - """A customized cell renderer for messages.""" - - __gproperties__ = { - 'message': (gobject.TYPE_PYOBJECT, - 'message', - 'A NetworkData object to be rendered', - '', - gobject.PARAM_WRITABLE) - } - - def __init__(self): - super(CellrendererNetworkData, self).__init__(self) - self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE) - return - - def on_render(self, window, widget, bg_area, cell_area, exp_area, flags): - """The render() method invokes the virtual render function of the - gtk.CellRenderer. The three passed-in rectangles are areas of window. - Most renderers will draw within cell_area; the xalign, yalign, xpad, - and ypad properties of the gtk.CellRenderer should be honored with - respect to cell_area. background_area includes the blank space around - the cell, and also the area containing the tree expander; so the - background_area rectangles for all cells tile to cover the entire - window. expose_area is a clip rectangle. - - The flags value is one of: gtk.CELL_RENDERER_SELECTED, - gtk.CELL_RENDERER_PRELIT, gtk.CELL_RENDERER_INSENSITIVE or - gtk.CELL_RENDERER_SORTED""" - - layout = self.get_layout(widget) - - if flags & gtk.CELL_RENDERER_SELECTED: - if widget.get_property('has-focus'): - state = gtk.STATE_SELECTED - else: - satte = gtk.STATE_ACTIVE - else: - state = gtk.STATE_NORMAL - - widget.style.paint_layout( - window, - state, - True, - cell_area, - widget, - 'foo', - cell_area.x + x_offset, - cell_area.y + y_offset, - layout - ) - return - - def on_get_size(sel, widget, cell_area): - """The get_size() method obtains the width and height needed to render - the cell. These values are returned as part of a tuple containing the - x_offset, y_offset, width and height. get_size() is used by view - widgets to determine the appropriate size for the cell_area to be - passed to the gtk.CellRenderer.render() method. If cell_area is not - None, the x and y offsets of the cell relative to this location are - returned. Please note that the values set in the returned width and - height, as well as those in x_offset and y_offset are inclusive of the - xpad and ypad properties.""" - return (x_offset, y_offset, width, height) - -gobject.type_register(CellRendererNetworkData) +#class CellRendererNetworkData(gtk.GenericCellRenderer): +# """A customized cell renderer for messages.""" +# +# __gproperties__ = { +# 'message': (gobject.TYPE_PYOBJECT, +# 'message', +# 'A NetworkData object to be rendered', +# '', +# gobject.PARAM_WRITABLE) +# } +# +# def __init__(self): +# super(CellrendererNetworkData, self).__init__(self) +# self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE) +# return +# +# def on_render(self, window, widget, bg_area, cell_area, exp_area, flags): +# """The render() method invokes the virtual render function of the +# gtk.CellRenderer. The three passed-in rectangles are areas of window. +# Most renderers will draw within cell_area; the xalign, yalign, xpad, +# and ypad properties of the gtk.CellRenderer should be honored with +# respect to cell_area. background_area includes the blank space around +# the cell, and also the area containing the tree expander; so the +# background_area rectangles for all cells tile to cover the entire +# window. expose_area is a clip rectangle. +# +# # The flags value is one of: gtk.CELL_RENDERER_SELECTED, +# gtk.CELL_RENDERER_PRELIT, gtk.CELL_RENDERER_INSENSITIVE or +# gtk.CELL_RENDERER_SORTED""" +# +# layout = self.get_layout(widget) +# +# if flags & gtk.CELL_RENDERER_SELECTED: +# if widget.get_property('has-focus'): +# state = gtk.STATE_SELECTED +# else: +# satte = gtk.STATE_ACTIVE +# else: +# state = gtk.STATE_NORMAL +# +# widget.style.paint_layout( +# window, +# state, +# True, +# cell_area, +# widget, +# 'foo', +# cell_area.x + x_offset, +# cell_area.y + y_offset, +# layout +# ) +# return +# +# def on_get_size(sel, widget, cell_area): +# """The get_size() method obtains the width and height needed to render +# the cell. These values are returned as part of a tuple containing the +# x_offset, y_offset, width and height. get_size() is used by view +# widgets to determine the appropriate size for the cell_area to be +# passed to the gtk.CellRenderer.render() method. If cell_area is not +# None, the x and y offsets of the cell relative to this location are +# returned. Please note that the values set in the returned width and +# height, as well as those in x_offset and y_offset are inclusive of the +# xpad and ypad properties.""" +# return (x_offset, y_offset, width, height) +# +#gobject.type_register(CellRendererNetworkData) # ---------------------------------------------------------------------- # Mitter interface object @@ -265,48 +265,11 @@ class Interface(object): # ------------------------------------------------------------ # Widget creation functions # ------------------------------------------------------------ - def _systray_setup(self): - if not (self._app_icon and self._app_icon_alert): - self._systray = None - return - - self._systray = gtk.StatusIcon() - self._systray.set_from_file(self._app_icon) - - #where is systray_cb??? - self._systray.connect('activate', self.systray_cb) - self._systray.connect('popup-menu', self.systray_popup) - - # should set tooltip to msg text if that come? - self._systray.set_tooltip('Mitter: Click to toggle window visibility.') - self._systray.set_visible(True) - return - - def systray_popup(self, icon, button, time): - sys_popup = gtk.Menu() - restore = gtk.MenuItem("Restore", False) - exit = gtk.MenuItem("Exit", False) - sys_popup.append(restore) - sys_popup.append(exit) - sys_popup.popup(None, None, None, 3, time) - sys_popup.show_all() - - def systray_cb(self, icon): - - #why window location move down and down? - if self._main_window.is_active(): - self._main_window.hide() - else: - self._main_window.show() - def _create_main_window(self): """Returns the object with the main window and the attached widgets.""" main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) - #where is this method? - self._systray_setup() - initial_width = int(self._options[self.NAMESPACE]['width']) initial_height = int(self._options[self.NAMESPACE]['height']) _log.debug('Initial size: %d x %d', initial_width, initial_height) @@ -508,7 +471,7 @@ class Interface(object): text_buffer = self._update_text.get_buffer() text_buffer.connect('changed', self._count_chars) - self._update_button = gtk.Button(label = "(140)") + self._update_button = gtk.Button(label = '(140)') self._update_button.connect('clicked', self._update_status) self._update_button.set_property('sensitive', False) @@ -518,14 +481,7 @@ class Interface(object): update_box.pack_start(self._update_button, expand=False, fill=False, padding=0) - #info_box = gtk.HBox(False, 0) - #self._char_count = gtk.Label() - #self._char_count.set_text('(140)') - #info_box.pack_start(gtk.Label('What are you doing?')) - #info_box.pack_start(self._char_count) - update_area = gtk.VBox(True, 0) - #update_area.pack_start(info_box) update_area.pack_start(update_box) return update_area @@ -649,6 +605,7 @@ class Interface(object): def _count_chars(self, text_buffer): """Count the number of chars in the edit field and update the label that shows the available space.""" + _log.debug('Counting chars') text = _buffer_text(text_buffer) count = len(text)