-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_func.py
More file actions
executable file
·76 lines (65 loc) · 2.35 KB
/
create_func.py
File metadata and controls
executable file
·76 lines (65 loc) · 2.35 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
# File name: create_func_const.py
"""
This module contains classes responsible for creating functions and constants
on the GUI or Text application.
"""
__author__ = 'Molinge'
class CreateFunc:
"""
This class provides methods for collecting data about a function and settings it's attributes.
It then provides a method that takes this data and create a function as a string
"""
def __init__(self):
self._name = None
self._type = 'Constant'
self._args = 0
self._section = 'Vertical'
self._function = None
def set_name(self, name):
if (not name.isalnum()) or (name[0].isnumeric()):
print("Invalid function name.")
return
self._name = name
def set_type(self, type):
if type not in ['Constant', 'Function']:
print("Invalid type. It can either be a Constant or Function")
return
self._type = type
def set_args(self, args):
if (not isinstance(args, int)) or (args < 0):
print("Argument is either not an integer or less than 0.")
print("Only integers >= 0 are accepted")
return
self._args = args
def set_section(self, section):
if section in ['Vertical', 'Horizontal']:
self._section = section
else:
print("Enter a valid section. either 'Vertical' or 'Horizontal'")
return
def create_function(self):
if self._name is None:
print("Function has no name or an invalid name")
return
if self._type == 'Constant':
if self._args == 0:
self._function = self._name
else:
print("Cannot create a constant with arguments")
return
else:
if self._args >= 0:
if self._section == 'Vertical':
variable = 'x'
else:
variable = 'y'
self._function = self._name + '('
for num in range(self._args):
self._function += variable + str(num+1)
if num < (self._args - 1):
self._function += ','
self._function += ')'
else:
print("A function should have an argument")
def get_function(self):
return self._function