-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
323 lines (263 loc) · 12.2 KB
/
__main__.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import kivy
kivy.require('1.1.3')
from kivy.app import App
from kivy.lang import Builder
from stations import master_data
from kivy.uix.scrollview import ScrollView
from kivy.uix.accordion import Accordion, AccordionItem
from kivy.properties import NumericProperty
from kivy.properties import OptionProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.widget import Widget
from kivy.uix.scatter import Scatter
from kivy.uix.treeview import TreeView, TreeViewLabel
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.properties import StringProperty, ListProperty, ObjectProperty
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen, WipeTransition
from kivy.lang import Builder
from kivy.uix.modalview import ModalView
import random
from train_ccs import train_ccs
from kivy.uix.textinput import TextInput
from kivy.adapters.listadapter import ListAdapter
from kivy.uix.listview import ListItemButton, ListView
import re
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.graphics import Color, Rectangle
from kivy.graphics import Line
from functools import partial
from kivy.core.window import Window
from kivy.uix.dropdown import DropDown
from kivy.uix.spinner import Spinner
from kivy.base import runTouchApp
class Trainccs(FloatLayout):
def __init__(self):
super(Trainccs, self).__init__(auto_dismiss=False)
self.on_open = self.show_selected_value
def show_selected_value(self, instance):
btnclose = Button(text='Close', size_hint_y=None, height='50sp')
content = BoxLayout(orientation='vertical')
content.add_widget(Label(text='Hello world'))
content.add_widget(btnclose)
popup = Popup(content=content, title='Acerca de',
size_hint=(None, None), size=('300dp', '300dp'))
btnclose.bind(on_release=popup.dismiss)
button = Button(text='Open popup', size_hint=(None, None),
size=('150sp', '70dp'),
on_release=popup.open)
popup.open()
pass
class ComboEdit(TextInput):
'''
This class defines a Editable Combo-Box in the traditional sense
that shows it's options
'''
options = ListProperty(('', ))
list_station=[]
'''
:data:`options` defines the list of options that will be displayed when
touch is released from this widget.ComboEdit
'''
def __init__(self, **kw):
ddn = self.drop_down = DropDown()
ddn.bind(on_select=self.on_select)
super(ComboEdit, self).__init__(**kw)
def on_options(self, instance, value):
ddn = self.drop_down
# clear old options
ddn.clear_widgets()
for option in value:
# create a button for each option
but = Button(text=option,
size_hint_y=None,
height='36sp',
# and make sure the press of the button calls select
# will results in calling `self.on_select`
on_release=lambda btn: ddn.select(btn.text))
ddn.add_widget(but)
def on_select(self, instance, value):
# on selection of Drop down Item... do what you want here
# update text of selection to the edit box
self.text = value
self.list_station.append(value)
class ColorLayout(FloatLayout):
pass
class MultiLineLabel(Button):
def __init__(self, **kwargs):
super(MultiLineLabel, self).__init__( **kwargs)
self.text_size = self.size
self.bind(size= self.on_size)
self.bind(text= self.on_text_changed)
self.size_hint_y = None # Not needed here
def on_size(self, widget, size):
self.text_size = size[0], None
self.texture_update()
if self.size_hint_y == None and self.size_hint_x != None:
self.height = max(self.texture_size[1]+32, self.line_height)
elif self.size_hint_x == None and self.size_hint_y != None:
self.width = self.texture_size[0]
def on_text_changed(self, widget, text):
self.on_size(self, self.size)
class OptionsView(ModalView):
def __init__(self,list_sta_trans):
super(OptionsView, self).__init__(auto_dismiss=False)
self.clear_widgets()
self.list_sta_trans = list_sta_trans
self.on_open = self.show_option_view
def show_list_stations(self, *args, **kwargs):
self.clear_widgets()
color = ColorLayout()
boxl = BoxLayout(orientation= 'vertical',anchor_y= "top",padding=10)
grid = GridLayout(cols=1, size_hint_y=None)
grid.bind(minimum_height=grid.setter('height'))
scroll = ScrollView(size_hint=(None, None))
scroll.size = (Window.width, Window.height)
scroll.center = Window.center
#2 Space added but button go back ocuppies space and first value hidden.
l_space = MultiLineLabel(text='',font_size="16dp", background_color=(255,255,255,255), markup=True)
grid.add_widget(l_space)
l_space = MultiLineLabel(text='',font_size="16dp", background_color=(255,255,255,255), markup=True)
grid.add_widget(l_space)
for j in args[0]:
text_st = '[color=333333]'+' '+ j + '[/color]'+' '
l = MultiLineLabel(text=text_st,font_size="16dp", background_color=(255,255,255,255), markup=True)
grid.add_widget(l)
button_back = Button(text="Go Back", auto_dismiss=False, size_hint=(None, None), pos_hint= {'center_x':.5, 'center_y':.7})
button_back.height="50dp"
button_back.width="100dp"
button_back.bind(on_press = lambda widget: self.show_view_list_path(args[1]))
scroll.add_widget(grid)
boxl.add_widget(scroll)
boxl.add_widget(button_back)
color.add_widget(boxl)
self.add_widget(color)
def show_view_list_path(self, *args, **kwargs):
self.clear_widgets()
color = ColorLayout()
boxl = BoxLayout(orientation= 'vertical',anchor_y= "top")
grid = GridLayout(cols=1, size_hint_y=None)
grid.bind(minimum_height=grid.setter('height'))
scroll = ScrollView(size_hint=(None, None))
scroll.size = (Window.width, Window.height)
scroll.center = Window.center
#2 Space added but button go back ocuppies space and first value hidden.
l_space = MultiLineLabel(text='',font_size="16dp", background_color=(255,255,255,255), markup=True)
grid.add_widget(l_space)
l_space = MultiLineLabel(text='',font_size="16dp", background_color=(255,255,255,255), markup=True)
grid.add_widget(l_space)
for i in args[0]:
text = '[color=333333]'+' '+i['text'] + '[/color]'+' '
#~ l = MultiLineLabel(text=text,font_size="16dp",markup=True)
l = MultiLineLabel(text=text,font_size="16dp", background_color=(255,255,255,255), markup=True)
i['stations'] and l.bind(on_press = partial(self.show_list_stations, i['stations'],args[0]))
grid.add_widget(l)
button_back = Button(text="Go Back", auto_dismiss=False, size_hint=(None, None), pos_hint= {'center_x':.5, 'center_y':.7})
button_back.height="50dp"
button_back.width="100dp"
button_back.bind(on_press = lambda widget: self.show_option_view())
scroll.add_widget(grid)
boxl.add_widget(scroll)
boxl.add_widget(button_back)
color.add_widget(boxl)
self.add_widget(color)
def show_option_view(self):
color = ColorLayout()
boxl = BoxLayout(orientation= 'vertical',anchor_y= "top")
gl1 = GridLayout(cols=3,size_hint_x=None, width="300dp",row_default_height= "60dp",row_force_default=True,pos_hint= {'center_x':.5, 'center_y':.7})
text=''
i=0
for resume in self.list_sta_trans:
i=i+1
text = 'OPCION ' + str(i)
color_text = '[color=000000]' + text + '[/color]'
label_option = Label(text=color_text,size_hint=(None, None),markup=True)
label_option.width="90dp"
gl1.add_widget(label_option)
text = 'Estaciones: '+str(resume['stations'] \
)+'\nTransferencias: '+str (resume['transfers'])
color_text = '[color=000000]' + text + '[/color]'
label_info = Label(text=color_text,halign='left',markup=True)
label_info.width="130dp"
gl1.add_widget(label_info)
button = Button(text='Button \n HOLA', size_hint=(None, None))
button.height="60dp"
button.width="80dp"
button.bind(on_press = partial(self.show_view_list_path, resume['path']))
gl1.add_widget(button)
button_back_1 = Button(text="Go Back", auto_dismiss=False, size_hint=(None, None), pos_hint= {'center_x':.5, 'center_y':.7})
button_back_1.height="50dp"
button_back_1.width="100dp"
button_back_1.bind(on_press=self.dismiss)
boxl.add_widget(gl1)
boxl.add_widget(button_back_1)
color.add_widget(boxl)
self.add_widget(color)
class StandardWidgets(Screen):
rtsstr = StringProperty("".join(("Caricuao,,,Zoologico,,,Caricuao",
",,,Propatria,,,Perez Bonalde,,,Plaza Sucre",
",,,Gato Negro,,,Agua Salud,,,Cano Amarillo",
",,,Capitolio,,,La Hoyada,,,Parque Carabobo",
",,,Bellas Artes,,,Colegio de Ingenieros,,,Plaza Venezuela",
",,,Sabana Grande,,,Chacaito,,,Chacao",
",,,Altamira,,,Miranda,,,Los Dos Caminos",
",,,Los Cortijos,,,La California,,,Palo Verde,,,Petare",
",,,Mamera,,,Antimano,,,Carapita,,,La Yaguara",
",,,La Paz,,,Artigas,,,Maternidad,,,Capuchinos,,,Silencio",
",,,Ruiz Pineda,,,Las Adjuntas",
",,,Teatros,,,Nuevo Circo,,,Parque Central,,,Zona Rental",
",,,Ciudad Universitaria,,,Los Simbolos,,,La Bandera",
",,,El Valle,,,Los Jardines,,,Coche,,,Mercado",
",,,La Rinconada,,,")))
def get_route(self, instance):
class_train_ccs = train_ccs()
list_sta_trans = class_train_ccs.get_options(self.station_a.text,self.station_b.text)
route = OptionsView(list_sta_trans)
route.open()
def on_text(self, instance, value):
if value == '':
instance.options=[]
else:
match = re.findall("(?<=,{3})(?:(?!,{3}).)*?%s.*?(?=,{3})" % value,\
self.rtsstr, re.IGNORECASE)
#using a set to remove duplicates, if any.
instance.options = list(set(match))
if instance.get_parent_window():
instance.drop_down.open(instance)
class MainWindow(Screen):
pass
class TrainccsApp(App):
def __init__(self):
super(TrainccsApp, self).__init__()
def build(self):
sm = ScreenManager(transition=WipeTransition())
sm.add_widget(MainWindow(name='mainwindow'))
sm.add_widget(StandardWidgets(name='inputstation'))
Window.bind(on_keyboard=self.hook_keyboard)
self.content = content = BoxLayout()
sc = Trainccs()
#~ spinner = Spinner(
#~ text='About',
#~ values=('About',),
#~ size_hint=(None, None),
#~ size=(100, 44),
#~
#~ )
#~ pos_hint={'center_x': 0.5, 'center_y': 0.5})
#~ sc.add_widget(spinner)
sc.content.add_widget(sm)
return sc
def hook_keyboard(self, window, key, *largs):
if key == 27: # BACK
return True
# Irrelevant code
pass
elif key in (282, 319): # SETTINGS
# Irrelevant code
pass
TrainccsApp().run()