Exemplo n.º 1
0
    def run(self):
        r = gtk.Dialog.run(self)
        if r != gtk.RESPONSE_OK:
            return None

        vendor = self.__vend.get_active_text()
        model = self.__modl.get_active_text()

        cs = CloneSettings()
        cs.port = self.__port.get_active_text()
        if model == _("Detect"):
            try:
                cs.radio_class = detect.DETECT_FUNCTIONS[vendor](cs.port)
                if not cs.radio_class:
                    raise Exception(
                        _("Unable to detect radio on {port}").format(
                            port=cs.port))
            except Exception as e:
                d = inputdialog.ExceptionDialog(e)
                d.run()
                d.destroy()
                return None
        else:
            for rclass in directory.DRV_TO_RADIO.values():
                if rclass.MODEL == model:
                    cs.radio_class = rclass
                    break
                alias_match = None
                for alias in rclass.ALIASES:
                    if alias.MODEL == model:
                        alias_match = rclass
                        alias_class = alias
                        break
                if alias_match:

                    class DynamicRadioAlias(rclass):
                        VENDOR = alias.VENDOR
                        MODEL = alias.MODEL
                        VARIANT = alias.VARIANT

                    cs.radio_class = DynamicRadioAlias
                    LOG.debug(
                        'Chose %s alias for %s because model %s selected' %
                        (alias_match, cs.radio_class, model))
                    break
            if not cs.radio_class:
                common.show_error(
                    _("Internal error: Unable to upload to {model}").format(
                        model=model))
                LOG.info(self.__vendors)
                return None

        conf = config.get("state")
        conf.set("last_port", cs.port)
        conf.set("last_vendor", cs.radio_class.VENDOR)
        conf.set("last_model", model)

        return cs
Exemplo n.º 2
0
def should_report():
    if not ENABLED:
        LOG.info("Not reporting due to recent failure")
        return False

    conf = config.get()
    if conf.get_bool("no_report"):
        LOG.info("Reporting disabled")
        return False

    return True
Exemplo n.º 3
0
def should_report():
    if not ENABLED:
        LOG.info("Not reporting due to recent failure")
        return False

    conf = config.get()
    if conf.get_bool("no_report"):
        LOG.info("Reporting disabled")
        return False

    return True
Exemplo n.º 4
0
    def __make_vendor(self, modelbox):
        vendors = collections.defaultdict(list)
        for name, rclass in sorted(directory.DRV_TO_RADIO.items()):
            if not issubclass(rclass, chirp_common.CloneModeRadio) and \
                    not issubclass(rclass, chirp_common.LiveRadio):
                continue

            vendors[rclass.VENDOR].append(rclass)
            for alias in rclass.ALIASES:
                vendors[alias.VENDOR].append(alias)

        self.__vendors = vendors

        conf = config.get("state")
        if not conf.get("last_vendor"):
            conf.set("last_vendor", sorted(vendors.keys())[0])

        last_vendor = conf.get("last_vendor")
        if last_vendor not in list(vendors.keys()):
            last_vendor = list(vendors.keys())[0]

        v = miscwidgets.make_choice(sorted(vendors.keys()), False, last_vendor)

        def _changed(box, vendors, boxes):
            (vendorbox, modelbox) = boxes
            models = vendors[vendorbox.value]

            added_models = []

            model_store = modelbox.get_model()
            model_store.clear()
            for rclass in sorted(models, key=lambda c: c.__name__):
                if rclass.MODEL not in added_models:
                    model_store.append([rclass.MODEL])
                    added_models.append(rclass.MODEL)

            if vendorbox.value in detect.DETECT_FUNCTIONS:
                model_store.append([_("Detect")])
                added_models.insert(0, _("Detect"))

            model_names = [x.MODEL for x in models]
            if conf.get("last_model") in model_names:
                modelbox.value = conf.get("last_model")
            elif added_models:
                modelbox.value = added_models[0]

        v.widget.connect("changed", _changed, vendors, (v, modelbox))
        _changed(v, vendors, (v, modelbox))

        return v
