Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/purk/windows.py
blob: 3cca44d683b747ef90d6a8fc03d0afd08440861a (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
from gi.repository import Gtk
from gi.repository import Gdk

import irc
from conf import conf
import widgets

def append(window, manager):
    print "** DEBUG :: Add Window: ", window
    manager.add(window)

def append(window1, manager):
    print "** DEBUG :: Add window1: ", window1
    manager.add(window1)

def remove(window, manager):
    print "** DEBUG :: Remove Window: ", window
    manager.remove(window)

    # i don't want to have to call this
    window.destroy()

def new(wclass, network, id, core):
    if network is None:
        network = irc.dummy_network
    
    w = get(wclass, network, id, core)
    if not w:
        w = wclass(network, id, core)
        append(w, core.manager)

    return w

def get(windowclass, network, id, core):
    if network:
        id = network.norm_case(id)

    for w in core.manager:
        if (type(w).__name__, w.network, w.id) == (windowclass.__name__, network, id):
            return w

def get_with(manager, wclass=None, network=None, id=None):
    if network and id:
        id = network.norm_case(id)

    for w in list(manager):
        for to_find, found in ((wclass, type(w)), (network, w.network), (id, w.id)):
            # to_find might be False but not None (if it's a DummyNetwork)
            if to_find is not None and to_find != found:
                break
        else:
            yield w
            
def get_default(network, manager):
    window = manager.get_active()

    if window.network == network:
        return window

    # There can be only one...
    for window in get_with(manager, None, network):
        return window

class Window(Gtk.VBox):
    need_vbox_init = True

    def transfer_text(self, _widget, event):
        if event.string and not self.input.is_focus():
            self.input.grab_focus()
            self.input.set_position(-1)
            self.input.event(event)
        
    def write(self, text, activity_type=None, line_ending='\n', fg=None):
        if activity_type is None:
            activity_type = widgets.EVENT
        if self.manager.get_active() != self:
            self.activity = activity_type
        self.output.write(text, line_ending, fg)

    def get_id(self):
        if self.network:
            return self.network.norm_case(self.rawid)
        else:
            return self.rawid
            
    def set_id(self, id):
        self.rawid = id
        self.update()

    id = property(get_id, set_id)
    
    def get_toplevel_title(self):
        return self.rawid
    
    def get_title(self):
        return self.rawid

    def get_activity(self):
        return self.__activity
    
    def set_activity(self, value):
        if value:
            self.__activity.add(value)
        else:
            self.__activity = set()
        self.update()
        
    activity = property(get_activity, set_activity)
    
    def focus(self):
        pass
    
    def activate(self):
        self.manager.set_active(self)
        self.focus()
    
    def close(self):
        self.events.trigger("Close", window=self)
        remove(self, self.manager)
        
    def update(self):
        self.manager.update(self)

    def __init__(self, network, id, core):
        self.manager = core.manager
        self.events = core.events

        if self.need_vbox_init:
            #make sure we don't call this an extra time when mutating
            Gtk.VBox.__init__(self, False)
            self.need_vbox_init = False
        
        if hasattr(self, "buffer"):
            self.output = widgets.TextOutput(core, self, self.buffer)
        else:
            self.output = widgets.TextOutput(core, self)
            self.buffer = self.output.get_buffer()

        if hasattr(self, "input"):
            if self.input.parent:
                self.input.parent.remove(self.input)
        else:
            self.input = widgets.TextInput(self, core)
        
        self.network = network
        self.rawid = id
        
        self.__activity = set()

    def is_query(self):
        return False

    def is_channel(self):
        return False
    
class SimpleWindow(Window):
    def __init__(self, network, id, core):    
        Window.__init__(self, network, id)

        self.focus = self.input.grab_focus
        self.connect("key-press-event", self.transfer_text)

        self.pack_end(self.input, False, True, 0)
        
        topbox = Gtk.ScrolledWindow()
        topbox.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
        topbox.add(self.output)

        self.pack_end(topbox, True, True, 0)

        self.show_all()

class StatusWindow(Window):
    def get_toplevel_title(self):
        return '%s - %s' % (self.network.me, self.get_title())

    def get_title(self):
        # Something about self.network.isupport
        if self.network.status:
            return "%s" % self.network.server
        else:
            return "[%s]" % self.network.server

    def __init__(self, network, id, core):
        Window.__init__(self, network, id, core)

        self.nick_label = widgets.NickEditor(self, core)

        self.focus = self.input.grab_focus
        self.connect("key-press-event", self.transfer_text)
        self.manager = core.manager
        botbox = Gtk.HBox()
        botbox.add(self.input)
        botbox.pack_end(self.nick_label, False, True, 0)

        self.pack_end(botbox, False, True, 0)
        
        topbox = Gtk.ScrolledWindow()
        topbox.set_vexpand(True)
        topbox.add(self.output)

        self.pack_end(topbox, True, True, 0)

        self.show_all()

class QueryWindow(Window):
    def __init__(self, network, id, core):    
        Window.__init__(self, network, id, core)

        self.nick_label = widgets.NickEditor(self, core)

        self.focus = self.input.grab_focus
        self.connect("key-press-event", self.transfer_text)

        botbox = Gtk.HBox()
        botbox.add(self.input)
        botbox.pack_end(self.nick_label, False, True, 0)

        self.pack_end(botbox, False, True, 0)
        
        topbox = Gtk.ScrolledWindow()
        topbox.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        topbox.add(self.output)

        self.pack_end(topbox, True, True, 0)

        self.show_all()

    def is_query(self):
        return True

def move_nicklist(paned, event):
    paned._moving = (
        event.type == Gdk.EventType._2BUTTON_PRESS,
        paned.get_position()
        )
        
def drop_nicklist(paned, event):
    width = paned.get_allocated_width()
    pos = paned.get_position()
    
    double_click, nicklist_pos = paned._moving

    if double_click:
        # if we're "hidden", then we want to unhide
        if width - pos <= 10:
            # get the normal nicklist width
            conf_nicklist = conf.get("ui-gtk/nicklist-width", 200)

            # if the normal nicklist width is "hidden", then ignore it
            if conf_nicklist <= 10:
                paned.set_position(width - 200)
            else:
                paned.set_position(width - conf_nicklist)

        # else we hide
        else:
            paned.set_position(width)
        
    else:    
        if pos != nicklist_pos:
            conf["ui-gtk/nicklist-width"] = width - pos - 6

class ChannelWindow(Window):
    def __init__(self, network, id, core):
        Window.__init__(self, network, id, core)
        print "** DEBUG :: NEW Channel Window: ", network, ", ", id, ", ", core

        self.nicklist = widgets.Nicklist(self, core)
        self.nick_label = widgets.NickEditor(self, core)

        self.focus = self.input.grab_focus
        self.connect("key-press-event", self.transfer_text)
        
        topbox = Gtk.ScrolledWindow()
        topbox.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        topbox.add(self.output)
        
        nlbox = Gtk.ScrolledWindow()
	    nlbox.set_size_request(conf.get("ui-gtk/nicklist-width", 112), -1)
        nlbox.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)   
        nlbox.add(self.nicklist)

        botbox = Gtk.HBox()
        botbox.add(self.input)
        botbox.pack_end(self.nick_label, False, True, 0)

        self.pack_end(botbox, False, True, 0)
        
        pane = Gtk.HPaned()
        pane.pack1(topbox, resize=True, shrink=False)
        pane.pack2(nlbox, resize=False, shrink=True)
        
        self.nicklist.pos = None
 
        pane.connect("button-press-event", move_nicklist)
        pane.connect("button-release-event", drop_nicklist)
        
        self.pack_end(pane, True, True, 0)
        self.show_all()

    def is_channel(self):
        return True

    def is_channel_other(self):
        return True