# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com # Fake Node ID 4f877cf677cccaee5316d1753f957240f3ac7b41
Fix style issues in common.py (#2355)
diff --git a/chirpui/common.py b/chirpui/common.py index 9fe8e23..dcbbb3f 100644 --- a/chirpui/common.py +++ b/chirpui/common.py @@ -27,11 +27,12 @@ from chirpui import reporting, config
CONF = config.get()
+ class Editor(gobject.GObject): __gsignals__ = { - 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), - 'usermsg' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, - (gobject.TYPE_STRING,)), + 'changed': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), + 'usermsg': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_STRING,)), }
root = None @@ -74,12 +75,14 @@ class Editor(gobject.GObject):
gobject.type_register(Editor)
+ def DBG(*args): if False: print " ".join(args)
VERBOSE = False
+ class RadioJob: def __init__(self, cb, func, *args, **kwargs): self.cb = cb @@ -137,11 +140,11 @@ class RadioJob:
self._execute(self.target, func)
+ class RadioThread(threading.Thread, gobject.GObject): __gsignals__ = { - "status" : (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING,)), + "status": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_STRING,)), }
def __init__(self, radio, parent=None): @@ -171,7 +174,7 @@ class RadioThread(threading.Thread, gobject.GObject): self.__lock.release()
def _qsubmit(self, job, priority): - if not self.__queue.has_key(priority): + if priority not in self.__queue: self.__queue[priority] = []
self.__queue[priority].append(job) @@ -179,7 +182,7 @@ class RadioThread(threading.Thread, gobject.GObject):
def _queue_clear_below(self, priority): for i in range(0, priority): - if self.__queue.has_key(i) and len(self.__queue[i]) != 0: + if i in self.__queue and len(self.__queue[i]) != 0: return False
return True @@ -221,13 +224,13 @@ class RadioThread(threading.Thread, gobject.GObject): self.flush() self.__counter.release() self.__enabled = False - + def _status(self, msg): jobs = 0 for i in dict(self.__queue): jobs += len(self.__queue[i]) gobject.idle_add(self.emit, "status", "[%i] %s" % (jobs, msg)) - + def _queue_pop(self, priority): try: return self.__queue[priority].pop(0) @@ -239,8 +242,8 @@ class RadioThread(threading.Thread, gobject.GObject): while self.__enabled: DBG("Waiting for a job") if last_job_desc: - self.status(_("Completed") + " " + last_job_desc + \ - " (" + _("idle") + ")") + self.status(_("Completed") + " " + last_job_desc + + " (" + _("idle") + ")") self.__counter.acquire()
self._qlock() @@ -260,15 +263,17 @@ class RadioThread(threading.Thread, gobject.GObject):
print "RadioThread exiting"
+ def log_exception(): - import traceback - import sys + import traceback + import sys
- reporting.report_exception(traceback.format_exc(limit=30)) + reporting.report_exception(traceback.format_exc(limit=30)) + + print "-- Exception: --" + traceback.print_exc(limit=30, file=sys.stdout) + print "------"
- print "-- Exception: --" - traceback.print_exc(limit=30, file=sys.stdout) - print "------"
def show_error(msg, parent=None): d = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, parent=parent, @@ -281,6 +286,7 @@ def show_error(msg, parent=None): d.run() d.destroy()
+ def ask_yesno_question(msg, parent=None): d = gtk.MessageDialog(buttons=gtk.BUTTONS_YES_NO, parent=parent, type=gtk.MESSAGE_QUESTION) @@ -294,6 +300,7 @@ def ask_yesno_question(msg, parent=None):
return r == gtk.RESPONSE_YES
+ def combo_select(box, value): store = box.get_model() iter = store.get_iter_first() @@ -305,6 +312,7 @@ def combo_select(box, value):
return False
+ def _add_text(d, text): v = gtk.TextView() v.get_buffer().set_text(text) @@ -314,9 +322,10 @@ def _add_text(d, text): sw = gtk.ScrolledWindow() sw.add(v) sw.show() - d.vbox.pack_start(sw, 1,1,1) + d.vbox.pack_start(sw, 1, 1, 1) return v
+ def show_error_text(msg, text, parent=None): d = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, parent=parent, type=gtk.MESSAGE_ERROR) @@ -330,6 +339,7 @@ def show_error_text(msg, text, parent=None): d.run() d.destroy()
+ def show_warning(msg, text, parent=None, buttons=None, title="Warning", can_squelch=False): @@ -363,6 +373,7 @@ def show_warning(msg, text, return r, cb.get_active() return r
+ def simple_diff(a, b, diffsonly=False): lines_a = a.split(os.linesep) lines_b = b.split(os.linesep) @@ -374,7 +385,7 @@ def simple_diff(a, b, diffsonly=False): diff += "-%s%s" % (lines_a[i], os.linesep) diff += "+%s%s" % (lines_b[i], os.linesep) blankprinted = False - elif diffsonly == True: + elif diffsonly is True: if blankprinted: continue diff += os.linesep @@ -383,6 +394,7 @@ def simple_diff(a, b, diffsonly=False): diff += " %s%s" % (lines_a[i], os.linesep) return diff
+ # A quick hacked up tool to show a blob of text in a dialog window # using fixed-width fonts. It also highlights lines that start with # a '-' in red bold font and '+' with blue bold font. @@ -430,6 +442,7 @@ def show_diff_blob(title, result): d.run() d.destroy()
+ def unpluralize(string): if string.endswith("s"): return string[:-1] diff --git a/tools/cpep8.blacklist b/tools/cpep8.blacklist index 35c48e4..a805274 100644 --- a/tools/cpep8.blacklist +++ b/tools/cpep8.blacklist @@ -70,7 +70,6 @@ ./chirp/wouxun.py ./chirp/wouxun_common.py ./chirp/yaesu_clone.py -./chirpui/common.py ./chirpui/editorset.py ./chirpui/fips.py ./chirpui/importdialog.py