clean code and update to using GTK/PyGTK 2.8; see #2248

This commit is contained in:
Nikos Kouremenos 2007-01-16 23:26:38 +00:00
parent abcb9a35f1
commit e9afe36ff3
17 changed files with 194 additions and 205 deletions

View File

@ -72,8 +72,7 @@ class AdvancedConfigurationWindow(object):
renderer_text, text = 1) renderer_text, text = 1)
col.set_cell_data_func(renderer_text, self.cb_value_column_data) col.set_cell_data_func(renderer_text, self.cb_value_column_data)
if gtk.gtk_version >= (2, 8, 0) and gtk.pygtk_version >= (2, 8, 0): col.props.resizable = True
col.set_resizable(True) # there is a bug in 2.6.x series
col.set_max_width(250) col.set_max_width(250)
renderer_text = gtk.CellRendererText() renderer_text = gtk.CellRendererText()

View File

@ -1,8 +1,25 @@
'''atom_window.py - a window to display atom entries from pubsub. For now greatly simplified, ## atom_window.py - a window to display atom entries from pubsub.
supports only simple feeds like the one from pubsub.com. ''' ##
## For now greatly simplified, supports only simple feeds like the
## one from pubsub.com.
##
## Copyright (C) 2006-2007 Yann Le Boulanger <asterix@lagaule.org>
## Copyright (C) 2007 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2006-2007 Liori (I think) put ur self here please
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
import gtk import gtk
import gtk.gdk import gobject
import gtkgui_helpers import gtkgui_helpers
from common import helpers from common import helpers
@ -11,7 +28,7 @@ class AtomWindow:
window = None window = None
entries = [] entries = []
@classmethod # python2.4 decorator @classmethod
def newAtomEntry(cls, entry): def newAtomEntry(cls, entry):
''' Queue new entry, open window if there's no one opened. ''' ''' Queue new entry, open window if there's no one opened. '''
cls.entries.append(entry) cls.entries.append(entry)
@ -52,22 +69,22 @@ class AtomWindow:
if newentry.feed_link is not None: if newentry.feed_link is not None:
self.feed_title_label.set_markup( self.feed_title_label.set_markup(
u'<span foreground="blue" underline="single">%s</span>' % \ u'<span foreground="blue" underline="single">%s</span>' % \
gtkgui_helpers.escape_for_pango_markup(newentry.feed_title)) gobject.markup_escape_text(newentry.feed_title))
else: else:
self.feed_title_label.set_markup( self.feed_title_label.set_markup(
gtkgui_helpers.escape_for_pango_markup(newentry.feed_title)) gobject.markup_escape_text(newentry.feed_title))
self.feed_tagline_label.set_markup( self.feed_tagline_label.set_markup(
u'<small>%s</small>' % \ u'<small>%s</small>' % \
gtkgui_helpers.escape_for_pango_markup(newentry.feed_tagline)) gobject.markup_escape_text(newentry.feed_tagline))
if newentry.uri is not None: if newentry.uri is not None:
self.entry_title_label.set_markup( self.entry_title_label.set_markup(
u'<span foreground="blue" underline="single">%s</span>' % \ u'<span foreground="blue" underline="single">%s</span>' % \
gtkgui_helpers.escape_for_pango_markup(newentry.title)) gobject.markup_escape_text(newentry.title))
else: else:
self.entry_title_label.set_markup( self.entry_title_label.set_markup(
gtkgui_helpers.escape_for_pango_markup(newentry.title)) gobject.markup_escape_text(newentry.title))
self.last_modified_label.set_text(newentry.updated) self.last_modified_label.set_text(newentry.updated)
@ -97,7 +114,7 @@ class AtomWindow:
self.displayNextEntry() self.displayNextEntry()
def on_entry_title_button_press_event(self, widget, event): def on_entry_title_button_press_event(self, widget, event):
# TODO: make it using special gtk2.10 widget #FIXME: make it using special gtk2.10 widget
if event.button == 1: # left click if event.button == 1: # left click
uri = self.entry.uri uri = self.entry.uri
if uri is not None: if uri is not None:
@ -105,7 +122,7 @@ class AtomWindow:
return True return True
def on_feed_title_button_press_event(self, widget, event): def on_feed_title_button_press_event(self, widget, event):
# TODO: make it using special gtk2.10 widget #FIXME: make it using special gtk2.10 widget
if event.button == 1: # left click if event.button == 1: # left click
uri = self.entry.feed_uri uri = self.entry.feed_uri
if uri is not None: if uri is not None:

View File

@ -133,6 +133,3 @@ class CellRendererImage(gtk.GenericCellRenderer):
(cell_area.height - calc_height - \ (cell_area.height - calc_height - \
self.get_property('ypad')) self.get_property('ypad'))
return x_offset, y_offset, calc_width, calc_height return x_offset, y_offset, calc_width, calc_height
if gtk.pygtk_version < (2, 8, 0):
gobject.type_register(CellRendererImage)

View File

@ -1,7 +1,7 @@
## chat_control.py ## chat_control.py
## ##
## Copyright (C) 2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2006 Yann Le Boulanger <asterix@lagaule.org>
## Copyright (C) 2006 Nikos Kouremenos <kourem@gmail.com> ## Copyright (C) 2006-2007 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2006 Travis Shirk <travis@pobox.com> ## Copyright (C) 2006 Travis Shirk <travis@pobox.com>
## Copyright (C) 2006 Dimitur Kirov <dkirov@gmail.com> ## Copyright (C) 2006 Dimitur Kirov <dkirov@gmail.com>
## ##
@ -1033,7 +1033,7 @@ class ChatControl(ChatControlBase):
if self.TYPE_ID == message_control.TYPE_PM: if self.TYPE_ID == message_control.TYPE_PM:
name = _('%(nickname)s from group chat %(room_name)s') %\ name = _('%(nickname)s from group chat %(room_name)s') %\
{'nickname': name, 'room_name': self.room_name} {'nickname': name, 'room_name': self.room_name}
name = gtkgui_helpers.escape_for_pango_markup(name) name = gobject.markup_escape_text(name)
# We know our contacts nick, but if another contact has the same nick # We know our contacts nick, but if another contact has the same nick
# in another account we need to also display the account. # in another account we need to also display the account.
@ -1048,14 +1048,14 @@ class ChatControl(ChatControlBase):
contact_ = gajim.contacts.get_first_contact_from_jid(account, jid) contact_ = gajim.contacts.get_first_contact_from_jid(account, jid)
if contact_.get_shown_name() == self.contact.get_shown_name(): if contact_.get_shown_name() == self.contact.get_shown_name():
acct_info = ' (%s)' % \ acct_info = ' (%s)' % \
gtkgui_helpers.escape_for_pango_markup(self.account) gobject.markup_escape_text(self.account)
break break
status = contact.status status = contact.status
if status is not None: if status is not None:
banner_name_label.set_ellipsize(pango.ELLIPSIZE_END) banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
status = helpers.reduce_chars_newlines(status, max_lines = 2) status = helpers.reduce_chars_newlines(status, max_lines = 2)
status_escaped = gtkgui_helpers.escape_for_pango_markup(status) status_escaped = gobject.markup_escape_text(status)
font_attrs, font_attrs_small = self.get_font_attrs() font_attrs, font_attrs_small = self.get_font_attrs()
st = gajim.config.get('displayed_chat_state_notifications') st = gajim.config.get('displayed_chat_state_notifications')
@ -1330,7 +1330,7 @@ class ChatControl(ChatControlBase):
name = self.contact.get_shown_name() name = self.contact.get_shown_name()
if self.resource: if self.resource:
name += '/' + self.resource name += '/' + self.resource
label_str = gtkgui_helpers.escape_for_pango_markup(name) label_str = gobject.markup_escape_text(name)
if num_unread: # if unread, text in the label becomes bold if num_unread: # if unread, text in the label becomes bold
label_str = '<b>' + unread + label_str + '</b>' label_str = '<b>' + unread + label_str + '</b>'
return (label_str, color) return (label_str, color)

