-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
96 lines (79 loc) · 2.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
import sys, threading, signal, re, time, getpass
from hashlib import md5
from PySide.QtGui import QApplication
from PySide.QtCore import QTimer
try:
from lib.honcore.client import HoNClient
from lib.honcore.exceptions import *
except ImportError:
print "HoNCore could not be found in the lib folder, please ensure it is available."
from core import log, events, ConnectionManager
from core.gui import HCPLoginWindow, HCPCoreWindow
class HCPHoNClient(HoNClient):
def __init__(self):
super(HCPHoNClient, self).__init__()
self.logged_in = False
@property
def is_logged_in(self):
return self.logged_in
def login(self, username, password):
log.info("Logging in..")
if len(password) != 32:
password = md5(password).hexdigest()
try:
self._login(username, password)
except MasterServerError, e:
log.error(e)
return False
self.logged_in = True
return True
def connect(self):
log.info("Connecting..")
try:
self._chat_connect()
except ChatServerError, e:
log.error(e)
return False
return True
def logout(self):
log.info("Logging out...")
try:
self._logout()
except MasterServerError, e:
log.error(e)
return False
self.logged_in = False
return True
def disconnect(self):
log.info("Disconnecting...")
try:
self._chat_disconnect()
except ChatServerError, e:
log.error(e)
return False
return True
def main():
client = HCPHoNClient()
# Temporary client config
# Move to self implementation using QSettings later.
client._configure(protocol=19)
app = QApplication(sys.argv)
app.setApplicationName("HoNChatPy")
#app.setQuitOnLastWindowClosed(True) # May need to change for system tray behaviour
login_window = HCPLoginWindow(client)
login_window.setObjectName('login_window')
core_window = HCPCoreWindow(client)
core_window.setObjectName('hcp_window')
while True:
while not client.is_logged_in:
login_window.show()
app.exec_()
while client.is_logged_in:
core_window.show()
client.connect()
app.exec_()
if __name__ == "__main__":
log.add_logger(sys.stdout, 'DEBUG', False)
log.add_logger('honchat_log', 'DEBUG', True)
main()