Skip to content

Commit

Permalink
added dummy in toolbar, dummy for filter function and skip of spots i…
Browse files Browse the repository at this point in the history
…n list
  • Loading branch information
infinitel8p committed Feb 12, 2022
1 parent 9aa6340 commit 7a1d029
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
1 change: 1 addition & 0 deletions filterarguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
filter_category = ["Skatepark"]
68 changes: 68 additions & 0 deletions filterpopupmenu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import certifi
from kivy.clock import Clock
from lib.dialog import MDInputDialog
from urllib import parse
from kivy.network.urlrequest import UrlRequest
from kivymd.app import MDApp
from kivymd.uix.snackbar import Snackbar
from kivymd.uix.button import MDFlatButton


class FilterPopupMenu(MDInputDialog):
title = "Search for a city"
text_button_ok = "Search"

def __init__(self):
super().__init__()
self.size_hint = [.8, .3]
self.events_callback = self.callback

def open(self, *args):
super().open()
Clock.schedule_once(self.set_field_focus, 0.5)

def callback(self, *args):
address = self.text_field.text
self.geocode_get_lat_lon(address)

def geocode_get_lat_lon(self, address):
apikey = "alhPapHUB_qtDB3MT9R4wEud3UcR77RjD3fgTlHYiCE"
print('[' + '\x1b[1;34;40m' + 'INFO' + '\x1b[0m' + ' ] [UrlRequest ] ' +
"UrlRequest for: " + '\x1b[1;34;40m' + f"{address}" + '\x1b[0m')
address = parse.quote(address)
url = f"https://geocoder.ls.hereapi.com/6.2/geocode.json?searchtext={address}&gen=9&apiKey={apikey}"
UrlRequest(url, on_success=self.success, on_failure=self.failure,
on_error=self.error, ca_file=certifi.where())

def success(self, urlrequest, result):
print('[' + '\x1b[1;32;40m' + 'SUCCESS' + '\x1b[0m' +
'] [UrlRequest ] ' + "UrlRequest status: " + '\x1b[1;32;40m' + 'successful' + '\x1b[0m')
try:
latitude = result["Response"]["View"][0]["Result"][0]["Location"]["NavigationPosition"][0]["Latitude"]
longitude = result["Response"]["View"][0]["Result"][0]["Location"]["NavigationPosition"][0]["Longitude"]
print('[' + '\x1b[1;32;40m' + 'RESULTS' + '\x1b[0m' +
'] [UrlRequest ] ' + "Coordinates: " + '\x1b[1;32;40m' + f'{longitude, latitude}' + '\x1b[0m')
app = MDApp.get_running_app()
mapview = app.root.ids.mapview
mapview.center_on(latitude, longitude)
except IndexError:
print('[' + '\x1b[1;33;40m' + 'ERROR' + '\x1b[0m' +
' ] [IndexError ] ' + '\x1b[1;33;40m' + f"{IndexError} " + '\x1b[0m' + f"while searching for: {self.text_field.text}")
Snackbar(
# [color=#ff0000]TEXT[/color] for red text
text=f"'{self.text_field.text}' could not be found",
bg_color=self.theme_cls.primary_color,
buttons=[
MDFlatButton(
text="[color=#ffffff]RETRY[/color]",
on_release=self.open)]).open()

def failure(self, urlrequest, result):
print('[' + '\x1b[1;31;40m' + 'FAILURE' + '\x1b[0m' +
'] [UrlRequest ] ' + "UrlRequest status: " + '\x1b[1;31;40m' + 'failure' + '\x1b[0m')
print(result)

def error(self, urlrequest, result):
print('[' + '\x1b[1;33;40m' + 'ERROR' + '\x1b[0m' +
' ] [UrlRequest ] ' + "UrlRequest status: " + '\x1b[1;33;40m' + 'error' + '\x1b[0m')
print(result)
2 changes: 1 addition & 1 deletion main.kv
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Screen:

MDToolbar:
title: "Topspot - Skatespot Map"
right_action_items: [["magnify", lambda x: app.search_menu.open()]] #[["filter-menu-outline", lambda x: app.spot_filter.open()],
right_action_items: [["filter-menu-outline", lambda x: app.spot_filter.open()],["magnify", lambda x: app.search_menu.open()]]
left_action_items: [["menu", lambda x: nav_drawer.set_state("open")]]
md_bg_color: app.theme_cls.primary_color

Expand Down
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sqlite3
from topspotmap import TopSpotMap
from searchpopupmenu import SearchPopupMenu
from filterpopupmenu import FilterPopupMenu
from gpshelper import GpsHelper
from kivy.uix.boxlayout import BoxLayout
from kivymd.theming import ThemableBehavior
Expand Down Expand Up @@ -50,6 +51,9 @@ def on_start(self):
# init SearchPopupMenu
self.search_menu = SearchPopupMenu()

# init FilterPopupMenu
self.spot_filter = FilterPopupMenu()


if __name__ == "__main__":
MainApp().run()
10 changes: 9 additions & 1 deletion topspotmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from kivymd.app import MDApp
from spotmarker import SpotMarker
from kivy.utils import platform
from filterarguments import filter_category


class TopSpotMap(MapView):
Expand Down Expand Up @@ -31,11 +32,18 @@ def get_spots_in_fov(self, *args):
print('[' + '\x1b[1;35;40m' + 'INFO' + '\x1b[0m' +
' ] [Mapview ] ' + "Spots in FOV: " + '\x1b[1;35;40m' + f"{len(spots)}" +
'\x1b[0m')
# add markers for spots not in filter_category nor in spot_names
for spot in spots:
name = spot[1]
if spot[14] in filter_category:
if name in self.spot_names:
try:
self.spot_names.remove(name)
except:
pass
if name in self.spot_names:
pass
else:
elif spot[14] not in filter_category:
self.add_spot(spot)
# update gps coordinates on screen
if platform == "android" or platform == "ios":
Expand Down

0 comments on commit 7a1d029

Please sign in to comment.