-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
131 lines (108 loc) · 4.05 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""Main startup for Qt4 and client initialization.
"""
import socket
import sys
import os.path
import os
import sys
import tracemalloc
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4 import QtWebKit
from pkg.qproxy import QProxy
from pkg.qsubwindow import QSubWindow
from pkg.client import Client
from pkg.client import ConnectionDead
from pkg.game import Game
from pkg.game import Priority
from pkg.qconsolewindow import QConsoleWindow
from pkg.providerstandardevent import ProviderStandardEvent
from plug.qpluglogin import QPlugLogin
from plug.qplugunknown import QPlugUnknown
from plug.qplugcharacter import QPlugCharacter
from plug.qchannelmanager import QChannelManager
from plug.qplugspellman import QPlugSpellMan
from plug.qplugmodhealth import QPlugMobHealth
from plug.qplugmapper import QPlugMapper
from plug.qplugmoblore import QPlugMobLore
class QMainWindow(QtGui.QWidget):
def __init__(self):
"""Initialization
"""
super().__init__()
# load the style sheet
if sys.platform.find('win') == 0:
fd = open('./styles/win_default.css', 'r')
css = fd.read()
fd.close()
else:
fd = open('./styles/default.css', 'r')
css = fd.read()
fd.close()
self.setStyleSheet(css)
self.setObjectName('MainWindow')
path = os.path.expanduser('~') + '/pybatmud'
if not os.path.exists(path):
os.makedirs(path)
self.resize(850, 700)
self.show()
# initialize the game, providers, and plugs - also order of
# creation effects what windows are stacked on top or bottom
self.g = Game()
self.stdep = ProviderStandardEvent(self.g)
#self.unknown = QPlugUnknown(self, self.g)
self.character = QPlugCharacter(self, self.g)
self.chanman = QChannelManager(self, self.g)
self.login = QPlugLogin(self, self.g)
self.spellman = QPlugSpellMan(self, self.g)
self.mobhealth = QPlugMobHealth(self, self.g)
self.mapper = QPlugMapper(self, self.g)
self.moblore = QPlugMobLore(self, self.g)
self.g.start()
self.ticktimer = QtCore.QTimer(self)
self.ticktimer.timeout.connect(lambda : self.gametick())
self.ticktimer.start(100)
self.setWindowTitle('PyBatMud (Python Client For BatMud Using Qt) [kmcg3413@gmail.com]')
def getwin(self, titlepad = 10):
tframe = QSubWindow(self)
tframe.setObjectName('TFrame')
return tframe
def gametick(self):
"""Allows the game instance to handle any tasks needed to be done.
"""
self.g.tick(block = 0)
class QLocalApplication(QtGui.QApplication):
def __init__(self, argv):
super().__init__(argv)
self.notifysuper = True
def notify(self, receiver, event):
if event.type() == QtCore.QEvent.KeyPress and event.key() == QtCore.Qt.Key_Tab:
if isinstance(receiver, QConsoleWindow):
receiver.keyPressEvent(event) # hand directly the QConsoleWindow
if isinstance(receiver.parent(), QConsoleWindow):
receiver.parent().keyPressEvent(event) # hand to parent which is QConsoleWindow
return True
if self.notifysuper:
return super().notify(receiver, event)
return None
def main(standalone = False):
tracemalloc.start()
if standalone:
app = QLocalApplication(sys.argv)
# Cleanlooks
# Plastique
# Motfif
# CDE
style = QtGui.QStyleFactory.create('Plastique')
#app.setStyle(style)
#app.setGraphicsSystem('raster')
w = QMainWindow()
if standalone:
sys.exit(app.exec_())
'''
What happens is if we are started directly just run as normal, but
if the updater starts us then do nothing yet and let the updater
tell us when to run. --kmcg
'''
if __name__ == '__main__':
main(True)