fix some little issues. Rename gui to core, use logging lib instead of the...

fix some little issues. Rename gui to core, use logging lib instead of the custom debug option. Add a -d option
parent df6d2fc2
#!/usr/bin/env sh
cd src/ && python3 poezio.py "$@"
python3 src/poezio.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
......
......@@ -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)
......@@ -58,3 +58,6 @@ class Connection(sleekxmpp.ClientXMPP):
else:
self.connect()
self.process(threaded=True)
# Global connection object
connection = Connection()
......@@ -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)
......@@ -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=''):
"""
......
......@@ -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
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment