summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.py10
-rw-r--r--src/config.py11
-rw-r--r--src/connection.py3
-rw-r--r--src/core.py (renamed from src/gui.py)21
-rw-r--r--src/multiuserchat.py7
-rw-r--r--src/poezio.py54
-rw-r--r--src/tab.py97
7 files changed, 101 insertions, 102 deletions
diff --git a/src/common.py b/src/common.py
index 53318e19..384fd28f 100644
--- a/src/common.py
+++ b/src/common.py
@@ -51,16 +51,6 @@ ROOM_STATE_PRIVATE = 15
ROOM_STATE_MESSAGE = 12
ROOM_STATE_HL = 13
-def debug(string):
- """
- Print a string in a file.
- Useful since debuging cannot be displayed on screen because it's
- a CLI software
- """
- fdes = open("/tmp/debug", 'a')
- fdes.write(string)
- fdes.close()
-
def get_base64_from_file(path):
"""
Convert the content of a file to base64
diff --git a/src/config.py b/src/config.py
index 287c47ec..a3f03849 100644
--- a/src/config.py
+++ b/src/config.py
@@ -137,13 +137,8 @@ if not path.isfile(CONFIG_PATH+'poezio.cfg'):
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename", default=CONFIG_PATH+'poezio.cfg',
- help="the config file you want to use", metavar="CONFIG_FILE")
+ help="The config file you want to use", metavar="CONFIG_FILE")
+parser.add_option("-d", "--debug", dest="debug",
+ help="The file where debug will be written", metavar="DEBUG_FILE")
(options, args) = parser.parse_args()
config = Config(options.filename)
-
-if __name__ == '__main__':
- # tests
- import sys
- (dummy, filename, section, option, value) = sys.argv
- conf = Config(sys.argv[1])
- conf.write_in_file(section, option, value)
diff --git a/src/connection.py b/src/connection.py
index 2e74e4e1..2f016901 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -58,3 +58,6 @@ class Connection(sleekxmpp.ClientXMPP):
else:
self.connect()
self.process(threaded=True)
+
+# Global connection object
+connection = Connection()
diff --git a/src/gui.py b/src/core.py
index 01fa38c8..23bc3ed4 100644
--- a/src/gui.py
+++ b/src/core.py
@@ -34,6 +34,7 @@ import common
import theme
import multiuserchat as muc
+from connection import connection
from handler import Handler
from config import config
from tab import MucTab, InfoTab, PrivateTab, RosterInfoTab, ConversationTab
@@ -68,7 +69,7 @@ SHOW_NAME = {
resize_lock = threading.Lock()
-class Gui(object):
+class Core(object):
"""
User interface using ncurses
"""
@@ -77,8 +78,8 @@ class Gui(object):
self.stdscr = curses.initscr()
self.init_curses(self.stdscr)
self.xmpp = xmpp
- default_tab = InfoTab(self.stdscr, "Info") if self.xmpp.anon\
- else RosterInfoTab(self.stdscr)
+ default_tab = InfoTab(self.stdscr, self, "Info") if self.xmpp.anon\
+ else RosterInfoTab(self.stdscr, self)
default_tab.on_gain_focus()
self.tabs = [default_tab]
# self.roster = Roster()
@@ -159,7 +160,7 @@ class Gui(object):
return
self.information_win_size += 1
for tab in self.tabs:
- tab.on_info_win_size_changed(self.information_win_size, self.stdscr)
+ tab.on_info_win_size_changed(self.stdscr)
self.refresh_window()
def shrink_information_win(self):
@@ -169,7 +170,7 @@ class Gui(object):
return
self.information_win_size -= 1
for tab in self.tabs:
- tab.on_info_win_size_changed(self.information_win_size, self.stdscr)
+ tab.on_info_win_size_changed(self.stdscr)
self.refresh_window()
def on_got_offline(self, presence):
@@ -639,7 +640,7 @@ class Gui(object):
Open a new MucTab containing a muc Room, using the specified nick
"""
r = Room(room, nick)
- new_tab = MucTab(self.stdscr, r, self.information_win_size)
+ new_tab = MucTab(self.stdscr, self, r)
if self.current_tab().nb == 0:
self.tabs.append(new_tab)
else:
@@ -738,7 +739,7 @@ class Gui(object):
open a new conversation tab and focus it if needed
"""
r = Room(room_name, self.xmpp.boundjid.full)
- new_tab = ConversationTab(self.stdscr, r, self.information_win_size)
+ new_tab = ConversationTab(self.stdscr, self, r)
# insert it in the rooms
if self.current_tab().nb == 0:
self.tabs.append(new_tab)
@@ -766,7 +767,7 @@ class Gui(object):
return None
own_nick = room.own_nick
r = Room(complete_jid, own_nick) # PrivateRoom here
- new_tab = PrivateTab(self.stdscr, r, self.information_win_size)
+ new_tab = PrivateTab(self.stdscr, self, r)
# insert it in the tabs
if self.current_tab().nb == 0:
self.tabs.append(new_tab)
@@ -1391,3 +1392,7 @@ class Gui(object):
def doupdate(self):
self.current_tab().just_before_refresh()
curses.doupdate()
+
+# # global core object
+core = Core(connection)
+
diff --git a/src/multiuserchat.py b/src/multiuserchat.py
index 311bce87..3927fc38 100644
--- a/src/multiuserchat.py
+++ b/src/multiuserchat.py
@@ -45,8 +45,7 @@ def change_show(xmpp, jid, own_nick, show, status):
"""
Change our 'Show'
"""
- pres = xmpp.makePresence(pto='%s/%s' % (jid, own_nick),
- pfrom=xmpp.boundjid.full)
+ pres = xmpp.makePresence(pto='%s/%s' % (jid, own_nick))
if show: # if show is None, don't put a <show /> tag. It means "online"
pres['type'] = show
if status:
@@ -60,15 +59,13 @@ def change_subject(xmpp, jid, subject):
msg = xmpp.makeMessage(jid)
msg['type'] = 'groupchat'
msg['subject'] = subject
- msg['from'] = xmpp.boundjid.bare
msg.send()
def change_nick(xmpp, jid, nick):
"""
Change our own nick in a room
"""
- xmpp.makePresence(pto='%s/%s' % (jid, nick),
- pfrom=xmpp.boundjid.bare).send()
+ xmpp.makePresence(pto='%s/%s' % (jid, nick)).send()
def join_groupchat(xmpp, jid, nick, passwd=''):
"""
diff --git a/src/poezio.py b/src/poezio.py
index a46381f9..03b6d3e6 100644
--- a/src/poezio.py
+++ b/src/poezio.py
@@ -21,14 +21,32 @@ Starting point of poezio. Launches both the Connection and Gui
"""
import os
-# chdir in the source directory, to import the modules
-# also, no need to use a sh script to "cd" in this directoy
-# before launching poezio.
-os.chdir(os.path.dirname(os.path.abspath(__file__)))
-
import curses
import sys
import traceback
+import threading
+
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
+
+def installThreadExcepthook():
+ """
+ Workaround for sys.excepthook thread bug
+ See http://bugs.python.org/issue1230540
+ Python, you made me sad :(
+ """
+ init_old = threading.Thread.__init__
+ def init(self, *args, **kwargs):
+ init_old(self, *args, **kwargs)
+ run_old = self.run
+ def run_with_except_hook(*args, **kw):
+ try:
+ run_old(*args, **kw)
+ except (KeyboardInterrupt, SystemExit):
+ raise
+ except:
+ sys.excepthook(*sys.exc_info())
+ self.run = run_with_except_hook
+ threading.Thread.__init__ = init
class MyStdErr(object):
def __init__(self, fd):
@@ -67,23 +85,15 @@ def exception_handler(type_, value, trace):
# sys.excepthook = exception_handler
import signal
+import logging
-from connection import Connection
-from config import config
-from gui import Gui
-
-signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
-
-def main():
- """
- The main function consist of the Connection initialization
- then the gui (ncurses) init, connection handlers and then the
- connection is "started"
- """
- xmpp = Connection() # Connection init
- gui = Gui(xmpp) # Gui init.
- xmpp.start() # Connect to remote server
- gui.main_loop() # Refresh the screen, wait for user events etc
+from connection import connection
+from config import config, options
+from core import core
if __name__ == '__main__':
- main()
+ signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
+ if options.debug:
+ logging.basicConfig(filename=options.debug,level=logging.DEBUG)
+ connection.start() # Connect to remote server
+ core.main_loop() # Refresh the screen, wait for user events etc
diff --git a/src/tab.py b/src/tab.py
index e6a8cc41..767ee353 100644
--- a/src/tab.py
+++ b/src/tab.py
@@ -33,11 +33,11 @@ from roster import RosterGroup, roster
from contact import Contact, Resource
class Tab(object):
- """
- """
number = 0
- def __init__(self, stdscr):
+ def __init__(self, stdscr, core):
+ self.core = core # a pointer to core, to access its attributes (ugly?)
+ self.tab_type = "Tab"
self.nb = Tab.number
Tab.number += 1
self.size = (self.height, self.width) = stdscr.getmaxyx()
@@ -132,8 +132,9 @@ class InfoTab(Tab):
The information tab, used to display global informations
when using a anonymous account
"""
- def __init__(self, stdscr, name):
- Tab.__init__(self, stdscr)
+ def __init__(self, stdscr, core, name):
+ Tab.__init__(self, stdscr, core)
+ self.tab_type = "InfoTab"
self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible)
self.text_win = window.TextWin(self.height-2, self.width, 0, 0, stdscr, self.visible)
self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible)
@@ -187,21 +188,21 @@ class MucTab(Tab):
The tab containing a multi-user-chat room.
It contains an userlist, an input, a topic, an information and a chat zone
"""
- def __init__(self, stdscr, room, info_win_size):
+ def __init__(self, stdscr, core, room):
"""
room is a Room object
The stdscr is passed to know the size of the
terminal
"""
- Tab.__init__(self, stdscr)
+ Tab.__init__(self, stdscr, core)
+ self.tab_type = "MucTab"
self._room = room
- self.info_win_size = info_win_size
self.topic_win = window.Topic(1, self.width, 0, 0, stdscr, self.visible)
- self.text_win = window.TextWin(self.height-4-info_win_size, (self.width//10)*9, 1, 0, stdscr, self.visible)
+ self.text_win = window.TextWin(self.height-4-self.core.information_win_size, (self.width//10)*9, 1, 0, stdscr, self.visible)
self.v_separator = window.VerticalSeparator(self.height-3, 1, 1, 9*(self.width//10), stdscr, self.visible)
self.user_win = window.UserList(self.height-3, (self.width//10), 1, 9*(self.width//10)+1, stdscr, self.visible)
- self.info_header = window.MucInfoWin(1, (self.width//10)*9, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win = window.TextWin(info_win_size, (self.width//10)*9, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ self.info_header = window.MucInfoWin(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win = window.TextWin(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible)
self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible)
@@ -212,11 +213,11 @@ class MucTab(Tab):
Tab.resize(self, stdscr)
text_width = (self.width//10)*9
self.topic_win.resize(1, self.width, 0, 0, stdscr, self.visible)
- self.text_win.resize(self.height-4-self.info_win_size, text_width, 1, 0, stdscr, self.visible)
+ self.text_win.resize(self.height-4-self.core.information_win_size, text_width, 1, 0, stdscr, self.visible)
self.v_separator.resize(self.height-3, 1, 1, 9*(self.width//10), stdscr, self.visible)
self.user_win.resize(self.height-3, self.width-text_width-1, 1, text_width+1, stdscr, self.visible)
- self.info_header.resize(1, (self.width//10)*9, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win.resize(self.info_win_size, (self.width//10)*9, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ self.info_header.resize(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win.resize(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
self.tab_win.resize(1, self.width, self.height-2, 0, stdscr, self.visible)
self.input.resize(1, self.width, self.height-1, 0, stdscr, self.visible)
@@ -297,12 +298,11 @@ class MucTab(Tab):
def on_scroll_down(self):
self._room.scroll_down(self.text_win.height-1)
- def on_info_win_size_changed(self, size, stdscr):
- self.info_win_size = size
+ def on_info_win_size_changed(self, stdscr):
text_width = (self.width//10)*9
- self.text_win.resize(self.height-4-self.info_win_size, text_width, 1, 0, stdscr, self.visible)
- self.info_header.resize(1, (self.width//10)*9, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win.resize(self.info_win_size, (self.width//10)*9, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ self.text_win.resize(self.height-4-self.core.information_win_size, text_width, 1, 0, stdscr, self.visible)
+ self.info_header.resize(1, (self.width//10)*9, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win.resize(self.core.information_win_size, (self.width//10)*9, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
def just_before_refresh(self):
self.input.move_cursor_to_pos()
@@ -311,21 +311,21 @@ class PrivateTab(Tab):
"""
The tab containg a private conversation (someone from a MUC)
"""
- def __init__(self, stdscr, room, info_win_size):
- Tab.__init__(self, stdscr)
- self.info_win_size = info_win_size
+ def __init__(self, stdscr, core, room):
+ Tab.__init__(self, stdscr, core)
+ self.tab_type = "PrivateTab"
self._room = room
- self.text_win = window.TextWin(self.height-3-self.info_win_size, self.width, 0, 0, stdscr, self.visible)
- self.info_header = window.PrivateInfoWin(1, self.width, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win = window.TextWin(self.info_win_size, self.width, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ self.text_win = window.TextWin(self.height-3-self.core.information_win_size, self.width, 0, 0, stdscr, self.visible)
+ self.info_header = window.PrivateInfoWin(1, self.width, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win = window.TextWin(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible)
self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible)
def resize(self, stdscr):
Tab.resize(self, stdscr)
- self.text_win.resize(self.height-3-self.info_win_size, self.width, 0, 0, stdscr, self.visible)
- self.info_header.resize(1, self.width, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win.resize(self.info_win_size, self.width, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, stdscr, self.visible)
+ self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
self.tab_win.resize(1, self.width, self.height-2, 0, stdscr, self.visible)
self.input.resize(1, self.width, self.height-1, 0, stdscr, self.visible)
@@ -369,11 +369,10 @@ class PrivateTab(Tab):
def on_scroll_down(self):
self._room.scroll_down(self.text_win.height-1)
- def on_info_win_size_changed(self, size, stdscr):
- self.info_win_size = size
- self.text_win.resize(self.height-3-self.info_win_size, self.width, 0, 0, stdscr, self.visible)
- self.info_header.resize(1, self.width, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win.resize(self.info_win_size, self.width, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ def on_info_win_size_changed(self, stdscr):
+ self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, stdscr, self.visible)
+ self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
def get_room(self):
return self._room
@@ -385,7 +384,7 @@ class RosterInfoTab(Tab):
"""
A tab, splitted in two, containing the roster and infos
"""
- def __init__(self, stdscr):
+ def __init__(self, stdscr, core):
self.single_key_commands = {
"^J": self.on_enter,
"^M": self.on_enter,
@@ -397,7 +396,8 @@ class RosterInfoTab(Tab):
"o": self.toggle_offline_show,
"^F": self.start_search,
}
- Tab.__init__(self, stdscr)
+ Tab.__init__(self, stdscr, core)
+ self.tab_type = "RosterInfoTab"
self.name = "Roster"
roster_width = self.width//2
info_width = self.width-roster_width-1
@@ -534,21 +534,21 @@ class ConversationTab(Tab):
"""
The tab containg a normal conversation (someone from our roster)
"""
- def __init__(self, stdscr, room, info_win_size):
- Tab.__init__(self, stdscr)
- self.info_win_size = info_win_size
+ def __init__(self, stdscr, core, room):
+ Tab.__init__(self, stdscr, core)
+ self.tab_type = "ConversationTab"
self._room = room
- self.text_win = window.TextWin(self.height-3-self.info_win_size, self.width, 0, 0, stdscr, self.visible)
- self.info_header = window.ConversationInfoWin(1, self.width, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win = window.TextWin(self.info_win_size, self.width, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ self.text_win = window.TextWin(self.height-3-self.core.information_win_size, self.width, 0, 0, stdscr, self.visible)
+ self.info_header = window.ConversationInfoWin(1, self.width, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win = window.TextWin(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible)
self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible)
def resize(self, stdscr):
Tab.resize(self, stdscr)
- self.text_win.resize(self.height-3-self.info_win_size, self.width, 0, 0, stdscr, self.visible)
- self.info_header.resize(1, self.width, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win.resize(self.info_win_size, self.width, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, stdscr, self.visible)
+ self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
self.tab_win.resize(1, self.width, self.height-2, 0, stdscr, self.visible)
self.input.resize(1, self.width, self.height-1, 0, stdscr, self.visible)
@@ -589,11 +589,10 @@ class ConversationTab(Tab):
def on_scroll_down(self):
self._room.scroll_down(self.text_win.height-1)
- def on_info_win_size_changed(self, size, stdscr):
- self.info_win_size = size
- self.text_win.resize(self.height-3-self.info_win_size, self.width, 0, 0, stdscr, self.visible)
- self.info_header.resize(1, self.width, self.height-3-self.info_win_size, 0, stdscr, self.visible)
- self.info_win.resize(self.info_win_size, self.width, self.height-2-self.info_win_size, 0, stdscr, self.visible)
+ def on_info_win_size_changed(self, stdscr):
+ self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0, stdscr, self.visible)
+ self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0, stdscr, self.visible)
+ self.info_win.resize(self.core.information_win_size, self.width, self.height-2-self.core.information_win_size, 0, stdscr, self.visible)
def get_room(self):
return self._room