annotate frontends/primitivus/primitivus @ 144:80661755ea8d

Primitivus: Tarot card game implementation - quick frontend: card_game added - wix: card_game splitted with quick frontend - tools: new game library - primitivus: new card_game widget (not finished yet) - primitivus: SàT XML UI management: first draft
author Goffi <goffi@goffi.org>
date Mon, 26 Jul 2010 19:43:44 +0800
parents 227394eb080c
children c8b231abfe96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Primitivus: a SAT frontend
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from quick_frontend.quick_app import QuickApp
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from quick_frontend.quick_chat_list import QuickChatList
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from quick_frontend.quick_contact_list import QuickContactList
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from quick_frontend.quick_contact_management import QuickContactManagement
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 import urwid
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from profile_manager import ProfileManager
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
29 from contact_list import ContactList
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
30 from chat import Chat
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
31 import custom_widgets
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 import pdb
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 """from window import Window
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from editbox import EditBox
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from statusbar import StatusBar
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from chat import Chat
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from tools.jid import JID"""
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 import logging
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 from logging import debug, info, error
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 #import locale
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 import sys, os
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
42 from tools.jid import JID
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 #from curses import ascii
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 #import locale
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 #from signal import signal, SIGWINCH
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 #import fcntl
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 #import struct
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 #import termios
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 #from boxsizer import BoxSizer
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 ### logging configuration FIXME: put this elsewhere ###
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 logging.basicConfig(level=logging.CRITICAL, #TODO: configure it to put messages in a log file
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 format='%(message)s')
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 ###
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 const_APP_NAME = "Primitivus"
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
58 const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
59 ('selected', 'default', 'dark red'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
60 ('selected_focus', 'default,bold', 'dark red'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
61 ('default', 'default', 'default'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
62 ('default_focus', 'default,bold', 'default'),
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
63 ('alert', 'default,underline', 'default'),
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
64 ('alert_focus', 'default,bold,underline', 'default'),
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
65 ('date', 'light gray', 'default'),
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
66 ('my_nick', 'dark red,bold', 'default'),
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
67 ('other_nick', 'dark cyan,bold', 'default'),
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
68 ('menubar', 'light gray,bold', 'dark red'),
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
69 ('selected_menu', 'light gray,bold', 'dark green'),
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
70 ('menuitem', 'light gray,bold', 'dark red'),
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
71 ('menuitem_focus', 'light gray,bold', 'dark green'),
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
72 ('card_neutral', 'dark gray', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
73 ('card_neutral_selected', 'dark gray', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
74 ('card_special', 'brown', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
75 ('card_special_selected', 'brown', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
76 ('card_red', 'dark red', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
77 ('card_red_selected', 'dark red', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
78 ('card_black', 'black', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
79 ('card_black_selected', 'black', 'dark green', 'standout,underline'),
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
80 ]
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
82 class ChatList(QuickChatList):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
83 """This class manage the list of chat windows"""
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
84
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
85 def __init__(self, host):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
86 QuickChatList.__init__(self, host)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
87
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
88 def createChat(self, target):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
89 return Chat(target, self.host)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
90
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 class PrimitivusApp(QuickApp):
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def __init__(self):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
94 self.CM = QuickContactManagement() #FIXME: not the best place
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 QuickApp.__init__(self) #XXX: yes it's an unusual place for the constructor of a parent class, but the init order is important
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 ## main loop setup ##
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
98 self.main_widget = ProfileManager(self)
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
99 self.loop = urwid.MainLoop(self.main_widget, const_PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
101 ##misc setup##
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
102 self.chat_wins=ChatList(self)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
103
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
104 def debug(self):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
105 """convenient method to reset screen and launch pdb"""
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
106 import os
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
107 os.system('reset')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
108 print 'Entered debug mode'
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
109 pdb.set_trace()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
110
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
111 def write_log(self, log, file_name='/tmp/primitivus_log'):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
112 """method to write log in a temporary file, useful for debugging"""
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
113 f=open(file_name, 'a')
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
114 f.write(log+"\n")
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
115 f.close()
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
116
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
117 def redraw(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
118 """redraw the screen"""
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
119 self.loop.draw_screen()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
120
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 def start(self):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
122 self.i = 0
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
123 self.loop.set_alarm_in(0,lambda a,b: self.postInit())
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 self.loop.run()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
126 def inputFilter(self, input, raw):
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
127 for i in input:
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
128 if i.__class__==tuple:
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
129 if i[0] == 'mouse press':
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
130 if i[1] == 4: #Mouse wheel up
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
131 input[input.index(i)] = 'up'
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
132 if i[1] == 5: #Mouse wheel down
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
133 input[input.index(i)] = 'down'
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
134 return input
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
135
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
136 def keyHandler(self, input):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
137 if input == 'meta m':
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
138 try:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
139 if self.main_widget.header == None:
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
140 self.main_widget.header = self.menu_roller
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
141 else:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
142 self.main_widget.header = None
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
143 except AttributeError:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
144 pass
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
145 elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
146 self.debug()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
147 elif input == 'f2': #user wants to (un)hide the contact_list
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
148 try:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
149 center_widgets = self.center_part.widget_list
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
150 if self.contactList in center_widgets:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
151 self.center_part.set_focus(0) #necessary as the focus change to the next object, we can go out of range if we are on the last object of self.center_part
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
152 center_widgets.remove(self.contactList)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
153 del self.center_part.column_types[0]
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
154 else:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
155 center_widgets.insert(0, self.contactList)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
156 self.center_part.column_types.insert(0, ('weight', 2))
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
157 except AttributeError:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
158 #The main widget is not built (probably in Profile Manager)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
159 pass
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
160 elif input == 'window resize':
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
161 width,height = self.loop.screen_size
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
162 if height<=5 and width<=35:
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
163 if not 'save_main_widget' in dir(self):
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
164 self.save_main_widget = self.loop.widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
165 self.loop.widget = urwid.Filler(urwid.Text(_("Pleeeeasse, I can't even breathe !")))
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
166 else:
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
167 if 'save_main_widget' in dir(self):
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
168 self.loop.widget = self.save_main_widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
169 del self.save_main_widget
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
170 try:
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
171 return self.menu_roller.checkShortcuts(input)
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
172 except AttributeError:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
173 return input
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
174
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
175 def __buildMenuRoller(self):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
176 menu = custom_widgets.Menu(self.loop)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
177 general = _("General")
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
178 menu.addMenu(general, _("Connect"), self.onConnectRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
179 menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
180 menu.addMenu(general, _("About"), self.onAboutRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
181 menu.addMenu(general, _("Exit"), self.onExitRequest, 'ctrl x')
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
182 contact = _("Contact")
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
183 menu.addMenu(contact, _("Add contact"), self.onAddContactRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
184 menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
185 communication = _("Communication")
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
186 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
187 menu_roller = custom_widgets.MenuRoller([(_('Main menu'),menu)])
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
188 return menu_roller
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
189
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 def __buildMainWidget(self):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
191 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw())
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
192 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))])
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
193 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))])
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
194 editBar = custom_widgets.AdvancedEdit('> ')
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
195 urwid.connect_signal(editBar,'click',self.onTextEntered)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
196 self.menu_roller = self.__buildMenuRoller()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
197 self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=editBar, focus_part='footer')
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
198 return self.main_widget
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
199
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
200 def plug_profile(self, profile_key='@DEFAULT@'):
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
201 self.loop.widget = self.__buildMainWidget()
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
202 QuickApp.plug_profile(self, profile_key)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
203
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
204 def removePopUp(self, widget=None):
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
205 self.loop.widget = self.main_widget
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
206
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
207 def showPopUp(self, pop_up_widget):
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
208 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40))
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
209 self.loop.widget = display_widget
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
210
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
211 def contactSelected(self, contact_list):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
212 contact = contact_list.get_contact()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
213 if contact:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
214 assert(len(self.center_part.widget_list)==2)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
215 self.center_part.widget_list[1] = self.chat_wins[contact]
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
216 self.menu_roller.addMenu(_('Chat menu'), self.chat_wins[contact].getMenu())
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
217
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
218 def onTextEntered(self, editBar):
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
219 """Called when text is entered in the main edit bar"""
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
220 contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
221 if contact:
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
222 chat = self.chat_wins[contact]
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
223 self.bridge.sendMessage(contact,
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
224 editBar.get_edit_text(),
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
225 type = "groupchat" if chat.type == 'group' else "chat",
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
226 profile_key=self.profile)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
227 editBar.set_edit_text('')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
228
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
229 def newMessage(self, from_jid, msg, type, to_jid, profile):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
230 if not self.check_profile(profile):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
231 return
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
232 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
233 sender = JID(from_jid)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
234 if JID(self.contactList.selected).short != sender.short:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
235 self.contactList.putAlert(sender)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
236
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
237 def onJoinRoom(self, button, edit):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
238 self.removePopUp()
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
239 room_jid = JID(edit.get_edit_text())
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
240 if room_jid.is_valid():
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
241 self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile)
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
242 else:
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
243 message = _("'%s' is an invalid JID !") % room_jid
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
244 error (message)
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
245 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
246
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
247 def onAddContact(self, button, edit):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
248 self.removePopUp()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
249 jid=JID(edit.get_edit_text())
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
250 if jid.is_valid():
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
251 self.bridge.addContact(jid.short, profile_key=self.profile)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
252 else:
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
253 message = _("'%s' is an invalid JID !") % jid
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
254 error (message)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
255 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
256
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
257 def onRemoveContact(self, button):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
258 self.removePopUp()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
259 info(_("Unsubscribing %s presence"),self.contactList.get_contact())
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
260 self.bridge.delContact(self.contactList.get_contact(), profile_key=self.profile)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
261
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
262 #Menu events#
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
263 def onConnectRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
264 self.bridge.connect(self.profile)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
265
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
266 def onDisconnectRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
267 self.bridge.disconnect(self.profile)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
268
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
269 def onExitRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
270 raise urwid.ExitMainLoop()
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
271
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
272 def onJoinRoomRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
273 """User wants to join a MUC room"""
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
274 pop_up_widget = custom_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'test@conference.necton2.int', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
275 self.showPopUp(pop_up_widget)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
276
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
277 def onAddContactRequest(self, menu):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
278 pop_up_widget = custom_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
279 self.showPopUp(pop_up_widget)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
280
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
281 def onRemoveContactRequest(self, menu):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
282 contact = self.contactList.get_contact()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
283 if not contact:
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
284 self.showPopUp(custom_widgets.Alert(_("Error"), _("You have not selected any contact to delete !"), ok_cb=self.removePopUp))
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
285 else:
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
286 pop_up_widget = custom_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
287 self.showPopUp(pop_up_widget)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
288
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
289
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
290
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
291
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
292 def onAboutRequest(self, menu):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
293 self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
294
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
295
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
296 sat = PrimitivusApp()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
297 sat.start()
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
298