little cleanup

This commit is contained in:
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 2010-02-10 16:47:43 +00:00
parent b9a05fe48a
commit d2a4ecf9a5
6 changed files with 35 additions and 26 deletions

View file

@ -19,7 +19,7 @@
import sys import sys
# disable any printout (this would mess the display) # disable any printout (this would mess the display)
stderr = sys.stderr STDERR = sys.stderr
sys.stderr = open('/dev/null', 'w') sys.stderr = open('/dev/null', 'w')
sys.stdout = open('/dev/null', 'w') sys.stdout = open('/dev/null', 'w')
@ -28,21 +28,22 @@ from multiuserchat import MultiUserChat
from config import config from config import config
from handler import Handler from handler import Handler
from gui import Gui from gui import Gui
from curses import wrapper, initscr from curses import initscr
import curses import curses
import signal import signal
signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGINT, signal.SIG_IGN)
import traceback import traceback
def exception_handler(type_, value, tb):
def exception_handler(type_, value, trace):
""" """
on any traceback: exit ncurses and print the traceback on any traceback: exit ncurses and print the traceback
then exit the program then exit the program
""" """
curses.echo() curses.echo()
curses.endwin() curses.endwin()
traceback.print_exception(type_, value, tb, None, stderr) traceback.print_exception(type_, value, trace, None, STDERR)
sys.exit() sys.exit()
sys.excepthook = exception_handler sys.excepthook = exception_handler
@ -63,9 +64,18 @@ class Client(object):
self.connection.start() self.connection.start()
self.gui = Gui(self.stdscr, MultiUserChat(self.connection.client)) self.gui = Gui(self.stdscr, MultiUserChat(self.connection.client))
def launch(self):
"""
launch
"""
self.gui.main_loop(self.stdscr)
def main(): def main():
"""
main function
"""
client = Client() client = Client()
client.gui.main_loop(client.stdscr) client.launch()
sys.exit() sys.exit()
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -45,7 +45,7 @@ class Config(RawConfigParser):
elif type(default) == float: elif type(default) == float:
res = self.getfloat(option) res = self.getfloat(option)
elif type(default) == bool: elif type(default) == bool:
res = self.getbool(option) res = self.getboolean(option)
else: else:
res = self.getstr(option) res = self.getstr(option)
except NoOptionError: except NoOptionError:
@ -75,7 +75,7 @@ class Config(RawConfigParser):
RawConfigParser.write(self, f) RawConfigParser.write(self, f)
f.close() f.close()
def setAndSave(self, option, value): def set_and_save(self, option, value):
self.set(option, value) self.set(option, value)
self.save() self.save()

View file

@ -23,7 +23,6 @@ import xmpp
from config import config from config import config
from logging import logger from logging import logger
from threading import Thread from threading import Thread
from multiuserchat import MultiUserChat
from handler import Handler from handler import Handler
class Connection(Thread): class Connection(Thread):
@ -100,7 +99,8 @@ class Connection(Thread):
def process(self, timeout=10): def process(self, timeout=10):
if self.online: if self.online:
try:self.client.Process(timeout) try:
self.client.Process(timeout)
except: except:
pass # FIXME pass # FIXME
else: else:

View file

@ -29,7 +29,6 @@ locale.setlocale(locale.LC_ALL, '')
import sys import sys
import curses import curses
from curses import textpad
from datetime import datetime from datetime import datetime
from handler import Handler from handler import Handler
@ -48,8 +47,8 @@ class User(object):
self.color = randrange(2, 10) self.color = randrange(2, 10)
def update(self, affiliation, show, status, role): def update(self, affiliation, show, status, role):
self.affiliation = None self.affiliation = affiliation
self.show = None self.show = show
self.status = status self.status = status
self.role = role self.role = role
@ -75,14 +74,15 @@ class Room(object):
if not msg: if not msg:
logger.info('msg is None..., %s' % (nick)) logger.info('msg is None..., %s' % (nick))
return 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): def add_info(self, info):
""" info, like join/quit/status messages""" """ info, like join/quit/status messages"""
try: try:
self.lines.append((datetime.now(), info.encode('utf-8'))) self.lines.append((datetime.now(), info.encode('utf-8')))
return 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)) self.lines.append((datetime.now(), info))
return info return info
@ -293,7 +293,7 @@ class Gui(object):
nick_from = '' nick_from = ''
room = self.get_room_by_name(room_from) room = self.get_room_by_name(room_from)
if not room: 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 return
body = stanza.getBody() body = stanza.getBody()
if not body: if not body:
@ -320,7 +320,7 @@ class Gui(object):
from_room = stanza.getFrom().getStripped() from_room = stanza.getFrom().getStripped()
room = self.get_room_by_name(from_room) room = self.get_room_by_name(from_room)
if not 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': if stanza.getType() == 'error':
msg = _("Error: %s") % stanza.getError() msg = _("Error: %s") % stanza.getError()
else: else:
@ -446,7 +446,7 @@ class Gui(object):
res = roomname+'/'+nick res = roomname+'/'+nick
else: else:
res = roomname res = roomname
config.setAndSave('rooms', bookmarked+':'+res) config.set_and_save('rooms', bookmarked+':'+res)
def command_set(self, args): def command_set(self, args):
if len(args) != 2: if len(args) != 2:
@ -454,7 +454,7 @@ class Gui(object):
return return
option = args[0] option = args[0]
value = args[1] value = args[1]
config.setAndSave(option, value) config.set_and_save(option, value)
msg = "%s=%s" % (option, value) msg = "%s=%s" % (option, value)
room = self.current_room() room = self.current_room()
room.add_info(msg) room.add_info(msg)

View file

@ -50,7 +50,7 @@ class MultiUserChat(object):
def on_connected(self, jid): def on_connected(self, jid):
self.own_jid = jid self.own_jid = jid
rooms = config.get('rooms', '') rooms = config.get('rooms', '')
if rooms == '': if rooms == '' or type(rooms) != str:
return return
else: else:
rooms = rooms.split(':') rooms = rooms.split(':')

View file

@ -18,7 +18,6 @@
# along with Poezio. If not, see <http://www.gnu.org/licenses/>. # along with Poezio. If not, see <http://www.gnu.org/licenses/>.
import curses import curses
from logging import logger
class Win(object): class Win(object):
def __init__(self, height, width, y, x, parent_win): def __init__(self, height, width, y, x, parent_win):