Skip to content

Commit

Permalink
Rework output dir chooser
Browse files Browse the repository at this point in the history
related to #2
  • Loading branch information
rafaelmardojai committed May 29, 2020
1 parent f97f111 commit 555c329
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 74 deletions.
12 changes: 1 addition & 11 deletions src/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ def __init__(self, **kwargs):
self.load_saved()

def setup(self):
self.directory.connect('changed', self._check_dir_entry)

# Setup font_display combo row
model = Gio.ListStore.new(Handy.ValueObject)
options = [_('Disabled'), 'auto', 'block', 'swap', 'fallback', 'optional']
Expand Down Expand Up @@ -142,12 +140,4 @@ def get_subsetting(self):

def get_font_display(self):
return self.font_display.get_selected_index()


def _check_dir_entry(self, entry):
path = entry.get_text()
if os.access(path, os.W_OK) and os.path.exists(path):
entry.get_style_context().remove_class('error')
else:
entry.get_style_context().add_class('error')


78 changes: 34 additions & 44 deletions src/resources/ui/options.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,54 @@
<property name="margin_top">40</property>
<property name="margin_bottom">40</property>
<child>
<object class="GtkBox">
<object class="HdyPreferencesGroup">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Output directory</property>
<property name="valign">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<object class="GtkBox">
<object class="HdyActionRow">
<property name="title" translatable="yes">Output directory</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<style>
<class name="linked"/>
</style>
<child>
<object class="GtkEntry" id="directory">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder-text" translatable="yes">Select a directory for generation</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<property name="valign">center</property>
<child>
<object class="GtkLabel" id="directory">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Select a directory</property>
<property name="valign">center</property>
<style>
<class name="h4"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<object class="GtkButton" id="browse">
<property name="label" translatable="yes">Browse...</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>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<object class="GtkButton" id="browse">
<property name="label" translatable="yes">Browse...</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>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>

<child>
Expand Down
30 changes: 11 additions & 19 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ def __init__(self, **kwargs):

self.processing = False
self.options = Options()
self.outpath = ''
self.outpath = None
self.outURI = None
self.log = Log(self.progressbar_label)

self.setup_widgets()

self.options.browse.connect('clicked', self.set_outpath)
self.options.directory.connect('changed', self._update_outpath)
self.options.directory.connect('changed', self._change_ready_state)

self.model = Gio.ListStore.new(Font)
self.model.connect('items-changed', self._change_ready_state)
Expand Down Expand Up @@ -157,20 +156,21 @@ def set_outpath(self, *args):

if response == Gtk.ResponseType.ACCEPT:
path = filechooser.get_filename()
self.options.directory.set_text(path)
uri = filechooser.get_uri()
name = os.path.basename(path)

self.outpath = path
self.outURI = uri
self.options.directory.set_label(name)

self._change_ready_state()
filechooser.destroy()

if filenames:
thread = Thread(target=self.load_fonts,
args=(filenames,))
thread.daemon = True
thread.start()
elif response == Gtk.ResponseType.REJECT:
filechooser.destroy()

def open_generation_folder(self, *args):
uri = 'file://' + self.outpath
uri = self.outURI
Gtk.show_uri_on_window(self, uri, Gdk.CURRENT_TIME)


Expand All @@ -182,13 +182,10 @@ def _create_font_widget(self, font):
widget = FontWidget(font, self.model)
return widget

def _update_outpath(self, entry):
self.outpath = entry.get_text()

def _change_ready_state(self, *args, **kwargs):
children = True if len(self.model) > 0 else False

if children and self._check_path_access(self.outpath):
if children and self.outpath:
self.btn_generate.set_sensitive(True)
else:
self.btn_generate.set_sensitive(False)
Expand All @@ -198,11 +195,6 @@ def _change_ready_state(self, *args, **kwargs):
else:
self.fonts_stack.set_visible_child_name('empty')

def _check_path_access(self, path):
if os.access(path, os.W_OK) and os.path.exists(path):
return True
return False

def _get_font_data(self, data_src):
data = {}
weights = {
Expand Down

0 comments on commit 555c329

Please sign in to comment.