/usr/share/pyshared/chirpui/memdetail.py is in chirp 0.3.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | # Copyright 2012 Dan Smith <dsmith@danplanet.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import gtk
import os
from chirp import chirp_common, settings
from chirpui import miscwidgets, common
POL = ["NN", "NR", "RN", "RR"]
class ValueEditor:
"""Base class"""
def __init__(self, features, memory, errfn, name, data=None):
self._features = features
self._memory = memory
self._errfn = errfn
self._name = name
self._widget = None
self._init(data)
def _init(self, data):
"""Type-specific initialization"""
def get_widget(self):
"""Returns the widget associated with this editor"""
return self._widget
def _mem_value(self):
"""Returns the raw value from the memory associated with this name"""
if self._name.startswith("extra_"):
return self._memory.extra[self._name.split("_", 1)[1]].value
else:
return getattr(self._memory, self._name)
def _get_value(self):
"""Returns the value from the widget that should be set in the memory"""
def update(self):
"""Updates the memory object with self._getvalue()"""
try:
newval = self._get_value()
except ValueError, e:
self._errfn(self._name, str(e))
return str(e)
if self._name.startswith("extra_"):
try:
self._memory.extra[self._name.split("_", 1)[1]].value = newval
except settings.InternalError, e:
self._errfn(self._name, str(e))
return str(e)
else:
try:
setattr(self._memory, self._name, newval)
except chirp_common.ImmutableValueError, e:
if getattr(self._memory, self._name) != self._get_value():
self._errfn(self._name, str(e))
return str(e)
except ValueError, e:
self._errfn(self._name, str(e))
return str(e)
all_msgs = self._features.validate_memory(self._memory)
errs = []
for msg in all_msgs:
if isinstance(msg, chirp_common.ValidationError):
errs.append(str(msg))
if errs:
self._errfn(self._name, errs)
else:
self._errfn(self._name, None)
class StringEditor(ValueEditor):
def _init(self, data):
self._widget = gtk.Entry(int(data))
self._widget.set_text(str(self._mem_value()))
self._widget.connect("changed", self.changed)
def _get_value(self):
return self._widget.get_text()
def changed(self, _widget):
self.update()
class ChoiceEditor(ValueEditor):
def _init(self, data):
self._widget = miscwidgets.make_choice([str(x) for x in data],
False,
str(self._mem_value()))
self._widget.connect("changed", self.changed)
def _get_value(self):
return self._widget.get_active_text()
def changed(self, _widget):
self.update()
class PowerChoiceEditor(ChoiceEditor):
def _init(self, data):
self._choices = data
ChoiceEditor._init(self, data)
def _get_value(self):
choice = self._widget.get_active_text()
for level in self._choices:
if str(level) == choice:
return level
raise Exception("Internal error: power level went missing")
class IntChoiceEditor(ChoiceEditor):
def _get_value(self):
return int(self._widget.get_active_text())
class FloatChoiceEditor(ChoiceEditor):
def _get_value(self):
return float(self._widget.get_active_text())
class FreqEditor(StringEditor):
def _init(self, data):
StringEditor._init(self, 0)
def _mem_value(self):
return chirp_common.format_freq(StringEditor._mem_value(self))
def _get_value(self):
return chirp_common.parse_freq(self._widget.get_text())
class BooleanEditor(ValueEditor):
def _init(self, data):
self._widget = gtk.CheckButton("Enabled")
self._widget.set_active(self._mem_value())
self._widget.connect("toggled", self.toggled)
def _get_value(self):
return self._widget.get_active()
def toggled(self, _widget):
self.update()
class OffsetEditor(FreqEditor):
pass
class MemoryDetailEditor(gtk.Dialog):
"""Detail editor for a memory"""
def _add(self, tab, row, name, editor, labeltxt):
label = gtk.Label(labeltxt)
img = gtk.Image()
label.show()
tab.attach(label, 0, 1, row, row+1)
editor.get_widget().show()
tab.attach(editor.get_widget(), 1, 2, row, row+1)
img.set_size_request(15, -1)
img.show()
tab.attach(img, 2, 3, row, row+1)
self._editors[name] = label, editor, img
def _set_doc(self, name, doc):
label, editor, _img = self._editors[name]
self._tips.set_tip(label, doc)
self._tips.set_tip(editor.get_widget(), doc)
def _make_ui(self):
tab = gtk.Table(len(self._order), 3, False)
self.vbox.pack_start(tab, 1, 1, 1)
tab.show()
row = 0
def _err(name, msg):
try:
_img = self._editors[name][2]
except KeyError:
print self._editors.keys()
if msg is None:
_img.clear()
self._tips.set_tip(_img, "")
else:
_img.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_MENU)
self._tips.set_tip(_img, str(msg))
self._errors[self._order.index(name)] = msg is not None
self.set_response_sensitive(gtk.RESPONSE_OK,
True not in self._errors)
for name in self._order:
labeltxt, editorcls, data = self._elements[name]
editor = editorcls(self._features, self._memory,
_err, name, data)
self._add(tab, row, name, editor, labeltxt)
row += 1
for setting in self._memory.extra:
name = "extra_%s" % setting.get_name()
if isinstance(setting.value,
settings.RadioSettingValueBoolean):
editor = BooleanEditor(self._features, self._memory,
_err, name)
self._add(tab, row, name, editor, setting.get_shortname())
self._set_doc(name, setting.__doc__)
elif isinstance(setting.value,
settings.RadioSettingValueList):
editor = ChoiceEditor(self._features, self._memory,
_err, name, setting.value.get_options())
self._add(tab, row, name, editor, setting.get_shortname())
self._set_doc(name, setting.__doc__)
row += 1
self._order.append(name)
def __init__(self, features, memory, parent=None):
gtk.Dialog.__init__(self,
title=_("Edit Memory"
"#{num}").format(num=memory.number),
flags=gtk.DIALOG_MODAL,
parent=parent,
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
self._tips = gtk.Tooltips()
self._features = features
self._memory = memory
self._editors = {}
self._elements = {
"freq" : (_("Frequency"), FreqEditor, None),
"name" : (_("Name"), StringEditor, features.valid_name_length),
"tmode" : (_("Tone Mode"), ChoiceEditor, features.valid_tmodes),
"rtone" : (_("Tone"), FloatChoiceEditor, chirp_common.TONES),
"ctone" : (_("ToneSql"), FloatChoiceEditor, chirp_common.TONES),
"dtcs" : (_("DTCS Code"), IntChoiceEditor,
chirp_common.DTCS_CODES),
"dtcs_polarity" : (_("DTCS Pol"), ChoiceEditor, POL),
"cross_mode" : (_("Cross mode"),
ChoiceEditor,
features.valid_cross_modes),
"duplex" : (_("Duplex"), ChoiceEditor, features.valid_duplexes),
"offset" : (_("Offset"), OffsetEditor, None),
"mode" : (_("Mode"), ChoiceEditor, features.valid_modes),
"tuning_step" : (_("Tune Step"),
FloatChoiceEditor,
features.valid_tuning_steps),
"skip" : (_("Skip"), ChoiceEditor, features.valid_skips),
"comment" : (_("Comment"), StringEditor, 256),
}
self._order = ["freq", "name", "tmode", "rtone", "ctone", "cross_mode",
"dtcs", "dtcs_polarity", "duplex", "offset",
"mode", "tuning_step", "skip", "comment"]
if self._features.has_rx_dtcs:
self._elements['rx_dtcs'] = (_("RX DTCS Code"),
IntChoiceEditor,
chirp_common.DTCS_CODES)
self._order.insert(self._order.index("dtcs") + 1, "rx_dtcs")
if self._features.valid_power_levels:
self._elements["power"] = (_("Power"),
PowerChoiceEditor,
features.valid_power_levels)
self._order.insert(self._order.index("skip"), "power")
self._make_ui()
self.set_default_size(400, -1)
hide_rules = [
("name", features.has_name),
("tmode", len(features.valid_tmodes) > 0),
("ctone", features.has_ctone),
("dtcs", features.has_dtcs),
("dtcs_polarity", features.has_dtcs_polarity),
("cross_mode", "Cross" in features.valid_tmodes),
("duplex", len(features.valid_duplexes) > 0),
("offset", features.has_offset),
("mode", len(features.valid_modes) > 0),
("tuning_step", features.has_tuning_step),
("skip", len(features.valid_skips) > 0),
("comment", features.has_comment),
]
for name, visible in hide_rules:
if not visible:
for widget in self._editors[name]:
if isinstance(widget, ValueEditor):
widget.get_widget().hide()
else:
widget.hide()
self._errors = [False] * len(self._order)
self.connect("response", self._validate)
def _validate(self, _dialog, response):
if response == gtk.RESPONSE_OK:
all_msgs = self._features.validate_memory(self._memory)
errors = []
for msg in all_msgs:
if isinstance(msg, chirp_common.ValidationError):
errors.append(msg)
if errors:
common.show_error_text(_("Memory validation failed:"),
os.linesep +
os.linesep.join(errors))
self.emit_stop_by_name('response')
def get_memory(self):
self._memory.empty = False
return self._memory
|