diff options
author | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-02-10 16:47:43 +0000 |
---|---|---|
committer | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-02-10 16:47:43 +0000 |
commit | d2a4ecf9a5214b784720dd6a7b2ad79c298a05b9 (patch) | |
tree | d32bb1b64829405677d7a5fc5fbc0bc12cb7b3b8 | |
parent | b9a05fe48a4a5221ff0e09d86268ef75ffb17baf (diff) | |
download | poezio-d2a4ecf9a5214b784720dd6a7b2ad79c298a05b9.tar.gz poezio-d2a4ecf9a5214b784720dd6a7b2ad79c298a05b9.tar.bz2 poezio-d2a4ecf9a5214b784720dd6a7b2ad79c298a05b9.tar.xz poezio-d2a4ecf9a5214b784720dd6a7b2ad79c298a05b9.zip |
little cleanup
-rw-r--r-- | src/client.py | 20 | ||||
-rw-r--r-- | src/config.py | 4 | ||||
-rw-r--r-- | src/connection.py | 4 | ||||
-rw-r--r-- | src/gui.py | 30 | ||||
-rw-r--r-- | src/multiuserchat.py | 2 | ||||
-rw-r--r-- | src/window.py | 1 |
6 files changed, 35 insertions, 26 deletions
diff --git a/src/client.py b/src/client.py index 0d81e0f2..f64dc5e6 100644 --- a/src/client.py +++ b/src/client.py @@ -19,7 +19,7 @@ import sys # disable any printout (this would mess the display) -stderr = sys.stderr +STDERR = sys.stderr sys.stderr = open('/dev/null', 'w') sys.stdout = open('/dev/null', 'w') @@ -28,21 +28,22 @@ from multiuserchat import MultiUserChat from config import config from handler import Handler from gui import Gui -from curses import wrapper, initscr +from curses import initscr import curses import signal signal.signal(signal.SIGINT, signal.SIG_IGN) import traceback -def exception_handler(type_, value, tb): + +def exception_handler(type_, value, trace): """ on any traceback: exit ncurses and print the traceback then exit the program """ curses.echo() curses.endwin() - traceback.print_exception(type_, value, tb, None, stderr) + traceback.print_exception(type_, value, trace, None, STDERR) sys.exit() sys.excepthook = exception_handler @@ -63,9 +64,18 @@ class Client(object): self.connection.start() self.gui = Gui(self.stdscr, MultiUserChat(self.connection.client)) + def launch(self): + """ + launch + """ + self.gui.main_loop(self.stdscr) + def main(): + """ + main function + """ client = Client() - client.gui.main_loop(client.stdscr) + client.launch() sys.exit() if __name__ == '__main__': diff --git a/src/config.py b/src/config.py index 4201be4d..57c3d90a 100644 --- a/src/config.py +++ b/src/config.py @@ -45,7 +45,7 @@ class Config(RawConfigParser): elif type(default) == float: res = self.getfloat(option) elif type(default) == bool: - res = self.getbool(option) + res = self.getboolean(option) else: res = self.getstr(option) except NoOptionError: @@ -75,7 +75,7 @@ class Config(RawConfigParser): RawConfigParser.write(self, f) f.close() - def setAndSave(self, option, value): + def set_and_save(self, option, value): self.set(option, value) self.save() diff --git a/src/connection.py b/src/connection.py index 68030e7c..c651032e 100644 --- a/src/connection.py +++ b/src/connection.py @@ -23,7 +23,6 @@ import xmpp from config import config from logging import logger from threading import Thread -from multiuserchat import MultiUserChat from handler import Handler class Connection(Thread): @@ -100,7 +99,8 @@ class Connection(Thread): def process(self, timeout=10): if self.online: - try:self.client.Process(timeout) + try: + self.client.Process(timeout) except: pass # FIXME else: @@ -29,7 +29,6 @@ locale.setlocale(locale.LC_ALL, '') import sys import curses -from curses import textpad from datetime import datetime from handler import Handler @@ -48,8 +47,8 @@ class User(object): self.color = randrange(2, 10) def update(self, affiliation, show, status, role): - self.affiliation = None - self.show = None + self.affiliation = affiliation + self.show = show self.status = status self.role = role @@ -75,14 +74,15 @@ class Room(object): if not msg: logger.info('msg is None..., %s' % (nick)) return - self.lines.append((datetime.now(), nick.encode('utf-8'), msg.encode('utf-8'))) + self.lines.append((datetime.now(), nick.encode('utf-8'), + msg.encode('utf-8'))) def add_info(self, info): """ info, like join/quit/status messages""" try: self.lines.append((datetime.now(), info.encode('utf-8'))) return info.encode('utf-8') - except: # I JUST FUCKING HATE THIS .encode.decode.shit !!! + except: self.lines.append((datetime.now(), info)) return info @@ -100,11 +100,11 @@ class Room(object): status = stanza.getStatus() role = stanza.getRole() if not self.joined: # user in the room BEFORE us. - self.users.append(User(nick, affiliation, show, status, role)) - if nick.encode('utf-8') == self.own_nick: - self.joined = True - return self.add_info(_("Your nickname is %s") % (nick)) - return self.add_info(_("%s is in the room") % (nick.encode-('utf-8'))) + self.users.append(User(nick, affiliation, show, status, role)) + if nick.encode('utf-8') == self.own_nick: + self.joined = True + return self.add_info(_("Your nickname is %s") % (nick)) + return self.add_info(_("%s is in the room") % (nick.encode-('utf-8'))) change_nick = stanza.getStatusCode() == '303' kick = stanza.getStatusCode() == '307' user = self.get_user_by_name(nick) @@ -239,7 +239,7 @@ class Gui(object): self.window.do_command(key) def current_room(self): - return self.rooms[0] + return self.rooms[0] def get_room_by_name(self, name): for room in self.rooms: @@ -293,7 +293,7 @@ class Gui(object): nick_from = '' room = self.get_room_by_name(room_from) if not room: - self.information(_("message received for a non-existing room: %s") % (name)) + self.information(_("message received for a non-existing room: %s") % (room_from)) return body = stanza.getBody() if not body: @@ -320,7 +320,7 @@ class Gui(object): from_room = stanza.getFrom().getStripped() room = self.get_room_by_name(from_room) if not room: - self.information(_("presence received for a non-existing room: %s") % (name)) + self.information(_("presence received for a non-existing room: %s") % (from_room)) if stanza.getType() == 'error': msg = _("Error: %s") % stanza.getError() else: @@ -446,7 +446,7 @@ class Gui(object): res = roomname+'/'+nick else: res = roomname - config.setAndSave('rooms', bookmarked+':'+res) + config.set_and_save('rooms', bookmarked+':'+res) def command_set(self, args): if len(args) != 2: @@ -454,7 +454,7 @@ class Gui(object): return option = args[0] value = args[1] - config.setAndSave(option, value) + config.set_and_save(option, value) msg = "%s=%s" % (option, value) room = self.current_room() room.add_info(msg) diff --git a/src/multiuserchat.py b/src/multiuserchat.py index 5101b708..4f132fd4 100644 --- a/src/multiuserchat.py +++ b/src/multiuserchat.py @@ -50,7 +50,7 @@ class MultiUserChat(object): def on_connected(self, jid): self.own_jid = jid rooms = config.get('rooms', '') - if rooms == '': + if rooms == '' or type(rooms) != str: return else: rooms = rooms.split(':') diff --git a/src/window.py b/src/window.py index f91bb7c8..8aa95995 100644 --- a/src/window.py +++ b/src/window.py @@ -18,7 +18,6 @@ # along with Poezio. If not, see <http://www.gnu.org/licenses/>. import curses -from logging import logger class Win(object): def __init__(self, height, width, y, x, parent_win): |