-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadedFunctions.py
65 lines (49 loc) · 2.1 KB
/
LoadedFunctions.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
from extensions import *
from sympy import *
import sympy
from inspect import signature # for showing function parameters for LoadedFunctions
from PyQt5 import QtWidgets, uic
from os import getcwd, listdir
# class wrapper for loaded_functions.ui
# shows all currently loaded extensions and parameters if available
class LoadedFunctions(QtWidgets.QDialog):
def __init__(self, caller):
super().__init__() # call parent constructor
self.caller = caller # main window object
uic.loadUi('assets/loaded_functions.ui', self) # load .ui file, and convert
# excluded objects from being displayed
self.exclude = ['__builtins__', '__cached__', '__doc__',
'__file__', '__loader__', '__name__', '__package__',
'__spec__', 'gmpy2', 'mpfr', 'mpnum', 'mpq', 'mpratio',
'__path__'
]
# iterate through available extensions and call add_group on them
for item in listdir(getcwd()+'/extensions'):
if item.endswith('.py') and item != '__init__.py':
self.add_group(item, eval(item[:-3]), excludes=dir(sympy))
self.add_group('Advanced Math', sympy)
self.listWidget.itemClicked.connect(lambda item: self.load_clicked_function(item))
self.show()
# add an extension and it's functions to self.listWidget using add_item
def add_group(self, groupname, module, excludes=[]):
self.add_item(' ------ ' + groupname + ' ------')
for i in dir(module):
if i not in self.exclude and i not in excludes:
try:
i += str(signature(eval(i)))
except Exception:
pass
self.add_item(i)
# used for list item click event
# takes an item and adds it to calculator's current equation in main window
def load_clicked_function(self, item):
try:
if self.caller.current_equ.text() == '' or not self.caller.current_equ.text().endswith(' '):
self.caller.current_equ.setText(self.caller.current_equ.text()+' '+item.text())
else:
self.caller.current_equ.setText(self.caller.current_equ.text()+item.text())
except AttributeError as e:
print(' -- debug -- -> ' + str(e))
# add an item to self.listWidget
def add_item(self, name: str):
self.listWidget.addItem(QtWidgets.QListWidgetItem(name))