Esempio n. 1
0
def prompt_for_account(config):
    accounts = {}
    for section in config.options("incoming_email"):
        info = config.get("incoming_email", section).split(",")
        key = "%s on %s" % (info[1], info[0])
        accounts[key] = info

    wl2k_call = config.get("user", "callsign")
    wl2k_ssid = config.get("prefs", "msg_wl2k_ssid").strip()
    if wl2k_ssid:
        wl2k_call = "%s-%s" % (wl2k_call, wl2k_ssid)

    accounts["Other"] = ["", "", "", "", "", "110"]
    accounts["WL2K"] = ["@WL2K", wl2k_call, "", "", "", "0"]
    default = list(accounts.keys())[0]

    account = miscwidgets.make_choice(list(accounts.keys()), False, default)
    host = Gtk.Entry()
    user = Gtk.Entry()
    pasw = Gtk.Entry()
    ussl = Gtk.CheckButton()
    port = Gtk.SpinButton(Gtk.Adjustment(110, 1, 65535, 1), digits=0)

    disable = [host, user, pasw, ussl, port]

    pasw.set_visibility(False)

    def choose_account(box):
        info = accounts[box.get_active_text()]
        for i in disable:
            i.set_sensitive(not info[0])
        host.set_text(info[0])
        user.set_text(info[1])
        pasw.set_text(info[2])
        ussl.set_active(info[4] == "True")
        port.set_value(int(info[5]))

    account.connect("changed", choose_account)
    choose_account(account)

    d = inputdialog.FieldDialog(title="Select account")
    d.add_field("Account", account)
    d.add_field("Server", host)
    d.add_field("Username", user)
    d.add_field("Password", pasw)
    d.add_field("Use SSL", ussl)
    d.add_field("Port", port)
    r = d.run()
    d.destroy()
    if r == Gtk.RESPONSE_CANCEL:
        return None

    return host.get_text(), user.get_text(), pasw.get_text(), \
        str(ussl.get_active()), str(int(port.get_value()))
Esempio n. 2
0
def prompt_for_station(_station_list, config, parent=None):
    station_list = [str(x) for x in _station_list]
    port_list = []
    for i in config.options("ports"):
        enb, port, rate, sniff, raw, name = config.get("ports", i).split(",")
        if enb == "True":
            port_list.append(name)

    defsta = defprt = ""
    if station_list:
        defsta = str(station_list[0])
    if port_list:
        defprt = port_list[0]

    port_list.sort()
    station_list.sort()

    station = miscwidgets.make_choice(station_list, True, defsta)
    port = miscwidgets.make_choice(port_list, False, defprt)

    d = inputdialog.FieldDialog(title=_("Enter destination"), parent=parent)
    d.add_field(_("Station"), station)
    d.add_field(_("Port"), port)
    station.child.set_activates_default(True)

    while True:
        res = d.run()
        if res != gtk.RESPONSE_OK:
            break
        s = station.get_active_text().upper()
        if "@" in s:
            display_error(
                _("You must enter a station callsign.  " +
                  "You cannot use an email address here"), d)
            continue
        elif not re.match(STATION_REGEX, s):
            display_error(_("Invalid character in callsign"), d)
            continue
        break

    p = port.get_active_text()
    d.destroy()
    if res == gtk.RESPONSE_OK:
        return s, p
    else:
        return None, None