Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha-org-sugar-git@silbe.org>2009-03-27 22:48:03 (GMT)
committer Sascha Silbe <sascha-org-sugar-git@silbe.org>2009-03-27 22:48:03 (GMT)
commitca31343dd86ceaa46b614c4d45a71bbcf2881427 (patch)
tree0d407546d585914e220006aecc26306e7a9d73b0
parentc5f008a76831bc99c45bfdb7ec2e7259044a957d (diff)
finished GUI mockup
-rwxr-xr-xgtktest.py193
1 files changed, 151 insertions, 42 deletions
diff --git a/gtktest.py b/gtktest.py
index d707264..5bb919a 100755
--- a/gtktest.py
+++ b/gtktest.py
@@ -7,83 +7,192 @@ import gtk
PROGNAME = "soas-assimilator"
-class tMainWindow (gtk.Window) :
+class tColoredListWindow (gtk.Window) :
- _listColumns = [
- ('status', str, gtk.CellRendererText),
- ('device', str, gtk.CellRendererText),
- ('image', str, gtk.CellRendererText),
- ('model', str, gtk.CellRendererText),
- ('color', str, None),
- ]
- _colorColIdx = len(_listColumns)-1
- _colorMap = {
- 'writing': '#FFFF00',
- 'finished': '#00FF00',
- 'error': '#FF0000',
- }
-
- def __init__(self, model, title) :
+ def __init__(self, title) :
gtk.Window.__init__(self)
- self._model = model
self.set_title(title)
- self._initWidgets()
-
- def setStatus(self, device, status, image, model) :
- row = self._findRow(device)
- if row is None :
- row = self._listModel.append()
-
- self._listModel[row] = (status, device, image, model, self._colorMap[status])
+ self.initWidgets()
- def _initWidgets(self) :
- self._vbox = gtk.VBox()
- self.add(self._vbox)
+ def initWidgets(self) :
+ self.vbox = gtk.VBox(False, 10)
+ self.add(self.vbox)
self._scrolledList = gtk.ScrolledWindow()
self._scrolledList.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self._vbox.pack_start(self._scrolledList)
- self._listModel = gtk.ListStore(*[_type for (name, _type, r) in self._listColumns])
- self._listView = gtk.TreeView(self._listModel)
- self._listView.set_rules_hint(True)
+ self.vbox.pack_start(self._scrolledList)
+ self.listModel = gtk.ListStore(*[_type for (name, _type, r) in self.listColumns])
+ self._listView = gtk.TreeView(self.listModel)
self._scrolledList.add(self._listView)
self._addListColumns()
self.show_all()
def _addListColumns(self) :
- for (idx, (name, _type, renderer)) in enumerate(self._listColumns) :
+ for (idx, (name, _type, renderer)) in enumerate(self.listColumns) :
if not renderer :
continue
r = renderer()
r.set_property('background-set', True)
if (_type == bool) :
- col = gtk.TreeViewColumn(name, r, active=idx, background=self._colorColIdx)
+ col = gtk.TreeViewColumn(name, r, active=idx, background=self.colorColIdx)
else :
- col = gtk.TreeViewColumn(name, r, text=idx, background=self._colorColIdx)
+ col = gtk.TreeViewColumn(name, r, text=idx, background=self.colorColIdx)
col.set_sort_column_id(idx)
self._listView.append_column(col)
- def _findRow(self, device) :
- for idx in range(len(self._listModel)) :
- if (self._listModel[idx][1] == device) :
+ def findRow(self, col, content) :
+ for idx in range(len(self.listModel)) :
+ if (self.listModel[idx][col] == content) :
return idx
+class tReadWindow (tColoredListWindow) :
+
+ listColumns = [
+ ('status', str, gtk.CellRendererText),
+ ('image', str, gtk.CellRendererText),
+ ('model', str, gtk.CellRendererText),
+ ('device', str, None),
+ ('color', str, None),
+ ]
+ _deviceColIdx = 3
+ colorColIdx = len(listColumns)-1
+ _colorMap = {
+ 'reading': '#FFFF00',
+ 'finished': '#00FF00',
+ 'error': '#FF0000',
+ }
+
+ def __init__(self, model) :
+ self._model = model
+ tColoredListWindow.__init__(self, "%s: Read USB sticks" % (PROGNAME,))
+
+ def initWidgets(self) :
+ tColoredListWindow.initWidgets(self)
+ self._hButtonBox = gtk.HButtonBox()
+ self.writeButton = gtk.Button("Continue to write mode")
+ self.writeButton.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#F00000"))
+ self.writeButton.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse("#FF0000"))
+ self.writeButton.show()
+ self._hButtonBox.pack_start(self.writeButton)
+ self._hButtonBox.show()
+ self.vbox.pack_end(self._hButtonBox, expand=False)
+
+ def setStatus(self, device, status, image, model) :
+ row = self.findRow(device)
+ if row is None :
+ row = self.listModel.append()
+
+ color = self._colorMap[status]
+ self.listModel[row] = [locals()[name] for (name, t, r) in self.listColumns]
+
+ def findRow(self, device) :
+ return tColoredListWindow.findRow(self, self._deviceColIdx, device)
+
+
+class tWriteWindow (tColoredListWindow) :
+
+ listColumns = [
+ ('device', str, gtk.CellRendererText),
+ ('status', str, gtk.CellRendererText),
+ ('image', str, gtk.CellRendererText),
+ ('model', str, gtk.CellRendererText),
+ ('color', str, None),
+ ]
+ colorColIdx = len(listColumns)-1
+ _deviceColIdx = 0
+ _colorMap = {
+ 'writing': '#FFFF00',
+ 'verifying': '#6060FF',
+ 'finished': '#00FF00',
+ 'error': '#FF0000',
+ }
+
+ def __init__(self, model) :
+ self._model = model
+ tColoredListWindow.__init__(self, "%s: Write USB sticks" % (PROGNAME,))
+
+ def setStatus(self, device, status, image, model) :
+ row = self.findRow(device)
+ if row is None :
+ row = self.listModel.append()
+
+ color = self._colorMap[status]
+ self.listModel[row] = [locals()[name] for (name, t, r) in self.listColumns]
+
+ def findRow(self, device) :
+ return tColoredListWindow.findRow(self, self._deviceColIdx, device)
+
+
class tModel (object) :
def __init__(self, imageprefix) :
self.imageprefix = imageprefix
+ self.mode = 'read'
+
+ def setMode(self, mode) :
+ if mode not in ['read', 'write'] :
+ raise ValueError("Unknown mode: %r" % (mode,))
+
+ self.mode = mode
class tApp (object) :
def __init__(self) :
- self._model = tModel("test")
- self._win = tMainWindow(self._model, PROGNAME)
- self._win.setStatus("/dev/sda", "writing", "test-1gb.img", "FOOBAR STICK")
- self._win.setStatus("/dev/sdb", "finished", "test-1gb.img", "SL STICK")
+ self._imageDir = self._chooseImageDir()
+ self._model = tModel(self._imageDir)
+ if self._askReadImage() :
+ self._win = tReadWindow(self._model)
+ self._win.writeButton.connect("clicked", self._showWriteWindow)
+ else :
+ self._win = None
+ self._showWriteWindow()
+
+ def _showWriteWindow(self, *args) :
+ if self._win :
+ # close read window
+ self._win.destroy()
+
+ self._win = tWriteWindow(self._model)
+ self._win.setStatus("/dev/sda", "writing", os.path.join(self._imageDir, "test-1gb.img"), "FOOBAR STICK")
+ self._win.setStatus("/dev/sdb", "verifying", os.path.join(self._imageDir, "test-1gb.img"), "SL STICK")
+ self._win.setStatus("/dev/sdc", "finished", os.path.join(self._imageDir, "test-1gb.img"), "SL STICK")
+ self._win.setStatus("/dev/sdd", "error", os.path.join(self._imageDir, "test-1gb.img"), "SL STICK")
self._win.connect('destroy', lambda *w: self._close())
+ self._model.setMode('write')
+
+ def _chooseImageDir(self) :
+ """
+ Query image directory from user. Will exit program in case user cancels.
+ """
+ imageChooserDialog = gtk.FileChooserDialog(title="Choose directory containing image files",
+ action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
+ imageChooserDialog.set_default_response(gtk.RESPONSE_OK)
+ if imageChooserDialog.run() != gtk.RESPONSE_OK :
+ sys.exit(10)
+
+ dir = imageChooserDialog.get_filename()
+ imageChooserDialog.destroy()
+ return dir
+
+ def _askReadImage(self) :
+ """
+ Ask the user whether to create an image of a USB stick.
+ """
+ askDialog = gtk.MessageDialog(type=gtk.MESSAGE_QUESTION,
+ buttons=gtk.BUTTONS_NONE,
+ message_format="\n".join([x.strip() for x in """
+ Once the write mode is active, it will overwrite ANY USB stick you plug in. You now (and only now) have the chance to read an existing USB stick and save an image of it to the directory you just chose.
+ What do you want to do?
+ """.split("\n")]))
+
+ askDialog.add_buttons("Continue to write mode", gtk.RESPONSE_CANCEL, "Create image first", gtk.RESPONSE_OK)
+ res = askDialog.run()
+ askDialog.destroy()
+ return (res == gtk.RESPONSE_OK)
def run(self) :
gtk.main()