DevConsole/Purk: Support for auto-join channels on connect, new button to connect to #olpc-help
This commit is contained in:
parent
9eb9d79cee
commit
104b158a80
@ -54,7 +54,7 @@ class Console(object):
|
|||||||
self._load_interface('memphis', 'Memphis')
|
self._load_interface('memphis', 'Memphis')
|
||||||
self._load_interface('logviewer', 'Log Viewer')
|
self._load_interface('logviewer', 'Log Viewer')
|
||||||
self._load_interface('terminal', 'Terminal')
|
self._load_interface('terminal', 'Terminal')
|
||||||
self._load_interface('irc_client', 'IRC')
|
self._load_interface('irc_client', 'IRC Client')
|
||||||
self._load_interface('ps_watcher', 'Presence')
|
self._load_interface('ps_watcher', 'Presence')
|
||||||
|
|
||||||
main_hbox = gtk.HBox()
|
main_hbox = gtk.HBox()
|
||||||
|
@ -1,10 +1,28 @@
|
|||||||
|
import gtk
|
||||||
import purk
|
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):
|
class Interface(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
client = purk.Client()
|
self.widget = IRCGui()
|
||||||
client.show()
|
|
||||||
client.join_server('irc.freenode.net')
|
|
||||||
self.widget = client.get_widget()
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,8 @@ class Core(object):
|
|||||||
self.trigger = Trigger()
|
self.trigger = Trigger()
|
||||||
self.events = self.trigger.events
|
self.events = self.trigger.events
|
||||||
self.manager = widgets.UrkUITabs(self)
|
self.manager = widgets.UrkUITabs(self)
|
||||||
|
self.channels = []
|
||||||
|
|
||||||
mods = self.trigger.get_modules()
|
mods = self.trigger.get_modules()
|
||||||
for m in mods:
|
for m in mods:
|
||||||
m.core = self
|
m.core = self
|
||||||
@ -79,6 +80,7 @@ class Client(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.core = Core()
|
self.core = Core()
|
||||||
self.widget = self.core.manager.box
|
self.widget = self.core.manager.box
|
||||||
|
|
||||||
def run_command(self, command):
|
def run_command(self, command):
|
||||||
self.core.run_command(command)
|
self.core.run_command(command)
|
||||||
|
|
||||||
@ -92,3 +94,8 @@ class Client(object):
|
|||||||
def show(self):
|
def show(self):
|
||||||
self.widget.show_all()
|
self.widget.show_all()
|
||||||
|
|
||||||
|
def add_channel(self, channel):
|
||||||
|
self.core.channels.append(channel)
|
||||||
|
|
||||||
|
def clear_channels(self):
|
||||||
|
self.core.channels = []
|
||||||
|
@ -192,17 +192,11 @@ def run(text, window, network):
|
|||||||
c_data.args = split
|
c_data.args = split
|
||||||
|
|
||||||
event_name = "Command" + c_data.name.capitalize()
|
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:
|
if event_name in all_events:
|
||||||
result = trigger(event_name, c_data)
|
result = trigger(event_name, c_data)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
print "* /%s: %s" % (c_data.name, result[0])
|
|
||||||
c_data.window.write("* /%s: %s" % (c_data.name, result[0]))
|
c_data.window.write("* /%s: %s" % (c_data.name, result[0]))
|
||||||
else:
|
else:
|
||||||
trigger("Command", c_data)
|
trigger("Command", c_data)
|
||||||
|
@ -54,6 +54,7 @@ class Network(object):
|
|||||||
|
|
||||||
def __init__(self, core, server="irc.default.org", port=6667, nicks=[],
|
def __init__(self, core, server="irc.default.org", port=6667, nicks=[],
|
||||||
username="", fullname="", name=None, **kwargs):
|
username="", fullname="", name=None, **kwargs):
|
||||||
|
self.core = core
|
||||||
self.manager = core.manager
|
self.manager = core.manager
|
||||||
self.server = server
|
self.server = server
|
||||||
self.port = port
|
self.port = port
|
||||||
@ -131,7 +132,7 @@ class Network(object):
|
|||||||
self.disconnect(error=error[1])
|
self.disconnect(error=error[1])
|
||||||
#we should immediately retry if we failed to open the socket and there are hosts left
|
#we should immediately retry if we failed to open the socket and there are hosts left
|
||||||
if self.status == DISCONNECTED and not self.failedlasthost:
|
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()
|
self.connect()
|
||||||
else:
|
else:
|
||||||
self.source = source = ui.Source()
|
self.source = source = ui.Source()
|
||||||
@ -143,6 +144,10 @@ class Network(object):
|
|||||||
if source.enabled:
|
if source.enabled:
|
||||||
self.source = ui.fork(self.on_read, self.socket.recv, 8192)
|
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
|
#called when we read data or failed to read data
|
||||||
def on_read(self, result, error):
|
def on_read(self, result, error):
|
||||||
if error:
|
if error:
|
||||||
@ -164,7 +169,7 @@ class Network(object):
|
|||||||
|
|
||||||
if source.enabled:
|
if source.enabled:
|
||||||
self.source = ui.fork(self.on_read, self.socket.recv, 8192)
|
self.source = ui.fork(self.on_read, self.socket.recv, 8192)
|
||||||
|
|
||||||
def raw(self, msg):
|
def raw(self, msg):
|
||||||
self.events.trigger("OwnRaw", network=self, raw=msg)
|
self.events.trigger("OwnRaw", network=self, raw=msg)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user