created routes in app
This commit is contained in:
51
main.py
51
main.py
@@ -15,6 +15,7 @@ from kivy.uix.popup import Popup
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.button import Button
|
||||
from kivy.uix.label import Label
|
||||
|
||||
kivy.require("2.0.0") # Ensure the correct Kivy version is used
|
||||
|
||||
# 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.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):
|
||||
"""Handle the Get trip server data button press."""
|
||||
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}..."
|
||||
|
||||
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:
|
||||
print("Positions received:")
|
||||
for pos in positions:
|
||||
|
||||
Reference in New Issue
Block a user