~martijnbraam/thumbdrives

7b25049bac506749139cc827333f63249ad64c7e — Martijn Braam 4 years ago da21026
Made create function work
3 files changed, 78 insertions(+), 47 deletions(-)

M meson.build
M src/window.py
M src/window.ui
M meson.build => meson.build +1 -1
@@ 1,5 1,5 @@
project('thumbdrives',  
          version: '0.1.0',
          version: '0.2.0',
    meson_version: '>= 0.50.0',
  default_options: [ 'warning_level=2',
                   ],

M src/window.py => src/window.py +24 -0
@@ 30,6 30,10 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
    frame_iso = Gtk.Template.Child()
    no_iso = Gtk.Template.Child()

    image_name = Gtk.Template.Child()
    image_size = Gtk.Template.Child()
    size_adj = Gtk.Template.Child()

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



@@ 47,6 51,8 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
        if downloads.is_dir():
            for iso in downloads.glob('*.iso'):
                self.add_iso(iso)
            for img in downloads.glob('*.img'):
                self.add_img(img)

        self.update_mounted()



@@ 54,6 60,8 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
        self.iso_list.show_all()
        self.update_visibility()

        self.datadir = datadir

    def add_img(self, path):
        box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
        icon = Gtk.Image()


@@ 159,3 167,19 @@ class ThumbdrivesWindow(Gtk.ApplicationWindow):
        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')

    @Gtk.Template.Callback()
    def on_create_clicked(self, button):
        name = self.image_name.get_text()
        size = self.size_adj.get_value()

        filename = os.path.join(self.datadir, name + ".img")

        with open(filename, 'ab') as handle:
            handle.truncate(size * 1024 * 1024)
        self.add_img(filename)
        self.thumbdrive_list.show_all()
        self.update_visibility()
        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')

M src/window.ui => src/window.ui +53 -46
@@ 1,54 1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<!-- Generated with glade 3.36.0 -->
<interface>
  <requires lib="gtk+" version="3.20"/>
  <requires lib="libhandy" version="0.0"/>
  <object class="GtkAdjustment" id="size_adj">
    <property name="upper">16000</property>
    <property name="step_increment">1</property>
    <property name="page_increment">128</property>
  </object>
  <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="HdyHeaderBar" id="headerbar">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="title">Thumbdrives</property>
        <property name="subtitle">No drive mounted</property>
        <child>
          <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>
    <child>
      <object class="GtkStack" id="main_stack">
        <property name="visible">True</property>


@@ 349,6 312,7 @@ Use the add button to download one of the templates or download an .iso file int
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="input_purpose">digits</property>
                            <property name="adjustment">size_adj</property>
                            <property name="numeric">True</property>
                          </object>
                          <packing>


@@ 374,15 338,13 @@ Use the add button to download one of the templates or download an .iso file int
                          <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>
                                <signal name="clicked" handler="on_create_clicked" swapped="no"/>
                              </object>
                              <packing>
                                <property name="expand">False</property>


@@ 390,6 352,9 @@ Use the add button to download one of the templates or download an .iso file int
                                <property name="position">1</property>
                              </packing>
                            </child>
                            <child>
                              <placeholder/>
                            </child>
                          </object>
                          <packing>
                            <property name="left_attach">0</property>


@@ 426,5 391,47 @@ Use the add button to download one of the templates or download an .iso file int
        </child>
      </object>
    </child>
    <child type="titlebar">
      <object class="HdyHeaderBar" id="headerbar">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="title">Thumbdrives</property>
        <property name="subtitle">No drive mounted</property>
        <child>
          <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>
  </template>
</interface>