@@ 1,31 1,3 @@
-# window.py
-#
-# Copyright 2020 Martijn Braam
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY
-# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-# Except as contained in this notice, the name(s) of the above copyright
-# holders shall not be used in advertising or otherwise to promote the sale,
-# use or other dealings in this Software without prior written
-# authorization.
-
import subprocess
import os
from pathlib import Path
@@ 45,6 17,11 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
__gtype_name__ = 'ThumbdrivesWindow'
headerbar = Gtk.Template.Child()
+ main_stack =Gtk.Template.Child()
+ header_stack =Gtk.Template.Child()
+
+ unmount = Gtk.Template.Child()
+
thumbdrive_list = Gtk.Template.Child()
iso_list = Gtk.Template.Child()
@@ 55,11 32,17 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
if not datadir.is_dir():
datadir.mkdir()
+ downloads = Path("~/Downloads").expanduser()
+
for img in datadir.glob('*.img'):
self.add_img(img)
for iso in datadir.glob('*.iso'):
self.add_iso(iso)
+ if downloads.is_dir():
+ for iso in downloads.glob('*.iso'):
+ self.add_iso(iso)
+
self.update_mounted()
self.thumbdrive_list.show_all()
@@ 68,6 51,7 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
def add_img(self, path):
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
icon = Gtk.Image()
+ icon.set_size_request(16, 16)
label = Gtk.Label(path.name.replace(".img", ""), xalign=0)
label.set_margin_top(8)
label.set_margin_bottom(8)
@@ 79,6 63,7 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
def add_iso(self, path):
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
icon = Gtk.Image()
+ icon.set_size_request(16, 16)
label = Gtk.Label(path.name.replace(".iso", ""), xalign=0)
label.set_margin_top(8)
label.set_margin_bottom(8)
@@ 90,30 75,30 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
def update_mounted(self):
filename = vdisk.get_mounted()
if filename is None:
+ self.unmount.set_sensitive(False)
self.headerbar.set_subtitle("No drive mounted")
else:
+ self.unmount.set_sensitive(True)
self.headerbar.set_subtitle("Loaded " + os.path.basename(filename))
for row_wrapper in self.thumbdrive_list:
box = row_wrapper.get_child()
- filename = box.filename
icon = None
for widget in box:
if isinstance(widget, Gtk.Image):
icon = widget
- if filename == filename:
+ if box.filename == filename:
icon.set_from_icon_name('object-select-symbolic', Gtk.IconSize.BUTTON)
else:
icon.clear()
for row_wrapper in self.iso_list:
box = row_wrapper.get_child()
- filename = box.filename
icon = None
for widget in box:
if isinstance(widget, Gtk.Image):
icon = widget
- if filename == filename:
+ if box.filename == filename:
icon.set_from_icon_name('object-select-symbolic', Gtk.IconSize.BUTTON)
else:
icon.clear()
@@ 130,3 115,20 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
vdisk.mount(filename)
self.update_mounted()
+
+ @Gtk.Template.Callback()
+ def on_unmount_clicked(self, button):
+ vdisk.unmount()
+ self.update_mounted()
+
+ @Gtk.Template.Callback()
+ def on_back_clicked(self, button):
+ self.main_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_RIGHT)
+ self.main_stack.set_visible_child_name('home')
+ self.header_stack.set_visible_child_name('home')
+
+ @Gtk.Template.Callback()
+ def on_add_thumbdrive_clicked(self, button):
+ self.main_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT)
+ self.main_stack.set_visible_child_name('add_thumbdrive')
+ self.header_stack.set_visible_child_name('back')
@@ 14,7 14,38 @@
<property name="title">Thumbdrives</property>
<property name="subtitle">No drive mounted</property>
<child>
- <placeholder/>
+ <object class="GtkStack" id="header_stack">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkButton" id="unmount">
+ <property name="label" translatable="yes">Eject</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="on_unmount_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="name">home</property>
+ <property name="title" translatable="yes">page0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="back_button">
+ <property name="label">gtk-go-back</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ <signal name="clicked" handler="on_back_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="name">back</property>
+ <property name="title" translatable="yes">page1</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
</child>
</object>
</child>
@@ 22,6 53,7 @@
<object class="GtkStack" id="main_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="transition_type">slide-left</property>
<child>
<object class="GtkScrolledWindow" id="page_home">
<property name="visible">True</property>
@@ 73,6 105,7 @@
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
+ <signal name="clicked" handler="on_add_thumbdrive_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ 149,6 182,7 @@
<object class="GtkButton" id="add_iso">
<property name="label">gtk-add</property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
@@ 209,12 243,12 @@
</child>
</object>
<packing>
- <property name="name">page0</property>
+ <property name="name">home</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
- <object class="GtkScrolledWindow" id="page_add">
+ <object class="GtkScrolledWindow" id="page_add_thumbdrive">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="vscrollbar_policy">never</property>
@@ 233,7 267,113 @@
<property name="margin_bottom">12</property>
<property name="orientation">vertical</property>
<child>
- <placeholder/>
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">8</property>
+ <property name="column_spacing">8</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Name</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="image_name">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Size</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="image_size">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="input_purpose">digits</property>
+ <property name="numeric">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">MB</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child type="center">
+ <object class="GtkButton" id="create">
+ <property name="label" translatable="yes">Create</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">3</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
</child>
<child>
<placeholder/>
@@ 247,7 387,7 @@
</child>
</object>
<packing>
- <property name="name">page1</property>
+ <property name="name">add_thumbdrive</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>