From 104b158a8003b0967ed1dea19ed5652e4fba8d8c Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Tue, 21 Aug 2007 17:31:56 -0400 Subject: [PATCH] DevConsole/Purk: Support for auto-join channels on connect, new button to connect to #olpc-help --- services/console/console.py | 2 +- .../interface/irc_client/irc_client.py | 28 +++++++++++++++---- services/console/lib/purk/__init__.py | 9 +++++- services/console/lib/purk/events.py | 8 +----- services/console/lib/purk/irc.py | 9 ++++-- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/services/console/console.py b/services/console/console.py index cf33a765..7f3d3ca8 100755 --- a/services/console/console.py +++ b/services/console/console.py @@ -54,7 +54,7 @@ class Console(object): self._load_interface('memphis', 'Memphis') self._load_interface('logviewer', 'Log Viewer') self._load_interface('terminal', 'Terminal') - self._load_interface('irc_client', 'IRC') + self._load_interface('irc_client', 'IRC Client') self._load_interface('ps_watcher', 'Presence') main_hbox = gtk.HBox() diff --git a/services/console/interface/irc_client/irc_client.py b/services/console/interface/irc_client/irc_client.py index a7189594..3cc2a83c 100644 --- a/services/console/interface/irc_client/irc_client.py +++ b/services/console/interface/irc_client/irc_client.py @@ -1,10 +1,28 @@ +import gtk import purk +class IRCGui(gtk.VBox): + _DEFAULT_SERVER = "irc.freenode.net" + _AUTO_JOIN_CHANNEL = "#olpc-help" + + def __init__(self): + gtk.VBox.__init__(self, False) + + connect_button = gtk.Button('Connect to OLPC Help Channel') + connect_button.connect('clicked', self._on_connect_clicked_cb) + + self._client = purk.Client() + self._client.add_channel(self._AUTO_JOIN_CHANNEL) + client_widget = self._client.get_widget() + + self.pack_start(connect_button, False, False, 1) + self.pack_start(client_widget) + self.show_all() + + def _on_connect_clicked_cb(self, widget): + self._client.join_server(self._DEFAULT_SERVER) + class Interface(object): def __init__(self): - client = purk.Client() - client.show() - client.join_server('irc.freenode.net') - self.widget = client.get_widget() - + self.widget = IRCGui() diff --git a/services/console/lib/purk/__init__.py b/services/console/lib/purk/__init__.py index 35d93ad6..7a87e549 100644 --- a/services/console/lib/purk/__init__.py +++ b/services/console/lib/purk/__init__.py @@ -49,7 +49,8 @@ class Core(object): self.trigger = Trigger() self.events = self.trigger.events self.manager = widgets.UrkUITabs(self) - + self.channels = [] + mods = self.trigger.get_modules() for m in mods: m.core = self @@ -79,6 +80,7 @@ class Client(object): def __init__(self): self.core = Core() self.widget = self.core.manager.box + def run_command(self, command): self.core.run_command(command) @@ -92,3 +94,8 @@ class Client(object): def show(self): self.widget.show_all() + def add_channel(self, channel): + self.core.channels.append(channel) + + def clear_channels(self): + self.core.channels = [] diff --git a/services/console/lib/purk/events.py b/services/console/lib/purk/events.py index 2a0d45e5..4142003f 100644 --- a/services/console/lib/purk/events.py +++ b/services/console/lib/purk/events.py @@ -192,17 +192,11 @@ def run(text, window, network): c_data.args = split event_name = "Command" + c_data.name.capitalize() - #print "searching: " + event_name - #for s in all_events: - # print "match: " + s - # if s == event_name: - # print "we got it!" - + if event_name in all_events: result = trigger(event_name, c_data) if result: - print "* /%s: %s" % (c_data.name, result[0]) c_data.window.write("* /%s: %s" % (c_data.name, result[0])) else: trigger("Command", c_data) diff --git a/services/console/lib/purk/irc.py b/services/console/lib/purk/irc.py index d5a01aad..48d1fb8b 100644 --- a/services/console/lib/purk/irc.py +++ b/services/console/lib/purk/irc.py @@ -54,6 +54,7 @@ class Network(object): def __init__(self, core, server="irc.default.org", port=6667, nicks=[], username="", fullname="", name=None, **kwargs): + self.core = core self.manager = core.manager self.server = server self.port = port @@ -131,7 +132,7 @@ class Network(object): self.disconnect(error=error[1]) #we should immediately retry if we failed to open the socket and there are hosts left if self.status == DISCONNECTED and not self.failedlasthost: - windows.get_default(self).write("* Retrying with next available host") + windows.get_default(self, self.core.manager).write("* Retrying with next available host") self.connect() else: self.source = source = ui.Source() @@ -143,6 +144,10 @@ class Network(object): if source.enabled: self.source = ui.fork(self.on_read, self.socket.recv, 8192) + # Auto join channels on connect + for channel in self.core.channels: + self.core.run_command("/join %s" % channel) + #called when we read data or failed to read data def on_read(self, result, error): if error: @@ -164,7 +169,7 @@ class Network(object): if source.enabled: self.source = ui.fork(self.on_read, self.socket.recv, 8192) - + def raw(self, msg): self.events.trigger("OwnRaw", network=self, raw=msg)