View File

@ -3,7 +3,7 @@
## ##
## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
## Copyright (C) 2003-2004 Vincent Hanquez <tab@snarc.org> ## Copyright (C) 2003-2004 Vincent Hanquez <tab@snarc.org>
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com> ## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2005 Dimitur Kirov <dkirov@gmail.com> ## Copyright (C) 2005 Dimitur Kirov <dkirov@gmail.com>
## Copyright (C) 2005-2006 Travis Shirk <travis@pobox.com> ## Copyright (C) 2005-2006 Travis Shirk <travis@pobox.com>
## Copyright (C) 2005 Norman Rasmussen <norman@rasmussen.co.za> ## Copyright (C) 2005 Norman Rasmussen <norman@rasmussen.co.za>
@ -768,8 +768,7 @@ class AboutDialog:
dlg.set_authors(authors) dlg.set_authors(authors)
if gtk.pygtk_version >= (2, 8, 0) and gtk.gtk_version >= (2, 8, 0): dlg.props.wrap_license = True
dlg.props.wrap_license = True
pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join( pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(
gajim.DATA_DIR, 'pixmaps', 'gajim_about.png')) gajim.DATA_DIR, 'pixmaps', 'gajim_about.png'))
@ -1855,7 +1854,7 @@ class PrivacyListWindow:
self.privacy_lists_title_label.set_label( self.privacy_lists_title_label.set_label(
_('Privacy List <b><i>%s</i></b>') % \ _('Privacy List <b><i>%s</i></b>') % \
gtkgui_helpers.escape_for_pango_markup(self.privacy_list_name)) gobject.markup_escape_text(self.privacy_list_name))
if len(gajim.connections) > 1: if len(gajim.connections) > 1:
title = _('Privacy List for %s') % self.account title = _('Privacy List for %s') % self.account

View File

@ -2,7 +2,7 @@
## config.py ## config.py
## ##
## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org>
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com> ## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2005-2006 Stéphan Kochen <stephan@kochen.nl> ## Copyright (C) 2005-2006 Stéphan Kochen <stephan@kochen.nl>
## ##
## This program is free software; you can redistribute it and/or modify ## This program is free software; you can redistribute it and/or modify
@ -41,6 +41,7 @@ import inspect
import weakref import weakref
import gobject import gobject
import gtk import gtk
import gobject
import pango import pango
import dialogs import dialogs
@ -497,10 +498,7 @@ _('Without a connection, you can not browse available services'))
title_text = _('Service Discovery using account %s') % self.account title_text = _('Service Discovery using account %s') % self.account
self.window.set_title(title_text) self.window.set_title(title_text)
self._set_window_banner_text(_('Service Discovery')) self._set_window_banner_text(_('Service Discovery'))
if gtk.gtk_version >= (2, 8, 0) and gtk.pygtk_version >= (2, 8, 0): self.banner_icon.clear()
self.banner_icon.clear()
else:
self.banner_icon.set_from_file(None)
self.banner_icon.hide() # Just clearing it doesn't work self.banner_icon.hide() # Just clearing it doesn't work
def _set_window_banner_text(self, text, text_after = None): def _set_window_banner_text(self, text, text_after = None):
@ -1730,7 +1728,7 @@ class DiscussionGroupsBrowser(AgentBrowser):
dunno = True dunno = True
subscribed = False subscribed = False
name = gtkgui_helpers.escape_for_pango_markup(name) name = gobject.markup_escape_text(name)
name = '<b>%s</b>' % name name = '<b>%s</b>' % name
model.append((jid, node, name, dunno, subscribed)) model.append((jid, node, name, dunno, subscribed))

View File

@ -1,7 +1,7 @@
## filetransfers_window.py ## filetransfers_window.py
## ##
## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com> ## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2005 ## Copyright (C) 2005
## Dimitur Kirov <dkirov@gmail.com> ## Dimitur Kirov <dkirov@gmail.com>
## Travis Shirk <travis@pobox.com> ## Travis Shirk <travis@pobox.com>
@ -575,7 +575,7 @@ _('Connection with peer cannot be established.'))
(file_path, file_name) = os.path.split(file_props['file-name']) (file_path, file_name) = os.path.split(file_props['file-name'])
else: else:
file_name = file_props['name'] file_name = file_props['name']
text_props = gtkgui_helpers.escape_for_pango_markup(file_name) + '\n' text_props = gobject.markup_escape_text(file_name) + '\n'
text_props += contact.get_shown_name() text_props += contact.get_shown_name()
self.model.set(iter, 1, text_labels, 2, text_props, C_SID, self.model.set(iter, 1, text_labels, 2, text_props, C_SID,
file_props['type'] + file_props['sid']) file_props['type'] + file_props['sid'])

View File

@ -122,12 +122,12 @@ except RuntimeError, msg:
print >> sys.stderr, _('Gajim needs X server to run. Quiting...') print >> sys.stderr, _('Gajim needs X server to run. Quiting...')
sys.exit() sys.exit()
pritext = '' pritext = ''
if gtk.pygtk_version < (2, 6, 0): if gtk.pygtk_version < (2, 8, 0):
pritext = _('Gajim needs PyGTK 2.6 or above') pritext = _('Gajim needs PyGTK 2.8 or above')
sectext = _('Gajim needs PyGTK 2.6 or above to run. Quiting...') sectext = _('Gajim needs PyGTK 2.8 or above to run. Quiting...')
elif gtk.gtk_version < (2, 6, 0): elif gtk.gtk_version < (2, 8, 0):
pritext = _('Gajim needs GTK 2.6 or above') pritext = _('Gajim needs GTK 2.8 or above')
sectext = _('Gajim needs GTK 2.6 or above to run. Quiting...') sectext = _('Gajim needs GTK 2.8 or above to run. Quiting...')
try: try:
import gtk.glade # check if user has libglade (in pygtk and in gtk) import gtk.glade # check if user has libglade (in pygtk and in gtk)
@ -340,10 +340,9 @@ class GlibIdleQueue(idlequeue.IdleQueue):
''' this method is called at the end of class constructor. ''' this method is called at the end of class constructor.
Creates a dict, which maps file/pipe/sock descriptor to glib event id''' Creates a dict, which maps file/pipe/sock descriptor to glib event id'''
self.events = {} self.events = {}
if gtk.pygtk_version >= (2, 8, 0): # time() is already called in glib, we just get the last value
# time() is already called in glib, we just get the last value # overrides IdleQueue.current_time()
# overrides IdleQueue.current_time() self.current_time = lambda: gobject.get_current_time()
self.current_time = lambda: gobject.get_current_time()
def add_idle(self, fd, flags): def add_idle(self, fd, flags):
''' this method is called when we plug a new idle object. ''' this method is called when we plug a new idle object.
@ -2107,9 +2106,9 @@ class Interface:
else: else:
gajim.log.setLevel(None) gajim.log.setLevel(None)
# pygtk2.8 on win, breaks io_add_watch. We use good old select.select() # pygtk2.8+ on win, breaks io_add_watch.
if os.name == 'nt' and (gtk.pygtk_version > (2, 8, 0) or # We use good old select.select()
gtk.gtk_version > (2, 8, 0)): if os.name == 'nt':
gajim.idlequeue = idlequeue.SelectIdleQueue() gajim.idlequeue = idlequeue.SelectIdleQueue()
else: else:
# in a nongui implementation, just call: # in a nongui implementation, just call:

