-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.py
More file actions
111 lines (85 loc) · 3.66 KB
/
console.py
File metadata and controls
111 lines (85 loc) · 3.66 KB
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
from PySide.QtCore import *
from PySide.QtGui import *
import webbrowser
class Console(QDialog):
def __init__(self, parent):
super(Console, self).__init__(parent)
self.parent = parent
self.setWindowTitle("Developer Console")
self.desc = 'Developer console for The Mapper version r %s. Current commands are: print <variable>, help, restart, exit, func <function>, wiki, py <python function>.\n' %(self.parent.VERSION)
self.prev_text = QTextEdit("<Bald Engineers Developer Console>")
self.prev_text.setText(self.desc)
self.prev_text.setReadOnly(True)
self.curr_text = QLineEdit()
self.curr_text_btn = QPushButton("Enter")
self.curr_text_btn.clicked.connect(self.console_enter)
self.curr_text_layout = QHBoxLayout()
self.curr_text_layout.addWidget(self.curr_text)
self.curr_text_layout.addWidget(self.curr_text_btn)
self.console_form = QFormLayout()
self.console_form.addRow(self.prev_text)
self.console_form.addRow(self.curr_text_layout)
self.setLayout(self.console_form)
self.show()
def console_enter(self):
command = ""
char_num = 0
text = self.curr_text.displayText()
text_prefix = text + " --> "
command = text.split()[0]
try:
value = text.split()[1]
except IndexError:
value = ""
if command == "print":
try:
new_text = text_prefix + str(eval(value))
except Exception as e:
new_text = text_prefix + str(e)
elif command == "help":
new_text = text_prefix + self.desc
elif command == "exit":
self.parent.close_application()
elif command == "restart":
self.parent.close_application(True)
elif command == "pootis":
new_text = '<img src="icons/thedoobs.jpg">'
elif command == "sterries" or command == "jerries":
new_text = text_prefix + "Gimme all those berries, berries, berries!"
elif command == "sideshow":
new_text = ''
self.sideshow()
elif command == "func":
try:
eval("self.parent."+value + "()")
new_text = text_prefix + "Function "+value+" has been run."
except Exception as e:
new_text = text_prefix + str(e)
elif command == "wiki":
try:
webbrowser.open("http://github.com/baldengineers/easytf2_mapper/wiki")
new_text = text_prefix + "Wiki has been opened in your default browser"
except Exception as e:
print(str(e))
elif command == "py":
try:
new_text = text_prefix + str(eval(value))
except Exception as e:
new_text = text_prefix + str(e)
else:
new_text = text_prefix + "\"" + command + "\" is not a valid command"
self.prev_text.append(new_text)
self.curr_text.setText("")
def sideshow(self):
self.gif("icons/sideshow.gif", (350,262,154,103), "SIDESHOW", "icons/ss.ico")
def heavy(self):
self.gif("icons/heavy.gif", (350,262,150,99), "DANCE HEAVY DANCE!")
def gif(self, file, geo, title, icon="icons\icon.ico"):
self.gif = QLabel()
movie = QMovie(file)
self.gif.setMovie(movie)
self.gif.setGeometry(geo[0],geo[1],geo[2],geo[3])
self.gif.setWindowTitle(title)
self.gif.setWindowIcon(QIcon(icon))
self.gif.show()
movie.start()