-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
94 lines (72 loc) · 3.11 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
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy_garden.mapview import MapView, MapMarker
from kivy.animation import Animation
from kivymd.app import MDApp
from kivymd.uix.toolbar import MDToolbar
from kivymd.uix.button import MDFloatingActionButton
from kivymd.uix.label import MDLabel
from kivy.uix.screenmanager import Screen, ScreenManager
class MainView(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.build_ui()
def build_ui(self):
layout = BoxLayout(orientation='vertical')
toolbar = MDToolbar(title="Stray Dog Map Iran")
toolbar.md_bg_color = 0, 0, 0, 1
toolbar.specific_text_color = 1, 1, 0, 1
toolbar.right_action_items = [["account", lambda x: self.change_to_profile()],
["theme-light-dark", lambda x: MDApp.get_running_app().toggle_theme()]]
layout.add_widget(toolbar)
self.mapview = MapView(lat=35.6892, lon=51.3890, zoom=10)
layout.add_widget(self.mapview)
fab = MDFloatingActionButton(icon="plus", md_bg_color=(1, 1, 0, 1))
fab.pos_hint = {"center_x": 0.5, "center_y": 0.1}
fab.bind(on_press=self.animate_fab)
layout.add_widget(fab)
self.add_widget(layout)
def on_enter(self):
marker = MapMarker(lat=35.6892, lon=51.3890)
self.mapview.add_marker(marker)
def change_to_profile(self):
self.manager.current = 'profile'
def report_dog(self, instance):
print("Report a Dog functionality triggered!")
def animate_fab(self, instance):
animation = Animation(size=(80, 80), duration=0.2) + Animation(size=(56, 56), duration=0.2)
animation.start(instance)
self.report_dog(instance)
class ProfileView(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.build_ui()
def build_ui(self):
layout = BoxLayout(orientation='vertical')
toolbar = MDToolbar(title="Profile")
toolbar.md_bg_color = 0, 0, 0, 1
toolbar.specific_text_color = 1, 1, 0, 1
toolbar.left_action_items = [["arrow-left", lambda x: self.change_to_main()]]
layout.add_widget(toolbar)
profile_label = MDLabel(text="User Profile", halign="center", theme_text_color="Custom")
profile_label.text_color = 1, 1, 0, 0.8
profile_label.pos_hint = {"center_x": 0.5, "center_y": 0.5}
layout.add_widget(profile_label)
self.add_widget(layout)
def change_to_main(self):
self.manager.current = 'main'
class MainApp(MDApp):
def build(self):
self.screen_manager = ScreenManager()
self.screen_manager.add_widget(MainView(name="main"))
self.screen_manager.add_widget(ProfileView(name="profile"))
return self.screen_manager
def on_start(self):
self.screen_manager.get_screen('main').on_enter()
def toggle_theme(self):
if self.theme_cls.theme_style == "Light":
self.theme_cls.theme_style = "Dark"
else:
self.theme_cls.theme_style = "Light"
if __name__ == '__main__':
MainApp().run()