Пример #1
0
def askCityBox(parent):
  if parent == "?": parent = mainWin
  row = gtk.HBox()
  row.show()
  label = gtk.Label("Location:")
  label.set_width_chars(7)
  label.set_alignment(1,0.5)
  choices = backends.getCityList()
  loc = gtk.combo_box_new_text()
  loc.set_size_request(200,32)
  keys = []
  i = 0
  for key in sorted(choices.keys()):
    if choices.get(key) and choices[key][0] and choices[key][2]:
      loc.append_text("%s, %s" % (choices[key][0],choices[key][2]))
      keys.append(key)
      i += 1
  askBox = None
  if len(keys) > 0:
    askbox = gtk.MessageDialog(parent,gtk.DIALOG_DESTROY_WITH_PARENT,gtk.MESSAGE_QUESTION,gtk.BUTTONS_OK_CANCEL)
  else:
    askbox = gtk.MessageDialog(parent,gtk.DIALOG_DESTROY_WITH_PARENT,gtk.MESSAGE_WARNING,gtk.BUTTONS_OK)
  if len(keys) > 0:
    askbox.set_markup("Choose a city:")
    label.show()
    row.pack_start(label,False,False,2)
    loc.show()
    row.pack_start(loc,True,True,2)
  else:
    askbox.format_secondary_markup("Please create at least one city and state before using this dialog.")
  askbox.vbox.pack_end(row,True,True,0)
  width, height = askbox.get_size()
  askbox.move((gtk.gdk.screen_width() / 2) - (width / 2),(gtk.gdk.screen_height() / 2) - (height / 2))
  askbox.move((gtk.gdk.screen_width() / 2) - (width / 2),(gtk.gdk.screen_height() / 2) - (height / 2))
  askbox.run()
  key = None
  if len(keys) > 0:
    key = loc.get_active_text()
  askbox.destroy()
  loc.destroy()
  loc = [False,None,None,None,None]
  lockeys = {}
  if key is not None and len(key) > 0:
    lockeys = backends.getCityList(1)
    key = lockeys.get(key,'N')
    lockeys = backends.getCityList()
    if config['debug'] > 0: print "new key: %s" % key
    print "%s (%s), %s (%s)" % (lockeys[key][0],key,lockeys[key][2],lockeys[key][1])
    loc[1] = key
    loc[2] = lockeys[key][0]
    loc[3] = lockeys[key][1]
    loc[4] = lockeys[key][2]
    loc[0] = True
  if config['debug'] > 0: printPretty(loc)
  return loc
Пример #2
0
def chooseCity(parent,target,tabs,scroll,data,statef,ar,stalts,title = ""):
  global status
  global cities
  city = recordSelectBox(None,statef,title,'c')
  if city and city[1] == "city":
    cityname = ""
    citlist = getCityList(0)
    cityf = validateFileid(citlist.get(statef,["",""])[1])
    cityname = citlist.get(statef,["",""])[0]
    statename = citlist.get(statef,["","",""])[2]
    try:
      cityname = cities[city[0]]['info']['name'][0]
      cities[city[0]]['info']['state'] = [statename,True]
      cities[city[0]]['info']['statefile'] = [statef,True]
      cities[city[0]]['info']['loc'] = [cityname,True]
      cities[city[0]]['info']['locfile'] = [cityf,True]
      cities[city[0]]['changed'] = True
      saveThisC(parent,city[0])
#      reloadPlaceTab(place[0]) # TODO: Write a function like this
    except KeyError:
#      placename = getPlaceNameFromID(place[0])
      cityname = askBox("?","  Please type the city name that goes with %s" % city[0],"Name",subtext="  I tried to load this from memory, but you\ndon't have %s open. Without it open, I can't\nsynchronize its city and state values.\n  This requirement prevents unintentional\nchanges to your place records." % city[0])
      # Maybe some day, I'll make this grab the placename from the file, and automatically load its record for updating
    if cityname == "":
      status.push(0,"Registering place in %s cancelled" % cityf)
      return False
    packCity(target,scroll,data,statef,city[0],cityname,tabs,True,ar,stalts)
    status.push(0,"Registered %s in %s" % (city[1],statef))
    return True
  else:
    status.push(0,"Registering place in %s cancelled" % statef)
    return False
Пример #3
0
def setLoc(caller,fileid,key):
  global places
  lockeys = {}
  if len(key) > 1:
    lockeys = getCityList(1)
    key = lockeys.get(key,'N')
    lockeys = getCityList()
    if config['debug'] > 3: print "new key: %s" % key
    print "%s (%s), %s (%s)" % (lockeys[key][0],key,lockeys[key][2],lockeys[key][1])
    if preRead(False,'l',[fileid,"info"],2):
      places[fileid]['info']['locfile'] = [key,True]
      places[fileid]['info']['loc'] = [lockeys[key][0],True]
      places[fileid]['info']['statefile'] = [lockeys[key][1],True]
      places[fileid]['info']['state'] = [lockeys[key][2],True]
      places[fileid]['changed'] = True
      if config['debug'] > 0: print "New Loc: %s" % key
  else:
    bsay(None,"setLoc: Could not set loc for %s." % fileid)
Пример #4
0
def buildLocRow(data,fileid):
  row = gtk.HBox()
  row.show()
  label = gtk.Label("Location:")
  label.show()
  row.pack_start(label,False,False,2)
  label.set_width_chars(20)
  label.set_alignment(1,0.5)
  choices = getCityList()
  loc = gtk.Label()
  loc.show()
  row.pack_start(loc,True,True,2)
  g = getInf(data,["info","loc"])
  h = getInf(data,["info","state"])
  loc.set_text("%s, %s" % (g,h))
  addLocButton(row,1,entry=loc,cat='l',city="loc",cityfile="locfile",state="state",statefile="statefile",data=data)
  return row
Пример #5
0
def choosePlace(parent, target, tabs, scroll, data, cityf, ar, ctalts, title=""):
    global status
    global places
    place = recordSelectBox(None, cityf, title, "l")
    if place and place[1] == "place":
        placename = ""
        citlist = getCityList(0)
        statef = validateFileid(citlist.get(cityf, ["", ""])[1])
        cityname = citlist.get(cityf, ["", ""])[0]
        statename = citlist.get(cityf, ["", "", ""])[2]
        try:
            placename = places[place[0]]["info"]["name"][0]
            places[place[0]]["info"]["state"] = [statename, True]
            places[place[0]]["info"]["statefile"] = [statef, True]
            places[place[0]]["info"]["loc"] = [cityname, True]
            places[place[0]]["info"]["locfile"] = [cityf, True]
            places[place[0]]["changed"] = True
            saveThisL(parent, place[0])
        #      reloadPlaceTab(place[0]) # TODO: Write a function like this
        except KeyError:
            #      placename = getPlaceNameFromID(place[0])
            placename = askBox(
                None,
                "  Please type the location name that goes with %s" % place[0],
                "Name",
                subtext="  I tried to load this from memory, but you\ndon't have %s open. Without it open, I can't\nsynchronize its city and state values.\n  This requirement prevents unintentional\nchanges to your place records."
                % place[0],
            )
            # Maybe some day, I'll make this grab the placename from the file, and automatically load its record for updating
        if placename == "":
            status.push(0, "Registering place in %s cancelled" % cityf)
            return False
        packPlace(target, scroll, data, cityf, place[0], placename, tabs, True, ar, ctalts)
        status.push(0, "Registered %s in %s" % (place[1], cityf))
        return True
    else:
        status.push(0, "Registering place in %s cancelled" % cityf)
        return False