created routes in app

This commit is contained in:
2025-06-04 17:03:08 +03:00
parent 2eaafedf5b
commit 26640678cb
6 changed files with 23204 additions and 3 deletions
+51
View File
@@ -15,6 +15,7 @@ from kivy.uix.popup import Popup
from kivy.uix.gridlayout import GridLayout from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button from kivy.uix.button import Button
from kivy.uix.label import Label from kivy.uix.label import Label
kivy.require("2.0.0") # Ensure the correct Kivy version is used kivy.require("2.0.0") # Ensure the correct Kivy version is used
# Paths # Paths
@@ -253,6 +254,54 @@ class GetTripFromServer(Screen): # Renamed from HomeScreen
popup = Popup(title="Select a Date", content=layout, size_hint=(0.8, 0.8)) popup = Popup(title="Select a Date", content=layout, size_hint=(0.8, 0.8))
popup.open() popup.open()
def update_points_count(self, count):
"""Update the label showing the number of points."""
self.ids.points_count_label.text = f"Points: {count}"
def save_route(self):
"""Save the current list of positions as a route in resources/projects/<route_name>/positions.json."""
route_name = self.ids.route_name_input.text.strip()
if not route_name:
self.ids.result_label.text = "Please enter a route name."
return
positions = getattr(self, "last_positions", None)
if not positions:
self.ids.result_label.text = "No positions to save."
return
folder_path = os.path.join("resources", "projects", route_name)
os.makedirs(folder_path, exist_ok=True)
file_path = os.path.join(folder_path, "positions.json")
try:
with open(file_path, "w") as f:
json.dump(positions, f, indent=2)
self.ids.result_label.text = f"Route '{route_name}' saved!"
# Reset UI fields
self.ids.devices_spinner.text = "Select a device"
self.ids.start_date_picker_button.text = "Select Start Date"
self.ids.end_date_picker_button.text = "Select End Date"
self.ids.start_hour_spinner.text = "00"
self.ids.end_hour_spinner.text = "23"
self.ids.points_count_label.text = "Points: 0"
self.ids.route_name_input.text = ""
# Show popup and schedule reroute to home
popup = Popup(title="Success",
content=Label(text=f"Route '{route_name}' saved!"),
size_hint=(None, None), size=(300, 150),
auto_dismiss=False)
popup.open()
def close_and_go_home(dt):
popup.dismiss()
self.manager.current = "home"
Clock.schedule_once(close_and_go_home, 3)
except Exception as e:
self.ids.result_label.text = f"Failed to save route: {str(e)}"
def get_trip_server_data(self): def get_trip_server_data(self):
"""Handle the Get trip server data button press.""" """Handle the Get trip server data button press."""
selected_device = self.ids.devices_spinner.text selected_device = self.ids.devices_spinner.text
@@ -274,6 +323,8 @@ class GetTripFromServer(Screen): # Renamed from HomeScreen
self.ids.result_label.text = f"Fetching trip data for {selected_device} from {start_date} to {end_date}..." self.ids.result_label.text = f"Fetching trip data for {selected_device} from {start_date} to {end_date}..."
positions = self.fetch_positions_for_selected_day() positions = self.fetch_positions_for_selected_day()
self.last_positions = positions # Store for saving
self.update_points_count(len(positions) if positions else 0)
if positions: if positions:
print("Positions received:") print("Positions received:")
for pos in positions: for pos in positions:
+1 -1
View File
@@ -1 +1 @@
gAAAAABoPvoeyS-tuW1N-ItemRHlLPfY4XS53ghwhEuE2_LVaaYw3pa8ETldvWFYtW0GZHZbz2cFcZE6-HKXURQ5mKHPnvymaMMc00aLIN2iHPbJKr7LQvbUh-sSb3fxc8zOJZ0W847z gAAAAABoQFHNaG_pnMnzlvJJFMIV7sbnJPMG1qcbfMo7l9FqOUdbOXmP4KtjW0JfrRwFN2daFSD92zjWvarQCDgSBcCN3EDOD_T4IXgscWBscygqIJ_UY5QnkGAeczT0SgbcUyyRgn-v
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+39 -2
View File
@@ -324,14 +324,51 @@
background_color: 0.341, 0.235, 0.980, 1 # Purple color (#573CFA) background_color: 0.341, 0.235, 0.980, 1 # Purple color (#573CFA)
on_press: root.get_trip_server_data() on_press: root.get_trip_server_data()
# Third row: Result label # Third row: Route info and save
BoxLayout:
orientation: "horizontal"
size_hint_y: None
height: 50
spacing: 10
padding: 10
canvas.before:
Color:
rgba: 0.15, 0.15, 0.15, 1
Rectangle:
pos: self.pos
size: self.size
Label:
id: points_count_label
text: "Points: 0"
font_size: 16
size_hint_x: 0.2
Label:
text: "Create Route"
font_size: 16
size_hint_x: 0.2
TextInput:
id: route_name_input
hint_text: "Enter route name"
multiline: False
size_hint_x: 0.4
Button:
text: "Save"
size_hint_x: 0.2
background_color: 0.008, 0.525, 0.290, 1
on_press: root.save_route()
# Fourth row: Result label
Label: Label:
id: result_label id: result_label
text: "Welcome to the Home Screen!" text: "Welcome to the Home Screen!"
font_size: 14 # Reduced font size font_size: 14 # Reduced font size
size_hint: (1, 0.8) size_hint: (1, 0.8)
# Fourth row: Back to Home button # Fifth row: Back to Home button
Button: Button:
text: "Back to Home" text: "Back to Home"
size_hint_y: None size_hint_y: None