diff options
| author | Bdale Garbee <bdale@gag.com> | 2014-06-26 12:55:21 -0600 |
|---|---|---|
| committer | Iain R. Learmonth <irl@fsfe.org> | 2015-05-03 18:29:34 +0100 |
| commit | 5e9167a4a78a45e58ae9969b41e70e9d77176376 (patch) | |
| tree | ebc0c218856d44b1c60b62ba20ec9cd1b90e4791 /chirpui/mainapp.py | |
| parent | df2e8c36e9ce0a448c1ec9a9665644d95d3014c2 (diff) | |
| parent | c86187dcdf158df59977baee6c8d6385f964b69b (diff) | |
Imported Debian patch 0.4.0-1debian/0.4.0-1
Diffstat (limited to 'chirpui/mainapp.py')
| -rw-r--r-- | chirpui/mainapp.py | 316 |
1 files changed, 238 insertions, 78 deletions
diff --git a/chirpui/mainapp.py b/chirpui/mainapp.py index e3b2eb1..719d096 100644 --- a/chirpui/mainapp.py +++ b/chirpui/mainapp.py @@ -40,6 +40,7 @@ from chirp import ic9x, kenwood_live, idrp, vx7, vx5, vx6 from chirp import CHIRP_VERSION, chirp_common, detect, errors from chirp import icf, ic9x_icf from chirpui import editorset, clone, miscwidgets, config, reporting, fips +from chirpui import bandplans CONF = config.get() @@ -129,7 +130,7 @@ class ChirpMain(gtk.Window): for _editortype, actions in mappings.items(): for _action in actions: action = self.menu_ag.get_action(_action) - action.set_sensitive(_editortype == editortype) + action.set_sensitive(editortype.startswith(_editortype)) def _connect_editorset(self, eset): eset.connect("want-close", self.do_close) @@ -300,8 +301,6 @@ If you think that it is valid, you can select a radio model below to force an op # We have to actually instantiate the IC9xICFRadio to get its # sub-devices radio = ic9x_icf.IC9xICFRadio(fname) - devices = radio.get_sub_devices() - del radio else: try: radio = directory.get_radio_by_image(fname) @@ -315,39 +314,30 @@ If you think that it is valid, you can select a radio model below to force an op common.show_error(os.path.basename(fname) + ": " + str(e)) return - if radio.get_features().has_sub_devices: - devices = radio.get_sub_devices() - else: - devices = [radio] - - prio = len(devices) first_tab = False - for device in devices: - try: - eset = editorset.EditorSet(device, self, - filename=fname, - tempname=tempname) - except Exception, e: - common.log_exception() - common.show_error( - _("There was an error opening {fname}: {error}").format( - fname=fname, - error=error)) - return - - eset.set_read_only(read_only) - self._connect_editorset(eset) - eset.show() - tab = self.tabs.append_page(eset, eset.get_tab_label()) - if first_tab: - self.tabs.set_current_page(tab) - first_tab = False - - if hasattr(eset.rthread.radio, "errors") and \ - eset.rthread.radio.errors: - msg = _("{num} errors during open:").format(num=len(eset.rthread.radio.errors)) - common.show_error_text(msg, - "\r\n".join(eset.rthread.radio.errors)) + try: + eset = editorset.EditorSet(radio, self, + filename=fname, + tempname=tempname) + except Exception, e: + common.log_exception() + common.show_error( + _("There was an error opening {fname}: {error}").format( + fname=fname, + error=e)) + return + + eset.set_read_only(read_only) + self._connect_editorset(eset) + eset.show() + self.tabs.append_page(eset, eset.get_tab_label()) + + if hasattr(eset.rthread.radio, "errors") and \ + eset.rthread.radio.errors: + msg = _("{num} errors during open:").format( + num=len(eset.rthread.radio.errors)) + common.show_error_text(msg, + "\r\n".join(eset.rthread.radio.errors)) def do_live_warning(self, radio): d = gtk.MessageDialog(parent=self, buttons=gtk.BUTTONS_OK) @@ -369,23 +359,12 @@ If you think that it is valid, you can select a radio model below to force an op d.destroy() def do_open_live(self, radio, tempname=None, read_only=False): - if radio.get_features().has_sub_devices: - devices = radio.get_sub_devices() - else: - devices = [radio] - - first_tab = True - for device in devices: - eset = editorset.EditorSet(device, self, tempname=tempname) - eset.connect("want-close", self.do_close) - eset.connect("status", self.ev_status) - eset.set_read_only(read_only) - eset.show() - - tab = self.tabs.append_page(eset, eset.get_tab_label()) - if first_tab: - self.tabs.set_current_page(tab) - first_tab = False + eset = editorset.EditorSet(radio, self, tempname=tempname) + eset.connect("want-close", self.do_close) + eset.connect("status", self.ev_status) + eset.set_read_only(read_only) + eset.show() + self.tabs.append_page(eset, eset.get_tab_label()) if isinstance(radio, chirp_common.LiveRadio): reporting.report_model_usage(radio, "live", True) @@ -585,7 +564,7 @@ If you think that it is valid, you can select a radio model below to force an op return True title = _("Proceed with experimental driver?") - text = rclass.get_experimental_warning() + text = rclass.get_prompts().experimental msg = _("This radio's driver is experimental. " "Do you want to proceed?") resp, squelch = common.show_warning(msg, text, @@ -596,6 +575,34 @@ If you think that it is valid, you can select a radio model below to force an op CONF.set_bool(sql_key, not squelch, "state") return resp == gtk.RESPONSE_YES + def _show_instructions(self, radio, message): + if message is None: + return + + if CONF.get_bool("clone_instructions", "noconfirm"): + return + + d = gtk.MessageDialog(parent=self, buttons=gtk.BUTTONS_OK) + d.set_markup("<big><b>" + _("{name} Instructions").format( + name=radio.get_name()) + "</b></big>") + msg = _("{instructions}").format(instructions=message) + d.format_secondary_markup(msg) + + again = gtk.CheckButton(_("Don't show instructions for any radio again")) + again.show() + d.vbox.pack_start(again, 0, 0, 0) + h_button_box = d.vbox.get_children()[2] + try: + ok_button = h_button_box.get_children()[0] + ok_button.grab_default() + ok_button.grab_focus() + except AttributeError: + # don't grab focus on GTK+ 2.0 + pass + d.run() + d.destroy() + CONF.set_bool("clone_instructions", again.get_active(), "noconfirm") + def do_download(self, port=None, rtype=None): d = clone.CloneSettingsDialog(parent=self) settings = d.run() @@ -609,6 +616,8 @@ If you think that it is valid, you can select a radio model below to force an op # User does not want to proceed with experimental driver return + self._show_instructions(rclass, rclass.get_prompts().pre_download) + print "User selected %s %s on port %s" % (rclass.VENDOR, rclass.MODEL, settings.port) @@ -646,6 +655,11 @@ If you think that it is valid, you can select a radio model below to force an op d.destroy() if not settings: return + prompts = radio.get_prompts() + + if prompts.display_pre_upload_prompt_before_opening_port == True: + print "Opening port after pre_upload prompt." + self._show_instructions(radio, prompts.pre_upload) if isinstance(radio, chirp_common.ExperimentalRadio) and \ not self._confirm_experimental(radio.__class__): @@ -664,6 +678,10 @@ If you think that it is valid, you can select a radio model below to force an op d.destroy() return + if prompts.display_pre_upload_prompt_before_opening_port == False: + print "Opening port before pre_upload prompt." + self._show_instructions(radio, prompts.pre_upload) + radio.set_pipe(ser) ct = clone.CloneThread(radio, "out", cb=self.cb_cloneout, parent=self) @@ -718,6 +736,7 @@ If you think that it is valid, you can select a radio model below to force an op (_("EVE Files (VX5)") + " (*.eve)", "*.eve"), (_("ICF Files") + " (*.icf)", "*.icf"), (_("Kenwood HMK Files") + " (*.hmk)", "*.hmk"), + (_("Kenwood ITM Files") + " (*.itm)", "*.itm"), (_("Travel Plus Files") + " (*.tpe)", "*.tpe"), (_("VX5 Commander Files") + " (*.vx5)", "*.vx5"), (_("VX6 Commander Files") + " (*.vx6)", "*.vx6"), @@ -783,7 +802,7 @@ If you think that it is valid, you can select a radio model below to force an op county.set_active(0) state.connect("changed", _changed, county) - d = inputdialog.FieldDialog(title="RepeaterBook Query", parent=self) + d = inputdialog.FieldDialog(title=_("RepeaterBook Query"), parent=self) d.add_field("State", state) d.add_field("County", county) d.add_field("Band", band) @@ -842,7 +861,7 @@ If you think that it is valid, you can select a radio model below to force an op if not os.path.exists(filename): print "Failed, headers were:" print str(headers) - common.show_error("RepeaterBook query failed") + common.show_error(_("RepeaterBook query failed")) self.window.set_cursor(None) return @@ -875,6 +894,87 @@ If you think that it is valid, you can select a radio model below to force an op else: self.do_open_live(radio, read_only=True) + def do_przemienniki_prompt(self): + d = inputdialog.FieldDialog(title='przemienniki.net query', + parent=self) + fields = { + "Country": + (miscwidgets.make_choice(['by', 'cz', 'de', 'lt', 'pl', + 'sk', 'uk'], False), + lambda x: str(x.get_active_text())), + "Band": + (miscwidgets.make_choice(['10m', '4m', '6m', '2m', '70cm', + '23cm', '13cm', '3cm'], False, '2m'), + lambda x: str(x.get_active_text())), + "Mode": + (miscwidgets.make_choice(['fm', 'dv'], False), + lambda x: str(x.get_active_text())), + "Only Working": + (miscwidgets.make_choice(['', 'yes'], False), + lambda x: str(x.get_active_text())), + "Latitude": (gtk.Entry(), lambda x: float(x.get_text())), + "Longitude": (gtk.Entry(), lambda x: float(x.get_text())), + "Range": (gtk.Entry(), lambda x: int(x.get_text())), + } + for name in sorted(fields.keys()): + value, fn = fields[name] + d.add_field(name, value) + while d.run() == gtk.RESPONSE_OK: + query = "http://przemienniki.net/export/chirp.csv?" + args = [] + for name, (value, fn) in fields.items(): + if isinstance(value, gtk.Entry): + contents = value.get_text() + else: + contents = value.get_active_text() + if contents: + try: + _value = fn(value) + except ValueError: + common.show_error(_("Invalid value for %s") % name) + query = None + continue + + args.append("=".join((name.replace(" ", "").lower(), + contents))) + query += "&".join(args) + print query + d.destroy() + return query + + d.destroy() + return query + + def do_przemienniki(self, do_import): + url = self.do_przemienniki_prompt() + if not url: + return + + fn = tempfile.mktemp(".csv") + filename, headers = urllib.urlretrieve(url, fn) + if not os.path.exists(filename): + print "Failed, headers were:" + print str(headers) + common.show_error(_("Query failed")) + return + + class PRRadio(generic_csv.CSVRadio, + chirp_common.NetworkSourceRadio): + VENDOR = "przemienniki.net" + MODEL = "" + + try: + radio = PRRadio(filename) + except Exception, e: + common.show_error(str(e)) + return + + if do_import: + eset = self.get_current_editorset() + count = eset.do_import(filename) + else: + self.do_open_live(radio, read_only=True) + def do_rfinder_prompt(self): fields = {"1Email" : (gtk.Entry(), lambda x: "@" in x), @@ -952,7 +1052,8 @@ If you think that it is valid, you can select a radio model below to force an op "3Zipcode" : (gtk.Entry(), lambda x: x), } - d = inputdialog.FieldDialog(title="RadioReference.com Query", parent=self) + d = inputdialog.FieldDialog(title=_("RadioReference.com Query"), + parent=self) for k in sorted(fields.keys()): d.add_field(k[1:], fields[k][0]) fields[k][0].set_text(CONF.get(k[1:], "radioreference") or "") @@ -1051,14 +1152,13 @@ If you think that it is valid, you can select a radio model below to force an op d.set_name("CHIRP") d.set_version(CHIRP_VERSION) - d.set_copyright("Copyright 2012 Dan Smith (KK7DS)") + d.set_copyright("Copyright 2013 Dan Smith (KK7DS)") d.set_website("http://chirp.danplanet.com") - d.set_authors(("Dan Smith <dsmith@danplanet.com>", - _("With significant contributions by:"), - "Marco IZ3GME", - "Rick WZ3RO", + d.set_authors(("Dan Smith KK7DS <dsmith@danplanet.com>", + _("With significant contributions from:"), "Tom KD7LXL", - "Vernon N7OH" + "Marco IZ3GME", + "Jim KC9HI" )) d.set_translator_credits("Polish: Grzegorz SQ2RBY" + os.linesep + @@ -1066,12 +1166,33 @@ If you think that it is valid, you can select a radio model below to force an op os.linesep + "Dutch: Michael PD4MT" + os.linesep + - "German: Benjamin HB9EUK") + "German: Benjamin HB9EUK" + + os.linesep + + "Hungarian: Attila HA7JA" + + os.linesep + + "Russian: Dmitry Slukin" + + os.linesep + + "Portuguese (BR): Crezivando PP7CJ") d.set_comments(verinfo) d.run() d.destroy() + def do_documentation(self): + d = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, parent=self, + type=gtk.MESSAGE_INFO) + + d.set_markup("<b><big>" + _("CHIRP Documentation") + "</big></b>\r\n") + msg = _("Documentation for CHIRP, including FAQs, and help for common " + "problems is available on the CHIRP web site, please go to\n\n" + "<a href=\"http://chirp.danplanet.com/projects/chirp/wiki/" + "Documentation\">" + "http://chirp.danplanet.com/projects/chirp/wiki/" + "Documentation</a>\n") + d.format_secondary_markup(msg.replace("\n","\r\n")) + d.run() + d.destroy() + def do_columns(self): eset = self.get_current_editorset() driver = directory.get_driver(eset.rthread.radio.__class__) @@ -1098,7 +1219,7 @@ If you think that it is valid, you can select a radio model below to force an op vbox.pack_start(label) fields = [] - memedit = eset.editors["memedit"] + memedit = eset.get_current_editor() #.editors["memedit"] unsupported = memedit.get_unsupported_columns() for colspec in memedit.cols: if colspec[0].startswith("_"): @@ -1132,7 +1253,9 @@ If you think that it is valid, you can select a radio model below to force an op conf = config.get("memedit") conf.set_bool("hide_unused", action.get_active()) else: - eset.editors["memedit"].set_hide_unused(action.get_active()) + for editortype, editor in eset.editors.iteritems(): + if "memedit" in editortype: + editor.set_hide_unused(action.get_active()) def do_clearq(self): eset = self.get_current_editorset() @@ -1173,8 +1296,8 @@ If you think that it is valid, you can select a radio model below to force an op conf = config.get() conf.set_bool("no_report", not action.get_active()) - def do_toggle_autorpt(self, action): - CONF.set_bool("autorpt", action.get_active(), "memedit") + def do_toggle_no_smart_tmode(self, action): + CONF.set_bool("no_smart_tmode", not action.get_active(), "memedit") def do_toggle_developer(self, action): conf = config.get() @@ -1186,7 +1309,7 @@ If you think that it is valid, you can select a radio model below to force an op def do_change_language(self): langs = ["Auto", "English", "Polish", "Italian", "Dutch", "German", - "Hungarian"] + "Hungarian", "Russian", "Portuguese (BR)"] d = inputdialog.ChoiceDialog(langs, parent=self, title="Choose Language") d.label.set_text(_("Choose a language or Auto to use the " @@ -1253,8 +1376,12 @@ If you think that it is valid, you can select a radio model below to force an op self.do_export() elif action in ["qrbook", "irbook"]: self.do_repeaterbook(action[0] == "i") + elif action in ["qpr", "ipr"]: + self.do_przemienniki(action[0] == "i") elif action == "about": self.do_about() + elif action == "documentation": + self.do_documentation() elif action == "columns": self.do_columns() elif action == "hide_unused": @@ -1263,8 +1390,12 @@ If you think that it is valid, you can select a radio model below to force an op self.do_clearq() elif action == "report": self.do_toggle_report(_action) - elif action == "autorpt": - self.do_toggle_autorpt(_action) + elif action == "channel_defaults": + # The memedit thread also has an instance of bandplans. + bp = bandplans.BandPlans(CONF) + bp.select_bandplan(self) + elif action == "no_smart_tmode": + self.do_toggle_no_smart_tmode(_action) elif action == "developer": self.do_toggle_developer(_action) elif action in ["cut", "copy", "paste", "delete", @@ -1314,6 +1445,7 @@ If you think that it is valid, you can select a radio model below to force an op <menu action="view"> <menuitem action="columns"/> <menuitem action="hide_unused"/> + <menuitem action="no_smart_tmode"/> <menu action="viewdeveloper"> <menuitem action="devshowraw"/> <menuitem action="devdiffraw"/> @@ -1327,21 +1459,24 @@ If you think that it is valid, you can select a radio model below to force an op <menu action="importsrc" name="importsrc"> <menuitem action="iradioreference"/> <menuitem action="irbook"/> + <menuitem action="ipr"/> <menuitem action="irfinder"/> </menu> <menu action="querysrc" name="querysrc"> <menuitem action="qradioreference"/> <menuitem action="qrbook"/> + <menuitem action="qpr"/> <menuitem action="qrfinder"/> </menu> <menu action="stock" name="stock"/> <separator/> - <menuitem action="autorpt"/> + <menuitem action="channel_defaults"/> <separator/> <menuitem action="cancelq"/> </menu> <menu action="help"> <menuitem action="about"/> + <menuitem action="documentation"/> <menuitem action="report"/> <menuitem action="developer"/> </menu> @@ -1383,28 +1518,32 @@ If you think that it is valid, you can select a radio model below to force an op ('iradioreference', None, _("RadioReference.com"), None, None, self.mh), ('irfinder', None, _("RFinder"), None, None, self.mh), ('irbook', None, _("RepeaterBook"), None, None, self.mh), + ('ipr', None, _("przemienniki.net"), None, None, self.mh), ('querysrc', None, _("Query data source"), None, None, self.mh), ('qradioreference', None, _("RadioReference.com"), None, None, self.mh), ('qrfinder', None, _("RFinder"), None, None, self.mh), + ('qpr', None, _("przemienniki.net"), None, None, self.mh), ('qrbook', None, _("RepeaterBook"), None, None, self.mh), ('export_chirp', None, _("CHIRP Native File"), None, None, self.mh), ('export_csv', None, _("CSV File"), None, None, self.mh), ('stock', None, _("Import from stock config"), None, None, self.mh), + ('channel_defaults', None, _("Channel defaults"), None, None, self.mh), ('cancelq', gtk.STOCK_STOP, None, "Escape", None, self.mh), ('help', None, _('Help'), None, None, self.mh), ('about', gtk.STOCK_ABOUT, None, None, None, self.mh), + ('documentation', None, _("Documentation"), None, None, self.mh), ] conf = config.get() re = not conf.get_bool("no_report"); hu = conf.get_bool("hide_unused", "memedit") - ro = conf.get_bool("autorpt", "memedit") dv = conf.get_bool("developer", "state") + st = not conf.get_bool("no_smart_tmode", "memedit") toggles = [\ ('report', None, _("Report statistics"), None, None, self.mh, re), ('hide_unused', None, _("Hide Unused Fields"), None, None, self.mh, hu), - ('autorpt', None, _("Automatic Repeater Offset"), None, None, self.mh, ro), + ('no_smart_tmode', None, _("Smart Tone Modes"), None, None, self.mh, st), ('developer', None, _("Enable Developer Functions"), None, None, self.mh, dv), ] @@ -1539,6 +1678,9 @@ If you think that it is valid, you can select a radio model below to force an op aboutitem = self.menu_uim.get_widget("/MenuBar/help/about") macapp.insert_app_menu_item(aboutitem, 0) + documentationitem = self.menu_uim.get_widget("/MenuBar/help/documentation") + macapp.insert_app_menu_item(documentationitem, 0) + macapp.set_use_quartz_accelerators(False) macapp.ready() @@ -1547,6 +1689,19 @@ If you think that it is valid, you can select a radio model below to force an op def __init__(self, *args, **kwargs): gtk.Window.__init__(self, *args, **kwargs) + def expose(window, event): + allocation = window.get_allocation() + CONF.set_int("window_w", allocation.width, "state") + CONF.set_int("window_h", allocation.height, "state") + self.connect("expose_event", expose) + + def state_change(window, event): + CONF.set_bool( + "window_maximized", + event.new_window_state == gtk.gdk.WINDOW_STATE_MAXIMIZED, + "state") + self.connect("window-state-event", state_change) + d = CONF.get("last_dir", "state") if d and os.path.isdir(d): platform.get_platform().set_last_dir(d) @@ -1579,7 +1734,16 @@ If you think that it is valid, you can select a radio model below to force an op self.add(vbox) - self.set_default_size(800, 600) + try: + width = CONF.get_int("window_w", "state") + height = CONF.get_int("window_h", "state") + except Exception: + width = 800 + height = 600 + + self.set_default_size(width, height) + if CONF.get_bool("window_maximized", "state"): + self.maximize() self.set_title("CHIRP") self.connect("delete_event", self.ev_delete) @@ -1598,10 +1762,6 @@ If you think that it is valid, you can select a radio model below to force an op d.destroy() CONF.set_bool("warned_about_reporting", True) - if not CONF.is_defined("autorpt", "memedit"): - print "autorpt not set et" - CONF.set_bool("autorpt", True, "memedit") - self.update_recent_files() self.update_stock_configs() self.setup_extra_hotkeys() |