Exemplo n.º 5
0
    def __make_vendor(self, model):
        vendors = {}
        for rclass in sorted(directory.DRV_TO_RADIO.values()):
            if not issubclass(rclass, chirp_common.CloneModeRadio) and \
                    not issubclass(rclass, chirp_common.LiveRadio):
                continue

            if rclass.VENDOR not in vendors:
                vendors[rclass.VENDOR] = []

            vendors[rclass.VENDOR].append(rclass)

        self.__vendors = vendors

        conf = config.get("state")
        if not conf.get("last_vendor"):
            conf.set("last_vendor", sorted(vendors.keys())[0])

        last_vendor = conf.get("last_vendor")
        if last_vendor not in vendors.keys():
            last_vendor = vendors.keys()[0]

        v = miscwidgets.make_choice(sorted(vendors.keys()), False, last_vendor)

        def _changed(box, vendors, model):
            models = vendors[box.get_active_text()]

            added_models = []

            model.get_model().clear()
            for rclass in sorted(models, key=lambda c: c.__name__):
                if rclass.MODEL not in added_models:
                    model.append_text(rclass.MODEL)
                    added_models.append(rclass.MODEL)

            if box.get_active_text() in detect.DETECT_FUNCTIONS:
                model.insert_text(0, _("Detect"))
                added_models.insert(0, _("Detect"))

            model_names = [x.MODEL for x in models]
            if conf.get("last_model") in model_names:
                model.set_active(added_models.index(conf.get("last_model")))
            else:
                model.set_active(0)

        v.connect("changed", _changed, vendors, model)
        _changed(v, vendors, model)

        return v
Exemplo n.º 6
0
    def __make_port(self, port):
        conf = config.get("state")

        ports = platform.get_platform().list_serial_ports()
        if not port:
            if conf.get("last_port"):
                port = conf.get("last_port")
            elif ports:
                port = ports[0]
            else:
                port = ""
            if port not in ports:
                ports.insert(0, port)

        return miscwidgets.make_choice(ports, True, port)
Exemplo n.º 7
0
    def __make_port(self, port):
        conf = config.get("state")

        ports = platform.get_platform().list_serial_ports()
        if not port:
            if conf.get("last_port"):
                port = conf.get("last_port")
            elif ports:
                port = ports[0]
            else:
                port = ""
            if port not in ports:
                ports.insert(0, port)

        return miscwidgets.make_choice(ports, True, port)
Exemplo n.º 8
0
    def __make_vendor(self, model):
        vendors = collections.defaultdict(list)
        for rclass in sorted(directory.DRV_TO_RADIO.values()):
            if not issubclass(rclass, chirp_common.CloneModeRadio) and \
                    not issubclass(rclass, chirp_common.LiveRadio):
                continue

            vendors[rclass.VENDOR].append(rclass)
            for alias in rclass.ALIASES:
                vendors[alias.VENDOR].append(alias)

        self.__vendors = vendors

        conf = config.get("state")
        if not conf.get("last_vendor"):
            conf.set("last_vendor", sorted(vendors.keys())[0])

        last_vendor = conf.get("last_vendor")
        if last_vendor not in vendors.keys():
            last_vendor = vendors.keys()[0]

        v = miscwidgets.make_choice(sorted(vendors.keys()), False, last_vendor)

        def _changed(box, vendors, model):
            models = vendors[box.get_active_text()]

            added_models = []

            model.get_model().clear()
            for rclass in sorted(models, key=lambda c: c.__name__):
                if rclass.MODEL not in added_models:
                    model.append_text(rclass.MODEL)
                    added_models.append(rclass.MODEL)

            if box.get_active_text() in detect.DETECT_FUNCTIONS:
                model.insert_text(0, _("Detect"))
                added_models.insert(0, _("Detect"))

            model_names = [x.MODEL for x in models]
            if conf.get("last_model") in model_names:
                model.set_active(added_models.index(conf.get("last_model")))
            else:
                model.set_active(0)

        v.connect("changed", _changed, vendors, model)
        _changed(v, vendors, model)

        return v
