[chirp_devel] [PATCH 08/12] Fix style issues (4/4) (#2355)
Zach Welch
Fri Feb 27 02:24:45 PST 2015
# HG changeset patch
# User Zach Welch <zach at mandolincreekfarm.com>
# Fake Node ID 2c6f7fe587c81205d06c1522f68246cf7299349e
Fix style issues (4/4) (#2355)
More low-hanging style issues.
diff --git a/chirp/bitwise_grammar.py b/chirp/bitwise_grammar.py
index fe81b42..b6eb20c 100644
--- a/chirp/bitwise_grammar.py
+++ b/chirp/bitwise_grammar.py
@@ -21,63 +21,83 @@ TYPES = ["bit", "u8", "u16", "ul16", "u24", "ul24", "u32", "ul32",
"lbcd", "bbcd"]
DIRECTIVES = ["seekto", "seek", "printoffset"]
+
def string():
return re.compile(r"\"[^\"]*\"")
+
def symbol():
return re.compile(r"\w+")
+
def count():
return re.compile(r"([1-9][0-9]*|0x[0-9a-fA-F]+)")
+
def bitdef():
return symbol, ":", count, -1
+
def _bitdeflist():
return bitdef, -1, (",", bitdef)
+
def bitfield():
return -2, _bitdeflist
+
def array():
return symbol, '[', count, ']'
+
def _typedef():
return re.compile(r"(%s)" % "|".join(TYPES))
+
def definition():
return _typedef, [array, bitfield, symbol], ";"
+
def seekto():
return keyword("seekto"), count
+
def seek():
return keyword("seek"), count
+
def printoffset():
return keyword("printoffset"), string
+
def directive():
return "#", [seekto, seek, printoffset], ";"
+
def _block_inner():
return -2, [definition, struct, directive]
+
def _block():
return "{", _block_inner, "}"
+
def struct_defn():
return symbol, _block
+
def struct_decl():
return [symbol, _block], [array, symbol]
+
def struct():
return keyword("struct"), [struct_defn, struct_decl], ";"
+
def _language():
return _block_inner
+
def parse(data):
lines = data.split("\n")
for index, line in enumerate(lines):
diff --git a/chirp/errors.py b/chirp/errors.py
index 3fe1027..f4d9324 100644
--- a/chirp/errors.py
+++ b/chirp/errors.py
@@ -13,26 +13,32 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
class InvalidDataError(Exception):
"""The radio driver encountered some invalid data"""
pass
+
class InvalidValueError(Exception):
"""An invalid value for a given parameter was used"""
pass
+
class InvalidMemoryLocation(Exception):
"""The requested memory location does not exist"""
pass
+
class RadioError(Exception):
"""An error occurred while talking to the radio"""
pass
+
class UnsupportedToneError(Exception):
"""The radio does not support the specified tone value"""
pass
+
class ImageDetectFailed(Exception):
"""The driver for the supplied image could not be determined"""
pass
diff --git a/chirp/generic_csv.py b/chirp/generic_csv.py
index bf7ee1e..66a6005 100644
--- a/chirp/generic_csv.py
+++ b/chirp/generic_csv.py
@@ -18,10 +18,12 @@ import csv
from chirp import chirp_common, errors, directory
+
class OmittedHeaderError(Exception):
"""Internal exception to signal that a column has been omitted"""
pass
+
def get_datum_by_header(headers, data, header):
"""Return the column corresponding to @headers[@header] from @data"""
if header not in headers:
@@ -30,8 +32,9 @@ def get_datum_by_header(headers, data, header):
try:
return data[headers.index(header)]
except IndexError:
- raise OmittedHeaderError("Header %s not provided on this line" % \
- header)
+ raise OmittedHeaderError("Header %s not provided on this line" %
+ header)
+
def write_memory(writer, mem):
"""Write @mem using @writer if not empty"""
@@ -39,6 +42,7 @@ def write_memory(writer, mem):
return
writer.writerow(mem.to_csv())
+
@directory.register
class CSVRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
"""A driver for Generic CSV files"""
@@ -47,23 +51,23 @@ class CSVRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
FILE_EXTENSION = "csv"
ATTR_MAP = {
- "Location" : (int, "number"),
- "Name" : (str, "name"),
- "Frequency" : (chirp_common.parse_freq, "freq"),
- "Duplex" : (str, "duplex"),
- "Offset" : (chirp_common.parse_freq, "offset"),
- "Tone" : (str, "tmode"),
- "rToneFreq" : (float, "rtone"),
- "cToneFreq" : (float, "ctone"),
- "DtcsCode" : (int, "dtcs"),
- "DtcsPolarity" : (str, "dtcs_polarity"),
- "Mode" : (str, "mode"),
- "TStep" : (float, "tuning_step"),
- "Skip" : (str, "skip"),
- "URCALL" : (str, "dv_urcall"),
- "RPT1CALL" : (str, "dv_rpt1call"),
- "RPT2CALL" : (str, "dv_rpt2call"),
- "Comment" : (str, "comment"),
+ "Location": (int, "number"),
+ "Name": (str, "name"),
+ "Frequency": (chirp_common.parse_freq, "freq"),
+ "Duplex": (str, "duplex"),
+ "Offset": (chirp_common.parse_freq, "offset"),
+ "Tone": (str, "tmode"),
+ "rToneFreq": (float, "rtone"),
+ "cToneFreq": (float, "ctone"),
+ "DtcsCode": (int, "dtcs"),
+ "DtcsPolarity": (str, "dtcs_polarity"),
+ "Mode": (str, "mode"),
+ "TStep": (float, "tuning_step"),
+ "Skip": (str, "skip"),
+ "URCALL": (str, "dv_urcall"),
+ "RPT1CALL": (str, "dv_rpt1call"),
+ "RPT2CALL": (str, "dv_rpt2call"),
+ "Comment": (str, "comment"),
}
def _blank(self):
@@ -118,7 +122,7 @@ class CSVRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
fname = "_clean_%s" % attr
if hasattr(self, fname):
mem = getattr(self, fname)(headers, line, mem)
-
+
return mem
def _clean_tmode(self, headers, line, mem):
@@ -189,7 +193,8 @@ class CSVRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
print "Line %i has %i columns, expected %i" % (lineno,
len(line),
len(header))
- self.errors.append("Column number mismatch on line %i" % lineno)
+ self.errors.append("Column number mismatch on line %i" %
+ lineno)
continue
try:
@@ -247,7 +252,7 @@ class CSVRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
return
delta += 1
-
+
for i in range(len(self.memories), len(self.memories) + delta + 1):
mem = chirp_common.Memory()
mem.empty = True
@@ -313,7 +318,7 @@ class CommanderCSVRadio(CSVRadio):
def _clean_duplex(self, headers, line, mem):
try:
txfreq = chirp_common.parse_freq(
- get_datum_by_header(headers, line, "TX Freq"))
+ get_datum_by_header(headers, line, "TX Freq"))
except ValueError:
mem.duplex = "off"
return mem
@@ -325,7 +330,7 @@ class CommanderCSVRadio(CSVRadio):
mem.offset = txfreq
return mem
-
+
def _clean_tmode(self, headers, line, mem):
rtone = get_datum_by_header(headers, line, "Encode")
ctone = get_datum_by_header(headers, line, "Decode")
@@ -356,7 +361,8 @@ class CommanderCSVRadio(CSVRadio):
filedata.startswith("Name,RX Freq,TX Freq,Decode,Encode,TX Pwr,"
"Scan,TX Dev,Busy Lck,Group/Notes") or \
filedata.startswith('"#","Name","RX Freq","TX Freq","Decode",'
- '"Encode","TX Pwr","Scan","TX Dev","Busy Lck","Group/Notes"')
+ '"Encode","TX Pwr","Scan","TX Dev",'
+ '"Busy Lck","Group/Notes"')
@directory.register
@@ -372,7 +378,7 @@ class RTCSVRadio(CSVRadio):
"Simplex": "",
"Split": "split",
}
-
+
SKIP_MAP = {
"Off": "",
"On": "S",
@@ -391,19 +397,25 @@ class RTCSVRadio(CSVRadio):
}
ATTR_MAP = {
- "Channel Number": (int, "number"),
- "Receive Frequency":(chirp_common.parse_freq, "freq"),
- "Offset Frequency": (chirp_common.parse_freq, "offset"),
- "Offset Direction": (lambda v: RTCSVRadio.DUPLEX_MAP.get(v, v), "duplex"),
- "Operating Mode": (str, "mode"),
- "Name": (str, "name"),
- "Tone Mode": (lambda v: RTCSVRadio.TMODE_MAP.get(v, v), "tmode"),
- "CTCSS": (lambda v: float(v.split(" ")[0]), "rtone"),
- "DCS": (int, "dtcs"),
- "Skip": (lambda v: RTCSVRadio.SKIP_MAP.get(v, v), "skip"),
- "Step": (lambda v: float(v.split(" ")[0]), "tuning_step"),
- "Mask": (lambda v: RTCSVRadio.BOOL_MAP.get(v, v), "empty",),
- "Comment": (str, "comment"),
+ "Channel Number": (int, "number"),
+ "Receive Frequency": (chirp_common.parse_freq, "freq"),
+ "Offset Frequency": (chirp_common.parse_freq, "offset"),
+ "Offset Direction": (lambda v:
+ RTCSVRadio.DUPLEX_MAP.get(v, v), "duplex"),
+ "Operating Mode": (str, "mode"),
+ "Name": (str, "name"),
+ "Tone Mode": (lambda v:
+ RTCSVRadio.TMODE_MAP.get(v, v), "tmode"),
+ "CTCSS": (lambda v:
+ float(v.split(" ")[0]), "rtone"),
+ "DCS": (int, "dtcs"),
+ "Skip": (lambda v:
+ RTCSVRadio.SKIP_MAP.get(v, v), "skip"),
+ "Step": (lambda v:
+ float(v.split(" ")[0]), "tuning_step"),
+ "Mask": (lambda v:
+ RTCSVRadio.BOOL_MAP.get(v, v), "empty",),
+ "Comment": (str, "comment"),
}
def _clean_duplex(self, headers, line, mem):
@@ -441,5 +453,6 @@ class RTCSVRadio(CSVRadio):
# consistent across radio models.
return filename.lower().endswith("." + cls.FILE_EXTENSION) and \
filedata.startswith("Channel Number,Receive Frequency,"
- "Transmit Frequency,Offset Frequency,Offset Direction,"
- "Operating Mode,Name,Tone Mode,CTCSS,DCS")
+ "Transmit Frequency,Offset Frequency,"
+ "Offset Direction,Operating Mode,"
+ "Name,Tone Mode,CTCSS,DCS")
diff --git a/chirp/import_logic.py b/chirp/import_logic.py
index b787378..04f81ba 100644
--- a/chirp/import_logic.py
+++ b/chirp/import_logic.py
@@ -15,14 +15,17 @@
from chirp import chirp_common, errors
+
class ImportError(Exception):
"""An import error"""
pass
+
class DestNotCompatible(ImportError):
"""Memory is not compatible with the destination radio"""
pass
+
def ensure_has_calls(radio, memory):
"""Make sure @radio has the necessary D-STAR callsigns for @memory"""
ulist_changed = rlist_changed = False
@@ -62,10 +65,12 @@ def ensure_has_calls(radio, memory):
if rlist_changed:
radio.set_repeater_call_list(rlist)
+
# Filter the name according to the destination's rules
def _import_name(dst_radio, _srcrf, mem):
mem.name = dst_radio.filter_name(mem.name)
+
def _import_power(dst_radio, _srcrf, mem):
levels = dst_radio.get_features().valid_power_levels
if not levels:
@@ -75,7 +80,7 @@ def _import_power(dst_radio, _srcrf, mem):
# Source radio did not support power levels, so choose the
# first (highest) level from the destination radio.
mem.power = levels[0]
- return
+ return
# If both radios support power levels, we need to decide how to
# convert the source power level to a valid one for the destination
@@ -86,6 +91,7 @@ def _import_power(dst_radio, _srcrf, mem):
deltas = [abs(mem.power - power) for power in levels]
mem.power = levels[deltas.index(min(deltas))]
+
def _import_tone(dst_radio, srcrf, mem):
dstrf = dst_radio.get_features()
@@ -104,6 +110,7 @@ def _import_tone(dst_radio, srcrf, mem):
if mem.tmode == "TSQL":
mem.ctone = mem.rtone
+
def _import_dtcs(dst_radio, srcrf, mem):
dstrf = dst_radio.get_features()
@@ -122,6 +129,7 @@ def _import_dtcs(dst_radio, srcrf, mem):
if mem.tmode == "DTCS":
mem.rx_dtcs = mem.dtcs
+
def _guess_mode_by_frequency(freq):
ranges = [
(0, 136000000, "AM"),
@@ -135,6 +143,7 @@ def _guess_mode_by_frequency(freq):
# If we don't know, assume FM
return "FM"
+
def _import_mode(dst_radio, srcrf, mem):
dstrf = dst_radio.get_features()
@@ -148,9 +157,10 @@ def _import_mode(dst_radio, srcrf, mem):
raise DestNotCompatible("Destination does not support %s" % mode)
mem.mode = mode
+
def _make_offset_with_split(rxfreq, txfreq):
offset = txfreq - rxfreq
-
+
if offset == 0:
return "", offset
elif offset > 0:
@@ -158,24 +168,25 @@ def _make_offset_with_split(rxfreq, txfreq):
elif offset < 0:
return "-", offset * -1
+
def _import_duplex(dst_radio, srcrf, mem):
dstrf = dst_radio.get_features()
# If a radio does not support odd split, we can use an equivalent offset
if mem.duplex == "split" and mem.duplex not in dstrf.valid_duplexes:
mem.duplex, mem.offset = _make_offset_with_split(mem.freq, mem.offset)
-
+
# Enforce maximum offset
- ranges = [
- ( 0, 500000000, 15000000),
- (500000000, 3000000000, 50000000),
- ]
+ ranges = [(0, 500000000, 15000000),
+ (500000000, 3000000000, 50000000),
+ ]
for lo, hi, limit in ranges:
if lo < mem.freq <= hi:
if abs(mem.offset) > limit:
raise DestNotCompatible("Unable to create import memory: "
"offset is abnormally large.")
+
def import_mem(dst_radio, src_features, src_mem, overrides={}):
"""Perform import logic to create a destination memory from
src_mem that will be compatible with @dst_radio"""
@@ -183,7 +194,8 @@ def import_mem(dst_radio, src_features, src_mem, overrides={}):
if isinstance(src_mem, chirp_common.DVMemory):
if not isinstance(dst_radio, chirp_common.IcomDstarSupport):
- raise DestNotCompatible("Destination radio does not support D-STAR")
+ raise DestNotCompatible(
+ "Destination radio does not support D-STAR")
if dst_rf.requires_call_lists:
ensure_has_calls(dst_radio, src_mem)
@@ -206,17 +218,19 @@ def import_mem(dst_radio, src_features, src_mem, overrides={}):
msgs = dst_radio.validate_memory(dst_mem)
errs = [x for x in msgs if isinstance(x, chirp_common.ValidationError)]
if errs:
- raise DestNotCompatible("Unable to create import memory: %s" %\
- ", ".join(errs))
+ raise DestNotCompatible("Unable to create import memory: %s" %
+ ", ".join(errs))
return dst_mem
+
def _get_bank_model(radio):
for model in radio.get_mapping_models():
if isinstance(model, chirp_common.BankModel):
return model
return None
+
def import_bank(dst_radio, src_radio, dst_mem, src_mem):
"""Attempt to set the same banks for @mem(by index) in @dst_radio that
it has in @src_radio"""
diff --git a/chirp/platform.py b/chirp/platform.py
index 313dfbd..5429ebc 100644
--- a/chirp/platform.py
+++ b/chirp/platform.py
@@ -19,6 +19,7 @@ import glob
import re
from subprocess import Popen
+
def win32_comports_bruteforce():
import win32file
import win32con
@@ -36,7 +37,7 @@ def win32_comports_bruteforce():
win32con.OPEN_EXISTING,
0,
None)
- ports.append((portname,"Unknown","Serial"))
+ ports.append((portname, "Unknown", "Serial"))
win32file.CloseHandle(port)
port = None
except Exception, e:
@@ -44,19 +45,23 @@ def win32_comports_bruteforce():
return ports
+
try:
from serial.tools.list_ports import comports
except:
comports = win32_comports_bruteforce
+
def _find_me():
return sys.modules["chirp.platform"].__file__
+
def natural_sorted(l):
convert = lambda text: int(text) if text.isdigit() else text.lower()
natural_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
return sorted(l, key=natural_key)
+
class Platform:
"""Base class for platform-specific functions"""
@@ -229,6 +234,7 @@ class Platform:
return os.path.dirname(os.path.abspath(os.path.join(_find_me(),
"..")))
+
def _unix_editor():
macos_textedit = "/Applications/TextEdit.app/Contents/MacOS/TextEdit"
@@ -237,23 +243,24 @@ def _unix_editor():
else:
return "gedit"
+
class UnixPlatform(Platform):
"""A platform module suitable for UNIX systems"""
def __init__(self, basepath):
if not basepath:
basepath = os.path.abspath(os.path.join(self.default_dir(),
".chirp"))
-
+
if not os.path.isdir(basepath):
os.mkdir(basepath)
Platform.__init__(self, basepath)
- # This is a hack that needs to be properly fixed by importing the
- # latest changes to this module from d-rats. In the interest of
- # time, however, I'll throw it here
+ # This is a hack that needs to be properly fixed by importing the
+ # latest changes to this module from d-rats. In the interest of
+ # time, however, I'll throw it here
if sys.platform == "darwin":
- if not os.environ.has_key("DISPLAY"):
+ if "DISPLAY" not in os.environ:
print "Forcing DISPLAY for MacOS"
os.environ["DISPLAY"] = ":0"
@@ -302,6 +309,7 @@ class UnixPlatform(Platform):
return ver
+
class Win32Platform(Platform):
"""A platform module suitable for Windows systems"""
def __init__(self, basepath=None):
@@ -362,7 +370,7 @@ class Win32Platform(Platform):
def gui_save_file(self, start_dir=None, default_name=None, types=[]):
import win32gui
import win32api
-
+
(pform, _, _, _, _) = win32api.GetVersionEx()
typestrs = ""
@@ -405,14 +413,16 @@ class Win32Platform(Platform):
def os_version_string(self):
import win32api
- vers = { 4: "Win2k",
- 5: "WinXP",
- 6: "WinVista/7",
- }
+ vers = {4: "Win2k",
+ 5: "WinXP",
+ 6: "WinVista/7",
+ }
(pform, sub, build, _, _) = win32api.GetVersionEx()
- return vers.get(pform, "Win32 (Unknown %i.%i:%i)" % (pform, sub, build))
+ return vers.get(pform,
+ "Win32 (Unknown %i.%i:%i)" % (pform, sub, build))
+
def _get_platform(basepath):
if os.name == "nt":
@@ -421,6 +431,8 @@ def _get_platform(basepath):
return UnixPlatform(basepath)
PLATFORM = None
+
+
def get_platform(basepath=None):
"""Return the platform singleton"""
global PLATFORM
@@ -430,6 +442,7 @@ def get_platform(basepath=None):
return PLATFORM
+
def _do_test():
__pform = get_platform()
diff --git a/chirp/xml_ll.py b/chirp/xml_ll.py
index 28ec333..8713507 100644
--- a/chirp/xml_ll.py
+++ b/chirp/xml_ll.py
@@ -17,6 +17,7 @@ import re
from chirp import chirp_common, errors
+
def get_memory(doc, number):
"""Extract a Memory object from @doc"""
ctx = doc.xpathNewContext()
@@ -59,7 +60,7 @@ def get_memory(doc, number):
mem.ctone = float(_get("/squelch[@id='ctone']/tone/text()"))
mem.dtcs = int(_get("/squelch[@id='dtcs']/code/text()"), 10)
mem.dtcs_polarity = _get("/squelch[@id='dtcs']/polarity/text()")
-
+
try:
sql = _get("/squelchSetting/text()")
if sql == "rtone":
@@ -73,7 +74,7 @@ def get_memory(doc, number):
except IndexError:
mem.tmode = ""
- dmap = {"positive" : "+", "negative" : "-", "none" : ""}
+ dmap = {"positive": "+", "negative": "-", "none": ""}
dupx = _get("/duplex/text()")
mem.duplex = dmap.get(dupx, "")
@@ -97,6 +98,7 @@ def get_memory(doc, number):
return mem
+
def set_memory(doc, mem):
"""Set @mem in @doc"""
ctx = doc.xpathNewContext()
@@ -121,11 +123,11 @@ def set_memory(doc, mem):
lname_filter = "[^.A-Za-z0-9/ >-]"
lname = memnode.newChild(None, "longName", None)
lname.addContent(re.sub(lname_filter, "", mem.name[:16]))
-
+
freq = memnode.newChild(None, "frequency", None)
freq.newProp("units", "MHz")
freq.addContent(chirp_common.format_freq(mem.freq))
-
+
rtone = memnode.newChild(None, "squelch", None)
rtone.newProp("id", "rtone")
rtone.newProp("type", "repeater")
@@ -154,7 +156,7 @@ def set_memory(doc, mem):
elif mem.tmode == "DTCS":
sset.addContent("dtcs")
- dmap = {"+" : "positive", "-" : "negative", "" : "none"}
+ dmap = {"+": "positive", "-": "negative", "": "none"}
dupx = memnode.newChild(None, "duplex", None)
dupx.addContent(dmap[mem.duplex])
@@ -168,7 +170,7 @@ def set_memory(doc, mem):
step = memnode.newChild(None, "tuningStep", None)
step.newProp("units", "kHz")
step.addContent("%.5f" % mem.tuning_step)
-
+
if mem.skip:
skip = memnode.newChild(None, "skip", None)
skip.addContent(mem.skip)
@@ -197,6 +199,7 @@ def set_memory(doc, mem):
dc = dv.newChild(None, "digitalCode", None)
dc.addContent(str(mem.dv_code))
+
def del_memory(doc, number):
"""Remove memory @number from @doc"""
path = "//radio/memories/memory[@location=%i]" % number
@@ -205,13 +208,15 @@ def del_memory(doc, number):
for field in fields:
field.unlinkNode()
-
+
+
def _get_bank(node):
bank = chirp_common.Bank(node.prop("label"))
ident = int(node.prop("id"))
return ident, bank
+
def get_banks(doc):
"""Return a list of banks from @doc"""
path = "//radio/banks/bank"
@@ -229,6 +234,7 @@ def get_banks(doc):
return [x[1] for x in banks]
+
def set_banks(doc, banklist):
"""Set the list of banks in @doc"""
path = "//radio/banks/bank"
diff --git a/chirpui/bankedit.py b/chirpui/bankedit.py
index 19ea3e3..009f726 100644
--- a/chirpui/bankedit.py
+++ b/chirpui/bankedit.py
@@ -22,6 +22,7 @@ from gobject import TYPE_INT, TYPE_STRING, TYPE_BOOLEAN
from chirp import chirp_common
from chirpui import common, miscwidgets
+
class MappingNamesJob(common.RadioJob):
def __init__(self, model, editor, cb):
common.RadioJob.__init__(self, cb, None)
@@ -37,6 +38,7 @@ class MappingNamesJob(common.RadioJob):
gobject.idle_add(self.cb, *self.cb_args)
+
class MappingNameEditor(common.Editor):
def refresh(self):
def got_mappings():
@@ -117,6 +119,7 @@ class MappingNameEditor(common.Editor):
def mappings_changed(self):
pass
+
class MemoryMappingsJob(common.RadioJob):
def __init__(self, model, cb, number):
common.RadioJob.__init__(self, cb, None)
@@ -137,6 +140,7 @@ class MemoryMappingsJob(common.RadioJob):
indexes.append(self.__model.get_memory_index(mem, mapping))
self.cb(mem, mappings, indexes, *self.cb_args)
+
class MappingMembershipEditor(common.Editor):
def _number_to_path(self, number):
return (number - self._rf.memory_bounds[0],)
@@ -160,9 +164,9 @@ class MappingMembershipEditor(common.Editor):
indexes.sort()
for i in range(0, num_indexes):
if i not in indexes:
- return i + index_bounds[0] # In case not zero-origin index
+ return i + index_bounds[0] # In case not zero-origin index
- return 0 # If the mapping is full, just wrap around!
+ return 0 # If the mapping is full, just wrap around!
def _toggled_cb(self, rend, path, colnum):
try:
@@ -233,7 +237,7 @@ class MappingMembershipEditor(common.Editor):
def _index_edited_cb(self, rend, path, new):
loc, = self._store.get(self._store.get_iter(path), self.C_LOC)
-
+
def refresh_memory(*args):
self.refresh_memory(loc)
@@ -261,7 +265,7 @@ class MappingMembershipEditor(common.Editor):
job = common.RadioJob(get_mapping, "get_memory", loc)
job.set_desc(_("Getting memory {num}").format(num=loc))
self.rthread.submit(job)
-
+
def __init__(self, rthread, editorset, model):
super(MappingMembershipEditor, self).__init__(rthread)
@@ -278,16 +282,16 @@ class MappingMembershipEditor(common.Editor):
]
self._cols = [
- ("_filled", TYPE_BOOLEAN, None, ),
+ ("_filled", TYPE_BOOLEAN, None, ),
] + self._view_cols
self.C_FILLED = 0
- self.C_LOC = 1
- self.C_FREQ = 2
- self.C_NAME = 3
- self.C_INDEX = 4
- self.C_MAPPINGS = 5 # and beyond
-
+ self.C_LOC = 1
+ self.C_FREQ = 2
+ self.C_NAME = 3
+ self.C_INDEX = 4
+ self.C_MAPPINGS = 5 # and beyond
+
cols = list(self._cols)
self._index_cache = []
@@ -296,7 +300,7 @@ class MappingMembershipEditor(common.Editor):
label = "%s %i" % (self._type, (i+1))
cols.append((label, TYPE_BOOLEAN, gtk.CellRendererToggle))
- self._store = gtk.ListStore(*tuple([y for x,y,z in cols]))
+ self._store = gtk.ListStore(*tuple([y for x, y, z in cols]))
self._view = gtk.TreeView(self._store)
is_indexed = isinstance(self._model,
@@ -361,7 +365,7 @@ class MappingMembershipEditor(common.Editor):
for i in range(0, len(self.mappings)):
row.append(i + len(self._cols))
row.append(self.mappings[i][0] in mappings)
-
+
self._store.set(iter, *tuple(row))
job = MemoryMappingsJob(self._model, got_mem, number)
@@ -374,8 +378,7 @@ class MappingMembershipEditor(common.Editor):
(min, max) = self._rf.memory_bounds
for i in range(min, max+1):
self.refresh_memory(i)
- print "Got all %s info in %s" % (self._type,
- (time.time() - start))
+ print "Got all %s info in %s" % (self._type, (time.time() - start))
def refresh_mappings(self, and_memories=False):
def got_mappings():
diff --git a/chirpui/radiobrowser.py b/chirpui/radiobrowser.py
index a11d810..14673f9 100644
--- a/chirpui/radiobrowser.py
+++ b/chirpui/radiobrowser.py
@@ -9,6 +9,7 @@ from chirpui import common, config
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)
@@ -63,6 +64,7 @@ def do_insert_line_with_tags(b, line):
i(line)
+
def do_insert_with_tags(buf, text):
buf.set_text('')
lines = text.split(os.linesep)
@@ -70,12 +72,15 @@ def do_insert_with_tags(buf, text):
do_insert_line_with_tags(buf, line)
buf.insert_with_tags_by_name(buf.get_end_iter(), os.linesep)
+
def classname(obj):
return str(obj.__class__).split('.')[-1]
+
def bitwise_type(classname):
return classname.split("DataElement")[0]
+
class FixedEntry(gtk.Entry):
def __init__(self, *args, **kwargs):
super(FixedEntry, self).__init__(*args, **kwargs)
@@ -91,6 +96,7 @@ class FixedEntry(gtk.Entry):
fontdesc = pango.FontDescription("Courier bold %i" % fontsize)
self.modify_font(fontdesc)
+
class IntegerEntry(FixedEntry):
def _colorize(self, _self):
value = self.get_text()
@@ -106,12 +112,14 @@ class IntegerEntry(FixedEntry):
super(IntegerEntry, self).__init__(*args, **kwargs)
self.connect("changed", self._colorize)
+
class BitwiseEditor(gtk.HBox):
def __init__(self, element):
super(BitwiseEditor, self).__init__(False, 3)
self._element = element
self._build_ui()
+
class IntegerEditor(BitwiseEditor):
def _changed(self, entry, base):
if not self._update:
@@ -150,6 +158,7 @@ class IntegerEditor(BitwiseEditor):
ent.show()
self._update_entries()
+
class BCDArrayEditor(BitwiseEditor):
def _changed(self, entry, hexent):
self._element.set_value(int(entry.get_text()))
@@ -183,6 +192,7 @@ class BCDArrayEditor(BitwiseEditor):
ent.connect('changed', self._changed, hexent)
self._format_hexent(hexent)
+
class CharArrayEditor(BitwiseEditor):
def _changed(self, entry):
self._element.set_value(entry.get_text().ljust(len(self._element)))
@@ -194,6 +204,7 @@ class CharArrayEditor(BitwiseEditor):
ent.show()
self.pack_start(ent, 1, 1, 1)
+
class OtherEditor(BitwiseEditor):
def _build_ui(self):
name = classname(self._element)
@@ -207,6 +218,7 @@ class OtherEditor(BitwiseEditor):
l.show()
self.pack_start(l, 1, 1, 1)
+
class RadioBrowser(common.Editor):
def _build_ui(self):
self._display = gtk.Table(20, 2)
@@ -287,7 +299,7 @@ class RadioBrowser(common.Editor):
pack(l, 0)
if (isinstance(item, bitwise.intDataElement) or
- isinstance(item, bitwise.bcdDataElement)):
+ isinstance(item, bitwise.bcdDataElement)):
e = IntegerEditor(item)
elif (isinstance(item, bitwise.arrayDataElement) and
isinstance(item[0], bitwise.bcdDataElement)):
@@ -301,7 +313,6 @@ class RadioBrowser(common.Editor):
pack(e, 1)
next_row()
-
def __init__(self, rthread):
super(RadioBrowser, self).__init__(rthread)
self._radio = rthread.radio
@@ -317,14 +328,17 @@ class RadioBrowser(common.Editor):
self.emit("changed")
self._focused = False
+
if __name__ == "__main__":
from chirp import *
from chirp import directory
import sys
r = directory.get_radio_by_image(sys.argv[1])
+
class Foo:
radio = r
+
w = gtk.Window()
b = RadioBrowser(Foo)
w.set_default_size(1024, 768)
diff --git a/chirpui/settingsedit.py b/chirpui/settingsedit.py
index 69bbadf..76264c9 100644
--- a/chirpui/settingsedit.py
+++ b/chirpui/settingsedit.py
@@ -20,11 +20,13 @@ from chirp import chirp_common
from chirp import settings
from chirpui import common, miscwidgets
+
class RadioSettingProxy(settings.RadioSetting):
def __init__(self, setting, editor):
self._setting = setting
self._editor = editor
+
class SettingsEditor(common.Editor):
def __init__(self, rthread):
super(SettingsEditor, self).__init__(rthread)
@@ -36,13 +38,14 @@ class SettingsEditor(common.Editor):
paned = gtk.HPaned()
paned.show()
self.root.pack_start(paned, 1, 1, 0)
-
+
# The selection tree
self._store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT)
self._view = gtk.TreeView(self._store)
self._view.set_size_request(150, -1)
self._view.get_selection().connect("changed", self._view_changed_cb)
- self._view.append_column(gtk.TreeViewColumn("", gtk.CellRendererText(), text=0))
+ self._view.append_column(
+ gtk.TreeViewColumn("", gtk.CellRendererText(), text=0))
self._view.show()
paned.pack1(self._view)
@@ -88,9 +91,8 @@ class SettingsEditor(common.Editor):
elif isinstance(value, settings.RadioSettingValueString):
value.set_value(widget.get_text())
else:
- print "Unsupported widget type %s for %s" % (\
- element.value.__class__,
- element.get_name())
+ print "Unsupported widget type %s for %s" % \
+ (element.value.__class__, element.get_name())
self._changed = True
self._save_settings()
@@ -127,7 +129,9 @@ class SettingsEditor(common.Editor):
label.set_alignment(0.0, 0.5)
label.show()
- table.attach(label, 0, 1, row, row+1, xoptions=gtk.FILL, yoptions=0, xpadding=6, ypadding=3)
+ table.attach(label, 0, 1, row, row + 1,
+ xoptions=gtk.FILL, yoptions=0,
+ xpadding=6, ypadding=3)
if isinstance(element.value, list) and \
isinstance(element.value[0],
@@ -138,7 +142,9 @@ class SettingsEditor(common.Editor):
# Widget container
box.show()
- table.attach(box, 1, 2, row, row+1, xoptions=gtk.FILL, yoptions=0, xpadding=12, ypadding=3)
+ table.attach(box, 1, 2, row, row + 1,
+ xoptions=gtk.FILL, yoptions=0,
+ xpadding=12, ypadding=3)
for i in element.keys():
value = element[i]
@@ -154,7 +160,7 @@ class SettingsEditor(common.Editor):
widget.set_width_chars(16)
widget.set_text(value.format())
widget.connect("focus-out-event", lambda w, e, v:
- self._save_setting(w, v), value)
+ self._save_setting(w, v), value)
elif isinstance(value, settings.RadioSettingValueBoolean):
widget = gtk.CheckButton(_("Enabled"))
widget.set_active(value.get_value())
@@ -179,7 +185,7 @@ class SettingsEditor(common.Editor):
widget.set_sensitive(value.get_mutable())
widget.show()
-
+
box.pack_start(widget, 1, 1, 1)
row += 1
@@ -187,12 +193,11 @@ class SettingsEditor(common.Editor):
return tab
def _build_ui_group(self, group, parent):
-
tab = self._build_ui_tab(group)
-
+
iter = self._store.append(parent)
self._store.set(iter, 0, group.get_shortname(), 1, tab)
-
+
for element in group:
if not isinstance(element, settings.RadioSetting):
self._build_ui_group(element, iter)
@@ -213,4 +218,4 @@ class SettingsEditor(common.Editor):
def _view_changed_cb(self, selection):
(lst, iter) = selection.get_selected()
tab, = self._store.get(iter, 1)
- self._notebook.set_current_page(tab)
\ No newline at end of file
+ self._notebook.set_current_page(tab)
diff --git a/tools/cpep8.blacklist b/tools/cpep8.blacklist
index 39b452f..91f4275 100644
--- a/tools/cpep8.blacklist
+++ b/tools/cpep8.blacklist
@@ -12,11 +12,9 @@
./chirp/bandplan_na.py
./chirp/baofeng_uv3r.py
./chirp/bitwise.py
-./chirp/bitwise_grammar.py
./chirp/bjuv55.py
./chirp/chirp_common.py
./chirp/elib_intl.py
-./chirp/errors.py
./chirp/ft1802.py
./chirp/ft1d.py
./chirp/ft2800.py
@@ -28,7 +26,6 @@
./chirp/ft857.py
./chirp/ft90.py
./chirp/ftm350.py
-./chirp/generic_csv.py
./chirp/h777.py
./chirp/ic208.py
./chirp/ic2100.py
@@ -51,14 +48,12 @@
./chirp/id800.py
./chirp/id880.py
./chirp/idrp.py
-./chirp/import_logic.py
./chirp/kenwood_hmk.py
./chirp/kenwood_itm.py
./chirp/kenwood_live.py
./chirp/kguv8d.py
./chirp/kyd.py
./chirp/leixen.py
-./chirp/platform.py
./chirp/puxing.py
./chirp/pyPEG.py
./chirp/rfinder.py
@@ -85,9 +80,7 @@
./chirp/vxa700.py
./chirp/wouxun.py
./chirp/wouxun_common.py
-./chirp/xml_ll.py
./chirp/yaesu_clone.py
-./chirpui/bankedit.py
./chirpui/common.py
./chirpui/editorset.py
./chirpui/fips.py
@@ -96,9 +89,7 @@
./chirpui/memdetail.py
./chirpui/memedit.py
./chirpui/miscwidgets.py
-./chirpui/radiobrowser.py
./chirpui/reporting.py
-./chirpui/settingsedit.py
./csvdump/csvapp.py
./csvdump/csvdump.py
./setup.py
More information about the chirp_devel
mailing list