def Configure(self, location_id="Antwerp, Belgium", hl=""): text = self.text dialog = eg.ConfigPanel(self) sizer = dialog.sizer mySizer = wx.FlexGridSizer(cols=2) desc0 = wx.StaticText(dialog, -1, text.LanguageLabel) mySizer.Add(desc0, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) Language = wx.TextCtrl(dialog, -1, hl) mySizer.Add(Language, 0, wx.EXPAND | wx.ALL, 5) desc1 = wx.StaticText(dialog, -1, text.LocationLabel) mySizer.Add(desc1, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) Location = wx.TextCtrl(dialog, -1, location_id) mySizer.Add(Location, 0, wx.EXPAND | wx.ALL, 5) desc2 = wx.StaticText(dialog, -1, text.CountriesLabel) mySizer.Add(desc2, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) CountriesEdit = wx.ListBox(dialog, -1, choices=[], style=wx.LB_SINGLE) mySizer.Add(CountriesEdit, 0, wx.EXPAND | wx.ALL, 5) CountriesEdit.Clear() CountryList = pywapi.get_countries_from_google() i = 0 while i < len(CountryList): CountriesEdit.Append(CountryList[i]["name"]) i = i + 1 def OnCountrySelect(event): CitiesEdit.Clear() result = pywapi.get_cities_from_google(str(CountryList[CountriesEdit.GetSelection()]["iso_code"])) i = 0 while i < len(result): CitiesEdit.Append(result[i]["name"]) i = i + 1 Location.SetValue(CitiesEdit.GetStringSelection() + ", " + CountriesEdit.GetStringSelection()) CountriesEdit.Bind(wx.EVT_LISTBOX, OnCountrySelect) desc3 = wx.StaticText(dialog, -1, text.CitiesLabel) mySizer.Add(desc3, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) CitiesEdit = wx.ListBox(dialog, -1, choices=[], style=wx.LB_SINGLE) mySizer.Add(CitiesEdit, 0, wx.EXPAND | wx.ALL, 5) def OnCitySelect(event): Location.SetValue(CitiesEdit.GetStringSelection() + ", " + CountriesEdit.GetStringSelection()) CitiesEdit.Bind(wx.EVT_LISTBOX, OnCitySelect) sizer.Add(mySizer, 1, wx.EXPAND) while dialog.Affirmed(): dialog.SetResult(Location.GetValue(), Language.GetValue())
def country_name_attribute(country_name): print("with in validation fn:", country_name) countries = get_countries_from_google('en') country_lst = [] for ele in countries: country_lst.append(ele['name']) if country_name in country_lst: return {"country": country_name} else: return {"country": "Invalid"}
def Configure(self, location_id = "Antwerp, Belgium", hl=''): text=self.text dialog = eg.ConfigPanel(self) sizer = dialog.sizer mySizer = wx.FlexGridSizer(cols=2) desc0 = wx.StaticText(dialog, -1, text.LanguageLabel) mySizer.Add(desc0, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) Language = wx.TextCtrl(dialog, -1,hl) mySizer.Add(Language, 0, wx.EXPAND|wx.ALL, 5) desc1 = wx.StaticText(dialog, -1, text.LocationLabel) mySizer.Add(desc1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) Location = wx.TextCtrl(dialog, -1,location_id) mySizer.Add(Location, 0, wx.EXPAND|wx.ALL, 5) desc2 = wx.StaticText(dialog, -1, text.CountriesLabel) mySizer.Add(desc2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) CountriesEdit = wx.ListBox(dialog, -1, choices=[], style=wx.LB_SINGLE) mySizer.Add(CountriesEdit, 0, wx.EXPAND|wx.ALL, 5) CountriesEdit.Clear() CountryList = pywapi.get_countries_from_google() i=0 while i < len(CountryList): CountriesEdit.Append(CountryList[i]['name']) i=i+1 def OnCountrySelect(event): CitiesEdit.Clear() result = pywapi.get_cities_from_google(str(CountryList[CountriesEdit.GetSelection()]['iso_code'])) i=0 while i < len(result): CitiesEdit.Append(result[i]['name']) i=i+1 Location.SetValue(CitiesEdit.GetStringSelection() + ", " + CountriesEdit.GetStringSelection()) CountriesEdit.Bind(wx.EVT_LISTBOX, OnCountrySelect) desc3 = wx.StaticText(dialog, -1, text.CitiesLabel) mySizer.Add(desc3, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) CitiesEdit = wx.ListBox(dialog, -1, choices=[], style=wx.LB_SINGLE) mySizer.Add(CitiesEdit, 0, wx.EXPAND|wx.ALL, 5) def OnCitySelect(event): Location.SetValue(CitiesEdit.GetStringSelection() + ", " + CountriesEdit.GetStringSelection()) CitiesEdit.Bind(wx.EVT_LISTBOX, OnCitySelect) sizer.Add(mySizer, 1, wx.EXPAND) while dialog.Affirmed(): dialog.SetResult(Location.GetValue(), Language.GetValue())
def __call__(self, hl): return pywapi.get_countries_from_google(hl)
#!/usr/bin/env python import pywapi import pprint pp = pprint.PrettyPrinter(indent=4) countries = pywapi.get_countries_from_google('en') pp.pprint(countries)
def get_countries(): result = pywapi.get_countries_from_google('en') return { 'countries' : result }