Exemplo n.º 9
0
                        MODEL = alias.MODEL
                        VARIANT = alias.VARIANT

                    cs.radio_class = DynamicRadioAlias
                    LOG.debug(
                        'Chose %s alias for %s because model %s selected' %
                        (alias_match, cs.radio_class, model))
                    break
            if not cs.radio_class:
                common.show_error(
                    _("Internal error: Unable to upload to {model}").format(
                        model=model))
                LOG.info(self.__vendors)
                return None

        conf = config.get("state")
        conf.set("last_port", cs.port)
        conf.set("last_vendor", cs.radio_class.VENDOR)
        conf.set("last_model", model)

        return cs


class CloneCancelledException(Exception):
    pass


class CloneThread(threading.Thread):
    def __status(self, status):
        gobject.idle_add(self.__progw.status, status)
Exemplo n.º 10
0
    def __init__(self,
                 source,
                 parent_window=None,
                 filename=None,
                 tempname=None):
        gtk.VBox.__init__(self, True, 0)

        self.parent_window = parent_window

        if isinstance(source, str):
            self.filename = source
            self.radio = directory.get_radio_by_image(self.filename)
        elif isinstance(source, chirp_common.Radio):
            self.radio = source
            self.filename = filename or tempname or source.VARIANT
        else:
            raise Exception("Unknown source type")

        rthread = common.RadioThread(self.radio)
        rthread.setDaemon(True)
        rthread.start()

        rthread.connect("status", lambda e, m: self.emit("status", m))

        self.tabs = gtk.Notebook()
        self.tabs.connect("switch-page", self.tab_selected)
        self.tabs.set_tab_pos(gtk.POS_LEFT)

        self.editors = {}

        self.rf = self.radio.get_features()
        if self.rf.has_sub_devices:
            devices = self.radio.get_sub_devices()
        else:
            devices = [self.radio]

        index = 0
        for device in devices:
            devrthread = common.RadioThread(device, rthread)
            devrthread.setDaemon(True)
            devrthread.start()
            self._make_device_editors(device, devrthread, index)
            index += 1

        if self.rf.has_settings:
            editor = settingsedit.SettingsEditor(rthread)
            self.tabs.append_page(editor.root, gtk.Label(_("Settings")))
            editor.root.show()
            editor.connect("changed", self.editor_changed)
            self.editors["settings"] = editor

        conf = config.get()
        if (hasattr(self.rthread.radio, '_memobj')
                and conf.get_bool("developer", "state")):
            editor = radiobrowser.RadioBrowser(self.rthread)
            lab = gtk.Label(_("Browser"))
            self.tabs.append_page(editor.root, lab)
            editor.connect("changed", self.editor_changed)
            self.editors["browser"] = editor

        self.pack_start(self.tabs)
        self.tabs.show()

        self.label = self.text_label = None
        self.make_label()
        self.modified = (tempname is not None)
        if tempname:
            self.filename = tempname
        self.update_tab()
Exemplo n.º 11
0
import wx
import wx.aui
import wx.lib.newevent

from chirp import directory
from chirp.ui import config
from chirp.wxui import common
from chirp.wxui import clone
from chirp.wxui import developer
from chirp.wxui import memedit
from chirp.wxui import settingsedit
from chirp import CHIRP_VERSION

EditorSetChanged, EVT_EDITORSET_CHANGED = wx.lib.newevent.NewCommandEvent()
CONF = config.get()
LOG = logging.getLogger(__name__)