View File

@ -4,11 +4,11 @@
## Vincent Hanquez <tab@snarc.org> ## Vincent Hanquez <tab@snarc.org>
## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
## Vincent Hanquez <tab@snarc.org> ## Vincent Hanquez <tab@snarc.org>
## Nikos Kouremenos <kourem@gmail.com>
## Dimitur Kirov <dkirov@gmail.com> ## Dimitur Kirov <dkirov@gmail.com>
## Travis Shirk <travis@pobox.com> ## Travis Shirk <travis@pobox.com>
## Norman Rasmussen <norman@rasmussen.co.za> ## Norman Rasmussen <norman@rasmussen.co.za>
## Copyright (C) 2006 Travis Shirk <travis@pobox.com> ## Copyright (C) 2006 Travis Shirk <travis@pobox.com>
## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
## ##
## This program is free software; you can redistribute it and/or modify ## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published ## it under the terms of the GNU General Public License as published
@ -460,7 +460,7 @@ class GroupchatControl(ChatControlBase):
text = '<span %s>%s</span>' % (font_attrs, self.room_jid) text = '<span %s>%s</span>' % (font_attrs, self.room_jid)
if self.subject: if self.subject:
subject = helpers.reduce_chars_newlines(self.subject, max_lines = 2) subject = helpers.reduce_chars_newlines(self.subject, max_lines = 2)
subject = gtkgui_helpers.escape_for_pango_markup(subject) subject = gobject.markup_escape_text(subject)
text += '\n<span %s>%s</span>' % (font_attrs_small, subject) text += '\n<span %s>%s</span>' % (font_attrs_small, subject)
# tooltip must always hold ALL the subject # tooltip must always hold ALL the subject
@ -778,7 +778,7 @@ class GroupchatControl(ChatControlBase):
else: else:
image = state_images[gc_contact.show] image = state_images[gc_contact.show]
name = gtkgui_helpers.escape_for_pango_markup(gc_contact.name) name = gobject.markup_escape_text(gc_contact.name)
status = gc_contact.status status = gc_contact.status
# add status msg, if not empty, under contact name in the treeview # add status msg, if not empty, under contact name in the treeview
if status and gajim.config.get('show_status_msgs_in_roster'): if status and gajim.config.get('show_status_msgs_in_roster'):
@ -790,7 +790,7 @@ class GroupchatControl(ChatControlBase):
selected, focus) selected, focus)
colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue) colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue)
name += '\n' '<span size="small" style="italic" foreground="%s">%s</span>'\ name += '\n' '<span size="small" style="italic" foreground="%s">%s</span>'\
% (colorstring, gtkgui_helpers.escape_for_pango_markup(status)) % (colorstring, gobject.markup_escape_text(status))
model[iter][C_IMG] = image model[iter][C_IMG] = image
model[iter][C_TEXT] = name model[iter][C_TEXT] = name

View File

@ -172,19 +172,6 @@ def get_default_font():
return None return None
def escape_for_pango_markup(string):
# escapes < > & ' "
# for pango markup not to break
if string is None:
return
if gtk.pygtk_version >= (2, 8, 0) and gtk.gtk_version >= (2, 8, 0):
escaped_str = gobject.markup_escape_text(string)
else:
escaped_str = xml.sax.saxutils.escape(string, {"'": '&apos;',
'"': '&quot;'})
return escaped_str
def autodetect_browser_mailer(): def autodetect_browser_mailer():
# recognize the environment and set appropriate browser/mailer # recognize the environment and set appropriate browser/mailer
if user_runs_gnome(): if user_runs_gnome():
@ -354,8 +341,7 @@ def parse_server_xml(path_to_file):
def set_unset_urgency_hint(window, unread_messages_no): def set_unset_urgency_hint(window, unread_messages_no):
'''sets/unsets urgency hint in window argument '''sets/unsets urgency hint in window argument
depending if we have unread messages or not''' depending if we have unread messages or not'''
if gtk.gtk_version >= (2, 8, 0) and gtk.pygtk_version >= (2, 8, 0) and \ if gajim.config.get('use_urgency_hint'):
gajim.config.get('use_urgency_hint'):
if unread_messages_no > 0: if unread_messages_no > 0:
window.props.urgency_hint = True window.props.urgency_hint = True
else: else:

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
## history_manager.py ## history_manager.py
## ##
## Copyright (C) 2006 Nikos Kouremenos <kourem@gmail.com> ## Copyright (C) 2006-2007 Nikos Kouremenos <kourem@gmail.com>
## ##
## This program is free software; you can redistribute it and/or modify ## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published ## it under the terms of the GNU General Public License as published
@ -21,6 +21,7 @@ import sys
import os import os
import signal import signal
import gtk import gtk
import gobject
import time import time
import locale import locale
@ -337,7 +338,7 @@ class HistoryManager:
if color: if color:
message_ += ' foreground="%s"' % color message_ += ' foreground="%s"' % color
message_ += '>%s</span>' % \ message_ += '>%s</span>' % \
gtkgui_helpers.escape_for_pango_markup(message) gobject.markup_escape_text(message)
self.logs_liststore.append((log_line_id, jid_id, time_, message_, self.logs_liststore.append((log_line_id, jid_id, time_, message_,
subject, nickname)) subject, nickname))
@ -399,8 +400,7 @@ class HistoryManager:
dlg = xml.get_widget('filechooserdialog') dlg = xml.get_widget('filechooserdialog')
dlg.set_title(_('Exporting History Logs...')) dlg.set_title(_('Exporting History Logs...'))
dlg.set_current_folder(gajim.HOME_DIR) dlg.set_current_folder(gajim.HOME_DIR)
if gtk.pygtk_version > (2, 8, 0): dlg.props.do_overwrite_confirmation = True
dlg.props.do_overwrite_confirmation = True
response = dlg.run() response = dlg.run()
if response == gtk.RESPONSE_OK: # user want us to export ;) if response == gtk.RESPONSE_OK: # user want us to export ;)

View File

