-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhouston_utils.py
51 lines (39 loc) · 1.36 KB
/
houston_utils.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
#houston_utils.py
# contains some extraneous things that we don't want cluttering up our main files
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
class LoadDialog(FloatLayout):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
class SaveDialog(FloatLayout):
save = ObjectProperty(None)
text_input = ObjectProperty(None)
cancel = ObjectProperty(None)
def val_match_dict_in_list(in_list, key, value):
""" returns the index of a dict in a list of dicts where
the value of a particular entry matches"""
for i, dic in enumerate(in_list):
if dic[key] == value:
break
else:
i = -1
return i
def index_from_val(in_list, attribute, value):
""" Given a list of objects, returns first one with a specific value for an attribute"""
for i, obj in enumerate(in_list):
if getattr(obj, attribute) == value:
break
else:
i = -1
return i
def index_of_cmdid(in_list, cmdid_in):
""" Return list index of command with specific id"""
return index_from_val(in_list, 'cmdid', cmdid_in)
def string_find(in_string, pattern, beg=0):
if in_string.find(pattern, beg) != -1:
return True
else:
return False