class ChirpEditorSet(wx.Panel):
    def __init__(self, radio, filename, *a, **k):
        super(ChirpEditorSet, self).__init__(*a, **k)
        self._radio = radio
        if filename is None:
            filename = '%s.%s' % (self.default_filename, radio.FILE_EXTENSION)
        self._filename = filename
        self._modified = not os.path.exists(filename)

        self._editors = wx.Notebook(self, style=wx.NB_LEFT)

        self._editors.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING,
Exemplo n.º 12
0
    def __init__(self, source, parent_window=None,
                 filename=None, tempname=None):
        gtk.VBox.__init__(self, True, 0)

        self.parent_window = parent_window

        if isinstance(source, str):
            self.filename = source
            self.radio = directory.get_radio_by_image(self.filename)
        elif isinstance(source, chirp_common.Radio):
            self.radio = source
            self.filename = filename or tempname or source.VARIANT
        else:
            raise Exception("Unknown source type")

        rthread = common.RadioThread(self.radio)
        rthread.setDaemon(True)
        rthread.start()

        rthread.connect("status", lambda e, m: self.emit("status", m))

        self.tabs = gtk.Notebook()
        self.tabs.connect("switch-page", self.tab_selected)
        self.tabs.set_tab_pos(gtk.POS_LEFT)

        self.editors = {}

        self.rf = self.radio.get_features()
        if self.rf.has_sub_devices:
            devices = self.radio.get_sub_devices()
        else:
            devices = [self.radio]

        index = 0
        for device in devices:
            devrthread = common.RadioThread(device, rthread)
            devrthread.setDaemon(True)
            devrthread.start()
            self._make_device_editors(device, devrthread, index)
            index += 1

        if self.rf.has_settings:
            editor = settingsedit.SettingsEditor(rthread)
            self.tabs.append_page(editor.root, gtk.Label(_("Settings")))
            editor.root.show()
            editor.connect("changed", self.editor_changed)
            self.editors["settings"] = editor

        conf = config.get()
        if (hasattr(self.rthread.radio, '_memobj') and
                conf.get_bool("developer", "state")):
            editor = radiobrowser.RadioBrowser(self.rthread)
            lab = gtk.Label(_("Browser"))
            self.tabs.append_page(editor.root, lab)
            editor.connect("changed", self.editor_changed)
            self.editors["browser"] = editor

        self.pack_start(self.tabs)
        self.tabs.show()

        self.label = self.text_label = None
        self.make_label()
        self.modified = (tempname is not None)
        if tempname:
            self.filename = tempname
        self.update_tab()
Exemplo n.º 13
0
                        alias_match = rclass
                        break
                if alias_match:
                    cs.radio_class = rclass
                    LOG.debug(
                        'Chose %s alias for %s because model %s selected' % (
                            alias_match, cs.radio_class, model))
                    break
            if not cs.radio_class:
                common.show_error(
                    _("Internal error: Unable to upload to {model}").format(
                        model=model))
                LOG.info(self.__vendors)
                return None

        conf = config.get("state")
        conf.set("last_port", cs.port)
        conf.set("last_vendor", cs.radio_class.VENDOR)
        conf.set("last_model", model)

        return cs


class CloneCancelledException(Exception):
    pass


class CloneThread(threading.Thread):
    def __status(self, status):
        gobject.idle_add(self.__progw.status, status)
Exemplo n.º 14
0
import gtk
import gobject
import pango
import re
import os
import logging

from chirp import bitwise
from chirp.ui import common, config

LOG = logging.getLogger(__name__)

CONF = config.get()


def do_insert_line_with_tags(b, line):
    def i(text, *tags):
        b.insert_with_tags_by_name(b.get_end_iter(), text, *tags)

    def ident(name):
        if "unknown" in name:
            i(name, "grey", "bold")
        else:
            i(name, "bold")

    def nonzero(value):
        i(value, "red", "bold")

    def foo(value):
        i(value, "blue", "bold")