Skip to content

Commit

Permalink
Switch to a dropdown menu for BCotY
Browse files Browse the repository at this point in the history
And that's why you shouldn't program when you're tired. A freeform text
input isn't the best idea, when only a very limited range of years can
be accepted as input. So instead let's switch to a dropdown menu to
select the year for the best coubs of the year.
  • Loading branch information
HelpSeeker committed Mar 26, 2022
1 parent 36f5894 commit e8a8221
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions data/ui/add_item.ui
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
<property name="no-show-all">True</property>
</object>
</child>
<child>
<object class="GtkComboBoxText" id="best_dropdown">
<property name="no-show-all">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="placeholder">
<property name="label" translatable="yes">Browse...</property>
Expand Down
31 changes: 31 additions & 0 deletions gyre/interface/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class AddWindow(Handy.Window):
entry_label = Gtk.Template.Child("entry_label")
id_entry = Gtk.Template.Child("id_entry")
community_dropdown = Gtk.Template.Child("community_dropdown")
best_dropdown = Gtk.Template.Child("best_dropdown")
list_button = Gtk.Template.Child("placeholder")
sort_dropdown = Gtk.Template.Child("sort_dropdown")
limit_spin_button = Gtk.Template.Child("limit_spin_button")
Expand Down Expand Up @@ -254,6 +255,18 @@ class AddWindow(Handy.Window):
"Hidden gems",
],
"default_sort": 0,
"values": {
"2012": 0,
"2013": 1,
"2014": 2,
"2015": 3,
"2016": 4,
"2017": 5,
"2018": 6,
"2019": 7,
"2020": 8,
"2021": 9,
},
},
}

Expand Down Expand Up @@ -296,6 +309,7 @@ def __init__(self, model, item=None):
self.type_dropdown.connect("notify::active", self._on_type_changed)
self.id_entry.connect("notify::text", self._on_entry_changed)
self.community_dropdown.connect("changed", self._on_community_changed)
self.best_dropdown.connect("changed", self._on_best_changed)
self.list_button.connect("clicked", self._on_list_button_clicked)
self.sort_dropdown.connect("notify::active", self._on_sort_changed)
self.limit_spin_button.connect("value-changed", self._on_spin_button_changed)
Expand All @@ -306,6 +320,8 @@ def __init__(self, model, item=None):
# Populate dropdown lists
for community in self.SUPPORTED_FORMATS["Community"]["values"]:
self.community_dropdown.append_text(translate_community_name(community))
for best in self.SUPPORTED_FORMATS["Best"]["values"]:
self.best_dropdown.append_text(best)
for type in self.SUPPORTED_FORMATS:
self.type_dropdown.append_text(type)

Expand All @@ -323,6 +339,7 @@ def _on_type_changed(self, *args):
if self.type == "List":
self.id_entry.hide()
self.community_dropdown.hide()
self.best_dropdown.hide()
self.list_button.show()

# Don't set default file, unless ID is an existing path
Expand All @@ -331,13 +348,23 @@ def _on_type_changed(self, *args):
elif self.type == "Community":
self.id_entry.hide()
self.list_button.hide()
self.best_dropdown.hide()
self.community_dropdown.show()

if self.id and self.id in self.SUPPORTED_FORMATS[self.type]["values"]:
self.community_dropdown.set_active(self.SUPPORTED_FORMATS[self.type]["values"][self.id])
elif self.type == "Best":
self.id_entry.hide()
self.list_button.hide()
self.community_dropdown.hide()
self.best_dropdown.show()

if self.id and self.id in self.SUPPORTED_FORMATS[self.type]["values"]:
self.best_dropdown.set_active(self.SUPPORTED_FORMATS[self.type]["values"][self.id])
else:
self.list_button.hide()
self.community_dropdown.hide()
self.best_dropdown.hide()
self.id_entry.show()
self.id_entry.set_sensitive(self.SUPPORTED_FORMATS[self.type]["need_id"])
self.id_entry.set_placeholder_text(self.SUPPORTED_FORMATS[self.type]["placeholder"])
Expand Down Expand Up @@ -366,6 +393,10 @@ def _on_community_changed(self, dropdown):
self.id = translate_community_name(dropdown.get_active_text(), direction="to_api")
self._update_add_button()

def _on_best_changed(self, dropdown):
self.id = dropdown.get_active_text()
self._update_add_button()

def _on_list_button_clicked(self, dialog_button):
if dialog_button.run() == Gtk.ResponseType.ACCEPT:
self.id = dialog_button.filename
Expand Down

0 comments on commit e8a8221

Please sign in to comment.