From 9ea17aff427d54c941c6a50e2db023864a2906a6 Mon Sep 17 00:00:00 2001 From: Benjamin Kreuscher Date: Wed, 26 Aug 2026 16:34:10 +0200 Subject: [PATCH] [BUGFIX] GUI: show only continents in the continent combobox Since #275 the first combobox was filled from geofabrik_regions. That list holds every geofabrik entry having children, so besides the continents it also contains countries ('germany') and even sub-regions of a country ('baden-wuerttemberg', 'bayern', 'nordrhein-westfalen', 'england', 'greater-london', 'british-columbia', 'nunavut'). Add GeofabrikJson.get_continents() which returns the entries without a parent and use it for the combobox. geofabrik_regions is left untouched - the download logic in geofabrik.py needs it with all levels. Co-Authored-By: Claude Opus 5 --- tests/test_constants_geofabrik.py | 25 +++++++++++++++++++++++++ wahoomc/geofabrik_json.py | 10 ++++++++++ wahoomc/input.py | 8 ++++---- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/tests/test_constants_geofabrik.py b/tests/test_constants_geofabrik.py index fee68a55..28eba777 100644 --- a/tests/test_constants_geofabrik.py +++ b/tests/test_constants_geofabrik.py @@ -77,6 +77,31 @@ def test_regions_of_geofabrik(self): self.assertCountEqual(geofabrik_regions, regions_geofabrik) + def test_continents_of_geofabrik(self): + """ + the continent selection must only contain the continents - the geofabrik + entries without a parent. Countries like 'germany' and sub-regions of a + country like 'baden-wuerttemberg' are part of geofabrik_regions but must + not show up here + """ + continents = self.o_geofabrik_json.get_continents() + + self.assertCountEqual(continents, + ['africa', 'antarctica', 'asia', 'australia-oceania', + 'central-america', 'europe', 'north-america', + 'south-america', 'russia']) + + # no returned entry has a parent + for continent in continents: + self.assertNotIn( + 'parent', self.o_geofabrik_json.geofabrik_overview[continent]) + + # countries and their sub-regions are regions but no continents + for entry in ['germany', 'france', 'united-kingdom', 'canada', + 'baden-wuerttemberg', 'bayern', 'england', 'nunavut']: + self.assertIn(entry, self.o_geofabrik_json.geofabrik_regions) + self.assertNotIn(entry, continents) + def test_reading_geofabrik_parent(self): """ go through all files in the wahoo_mc/resources/json directory diff --git a/wahoomc/geofabrik_json.py b/wahoomc/geofabrik_json.py index 96e2d5bf..ede6ed16 100644 --- a/wahoomc/geofabrik_json.py +++ b/wahoomc/geofabrik_json.py @@ -80,6 +80,16 @@ def read_geofabrik_json_file(self): return raw_json, geofabrik_overview, geofabrik_region_overview, geofabrik_regions + def get_continents(self): + """ + return the continents - the geofabrik entries without a parent + + geofabrik_regions can not be used for this because it holds every map + having children. Besides the continents these are countries like + 'germany' and even sub-regions of a country like 'baden-wuerttemberg' + """ + return sorted(self.geofabrik_region_overview) + def get_geofabrik_parent_country(self, id_no): """ Get the parent map/region of a country from the already loaded json data diff --git a/wahoomc/input.py b/wahoomc/input.py index 3f95afcc..74f73b04 100644 --- a/wahoomc/input.py +++ b/wahoomc/input.py @@ -339,13 +339,13 @@ def __init__(self, parent, oInputData): # Labels self.lab_top = tk.Label( - self, text="Select continent/country and country/region to create a map") - self.lab_continent = tk.Label(self, text="Select continent/country:") - self.lab_country = tk.Label(self, text='Select country/region:') + self, text="Select continent and country to create a map") + self.lab_continent = tk.Label(self, text="Select continent:") + self.lab_country = tk.Label(self, text='Select country:') # Comboboxes self.cb_continent = ttk.Combobox( - self, values=GeofabrikJson().geofabrik_regions, state="readonly") + self, values=GeofabrikJson().get_continents(), state="readonly") self.cb_continent.current(0) # pre-select first entry in combobox self.cb_continent.bind("<>", self.callback_continent)