Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services/console/lib/purk/__init__.py
blob: 7a87e549947ba57b06b978ce3d34f7fb7d379c1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
import sys
import traceback
import events
import windows

urkpath = os.path.abspath(os.path.dirname(__file__))

if os.path.abspath(os.curdir) != os.path.join(urkpath):
    sys.path[0] = os.path.join(urkpath)    

sys.path = [
    os.path.join(urkpath, "scripts"),
    ] + sys.path

script_path = urkpath+"/scripts"

from ui import *

# Here I'm trying to handle the original URL IRC Client, urk don't use
# normal classes . Let's try to get a urk widget:
class Trigger(object):
    def __init__(self):
        self._mods = []
        self.events = events
        self._load_scripts()

    def _load_scripts(self):
        script_path = urkpath + "/scripts"
        try:
            suffix = os.extsep+"py"
            for script in os.listdir(script_path):
                if script.endswith(suffix):
                    try:
                        mod = self.events.load(script)
                        self._mods.append(mod)
                    except:
                        traceback.print_exc()
                        print "Failed loading script %s." % script
        except OSError:
            pass

    def get_modules(self):
        return self._mods

class Core(object):
    def __init__(self):
        self.window = None
        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
            m.manager = self.manager

        if not self.window:
           self.window = windows.new(windows.StatusWindow, irc.Network(self), "status", self)
           self.window.activate()

        register_idle(self.trigger_start)
        gtk.gdk.threads_enter()

    def run_command(self, command):
        offset = 0
        if command[0] == '/':
            offset = 1

        self.events.run(command[offset:], self.manager.get_active(), self.window.network)

    def trigger_start(self):
        self.events.trigger("Start")

    def _add_script(self, module):
        return 

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)

    def join_server(self, network_name, port=6667):
        command = 'server '+ network_name + ' ' + str(port)
        self.run_command(command)

    def get_widget(self):
        return self.widget

    def show(self):
        self.widget.show_all()

    def add_channel(self, channel):
        self.core.channels.append(channel)

    def clear_channels(self):
        self.core.channels = []