Browse Source

Merge hacking-mitter

master
Julio Biason 16 years ago
parent
commit
9acd7749b9
  1. 179
      mitterlib/ui/ui_pygtk.py

179
mitterlib/ui/ui_pygtk.py

@ -186,72 +186,72 @@ class _ThreadManager(object):
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Custom cell renderer # Custom cell renderer
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
class CellRendererNetworkData(gtk.GenericCellrenderer): #class CellRendererNetworkData(gtk.GenericCellRenderer):
"""A customized cell renderer for messages.""" # """A customized cell renderer for messages."""
#
__gproperties__ = { # __gproperties__ = {
'message': (gobject.TYPE_PYOBJECT, # 'message': (gobject.TYPE_PYOBJECT,
'message', # 'message',
'A NetworkData object to be rendered', # 'A NetworkData object to be rendered',
'', # '',
gobject.PARAM_WRITABLE) # gobject.PARAM_WRITABLE)
} # }
#
def __init__(self): # def __init__(self):
super(CellrendererNetworkData, self).__init__(self) # super(CellrendererNetworkData, self).__init__(self)
self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE) # self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)
return # return
#
def on_render(self, window, widget, bg_area, cell_area, exp_area, flags): # def on_render(self, window, widget, bg_area, cell_area, exp_area, flags):
"""The render() method invokes the virtual render function of the # """The render() method invokes the virtual render function of the
gtk.CellRenderer. The three passed-in rectangles are areas of window. # gtk.CellRenderer. The three passed-in rectangles are areas of window.
Most renderers will draw within cell_area; the xalign, yalign, xpad, # Most renderers will draw within cell_area; the xalign, yalign, xpad,
and ypad properties of the gtk.CellRenderer should be honored with # and ypad properties of the gtk.CellRenderer should be honored with
respect to cell_area. background_area includes the blank space around # respect to cell_area. background_area includes the blank space around
the cell, and also the area containing the tree expander; so the # the cell, and also the area containing the tree expander; so the
background_area rectangles for all cells tile to cover the entire # background_area rectangles for all cells tile to cover the entire
window. expose_area is a clip rectangle. # window. expose_area is a clip rectangle.
#
The flags value is one of: gtk.CELL_RENDERER_SELECTED, # # The flags value is one of: gtk.CELL_RENDERER_SELECTED,
gtk.CELL_RENDERER_PRELIT, gtk.CELL_RENDERER_INSENSITIVE or # gtk.CELL_RENDERER_PRELIT, gtk.CELL_RENDERER_INSENSITIVE or
gtk.CELL_RENDERER_SORTED""" # gtk.CELL_RENDERER_SORTED"""
#
layout = self.get_layout(widget) # layout = self.get_layout(widget)
#
if flags & gtk.CELL_RENDERER_SELECTED: # if flags & gtk.CELL_RENDERER_SELECTED:
if widget.get_property('has-focus'): # if widget.get_property('has-focus'):
state = gtk.STATE_SELECTED # state = gtk.STATE_SELECTED
else: # else:
satte = gtk.STATE_ACTIVE # satte = gtk.STATE_ACTIVE
else: # else:
state = gtk.STATE_NORMAL # state = gtk.STATE_NORMAL
#
widget.style.paint_layout( # widget.style.paint_layout(
window, # window,
state, # state,
True, # True,
cell_area, # cell_area,
widget, # widget,
'foo', # 'foo',
cell_area.x + x_offset, # cell_area.x + x_offset,
cell_area.y + y_offset, # cell_area.y + y_offset,
layout # layout
) # )
return # return
#
def on_get_size(sel, widget, cell_area): # def on_get_size(sel, widget, cell_area):
"""The get_size() method obtains the width and height needed to render # """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 # 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 # 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 # widgets to determine the appropriate size for the cell_area to be
passed to the gtk.CellRenderer.render() method. If cell_area is not # 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 # 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 # 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 # height, as well as those in x_offset and y_offset are inclusive of the
xpad and ypad properties.""" # xpad and ypad properties."""
return (x_offset, y_offset, width, height) # return (x_offset, y_offset, width, height)
#
gobject.type_register(CellRendererNetworkData) #gobject.type_register(CellRendererNetworkData)
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Mitter interface object # Mitter interface object
@ -265,48 +265,11 @@ class Interface(object):
# ------------------------------------------------------------ # ------------------------------------------------------------
# Widget creation functions # 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): def _create_main_window(self):
"""Returns the object with the main window and the attached """Returns the object with the main window and the attached
widgets.""" widgets."""
main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
#where is this method?
self._systray_setup()
initial_width = int(self._options[self.NAMESPACE]['width']) initial_width = int(self._options[self.NAMESPACE]['width'])
initial_height = int(self._options[self.NAMESPACE]['height']) initial_height = int(self._options[self.NAMESPACE]['height'])
_log.debug('Initial size: %d x %d', initial_width, initial_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 = self._update_text.get_buffer()
text_buffer.connect('changed', self._count_chars) 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.connect('clicked', self._update_status)
self._update_button.set_property('sensitive', False) 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, update_box.pack_start(self._update_button, expand=False, fill=False,
padding=0) 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 = gtk.VBox(True, 0)
#update_area.pack_start(info_box)
update_area.pack_start(update_box) update_area.pack_start(update_box)
return update_area return update_area
@ -649,6 +605,7 @@ class Interface(object):
def _count_chars(self, text_buffer): def _count_chars(self, text_buffer):
"""Count the number of chars in the edit field and update the """Count the number of chars in the edit field and update the
label that shows the available space.""" label that shows the available space."""
_log.debug('Counting chars')
text = _buffer_text(text_buffer) text = _buffer_text(text_buffer)
count = len(text) count = len(text)

Loading…
Cancel
Save