diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py
index ae080b9..84a5467 100644
--- a/mitterlib/ui/ui_pygtk.py
+++ b/mitterlib/ui/ui_pygtk.py
@@ -255,8 +255,9 @@ class Interface(object):
if self._app_icon:
main_window.set_icon_from_file(self._app_icon)
- main_window.connect('destroy', self.quit_app)
- main_window.connect('delete-event', self.quit_app)
+ main_window.connect('destroy', self._quit_app)
+ main_window.connect('delete-event', self._quit_app)
+ main_window.connect('size-request', self._window_resize)
grid = self._create_grid()
(menu, toolbar, accelerators) = self._create_menu_and_toolbar()
@@ -278,21 +279,21 @@ class Interface(object):
def _create_grid(self):
"""Add the displaying grid."""
- self._grid_store = gtk.ListStore(object)
+ grid_store = gtk.ListStore(object)
# Trying to store the NetworkData object only
# self.grid_store.set_sort_func(0, self._sort_by_time)
# self.grid_store.set_sort_column_id(0, gtk.SORT_DESCENDING)
- self.grid = gtk.TreeView(self._grid_store)
- self.grid.set_property('headers-visible', False)
- self.grid.set_rules_hint(True) # change color for each row
+ self._grid = gtk.TreeView(grid_store)
+ self._grid.set_property('headers-visible', False)
+ self._grid.set_rules_hint(True) # change color for each row
user_renderer = gtk.CellRendererPixbuf()
user_column = gtk.TreeViewColumn('User', user_renderer)
user_column.set_cell_data_func(user_renderer,
self._cell_renderer_user)
- self.grid.append_column(user_column)
+ self._grid.append_column(user_column)
message_renderer = gtk.CellRendererText()
message_renderer.set_property('wrap-mode', gtk.WRAP_WORD)
@@ -303,9 +304,9 @@ class Interface(object):
message_renderer)
message_column.set_cell_data_func(message_renderer,
self._cell_renderer_message)
- self.grid.append_column(message_column)
+ self._grid.append_column(message_column)
- self.grid.set_resize_mode(gtk.RESIZE_IMMEDIATE)
+ self._grid.set_resize_mode(gtk.RESIZE_IMMEDIATE)
#self.grid.connect('cursor-changed', self.check_post)
#self.grid.connect('row-activated', self.open_post)
#self.grid.connect('button-press-event', self.click_post)
@@ -314,7 +315,7 @@ class Interface(object):
scrolled_window = gtk.ScrolledWindow()
scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
- scrolled_window.add(self.grid)
+ scrolled_window.add(self._grid)
return scrolled_window
@@ -329,7 +330,7 @@ class Interface(object):
quit_action = gtk.Action('Quit', '_Quit',
'Exit Mitter', gtk.STOCK_QUIT)
- quit_action.connect('activate', self.quit_app)
+ quit_action.connect('activate', self._quit_app)
settings_action = gtk.Action('Settings', '_Settings',
'Settings', gtk.STOCK_PREFERENCES)
@@ -491,8 +492,9 @@ class Interface(object):
message = re.sub(r'&(?!(amp;|gt;|lt;|quot;|apos;))', r'&', message)
# highlight URLs
- message = URL_RE.sub(r'\1',
- message)
+ mask = r'\1' % (
+ self._options[self.NAMESPACE]['link_colour'])
+ message = URL_RE.sub(mask, message)
# use a different highlight for the current user
#message = re.sub(r'(@'+self.twitter.username+')',
@@ -536,7 +538,7 @@ class Interface(object):
#self._update_text.set_sensitive(False)
#self.statusbar.push(self.statusbar_context, 'Updating your status...')
- def quit_app(self, widget=None, user_data=None):
+ def _quit_app(self, widget=None, user_data=None):
"""Callback when the window is destroyed or the user selects
"Quit"."""
@@ -553,6 +555,34 @@ class Interface(object):
gtk.main_quit()
return
+ def _window_resize(self, widget, request, data=None):
+ """Called when the window is resized. We use it to set the proper
+ word-wrapping in the message column."""
+
+ (width, height) = widget.get_size()
+ model = self._grid.get_model()
+
+ if len(model) == 0:
+ # nothing in the list, so we don't have what to set proper word
+ # wrapping
+ return
+
+ column = self._grid.get_column(1)
+ iter = model.get_iter_first()
+ path = model.get_path(iter)
+
+ column_rectangle = self._grid.get_cell_area(path, column)
+
+ for renderer in column.get_cell_renderers():
+ renderer.set_property('wrap-width', column_rectangle.width)
+
+ while iter:
+ path = model.get_path(iter)
+ model.row_changed(path, iter)
+ iter = model.iter_next(iter)
+
+ return
+
# ------------------------------------------------------------
# Network related functions
# ------------------------------------------------------------
@@ -562,9 +592,10 @@ class Interface(object):
"""Function called after the data from the messages list is
retrieved."""
_log.debug('%d new tweets', len(results))
+ store = self._grid.get_model()
for message in results:
_log.debug('Data: %s', str(message))
- self._grid_store.prepend([message])
+ store.prepend([message])
return
def _exception_get_messages(self, widget, exception):
@@ -692,4 +723,13 @@ class Interface(object):
default=60,
conflict_group='interface',
is_cmd_option=False) # TODO: Should it be config only?
+ options.add_option(
+ group=self.NAMESPACE,
+ option='link_colour',
+ help='Color of links in the interface',
+ type='str',
+ metavar='COLOR',
+ default='blue',
+ conflict_group='interface',
+ is_cmd_option=False)