-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.py
48 lines (39 loc) · 1.39 KB
/
common.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
'''
This file contains common constants and methods used by all modules
'''
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
# Global flag for debug mode
DEBUG_MODE = False
# Global fixed height of form rows within scroll view
form_row_height = '30dp'
# Checks if a form input is a valid number
def is_valid_value(value):
if isinstance(value, int):
return True
elif isinstance(value, str) or isinstance(value, unicode):
return value != '' and value.isdigit()
else:
return False
# For labels with colored border
class WhiteBorderedLabel(Label):
pass
class ColoredBorderedLabel(Label):
pass
class ColoredButton(Button):
pass
# Global function for bad input handling
def display_error(grid, error, box_height='400dp'):
error_box = BoxLayout(orientation='horizontal', size_hint_y=None, height=box_height)
error_label = Label(text="Bad Input:\n" + error, size_hint_x=None, width=Window.width, valign='top', halign='center')
# error_label.text_size = error_label.size
error_box.add_widget(error_label)
grid.add_widget(error_box)
return error_box
# Exception class which stores error status
class OSAVAException(BaseException):
def __init__(self, error_status):
super(OSAVAException, self).__init__()
self.error_status = error_status