~martijnbraam/thumbdrives

6edc5fcf89b5b8642270b2d51df8ac2f7022648c — Martijn Braam 2 years ago 25b2a6e
Basic UI
4 files changed, 275 insertions(+), 22 deletions(-)

M meson.build
M nl.brixit.Thumbdrives.json
M src/window.py
M src/window.ui
M meson.build => meson.build +3 -1
@@ 5,6 5,8 @@ project('thumbdrives',
                   ],
)

dependency('libhandy-0.0', version: '>=0.0.10')

i18n = import('i18n')




@@ 12,4 14,4 @@ subdir('data')
subdir('src')
subdir('po')

meson.add_install_script('build-aux/meson/postinstall.py')
\ No newline at end of file
meson.add_install_script('build-aux/meson/postinstall.py')

M nl.brixit.Thumbdrives.json => nl.brixit.Thumbdrives.json +20 -0
@@ 22,6 22,26 @@
        "*.a"
    ],
    "modules" : [
    {
	    "name" : "libhandy",
	    "buildsystem" : "meson",
	    "config-opts" : [
		"-Dprofiling=false",
		"-Dintrospection=enabled",
		"-Dgtk_doc=false",
		"-Dtests=false",
		"-Dexamples=false",
		"-Dvapi=false",
		"-Dglade_catalog=disabled"
	    ],
	    "sources" : [
		{
		    "type" : "git",
		    "url" : "https://source.puri.sm/Librem5/libhandy.git",
		    "branch": "v0.0.11"
		}
	    ]
	},
        {
            "name" : "thumbdrives",
            "builddir" : true,

M src/window.py => src/window.py +29 -0
@@ 26,7 26,12 @@
# use or other dealings in this Software without prior written
# authorization.

import subprocess
import os

from gi.repository import Gtk
from xdg import XDG_DATA_HOME

import thumbdrives.vdisk as vdisk




@@ 37,9 42,21 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
    mount = Gtk.Template.Child()
    unmount = Gtk.Template.Child()

    thumbdrive_list = Gtk.Template.Child()
    iso_list = Gtk.Template.Child()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        datadir = XDG_DATA_HOME / "thumbdrives"
        if not datadir.is_dir():
            datadir.mkdir()

        for img in datadir.glob('*.img'):
            self.add_img(img)
        for iso in datadir.glob('*.iso'):
            self.add_iso(iso)

    def on_mount_clicked(self, widget, args):
        print("MOUNTING")
        subprocess.run(['truncate', '-s', '16G', '/tmp/test.img'])


@@ 47,3 64,15 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):

    def on_unmount_clicked(self, widget, args):
        vdisk.unmount()

    def add_img(path):
        box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
        label = Gtk.Label(path.name.replace(".img", ""))
        box.pack_start(label, True, True, False)
        self.thumbdrive_list.insert(box)

    def add_iso(path):
        box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
        label = Gtk.Label(path.name.replace(".iso", ""))
        box.pack_start(label, True, True, False)
        self.iso_list.insert(box)

M src/window.ui => src/window.ui +223 -21
@@ 2,54 2,256 @@
<!-- Generated with glade 3.22.2 -->
<interface>
  <requires lib="gtk+" version="3.20"/>
  <requires lib="libhandy" version="0.0"/>
  <template class="ThumbdrivesWindow" parent="GtkApplicationWindow">
    <property name="can_focus">False</property>
    <property name="default_width">600</property>
    <property name="default_height">300</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="header_bar">
      <object class="HdyHeaderBar">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="title">Hello, World!</property>
        <property name="show_close_button">True</property>
        <property name="title">Thumbdrives</property>
        <property name="subtitle">No drive mounted</property>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkBox">
      <object class="GtkStack" id="main_stack">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkButton" id="mount">
            <property name="label" translatable="yes">Mount</property>
          <object class="GtkScrolledWindow" id="page_home">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="on_mount_clicked" swapped="no"/>
            <property name="vscrollbar_policy">never</property>
            <child>
              <object class="GtkViewport">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="shadow_type">none</property>
                <child>
                  <object class="GtkBox">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="margin_left">12</property>
                    <property name="margin_right">12</property>
                    <property name="margin_top">12</property>
                    <property name="margin_bottom">12</property>
                    <property name="orientation">vertical</property>
                    <child>
                      <object class="GtkBox">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <child>
                          <object class="GtkLabel">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="halign">start</property>
                            <property name="hexpand">True</property>
                            <property name="label" translatable="yes">Thumbdrives</property>
                            <style>
                              <class name="heading"/>
                            </style>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">0</property>
                          </packing>
                        </child>
                        <child>
                          <placeholder/>
                        </child>
                        <child>
                          <object class="GtkButton" id="add_thumbdrive">
                            <property name="label">gtk-add</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">True</property>
                            <property name="use_stock">True</property>
                            <property name="always_show_image">True</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="pack_type">end</property>
                            <property name="position">2</property>
                          </packing>
                        </child>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="fill">True</property>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkFrame">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="margin_top">12</property>
                        <property name="margin_bottom">24</property>
                        <property name="label_xalign">0</property>
                        <property name="shadow_type">in</property>
                        <child>
                          <object class="GtkAlignment">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="left_padding">12</property>
                            <child>
                              <object class="GtkListBox">
                                <property name="name">thumbdrive_list</property>
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                              </object>
                            </child>
                          </object>
                        </child>
                        <child type="label_item">
                          <placeholder/>
                        </child>
                        <style>
                          <class name="view"/>
                        </style>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="fill">True</property>
                        <property name="position">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkBox">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <child>
                          <object class="GtkLabel">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="label" translatable="yes">ISO Images</property>
                            <style>
                              <class name="heading"/>
                            </style>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">0</property>
                          </packing>
                        </child>
                        <child>
                          <placeholder/>
                        </child>
                        <child>
                          <object class="GtkButton" id="add_iso">
                            <property name="label">gtk-add</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">True</property>
                            <property name="use_stock">True</property>
                            <property name="always_show_image">True</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="pack_type">end</property>
                            <property name="position">2</property>
                          </packing>
                        </child>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="fill">True</property>
                        <property name="position">2</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkFrame">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="margin_top">12</property>
                        <property name="margin_bottom">24</property>
                        <property name="label_xalign">0</property>
                        <property name="shadow_type">in</property>
                        <child>
                          <object class="GtkAlignment">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="left_padding">12</property>
                            <child>
                              <object class="GtkListBox">
                                <property name="name">iso_list</property>
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                              </object>
                            </child>
                          </object>
                        </child>
                        <child type="label_item">
                          <placeholder/>
                        </child>
                        <style>
                          <class name="view"/>
                        </style>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="fill">True</property>
                        <property name="position">3</property>
                      </packing>
                    </child>
                  </object>
                </child>
              </object>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
            <property name="name">page0</property>
            <property name="title" translatable="yes">page0</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="unmount">
            <property name="label" translatable="yes">Unmount</property>
          <object class="GtkScrolledWindow" id="page_add">
            <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"/>
            <property name="vscrollbar_policy">never</property>
            <child>
              <object class="GtkViewport">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="shadow_type">none</property>
                <child>
                  <object class="GtkBox">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="margin_left">12</property>
                    <property name="margin_right">12</property>
                    <property name="margin_top">12</property>
                    <property name="margin_bottom">12</property>
                    <property name="orientation">vertical</property>
                    <child>
                      <placeholder/>
                    </child>
                    <child>
                      <placeholder/>
                    </child>
                    <child>
                      <placeholder/>
                    </child>
                  </object>
                </child>
              </object>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="name">page1</property>
            <property name="title" translatable="yes">page1</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </template>