/usr/share/pyshared/chirpui/shiftdialog.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 | #
# Copyright 2008 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 gobject
import threading
from chirp import errors, chirp_common
class ShiftDialog(gtk.Dialog):
def __init__(self, rthread, parent=None):
gtk.Dialog.__init__(self,
title=_("Shift"),
buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_OK))
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
self.rthread = rthread
self.__prog = gtk.ProgressBar()
self.__prog.show()
self.__labl = gtk.Label("")
self.__labl.show()
self.vbox.pack_start(self.__prog, 1, 1, 1)
self.vbox.pack_start(self.__labl, 0, 0, 0)
self.quiet = False
self.thread = None
self.set_response_sensitive(gtk.RESPONSE_OK, False)
def _status(self, msg, prog):
self.__labl.set_text(msg)
self.__prog.set_fraction(prog)
def status(self, msg, prog):
gobject.idle_add(self._status, msg, prog)
def _shift_memories(self, delta, memories):
count = 0.0
for i in memories:
src = i.number
dst = src + delta
print "Moving %i to %i" % (src, dst)
self.status(_("Moving {src} to {dst}").format(src=src,
dst=dst),
count / len(memories))
i.number = dst
self.rthread.radio.set_memory(i)
count += 1.0
return int(count)
def _get_mems_until_hole(self, start, endokay=False):
mems = []
llimit, ulimit = self.rthread.radio.get_features().memory_bounds
pos = start
while pos <= ulimit:
self.status(_("Looking for a free spot ({number})").format(\
number=pos), 0)
try:
mem = self.rthread.radio.get_memory(pos)
if mem.empty:
break
except errors.InvalidMemoryLocation:
break
mems.append(mem)
pos += 1
if pos > ulimit and not endokay:
raise errors.InvalidMemoryLocation(_("No space to insert a row"))
print "Found a hole: %i" % pos
return mems
def _insert_hole(self, start):
mems = self._get_mems_until_hole(start)
mems.reverse()
if mems:
ret = self._shift_memories(1, mems)
if ret:
# Clear the hole we made
self.rthread.radio.erase_memory(start)
return ret
else:
print "No memory list?"
return 0
def _delete_hole(self, start):
mems = self._get_mems_until_hole(start+1, endokay=True)
if mems:
count = self._shift_memories(-1, mems)
self.rthread.radio.erase_memory(count+start)
return count
else:
print "No memory list?"
return 0
def finished(self):
if self.quiet:
gobject.idle_add(self.response, gtk.RESPONSE_OK)
else:
gobject.idle_add(self.set_response_sensitive, gtk.RESPONSE_OK, True)
def threadfn(self, newhole, func):
self.status("Waiting for radio to become available", 0)
self.rthread.lock()
try:
count = func(newhole)
except errors.InvalidMemoryLocation, e:
self.status(str(e), 0)
self.finished()
return
self.rthread.unlock()
self.status(_("Moved {count} memories").format(count=count), 1)
self.finished()
def insert(self, newhole, quiet=False):
self.quiet = quiet
self.thread = threading.Thread(target=self.threadfn,
args=(newhole,self._insert_hole))
self.thread.start()
gtk.Dialog.run(self)
def delete(self, newhole, quiet=False):
self.quiet = quiet
self.thread = threading.Thread(target=self.threadfn,
args=(newhole,self._delete_hole))
self.thread.start()
gtk.Dialog.run(self)
|