@ -17,7 +17,7 @@
### Boston, MA 02111-1307, USA. ### Boston, MA 02111-1307, USA.
""" '''
A gtk.TextView-based renderer for XHTML-IM, as described in: A gtk.TextView-based renderer for XHTML-IM, as described in:
http://www.jabber.org/jeps/jep-0071.html http://www.jabber.org/jeps/jep-0071.html
@ -26,7 +26,7 @@ I (Santiago Gala) am trying to make it more compatible
with the markup that docutils generate, and also more with the markup that docutils generate, and also more
modular. modular.
""" '''
import gobject import gobject
import pango import pango
@ -47,8 +47,8 @@ import tooltips
__all__ = ['HtmlTextView'] __all__ = ['HtmlTextView']
whitespace_rx = re.compile("\\s+") whitespace_rx = re.compile('\\s+')
allwhitespace_rx = re.compile("^\\s*$") allwhitespace_rx = re.compile('^\\s*$')
# pixels = points * display_resolution # pixels = points * display_resolution
display_resolution = 0.3514598*(gtk.gdk.screen_height() / display_resolution = 0.3514598*(gtk.gdk.screen_height() /
@ -84,7 +84,7 @@ element_styles['b'] = element_styles['strong']
class_styles = { class_styles = {
} }
""" '''
========== ==========
JEP-0071 JEP-0071
========== ==========
@ -154,7 +154,7 @@ Common.extra
# ( structural = br | span ) # ( structural = br | span )
#Param/Legacy param, font, basefont, center, s, strike, u, dir, menu, isindex #Param/Legacy param, font, basefont, center, s, strike, u, dir, menu, isindex
# #
""" '''
BLOCK_HEAD = set(( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', )) BLOCK_HEAD = set(( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', ))
BLOCK_PHRASAL = set(( 'address', 'blockquote', 'pre', )) BLOCK_PHRASAL = set(( 'address', 'blockquote', 'pre', ))
@ -223,7 +223,7 @@ def build_patterns(view, config, interface):
def _parse_css_color(color): def _parse_css_color(color):
'''_parse_css_color(css_color) -> gtk.gdk.Color''' '''_parse_css_color(css_color) -> gtk.gdk.Color'''
if color.startswith("rgb(") and color.endswith(')'): if color.startswith('rgb(') and color.endswith(')'):
r, g, b = [int(c)*257 for c in color[4:-1].split(',')] r, g, b = [int(c)*257 for c in color[4:-1].split(',')]
return gtk.gdk.Color(r, g, b) return gtk.gdk.Color(r, g, b)
else: else:
@ -246,15 +246,15 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
def _parse_style_color(self, tag, value): def _parse_style_color(self, tag, value):
color = _parse_css_color(value) color = _parse_css_color(value)
tag.set_property("foreground-gdk", color) tag.set_property('foreground-gdk', color)
def _parse_style_background_color(self, tag, value): def _parse_style_background_color(self, tag, value):
color = _parse_css_color(value) color = _parse_css_color(value)
tag.set_property("background-gdk", color) tag.set_property('background-gdk', color)
if gtk.gtk_version >= (2, 8): tag.set_property('paragraph-background-gdk', color)
tag.set_property("paragraph-background-gdk", color)
#FIXME: when we migrate to 2.10 rm this
if gtk.gtk_version >= (2, 8, 5) or gobject.pygtk_version >= (2, 8, 1): if gtk.gtk_version >= (2, 8, 5) or gobject.pygtk_version >= (2, 8, 1):
def _get_current_attributes(self): def _get_current_attributes(self):
@ -270,7 +270,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
def _get_current_style_attr(self, propname, comb_oper=None): def _get_current_style_attr(self, propname, comb_oper=None):
tags = [tag for tag in self.styles if tag is not None] tags = [tag for tag in self.styles if tag is not None]
tags.reverse() tags.reverse()
is_set_name = propname + "-set" is_set_name = propname + '-set'
value = None value = None
for tag in tags: for tag in tags:
if tag.get_property(is_set_name): if tag.get_property(is_set_name):
@ -283,15 +283,15 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
return value return value
class _FakeAttrs(object): class _FakeAttrs(object):
__slots__ = ("font", "font_scale") __slots__ = ('font', 'font_scale')
def _get_current_attributes(self): def _get_current_attributes(self):
attrs = self._FakeAttrs() attrs = self._FakeAttrs()
attrs.font_scale = self._get_current_style_attr("scale", attrs.font_scale = self._get_current_style_attr('scale',
operator.mul) operator.mul)
if attrs.font_scale is None: if attrs.font_scale is None:
attrs.font_scale = 1.0 attrs.font_scale = 1.0
attrs.font = self._get_current_style_attr("font-desc") attrs.font = self._get_current_style_attr('font-desc')
if attrs.font is None: if attrs.font is None:
attrs.font = self.textview.style.font_desc attrs.font = self.textview.style.font_desc
return attrs return attrs
@ -311,14 +311,14 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
font_size = attrs.font.get_size() / pango.SCALE font_size = attrs.font.get_size() / pango.SCALE
callback(frac*display_resolution*font_size, *args) callback(frac*display_resolution*font_size, *args)
else: else:
# CSS says "Percentage values: refer to width of the closest # CSS says 'Percentage values: refer to width of the closest
# block-level ancestor" # block-level ancestor'
# This is difficult/impossible to implement, so we use # This is difficult/impossible to implement, so we use
# textview width instead; a reasonable approximation.. # textview width instead; a reasonable approximation..
alloc = self.textview.get_allocation() alloc = self.textview.get_allocation()
self.__parse_length_frac_size_allocate(self.textview, alloc, self.__parse_length_frac_size_allocate(self.textview, alloc,
frac, callback, args) frac, callback, args)
self.textview.connect("size-allocate", self.textview.connect('size-allocate',
self.__parse_length_frac_size_allocate, self.__parse_length_frac_size_allocate,
frac, callback, args) frac, callback, args)
@ -341,10 +341,10 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
callback(int(value[:-2]), *args) callback(int(value[:-2]), *args)
else: else:
warnings.warn("Unable to parse length value '%s'" % value) warnings.warn('Unable to parse length value '%s'' % value)
def __parse_font_size_cb(length, tag): def __parse_font_size_cb(length, tag):
tag.set_property("size-points", length/display_resolution) tag.set_property('size-points', length/display_resolution)
__parse_font_size_cb = staticmethod(__parse_font_size_cb) __parse_font_size_cb = staticmethod(__parse_font_size_cb)
def _parse_style_display(self, tag, value): def _parse_style_display(self, tag, value):
@ -355,39 +355,39 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
def _parse_style_font_size(self, tag, value): def _parse_style_font_size(self, tag, value):
try: try:
scale = { scale = {
"xx-small": pango.SCALE_XX_SMALL, 'xx-small': pango.SCALE_XX_SMALL,
"x-small": pango.SCALE_X_SMALL, 'x-small': pango.SCALE_X_SMALL,
"small": pango.SCALE_SMALL, 'small': pango.SCALE_SMALL,
"medium": pango.SCALE_MEDIUM, 'medium': pango.SCALE_MEDIUM,
"large": pango.SCALE_LARGE, 'large': pango.SCALE_LARGE,
"x-large": pango.SCALE_X_LARGE, 'x-large': pango.SCALE_X_LARGE,
"xx-large": pango.SCALE_XX_LARGE, 'xx-large': pango.SCALE_XX_LARGE,
} [value] } [value]
except KeyError: except KeyError:
pass pass
else: else:
attrs = self._get_current_attributes() attrs = self._get_current_attributes()
tag.set_property("scale", scale / attrs.font_scale) tag.set_property('scale', scale / attrs.font_scale)
return return
if value == 'smaller': if value == 'smaller':
tag.set_property("scale", pango.SCALE_SMALL) tag.set_property('scale', pango.SCALE_SMALL)
return return
if value == 'larger': if value == 'larger':
tag.set_property("scale", pango.SCALE_LARGE) tag.set_property('scale', pango.SCALE_LARGE)
return return
self._parse_length(value, True, self.__parse_font_size_cb, tag) self._parse_length(value, True, self.__parse_font_size_cb, tag)
def _parse_style_font_style(self, tag, value): def _parse_style_font_style(self, tag, value):
try: try:
style = { style = {
"normal": pango.STYLE_NORMAL, 'normal': pango.STYLE_NORMAL,
"italic": pango.STYLE_ITALIC, 'italic': pango.STYLE_ITALIC,
"oblique": pango.STYLE_OBLIQUE, 'oblique': pango.STYLE_OBLIQUE,
} [value] } [value]
except KeyError: except KeyError:
warnings.warn("unknown font-style %s" % value) warnings.warn('unknown font-style %s' % value)
else: else:
tag.set_property("style", style) tag.set_property('style', style)
def __frac_length_tag_cb(self,length, tag, propname): def __frac_length_tag_cb(self,length, tag, propname):
styles = self._get_style_tags() styles = self._get_style_tags()
@ -398,11 +398,11 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
def _parse_style_margin_left(self, tag, value): def _parse_style_margin_left(self, tag, value):
self._parse_length(value, False, self.__frac_length_tag_cb, self._parse_length(value, False, self.__frac_length_tag_cb,
tag, "left-margin") tag, 'left-margin')
def _parse_style_margin_right(self, tag, value): def _parse_style_margin_right(self, tag, value):
self._parse_length(value, False, self.__frac_length_tag_cb, self._parse_length(value, False, self.__frac_length_tag_cb,
tag, "right-margin") tag, 'right-margin')
def _parse_style_font_weight(self, tag, value): def _parse_style_font_weight(self, tag, value):
# TODO: missing 'bolder' and 'lighter' # TODO: missing 'bolder' and 'lighter'
@ -421,12 +421,12 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
'bold': pango.WEIGHT_BOLD, 'bold': pango.WEIGHT_BOLD,
} [value] } [value]
except KeyError: except KeyError:
warnings.warn("unknown font-style %s" % value) warnings.warn('unknown font-style %s' % value)
else: else:
tag.set_property("weight", weight) tag.set_property('weight', weight)
def _parse_style_font_family(self, tag, value): def _parse_style_font_family(self, tag, value):
tag.set_property("family", value) tag.set_property('family', value)
def _parse_style_text_align(self, tag, value): def _parse_style_text_align(self, tag, value):
try: try:
@ -437,47 +437,47 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
'justify': gtk.JUSTIFY_FILL, 'justify': gtk.JUSTIFY_FILL,
} [value] } [value]
except KeyError: except KeyError:
warnings.warn("Invalid text-align:%s requested" % value) warnings.warn('Invalid text-align:%s requested' % value)
else: else:
tag.set_property("justification", align) tag.set_property('justification', align)
def _parse_style_text_decoration(self, tag, value): def _parse_style_text_decoration(self, tag, value):
if value == "none": if value == 'none':
tag.set_property("underline", pango.UNDERLINE_NONE) tag.set_property('underline', pango.UNDERLINE_NONE)
tag.set_property("strikethrough", False) tag.set_property('strikethrough', False)
elif value == "underline": elif value == 'underline':
tag.set_property("underline", pango.UNDERLINE_SINGLE) tag.set_property('underline', pango.UNDERLINE_SINGLE)
tag.set_property("strikethrough", False) tag.set_property('strikethrough', False)
elif value == "overline": elif value == 'overline':
warnings.warn("text-decoration:overline not implemented") warnings.warn('text-decoration:overline not implemented')
tag.set_property("underline", pango.UNDERLINE_NONE) tag.set_property('underline', pango.UNDERLINE_NONE)
tag.set_property("strikethrough", False) tag.set_property('strikethrough', False)
elif value == "line-through": elif value == 'line-through':
tag.set_property("underline", pango.UNDERLINE_NONE) tag.set_property('underline', pango.UNDERLINE_NONE)
tag.set_property("strikethrough", True) tag.set_property('strikethrough', True)
elif value == "blink": elif value == 'blink':
warnings.warn("text-decoration:blink not implemented") warnings.warn('text-decoration:blink not implemented')
else: else:
warnings.warn("text-decoration:%s not implemented" % value) warnings.warn('text-decoration:%s not implemented' % value)
def _parse_style_white_space(self, tag, value): def _parse_style_white_space(self, tag, value):
if value == 'pre': if value == 'pre':
tag.set_property("wrap_mode", gtk.WRAP_NONE) tag.set_property('wrap_mode', gtk.WRAP_NONE)
elif value == 'normal': elif value == 'normal':
tag.set_property("wrap_mode", gtk.WRAP_WORD) tag.set_property('wrap_mode', gtk.WRAP_WORD)
elif value == 'nowrap': elif value == 'nowrap':
tag.set_property("wrap_mode", gtk.WRAP_NONE) tag.set_property('wrap_mode', gtk.WRAP_NONE)
# build a dictionary mapping styles to methods, for greater speed # build a dictionary mapping styles to methods, for greater speed
__style_methods = dict() __style_methods = dict()
for style in ["background-color", "color", "font-family", "font-size", for style in ['background-color', 'color', 'font-family', 'font-size',
"font-style", "font-weight", "margin-left", "margin-right", 'font-style', 'font-weight', 'margin-left', 'margin-right',
"text-align", "text-decoration", "white-space", 'display' ]: 'text-align', 'text-decoration', 'white-space', 'display' ]:
try: try:
method = locals()["_parse_style_%s" % style.replace('-', '_')] method = locals()['_parse_style_%s' % style.replace('-', '_')]
except KeyError: except KeyError:
warnings.warn("Style attribute '%s' not yet implemented" % style) warnings.warn('Style attribute '%s' not yet implemented' % style)
else: else:
__style_methods[style] = method __style_methods[style] = method
del style del style
@ -515,8 +515,8 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
try: try:
method = self.__style_methods[attr] method = self.__style_methods[attr]
except KeyError: except KeyError:
warnings.warn("Style attribute '%s' requested " warnings.warn('Style attribute '%s' requested '
"but not yet implemented" % attr) 'but not yet implemented' % attr)
else: else:
method(self, tag, val) method(self, tag, val)
self.styles.append(tag) self.styles.append(tag)
@ -547,11 +547,11 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
text = text.replace('\n', ' ') text = text.replace('\n', ' ')
self.handle_specials(whitespace_rx.sub(' ', text)) self.handle_specials(whitespace_rx.sub(' ', text))
else: else:
self._insert_text(text.strip("\n")) self._insert_text(text.strip('\n'))
def _anchor_event(self, tag, textview, event, iter, href, type_): def _anchor_event(self, tag, textview, event, iter, href, type_):
if event.type == gtk.gdk.BUTTON_PRESS: if event.type == gtk.gdk.BUTTON_PRESS:
self.textview.emit("url-clicked", href, type_) self.textview.emit('url-clicked', href, type_)
return True return True
return False return False
@ -585,7 +585,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
if special_text.startswith('/'): # it's explicit italics if special_text.startswith('/'): # it's explicit italics
self.startElement('i', {}) self.startElement('i', {})
elif special_text.startswith('_'): # it's explicit underline elif special_text.startswith('_'): # it's explicit underline
self.startElement("u", {}) self.startElement('u', {})
if se: self._insert_text(special_text[0]) if se: self._insert_text(special_text[0])
self.handle_specials(special_text[1:-1]) self.handle_specials(special_text[1:-1])
if se: self._insert_text(special_text[0]) if se: self._insert_text(special_text[0])
@ -670,7 +670,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
li_head = unichr(0x2022) li_head = unichr(0x2022)
else: else:
self.list_counters[-1] += 1 self.list_counters[-1] += 1
li_head = "%i." % self.list_counters[-1] li_head = '%i.' % self.list_counters[-1]
self.text = ' '*len(self.list_counters)*4 + li_head + ' ' self.text = ' '*len(self.list_counters)*4 + li_head + ' '
self._flush_text() self._flush_text()
self.starting = True self.starting = True
@ -692,7 +692,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
except Exception, ex: except Exception, ex:
gajim.log.debug(str('Error loading image'+ex)) gajim.log.debug(str('Error loading image'+ex))
pixbuf = None pixbuf = None
alt = attrs.get('alt', "Broken image") alt = attrs.get('alt', 'Broken image')
try: try:
loader.close() loader.close()
except: pass except: pass
@ -709,7 +709,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
self.textbuf.apply_tag(tag, start, self.iter) self.textbuf.apply_tag(tag, start, self.iter)
self.textbuf.delete_mark(tmpmark) self.textbuf.delete_mark(tmpmark)
else: else:
self._insert_text("[IMG: %s]" % alt) self._insert_text('[IMG: %s]' % alt)
elif name == 'body' or name == 'html': elif name == 'body' or name == 'html':
pass pass
elif name == 'a': elif name == 'a':
@ -717,7 +717,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
elif name in INLINE: elif name in INLINE:
pass pass
else: else:
warnings.warn("Unhandled element '%s'" % name) warnings.warn('Unhandled element '%s'' % name)
def endElement(self, name): def endElement(self, name):
endPreserving = False endPreserving = False
@ -729,10 +729,10 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
self._jump_line() self._jump_line()
try: try:
self.textbuf.insert_pixbuf(self.iter, self.textview.focus_out_line_pixbuf) self.textbuf.insert_pixbuf(self.iter, self.textview.focus_out_line_pixbuf)
#self._insert_text(u"\u2550"*40) #self._insert_text(u'\u2550'*40)
self._jump_line() self._jump_line()
except Exception, e: except Exception, e:
gajim.log.debug(str("Error in hr"+e)) gajim.log.debug(str('Error in hr'+e))
elif name in LIST_ELEMS: elif name in LIST_ELEMS:
self.list_counters.pop() self.list_counters.pop()
elif name == 'li': elif name == 'li':
@ -751,7 +751,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
if name == 'pre': if name == 'pre':
endPreserving = True endPreserving = True
else: else:
warnings.warn("Unhandled element '%s'" % name) warnings.warn('Unhandled element '%s'' % name)
self._flush_text() self._flush_text()
if endPreserving: if endPreserving:
self.preserve = False self.preserve = False
@ -772,9 +772,9 @@ class HtmlTextView(gtk.TextView):
self.set_wrap_mode(gtk.WRAP_CHAR) self.set_wrap_mode(gtk.WRAP_CHAR)
self.set_editable(False) self.set_editable(False)
self._changed_cursor = False self._changed_cursor = False
self.connect("motion-notify-event", self.__motion_notify_event) self.connect('motion-notify-event', self.__motion_notify_event)
self.connect("leave-notify-event", self.__leave_event) self.connect('leave-notify-event', self.__leave_event)
self.connect("enter-notify-event", self.__motion_notify_event) self.connect('enter-notify-event', self.__motion_notify_event)
self.get_buffer().create_tag('eol', scale = pango.SCALE_XX_SMALL) self.get_buffer().create_tag('eol', scale = pango.SCALE_XX_SMALL)
self.tooltip = tooltips.BaseTooltip() self.tooltip = tooltips.BaseTooltip()
self.config = gajim.config self.config = gajim.config
@ -842,10 +842,8 @@ class HtmlTextView(gtk.TextView):
parser.parse(StringIO(html)) parser.parse(StringIO(html))
#if not eob.starts_line(): #if not eob.starts_line():
# buffer.insert(eob, "\n") # buffer.insert(eob, '\n')
if gobject.pygtk_version < (2, 8):
gobject.type_register(HtmlTextView)
change_cursor = None change_cursor = None
@ -900,25 +898,25 @@ if __name__ == '__main__':
' <img src="http://images.slashdot.org/topics/topicsoftware.gif"/><br/>\n' ' <img src="http://images.slashdot.org/topics/topicsoftware.gif"/><br/>\n'
' <span style="font-size: 500%; font-family: serif">World</span>\n' ' <span style="font-size: 500%; font-family: serif">World</span>\n'
'</div>\n') '</div>\n')
htmlview.display_html("<hr />") htmlview.display_html('<hr />')
htmlview.display_html(""" htmlview.display_html('''
<p style='font-size:large'> <p style='font-size:large'>
<span style='font-style: italic'>O<span style='font-size:larger'>M</span>G</span>, <span style='font-style: italic'>O<span style='font-size:larger'>M</span>G</span>,
I&apos;m <span style='color:green'>green</span> I&apos;m <span style='color:green'>green</span>
with <span style='font-weight: bold'>envy</span>! with <span style='font-weight: bold'>envy</span>!
</p> </p>
""") ''')
htmlview.display_html("<hr />") htmlview.display_html('<hr />')
htmlview.display_html(""" htmlview.display_html('''
<body xmlns='http://www.w3.org/1999/xhtml'> <body xmlns='http://www.w3.org/1999/xhtml'>
<p>As Emerson said in his essay <span style='font-style: italic; background-color:cyan'>Self-Reliance</span>:</p> <p>As Emerson said in his essay <span style='font-style: italic; background-color:cyan'>Self-Reliance</span>:</p>
<p style='margin-left: 5px; margin-right: 2%'> <p style='margin-left: 5px; margin-right: 2%'>
&quot;A foolish consistency is the hobgoblin of little minds.&quot; &quot;A foolish consistency is the hobgoblin of little minds.&quot;
</p> </p>
</body> </body>
""") ''')
htmlview.display_html("<hr />") htmlview.display_html('<hr />')
htmlview.display_html(""" htmlview.display_html('''
<body xmlns='http://www.w3.org/1999/xhtml'> <body xmlns='http://www.w3.org/1999/xhtml'>
<p style='text-align:center'>Hey, are you licensed to <a href='http://www.jabber.org/'>Jabber</a>?</p> <p style='text-align:center'>Hey, are you licensed to <a href='http://www.jabber.org/'>Jabber</a>?</p>
<p style='text-align:right'><img src='http://www.jabber.org/images/psa-license.jpg' <p style='text-align:right'><img src='http://www.jabber.org/images/psa-license.jpg'
@ -926,9 +924,9 @@ if __name__ == '__main__':
height='261' height='261'
width='537'/></p> width='537'/></p>
</body> </body>
""") ''')
htmlview.display_html("<hr />") htmlview.display_html('<hr />')
htmlview.display_html(""" htmlview.display_html('''
<body xmlns='http://www.w3.org/1999/xhtml'> <body xmlns='http://www.w3.org/1999/xhtml'>
<ul style='background-color:rgb(120,140,100)'> <ul style='background-color:rgb(120,140,100)'>
<li> One </li> <li> One </li>
@ -938,12 +936,12 @@ if __name__ == '__main__':
def faciter(n,acc): def faciter(n,acc):
if n==0: return acc if n==0: return acc
return faciter(n-1, acc*n) return faciter(n-1, acc*n)
if n&lt;0: raise ValueError("Must be non-negative") if n&lt;0: raise ValueError('Must be non-negative')
return faciter(n,1)</pre> return faciter(n,1)</pre>
</body> </body>
""") ''')
htmlview.display_html("<hr />") htmlview.display_html('<hr />')
htmlview.display_html(""" htmlview.display_html('''
<body xmlns='http://www.w3.org/1999/xhtml'> <body xmlns='http://www.w3.org/1999/xhtml'>
<ol style='background-color:rgb(120,140,100)'> <ol style='background-color:rgb(120,140,100)'>
<li> One </li> <li> One </li>
@ -954,12 +952,12 @@ if __name__ == '__main__':
</ul></li> </ul></li>
<li> Three </li></ol> <li> Three </li></ol>
</body> </body>
""") ''')
htmlview.show() htmlview.show()
sw = gtk.ScrolledWindow() sw = gtk.ScrolledWindow()
sw.set_property("hscrollbar-policy", gtk.POLICY_AUTOMATIC) sw.set_property('hscrollbar-policy', gtk.POLICY_AUTOMATIC)
sw.set_property("vscrollbar-policy", gtk.POLICY_AUTOMATIC) sw.set_property('vscrollbar-policy', gtk.POLICY_AUTOMATIC)
sw.set_property("border-width", 0) sw.set_property('border-width', 0)
sw.add(htmlview) sw.add(htmlview)
sw.show() sw.show()
frame = gtk.Frame() frame = gtk.Frame()
@ -970,5 +968,5 @@ if __name__ == '__main__':
w.add(frame) w.add(frame)
w.set_default_size(400, 300) w.set_default_size(400, 300)
w.show_all() w.show_all()
w.connect("destroy", lambda w: gtk.main_quit()) w.connect('destroy', lambda w: gtk.main_quit())
gtk.main() gtk.main()

View File

@ -62,9 +62,6 @@ class MessageTextView(gtk.TextView):
start, end = buffer.get_bounds() start, end = buffer.get_bounds()
buffer.delete(start, end) buffer.delete(start, end)
if gobject.pygtk_version < (2, 8, 0):
gobject.type_register(MessageTextView)
# We register depending on keysym and modifier some bindings # We register depending on keysym and modifier some bindings
# but we also pass those as param so we can construct fake Event # but we also pass those as param so we can construct fake Event

View File

@ -1,7 +1,7 @@
## notify.py ## notify.py
## ##
## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org>
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com> ## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2005-2006 Andrew Sayman <lorien420@myrealbox.com> ## Copyright (C) 2005-2006 Andrew Sayman <lorien420@myrealbox.com>
## ##
## Notification daemon connection via D-Bus code: ## Notification daemon connection via D-Bus code:
@ -20,6 +20,7 @@
import os import os
import time import time
import dialogs import dialogs
import gobject
import gtkgui_helpers import gtkgui_helpers
from common import gajim from common import gajim
@ -280,8 +281,8 @@ def popup(event_type, jid, account, msg_type = '', path_to_image = None,
'''Notifies a user of an event. It first tries to a valid implementation of '''Notifies a user of an event. It first tries to a valid implementation of
the Desktop Notification Specification. If that fails, then we fall back to the Desktop Notification Specification. If that fails, then we fall back to
the older style PopupNotificationWindow method.''' the older style PopupNotificationWindow method.'''
text = gtkgui_helpers.escape_for_pango_markup(text) text = gobject.markup_escape_text(text)
title = gtkgui_helpers.escape_for_pango_markup(title) title = gobject.markup_escape_text(title)
if gajim.config.get('use_notif_daemon') and dbus_support.supported: if gajim.config.get('use_notif_daemon') and dbus_support.supported:
try: try:

View File

@ -2,7 +2,7 @@
## roster_window.py ## roster_window.py
## ##
## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com> ## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com> ## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com>
## ##
## This program is free software; you can redistribute it and/or modify ## This program is free software; you can redistribute it and/or modify
@ -182,7 +182,7 @@ class RosterWindow:
our_jid = gajim.get_jid_from_account(account) our_jid = gajim.get_jid_from_account(account)
model.append(None, [self.jabber_state_images['16'][show], model.append(None, [self.jabber_state_images['16'][show],
gtkgui_helpers.escape_for_pango_markup(account), gobject.markup_escape_text(account),
'account', our_jid, account, tls_pixbuf]) 'account', our_jid, account, tls_pixbuf])
def draw_account(self, account): def draw_account(self, account):
@ -350,7 +350,7 @@ class RosterWindow:
IterAcct = self.get_account_iter(account) IterAcct = self.get_account_iter(account)
iterG = model.append(IterAcct, [ iterG = model.append(IterAcct, [
self.jabber_state_images['16']['closed'], self.jabber_state_images['16']['closed'],
gtkgui_helpers.escape_for_pango_markup(group), 'group', gobject.markup_escape_text(group), 'group',
group, account, None]) group, account, None])
self.draw_group(group, account) self.draw_group(group, account)
if model.iter_n_children(IterAcct) == 1: # We added the first one if model.iter_n_children(IterAcct) == 1: # We added the first one
@ -396,7 +396,7 @@ class RosterWindow:
accounts = accounts, groups = [group]) accounts = accounts, groups = [group])
text += ' (%s/%s)' % (repr(nbr_on), repr(nbr_total)) text += ' (%s/%s)' % (repr(nbr_on), repr(nbr_total))
model = self.tree.get_model() model = self.tree.get_model()
model.set_value(iter, 1 , gtkgui_helpers.escape_for_pango_markup(text)) model.set_value(iter, 1 , gobject.markup_escape_text(text))
def add_to_not_in_the_roster(self, account, jid, nick = ''): def add_to_not_in_the_roster(self, account, jid, nick = ''):
''' add jid to group "not in the roster", he MUST not be in roster yet, ''' add jid to group "not in the roster", he MUST not be in roster yet,
@ -558,7 +558,7 @@ class RosterWindow:
contact_instances) contact_instances)
if not contact: if not contact:
return return
name = gtkgui_helpers.escape_for_pango_markup(contact.get_shown_name()) name = gobject.markup_escape_text(contact.get_shown_name())
nb_connected_contact = 0 nb_connected_contact = 0
for c in contact_instances: for c in contact_instances:
@ -599,7 +599,7 @@ class RosterWindow:
colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue) colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue)
name += \ name += \
'\n<span size="small" style="italic" foreground="%s">%s</span>' \ '\n<span size="small" style="italic" foreground="%s">%s</span>' \
% (colorstring, gtkgui_helpers.escape_for_pango_markup(status)) % (colorstring, gobject.markup_escape_text(status))
iter = iters[0] # choose the icon with the first iter iter = iters[0] # choose the icon with the first iter
icon_name = helpers.get_icon_name_to_show(contact, account) icon_name = helpers.get_icon_name_to_show(contact, account)

View File

@ -225,9 +225,7 @@ class Systray:
sounds_mute_menuitem.set_active(not gajim.config.get('sounds_on')) sounds_mute_menuitem.set_active(not gajim.config.get('sounds_on'))
if os.name == 'nt': if os.name == 'nt':
# see http://bugzilla.gnome.org/show_bug.cgi?id=377349
#FIXME: until it is fixed, put under mouse coordinates
if gtk.pygtk_version >= (2, 10, 0) and gtk.gtk_version >= (2, 10, 0): if gtk.pygtk_version >= (2, 10, 0) and gtk.gtk_version >= (2, 10, 0):
if self.added_hide_menuitem is False: if self.added_hide_menuitem is False:
self.systray_context_menu.prepend(gtk.SeparatorMenuItem()) self.systray_context_menu.prepend(gtk.SeparatorMenuItem())

View File

@ -1,7 +1,7 @@
## tooltips.py ## tooltips.py
## ##
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com> ## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com>
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com> ## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org>
## ##
## This program is free software; you can redistribute it and/or modify ## This program is free software; you can redistribute it and/or modify
@ -178,8 +178,8 @@ class StatusTable:
status = unicode(status, encoding='utf-8') status = unicode(status, encoding='utf-8')
# reduce to 100 chars, 1 line # reduce to 100 chars, 1 line
status = helpers.reduce_chars_newlines(status, 100, 1) status = helpers.reduce_chars_newlines(status, 100, 1)
str_status = gtkgui_helpers.escape_for_pango_markup(str_status) str_status = gobject.markup_escape_text(str_status)
status = gtkgui_helpers.escape_for_pango_markup(status) status = gobject.markup_escape_text(status)
str_status += ' - <i>' + status + '</i>' str_status += ' - <i>' + status + '</i>'
return str_status return str_status
@ -233,7 +233,7 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
if isinstance(message, str): if isinstance(message, str):
message = unicode(message, encoding = 'utf-8') message = unicode(message, encoding = 'utf-8')
message = helpers.reduce_chars_newlines(message, 100, 1) message = helpers.reduce_chars_newlines(message, 100, 1)
message = gtkgui_helpers.escape_for_pango_markup(message) message = gobject.markup_escape_text(message)
if gajim.con_types.has_key(acct['name']) and \ if gajim.con_types.has_key(acct['name']) and \
gajim.con_types[acct['name']] in ('tls', 'ssl'): gajim.con_types[acct['name']] in ('tls', 'ssl'):
show_lock = True show_lock = True
@ -241,11 +241,11 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
show_lock = False show_lock = False
if message: if message:
self.add_status_row(file_path, acct['show'], self.add_status_row(file_path, acct['show'],
gtkgui_helpers.escape_for_pango_markup(acct['name']) + \ gobject.markup_escape_text(acct['name']) + \
' - ' + message, show_lock=show_lock) ' - ' + message, show_lock=show_lock)
else: else:
self.add_status_row(file_path, acct['show'], self.add_status_row(file_path, acct['show'],
gtkgui_helpers.escape_for_pango_markup(acct['name']) gobject.markup_escape_text(acct['name'])
, show_lock=show_lock) , show_lock=show_lock)
def populate(self, data): def populate(self, data):
@ -259,7 +259,7 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
self.table.set_property('column-spacing', 1) self.table.set_property('column-spacing', 1)
text = helpers.get_notification_icon_tooltip_text() text = helpers.get_notification_icon_tooltip_text()
text = gtkgui_helpers.escape_for_pango_markup(text) text = gobject.markup_escape_text(text)
self.add_text_row(text) self.add_text_row(text)
self.hbox.add(self.table) self.hbox.add(self.table)
@ -288,7 +288,7 @@ class GCTooltip(BaseTooltip):
properties = [] properties = []
nick_markup = '<b>' + \ nick_markup = '<b>' + \
gtkgui_helpers.escape_for_pango_markup(contact.get_shown_name()) \ gobject.markup_escape_text(contact.get_shown_name()) \
+ '</b>' + '</b>'
properties.append((nick_markup, None)) properties.append((nick_markup, None))
@ -298,7 +298,7 @@ class GCTooltip(BaseTooltip):
# escape markup entities # escape markup entities
status = helpers.reduce_chars_newlines(status, 100, 5) status = helpers.reduce_chars_newlines(status, 100, 5)
status = '<i>' +\ status = '<i>' +\
gtkgui_helpers.escape_for_pango_markup(status) + '</i>' gobject.markup_escape_text(status) + '</i>'
properties.append((status, None)) properties.append((status, None))
else: # no status message, show SHOW instead else: # no status message, show SHOW instead
show = helpers.get_uf_show(contact.show) show = helpers.get_uf_show(contact.show)
@ -310,7 +310,7 @@ class GCTooltip(BaseTooltip):
if hasattr(contact, 'resource') and contact.resource.strip() != '': if hasattr(contact, 'resource') and contact.resource.strip() != '':
properties.append((_('Resource: '), properties.append((_('Resource: '),
gtkgui_helpers.escape_for_pango_markup(contact.resource) )) gobject.markup_escape_text(contact.resource) ))
if contact.affiliation != 'none': if contact.affiliation != 'none':
uf_affiliation = helpers.get_uf_affiliation(contact.affiliation) uf_affiliation = helpers.get_uf_affiliation(contact.affiliation)
affiliation_str = \ affiliation_str = \
@ -411,7 +411,7 @@ class RosterTooltip(NotificationAreaTooltip):
properties = [] properties = []
name_markup = u'<span weight="bold">' + \ name_markup = u'<span weight="bold">' + \
gtkgui_helpers.escape_for_pango_markup(prim_contact.get_shown_name())\ gobject.markup_escape_text(prim_contact.get_shown_name())\
+ '</span>' + '</span>'
properties.append((name_markup, None)) properties.append((name_markup, None))
@ -485,7 +485,7 @@ class RosterTooltip(NotificationAreaTooltip):
# (no more than 100 chars on line and no more than 5 lines) # (no more than 100 chars on line and no more than 5 lines)
status = helpers.reduce_chars_newlines(status, 100, 5) status = helpers.reduce_chars_newlines(status, 100, 5)
# escape markup entities. # escape markup entities.
status = gtkgui_helpers.escape_for_pango_markup(status) status = gobject.markup_escape_text(status)
properties.append(('<i>%s</i>' % status, None)) properties.append(('<i>%s</i>' % status, None))
properties.append((show, None)) properties.append((show, None))
@ -494,13 +494,13 @@ class RosterTooltip(NotificationAreaTooltip):
# contact has only one ressource # contact has only one ressource
if num_resources == 1 and contact.resource: if num_resources == 1 and contact.resource:
properties.append((_('Resource: '), properties.append((_('Resource: '),
gtkgui_helpers.escape_for_pango_markup(contact.resource) +\ gobject.markup_escape_text(contact.resource) +\
' (' + unicode(contact.priority) + ')')) ' (' + unicode(contact.priority) + ')'))
if prim_contact.sub and prim_contact.sub != 'both': if prim_contact.sub and prim_contact.sub != 'both':
# ('both' is the normal sub so we don't show it) # ('both' is the normal sub so we don't show it)
properties.append(( _('Subscription: '), properties.append(( _('Subscription: '),
gtkgui_helpers.escape_for_pango_markup(helpers.get_uf_sub(prim_contact.sub)))) gobject.markup_escape_text(helpers.get_uf_sub(prim_contact.sub))))
if prim_contact.keyID: if prim_contact.keyID:
keyID = None keyID = None
@ -510,7 +510,7 @@ class RosterTooltip(NotificationAreaTooltip):
keyID = prim_contact.keyID[8:] keyID = prim_contact.keyID[8:]
if keyID: if keyID:
properties.append((_('OpenPGP: '), properties.append((_('OpenPGP: '),
gtkgui_helpers.escape_for_pango_markup(keyID))) gobject.markup_escape_text(keyID)))
while properties: while properties:
property = properties.pop(0) property = properties.pop(0)
@ -561,7 +561,7 @@ class FileTransfersTooltip(BaseTooltip):
else: else:
file_name = file_props['name'] file_name = file_props['name']
properties.append((_('Name: '), properties.append((_('Name: '),
gtkgui_helpers.escape_for_pango_markup(file_name))) gobject.markup_escape_text(file_name)))
if file_props['type'] == 'r': if file_props['type'] == 'r':
type = _('Download') type = _('Download')
actor = _('Sender: ') actor = _('Sender: ')
@ -577,7 +577,7 @@ class FileTransfersTooltip(BaseTooltip):
else: else:
name = receiver.split('/')[0] name = receiver.split('/')[0]
properties.append((_('Type: '), type)) properties.append((_('Type: '), type))
properties.append((actor, gtkgui_helpers.escape_for_pango_markup(name))) properties.append((actor, gobject.markup_escape_text(name)))
transfered_len = 0 transfered_len = 0
if file_props.has_key('received-len'): if file_props.has_key('received-len'):