nicer tabbed chat window without glade

This commit is contained in:
Yann Leboulanger 2005-02-24 14:34:22 +00:00
parent 75bdfa59de
commit c20266a561
2 changed files with 57 additions and 424 deletions

View File

@ -9495,361 +9495,18 @@ on the server.</property>
<signal name="switch_page" handler="on_notebook_switch_page" last_modification_time="Thu, 27 Jan 2005 23:16:57 GMT"/>
<child>
<widget class="GtkVBox" id="vbox_tab">
<property name="border_width">5</property>
<widget class="GtkLabel" id="label191">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox2907">
<property name="border_width">5</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">5</property>
<child>
<widget class="GtkButton" id="button_history">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_history_clicked" last_modification_time="Sun, 04 Apr 2004 05:30:58 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment36">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox2908">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image181">
<property name="visible">True</property>
<property name="stock">gtk-justify-fill</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label183">
<property name="visible">True</property>
<property name="label" translatable="yes">History</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button_clear">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_clear_clicked" last_modification_time="Thu, 18 Mar 2004 19:12:00 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment37">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox2909">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image182">
<property name="visible">True</property>
<property name="stock">gtk-clear</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label184">
<property name="visible">True</property>
<property name="label" translatable="yes">Clear</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkImage" id="image_status">
<property name="visible">True</property>
<property name="stock">gtk-no</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkToggleButton" id="toggle_gpg">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">False</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<child>
<widget class="GtkImage" id="image_gpg">
<property name="visible">True</property>
<property name="stock">gtk-dialog-authentication</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkFixed" id="fixed2">
<property name="width_request">20</property>
<property name="visible">True</property>
<child>
<widget class="GtkButton" id="button_contact">
<property name="width_request">0</property>
<property name="height_request">0</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Anonymous &lt;id@server/res&gt;</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button_contact_clicked" last_modification_time="Sun, 15 Feb 2004 14:26:53 GMT"/>
</widget>
<packing>
<property name="x">0</property>
<property name="y">0</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button_close">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_close_clicked" last_modification_time="Fri, 28 Jan 2005 20:16:24 GMT"/>
<child>
<widget class="GtkImage" id="image183">
<property name="visible">True</property>
<property name="stock">gtk-close</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkVPaned" id="vpaned3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="position">170</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow27">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="conversation">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="overwrite">False</property>
<property name="accepts_tab">True</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_WORD</property>
<property name="cursor_visible">False</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
</widget>
</child>
</widget>
<packing>
<property name="shrink">True</property>
<property name="resize">True</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow28">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="message">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="overwrite">False</property>
<property name="accepts_tab">True</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_WORD</property>
<property name="cursor_visible">True</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
<signal name="key_press_event" handler="on_msg_key_press_event" last_modification_time="Mon, 13 Oct 2003 17:48:48 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="shrink">True</property>
<property name="resize">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="tab_expand">False</property>

View File

