-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathpyquirks.py
35 lines (30 loc) · 1.17 KB
/
pyquirks.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
import os, sys, imp, re, ostools
from quirks import ScriptQuirks
from PyQt5 import QtGui, QtCore, QtWidgets
class PythonQuirks(ScriptQuirks):
def loadModule(self, name, filename):
return imp.load_source(name, filename)
def getExtension(self):
return '.py'
def modHas(self, module, attr):
if attr == 'commands':
variables = vars(module)
for name, obj in variables.items():
if self.modHas(obj, 'command'):
return True
return hasattr(module, attr)
def register(self, module):
variables = vars(module)
for name, obj in variables.items():
if self.modHas(obj, 'command'):
try:
if not isinstance(obj("test"), str):
raise Exception
except:
print("Quirk malformed: %s" % (obj.command))
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Error!")
msgbox.setText("Quirk malformed: %s" % (obj.command))
msgbox.exec_()
else:
self.quirks[obj.command] = obj