File: groupChatWindow.py

package info (click to toggle)
pythoncard 0.8.2-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,452 kB
  • sloc: python: 56,787; makefile: 56; sh: 22
file content (141 lines) | stat: -rw-r--r-- 4,849 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/python

"""
__version__ = "$Revision: 1.7 $"
__date__ = "$Date: 2004/04/25 23:12:46 $"
"""

import PythonCard
from PythonCard import dialog, log, model
import wx

import os
import time

import chatWindow

class GroupChatWindow(chatWindow.ChatWindow):

    # this isn't quite right, the wxFlexGridSizer
    # containing the headers should expand horizontally as the window
    # expands
    def initSizers(self):
        comp = self.components
        
        sizer1 = wx.BoxSizer(wx.VERTICAL)
        sizer2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer3 = wx.BoxSizer(wx.HORIZONTAL)
        
        stcSizerAttrs = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL         
        fldSizerAttrs = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND
        vertFlags = wx.LEFT | wx.TOP | wx.ALIGN_LEFT
        chkSizerAttrs = wx.RIGHT | wx.ALIGN_CENTER_VERTICAL

        sizer2.Add(comp.fldTranscript, 1, wx.EXPAND)
        #sizer2.Add(comp.fldInput, 1, fldSizerAttrs, 20)
        #sizer2.Add((5, 5), 0)  # spacer
        sizer2.Add(comp.listRoster, 0, wx.EXPAND, 20)

        sizer3.Add(comp.fldInput, 1, fldSizerAttrs, 20)
        sizer3.Add((5, 5), 0)  # spacer
        sizer3.Add(comp.btnSend, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 20)

        sizer1.Add(sizer2, 1, wx.EXPAND)
        sizer1.Add((5, 5), 0)  # spacer
        sizer1.Add(sizer3, 0, wx.EXPAND)

        self.sizer1 = sizer1

        sizer1.Fit(self)
        sizer1.SetSizeHints(self)
        self.panel.SetSizer(sizer1)
        self.panel.SetAutoLayout(1)
        self.panel.Layout()


    def setToJID(self, jid, toName):
        self.toJID = jid
        self.toName = toName
        if jid == toName:
            self.title = jid
        else:
            self.title = "%s (%s)" % (toName, jid)

    def appendMessage(self, jid, txt):
##        oldFocus = self.findFocus()

        jid = str(jid)
        # appendMessage could be called before
        # openBackground event is processed
        if not hasattr(self, 'parent'):
            self.parent = self.GetParent()
        # make sure the chat window is in front

        now = time.localtime(time.time())
        timeStr = time.strftime("[%H:%M:%S] ", now)
        
        # in groupchat, the resource is the nickname
        # jabber@conference.jabber.org/altis
        try:
            nickname = jid.split('/')[1]
            if nickname == 'default':
                # this is probably some status message like a user joining
                nickname = jid
        except:
            # this is probably some status message like a user joining
            nickname = jid

        f = self.components.fldTranscript.font.description()
        f['style'] = 'bold'
        color = 'black'
        if nickname == jid:
            color = 'green'
        elif nickname != self.nickname:
            color = 'blue'
        self.components.fldTranscript.SetDefaultStyle(wx.TextAttr(color, 
            font=PythonCard.font.fontFromDescription(f)))

        if len(self.components.fldTranscript.text) == 0:
            self.components.fldTranscript.appendText(timeStr + nickname + ":")
        else:
            self.components.fldTranscript.appendText("\n" + timeStr + nickname + ":")
        
        f['style'] = 'regular'
        if nickname == jid:
            color = 'green'
        else:
            color = 'black'
        self.components.fldTranscript.SetDefaultStyle(wx.TextAttr(color, 
            font=PythonCard.font.fontFromDescription(f)))

        # making it editable, should force auto-scroll
        # but it doesn't seem to work, setting the focus
        # appears to be the key
        #self.components.fldTranscript.editable = 1
        self.components.fldTranscript.appendText(" " + str(txt))
        ##self.components.fldTranscript.SetInsertionPointEnd()
        #self.components.fldTranscript.editable = 0
##        self.components.fldTranscript.setFocus()
##        if (oldFocus == self.components.fldInput) or (oldFocus == self.components.btnSend):
##            self.components.fldInput.setFocus()
##        elif oldFocus is not None:
##            oldFocus.setFocus()
##        if oldFocus:
##            oldFocus.setFocus()
##        else:
##            self.components.fldInput.setFocus()

        if self.GetParent().menuBar.getChecked('menuOptionsShowWindow'):
            if self.IsIconized():
                self.Iconize(0)
            self.visible = True
        if self.GetParent().menuBar.getChecked('menuOptionsRaiseWindow'):
            wx.CallAfter(self.Raise)

    def on_doSend_command(self, event):
        txt = self.components.fldInput.text.rstrip()
        if txt:
            self.parent.jabberConnection.sendGroupChatMessage(self.toJID, txt)
            #self.appendMessage(self.parent.jabberConnection.JID, txt)
            self.components.fldInput.text = ""