Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/chat
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2006-04-21 19:27:20 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2006-04-21 19:27:20 (GMT)
commit73e7360bab924b141a904ef3ab04c39e6749d70a (patch)
tree41fca89b2dba61d14732782f4c042f4252c9a6a7 /chat
parentb15ce388501edd516377e2fb8cc84538163ccff7 (diff)
More work on the notebook widget. Ellipsize labels.
Diffstat (limited to 'chat')
-rw-r--r--chat/BuddyList.py15
-rw-r--r--chat/chat.glade89
-rwxr-xr-xchat/main.py94
-rw-r--r--chat/network.py2
-rw-r--r--chat/presence.py2
5 files changed, 45 insertions, 157 deletions
diff --git a/chat/BuddyList.py b/chat/BuddyList.py
index 9bc63ba..e7cb7ca 100644
--- a/chat/BuddyList.py
+++ b/chat/BuddyList.py
@@ -1,5 +1,3 @@
-# -*- tab-width: 4; indent-tabs-mode: t -*-
-
import presence
import avahi
@@ -16,13 +14,6 @@ class Buddy(object):
self._host = host
self._address = address
self._port = port
- self._chat = None
-
- def set_chat(self, chat):
- self._chat = chat
-
- def chat(self):
- return self._chat
def nick(self):
return self._nick
@@ -75,12 +66,6 @@ class BuddyList(object):
return buddy
return None
- def find_buddy_by_address(self, address):
- for buddy in self._buddies.keys():
- if buddy.address() == address:
- return buddy
- return None
-
def _notify_listeners(self, action, buddy):
for listener in self._listeners:
listener(action, buddy)
diff --git a/chat/chat.glade b/chat/chat.glade
index 1058c23..f819576 100644
--- a/chat/chat.glade
+++ b/chat/chat.glade
@@ -31,6 +31,31 @@
<property name="column_spacing">0</property>
<child>
+ <widget class="GtkTextView" id="chatView">
+ <property name="visible">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_NONE</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>
+ </widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ </packing>
+ </child>
+
+ <child>
<widget class="GtkEntry" id="entry">
<property name="visible">True</property>
<property name="editable">True</property>
@@ -86,70 +111,6 @@
<property name="y_options">fill</property>
</packing>
</child>
-
- <child>
- <widget class="GtkVBox" id="vbox1">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">0</property>
-
- <child>
- <widget class="GtkLabel" id="chatLabel">
- <property name="visible">True</property>
- <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>
- <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
- <property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
- <property name="angle">0</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkTextView" id="chatView">
- <property name="visible">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_NONE</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>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="left_attach">0</property>
- <property name="right_attach">1</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
- <property name="x_options">fill</property>
- </packing>
- </child>
</widget>
</child>
</widget>
diff --git a/chat/main.py b/chat/main.py
index e22a13a..dff8cde 100755
--- a/chat/main.py
+++ b/chat/main.py
@@ -1,5 +1,4 @@
#!/usr/bin/python -t
-# -*- tab-width: 4; indent-tabs-mode: t -*-
import os, sys, pwd
sys.path.append(os.getcwd())
@@ -13,46 +12,9 @@ import BuddyList
glade_dir = os.getcwd()
-
-class Chat(object):
- def __init__(self, view, label):
- self._buffer = gtk.TextBuffer()
- self._view = view
- self._label = label
-
- def activate(self, label):
- self._view.set_buffer(self._buffer)
- self._label.set_text(label)
-
- def recv_message(self, buddy, msg):
- aniter = self._buffer.get_end_iter()
- self._buffer.insert(aniter, buddy.nick() + ": " + msg + "\n")
-
-
-
-class GroupChat(Chat):
- def __init__(self, parent, view, label):
- Chat.__init__(self, view, label)
- self._parent = parent
- self._gc_controller = network.GroupChatController('224.0.0.221', 6666, self._recv_group_message)
- self._gc_controller.start()
- self._label_prefix = "Cha"
-
- def activate(self):
- Chat.activate(self, "Group Chat")
-
- def send_message(self, text):
- if len(text) > 0:
- self._gc_controller.send_msg(text)
-
- def _recv_group_message(self, msg):
- buddy = self._parent.find_buddy_by_address(msg['addr'])
- if buddy:
- self.recv_message(buddy, msg['data'])
-
-
class ChatApp(SimpleGladeApp):
def __init__(self, glade_file="chat.glade", root="mainWindow", domain=None, **kwargs):
+
self._pannounce = presence.PresenceAnnounce()
self._buddy_list = BuddyList.BuddyList()
self._buddy_list.add_buddy_listener(self._on_buddy_presence_event)
@@ -79,57 +41,43 @@ class ChatApp(SimpleGladeApp):
print "Selected %s" % name
def _on_buddyList_buddy_double_clicked(self, widget, *args):
- """ Select the chat for this buddy or group """
(model, aniter) = widget.get_selection().get_selected()
- chat = None
- buddy = self.treemodel.get_value(aniter, 1)
- if not buddy:
- chat = self._group_chat
- else:
- chat = buddy.chat()
-
- if chat:
- chat.activate()
- else:
- # start a new chat with them
- pass
+ name = self.treemodel.get(aniter,0)
+ print "Double-clicked %s" % name
def _on_buddy_presence_event(self, action, buddy):
if action == BuddyList.ACTION_BUDDY_ADDED:
- aniter = self.treemodel.append(None)
- self.treemodel.set(aniter, 0, buddy.nick(), 1, buddy)
+ aniter = self.treemodel.insert_after(None,None)
+ self.treemodel.set(aniter, 0, buddy.nick())
elif action == BuddyList.ACCTION_BUDDY_REMOVED:
aniter = self.treemodel.get_iter(buddy.nick())
if aniter:
self.treemodel.remove(iter)
- def find_buddy_by_address(self, address):
- return self._buddy_list.find_buddy_by_address(address)
-
def _on_main_window_delete(self, widget, *args):
self.quit()
- def _get_current_chat(self):
- selection = self.buddyListView.get_selection()
- (model, aniter) = selection.get_selected()
- buddy = model.get_value(aniter, 1)
- if not buddy:
- return self._group_chat
- return buddy.chat()
+ def _recv_group_message(self, msg):
+ aniter = self._group_chat_buffer.get_end_iter()
+ self._group_chat_buffer.insert(aniter, msg['data'] + "\n")
+# print "Message: %s" % msg['data']
- def _send_chat_message(self, widget, *args):
- chat = self._get_current_chat()
+ def _send_group_message(self, widget, *args):
text = widget.get_text()
- chat.send_message(text)
+ if len(text) > 0:
+ self._gc_controller.send_msg(text)
widget.set_text("")
def new(self):
- self.treemodel = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
+ self._group_chat_buffer = gtk.TextBuffer()
+ self.chatView.set_buffer(self._group_chat_buffer)
+
+ self.treemodel = gtk.TreeStore(gobject.TYPE_STRING)
self.buddyListView.set_model(self.treemodel)
self.buddyListView.connect("cursor-changed", self._on_buddyList_buddy_selected)
self.buddyListView.connect("row-activated", self._on_buddyList_buddy_double_clicked)
self.mainWindow.connect("delete-event", self._on_main_window_delete)
- self.entry.connect("activate", self._send_chat_message)
+ self.entry.connect("activate", self._send_group_message)
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn("", renderer, text=0)
@@ -138,14 +86,12 @@ class ChatApp(SimpleGladeApp):
column.set_expand(True);
self.buddyListView.append_column(column)
- self._group_chat = GroupChat(self, self.chatView, self.chatLabel)
- aniter = self.treemodel.append(None)
- self.treemodel.set(aniter, 0, "Group", 1, None)
- self._group_chat.activate()
-
self._pannounce.register_service(self._realname, 6666, presence.OLPC_CHAT_SERVICE,
name = self._nick, realname = self._realname)
+ self._gc_controller = network.GroupChatController('224.0.0.221', 6666, self._recv_group_message)
+ self._gc_controller.start()
+
def cleanup(self):
pass
diff --git a/chat/network.py b/chat/network.py
index 1f2c904..a685a38 100644
--- a/chat/network.py
+++ b/chat/network.py
@@ -1,5 +1,3 @@
-# -*- tab-width: 4; indent-tabs-mode: t -*-
-
import socket
import threading
import traceback
diff --git a/chat/presence.py b/chat/presence.py
index 8b88492..45a31f9 100644
--- a/chat/presence.py
+++ b/chat/presence.py
@@ -1,5 +1,3 @@
-# -*- tab-width: 4; indent-tabs-mode: t -*-
-
import avahi, dbus, dbus.glib
OLPC_CHAT_SERVICE = "_olpc_chat._udp"