@ -185,62 +185,24 @@ class tabbed_chat_Window:
"""Class for tabbed chat window"""
def __init__(self, user, plugin, account):
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'tabbed_chat', APP)
self.widgets = {}
self.widgets[user.jid] = {}
self.widgets[user.jid]['conversation'] = \
self.xml.get_widget('conversation')
buffer_conv = self.widgets[user.jid]['conversation'].get_buffer()
self.widgets[user.jid]['message'] = self.xml.get_widget('message')
self.widgets[user.jid]['message'].grab_focus()
buffer_msg = self.widgets[user.jid]['message'].get_buffer()
end_iter = buffer_conv.get_end_iter()
buffer_conv.create_mark('end', end_iter, 0)
self.widgets[user.jid]['image_status'] = \
self.xml.get_widget('image_status')
self.widgets[user.jid]['button_contact'] = \
self.xml.get_widget('button_contact')
self.widgets[user.jid]['toggle_gpg'] = self.xml.get_widget('toggle_gpg')
self.widgets[user.jid]['vbox_tab'] = self.xml.get_widget('vbox_tab')
self.xml.get_widget('notebook').remove_page(0)
self.plugin = plugin
self.account = account
self.widgets = {}
self.tagIn = {}
self.tagOut = {}
self.tagStatus = {}
self.users = {user.jid: user}
self.nb_unread = {user.jid: 0}
self.redraw_tab(user.jid)
self.window = self.xml.get_widget('tabbed_chat')
self.new_user(user)
self.show_title()
self.draw_widgets(user)
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_focus', self.on_focus)
self.xml.signal_connect('on_chat_key_press_event', \
self.on_chat_key_press_event)
self.xml.signal_connect('on_notebook_switch_page', \
self.on_notebook_switch_page)
self.xml.signal_connect('on_history_clicked', self.on_history)
self.xml.signal_connect('on_clear_clicked', self.on_clear)
self.xml.signal_connect('on_close_clicked', self.on_close_clicked)
self.xml.signal_connect('on_msg_key_press_event', \
self.on_msg_key_press_event)
self.xml.signal_connect('on_button_contact_clicked', \
self.on_button_contact_clicked)
self.xml.get_widget('button_contact').set_use_underline(False)
self.tagIn = {user.jid: buffer_conv.create_tag("incoming")}
color = self.plugin.config['inmsgcolor']
self.tagIn[user.jid].set_property("foreground", color)
self.tagOut = {user.jid: buffer_conv.create_tag("outgoing")}
color = self.plugin.config['outmsgcolor']
self.tagOut[user.jid].set_property("foreground", color)
self.tagStatus = {user.jid: buffer_conv.create_tag("status")}
color = self.plugin.config['statusmsgcolor']
self.tagStatus[user.jid].set_property("foreground", color)
#print queued messages
if plugin.queues[account].has_key(user.jid):
self.read_queue(plugin.queues[account][user.jid])
if user.show != 'online':
self.print_conversation(_("%s is now %s (%s)") % (user.name, \
user.show, user.status), user.jid, 'status')
def update_tags(self):
for jid in self.tagIn:
@ -376,37 +338,49 @@ class tabbed_chat_Window:
self.widgets[user.jid] = {}
vb = gtk.VBox()
vb.set_border_width(5)
self.widgets[user.jid]['vbox_tab'] = vb
hb = gtk.HBox()
vb.pack_start(hb)
hb = gtk.HBox(spacing=5)
hb.set_border_width(5)
vb.pack_start(hb, expand=False)
button = gtk.Button("History", gtk.STOCK_JUSTIFY_FILL)
button = gtk.Button(stock=gtk.STOCK_JUSTIFY_FILL)
button.get_children()[0].get_children()[0].get_children()[1].set_text("History")
button.connect("clicked", self.on_history)
hb.pack_start(button)
hb.pack_start(button, expand=False, fill=False)
button = gtk.Button("Clear", gtk.STOCK_CLEAR)
button = gtk.Button(stock=gtk.STOCK_CLEAR)
button.connect("clicked", self.on_clear)
hb.pack_start(button)
hb.pack_start(button, expand=False, fill=False)
img = gtk.Image()
hb.pack_start(img)
hb.pack_start(img, expand=False, fill=False)
self.widgets[user.jid]['image_status'] = img
button = gtk.ToggleButton(gtk.STOK_DIALOG_AUTHENTICATION)
button.set_use_stock(True)
hb.pack_start(button)
img = gtk.Image()
img.set_from_stock(gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_BUTTON)
button = gtk.ToggleButton()
button.add(img)
button.set_relief(gtk.RELIEF_NONE)
hb.pack_start(button, expand=False, fill=False)
self.widgets[user.jid]['toggle_gpg'] = button
fixed = gtk.Fixed()
fixed.set_size_request(20, -1)
hb.pack_start(fixed)
button = gtk.Button("Anonymous")
button.set_relief(gtk.RELIEF_NONE)
button.connect("clicked", self.on_button_contact_clicked)
button.set_use_underline(False)
fixed.add(button, 0, 0)
fixed.put(button, 0, 0)
self.widgets[user.jid]['button_contact'] = button
button = gtk.Button(stock=gtk.STOCK_CLOSE)
img = gtk.Image()
img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_BUTTON)
button = gtk.Button()
button.add(img)
button.connect("clicked", self.on_close_clicked)
hb.pack_start(button)
hb.pack_start(button, expand=False, fill=False)
vp = gtk.VPaned()
vb.pack_start(vp)
@ -416,21 +390,12 @@ class tabbed_chat_Window:
vp.add1(sw)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
tv = gtk.TextView()
tv.set_wrap_mode(gtk.WRAP_WORD)
sw.add_with_viewport(tv)
self.widgets[user.jid]['conversation'] = tv
buffer = tv.get_buffer()
end_iter = buffer.get_end_iter()
buffer.create_mark('end', end_iter, 0)
sw = gtk.ScrolledWindow()
vp.add2(sw)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
tv = gtk.TextView()
sw.add_with_viewport(tv)
self.widgets[user.jid]['message'] = tv
tv.grab_focus()
tv.connect('key_press_event', self.on_msg_key_press_event)
buffer = tv.get_buffer()
self.tagIn[user.jid] = buffer.create_tag("incoming")
color = self.plugin.config['inmsgcolor']
self.tagIn[user.jid].set_property("foreground", color)
@ -441,6 +406,17 @@ class tabbed_chat_Window:
color = self.plugin.config['statusmsgcolor']
self.tagStatus[user.jid].set_property("foreground", color)
sw = gtk.ScrolledWindow()
vp.add2(sw)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
tv = gtk.TextView()
tv.set_wrap_mode(gtk.WRAP_WORD)
sw.add_with_viewport(tv)
self.widgets[user.jid]['message'] = tv
tv.grab_focus()
tv.connect('key_press_event', self.on_msg_key_press_event)
vb.show_all()
nb = self.xml.get_widget("notebook")
nb.set_current_page(nb.append_page(vb))
@ -448,8 +424,8 @@ class tabbed_chat_Window:
self.draw_widgets(user)
#print queued messages
if plugin.queues[account].has_key(user.jid):
self.read_queue(plugin.queues[account][user.jid])
if self.plugin.queues[self.account].has_key(user.jid):
self.read_queue(self.plugin.queues[self.account][user.jid])
if user.show != 'online':
self.print_conversation(_("%s is now %s (%s)") % (user.name, \
user.show, user.status), user.jid, 'status')
@ -492,7 +468,7 @@ class tabbed_chat_Window:
del self.tagIn[jid]
del self.tagOut[jid]
del self.tagStatus[jid]
elif (event.string in st) \
elif event.string and event.string in st \
and (event.state & gtk.gdk.MOD1_MASK):
nb.set_current_page(st.index(event.string))