Skip to content

Commit

Permalink
gui: replaced several GtkEntry with GtkSearchEntry.
Browse files Browse the repository at this point in the history
Inspired by trizen/pipe-viewer@81fca69

Also removed the `clear_text_entries_on_click` config-option.

The GUI now requires gtk+ >= 3.6.
  • Loading branch information
trizen committed Oct 12, 2022
1 parent d8e058e commit e61d210
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
55 changes: 35 additions & 20 deletions bin/gtk-youtube-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,15 @@ my %CONFIG = (
video_player_selected => undef, # autodetect it later

# GUI options
clear_text_entries_on_click => 0,
show_thumbs => 1,
clear_search_list => 1,
default_notebook_page => 1,
mainw_size => '700x400',
mainw_maximized => 0,
mainw_fullscreen => 0,
mainw_centered => 0,
hpaned_width => 250,
hpaned_position => 420,
show_thumbs => 1,
clear_search_list => 1,
default_notebook_page => 1,
mainw_size => '700x400',
mainw_maximized => 0,
mainw_fullscreen => 0,
mainw_centered => 0,
hpaned_width => 250,
hpaned_position => 420,

# Youtube options
dash_support => 1,
Expand Down Expand Up @@ -478,6 +477,21 @@ my $default_thumb = 'Gtk3::Gdk::Pixbuf'->new_from_file_at_size(catfile($
$mainw->set_title("$appname $version");
$mainw->set_icon($app_icon_pixbuf);

# Tweak search entries: allow clicking the search primary
# icon to activate, and disable said icon for other entries.
$search_entry->set_icon_sensitive('primary', 1);
$search_entry->set_icon_activatable('primary', 1);
$from_author_entry->set_icon_from_pixbuf('primary');
$category_id_entry->set_icon_from_pixbuf('primary');

# ---------------- Generic GTK signal handlers ---------------- #

sub gtk_widget_grab_focus {
my $widget = $_[-1] // $_[0];
$widget->grab_focus;
return 1;
}

our $CONFIG;
require $config_file; # Load the configuration file

Expand Down Expand Up @@ -2508,6 +2522,17 @@ sub check_keywords {
return 1;
}

sub search_or_focus {
my ($entry, $position) = @_;
if ($position eq 'primary') {
search();
}
elsif ($position eq 'secondary') {
$entry->grab_focus();
}
return 0;
}

sub search {
my $keywords = $search_entry->get_text();

Expand Down Expand Up @@ -3744,16 +3769,6 @@ sub list_local_playlist {
display_results(get_results_from_list(ids => \@video_ids));
}

sub clear_text {
my ($entry) = @_;

if ($entry->get_text() =~ /\.\.\.\z/ or $CONFIG{clear_text_entries_on_click}) {
$entry->set_text('');
}

return 0;
}

sub run_cli_youtube_viewer {
execute_cli_youtube_viewer('--interactive');
}
Expand Down
33 changes: 11 additions & 22 deletions share/gtk3-youtube-viewer.glade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0
<!-- Generated with glade 3.40.0
Copyright (C) Copyright © 2010-2022 Trizen
Expand All @@ -16,13 +16,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GTK YouTube Viewer. If not, see <https://www.gnu.org/licenses/>.
along with GTK YouTube Viewer. If not, see <http://www.gnu.org/licenses/>.
Author: Trizen https://github.com/trizen
-->
<interface>
<requires lib="gtk+" version="3.0"/>
<requires lib="gtk+" version="3.6"/>
<!-- interface-license-type gplv3 -->
<!-- interface-name GTK YouTube Viewer -->
<!-- interface-description Search and play YouTube videos. -->
Expand Down Expand Up @@ -494,19 +494,14 @@ Author: Trizen https://github.com/trizen
<property name="can-focus">False</property>
<property name="border-width">4</property>
<child>
<object class="GtkEntry" id="search_entry">
<object class="GtkSearchEntry" id="search_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="buffer">entrybuffer1</property>
<property name="invisible-char">•</property>
<property name="activates-default">True</property>
<property name="text" translatable="yes">Search for YouTube videos...</property>
<property name="caps-lock-warning">False</property>
<property name="primary-icon-stock">gtk-find</property>
<property name="secondary-icon-activatable">False</property>
<signal name="activate" handler="search" swapped="no"/>
<signal name="button-press-event" handler="clear_text" swapped="no"/>
<signal name="icon-release" handler="search" swapped="no"/>
<signal name="icon-press" handler="search_or_focus" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
Expand Down Expand Up @@ -1553,18 +1548,16 @@ standard – 480p and lower</property>
<property name="left-padding">12</property>
<property name="right-padding">12</property>
<child>
<object class="GtkEntry" id="from_author_entry">
<object class="GtkSearchEntry" id="from_author_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Search in videos uploaded by a specific author.
Unless the author name is valid, this field is ignored.</property>
<property name="invisible-char">•</property>
<property name="text" translatable="yes">Insert a valid author name...</property>
<property name="caps-lock-warning">False</property>
<property name="primary-icon-activatable">False</property>
<property name="secondary-icon-activatable">False</property>
<property name="placeholder-text" translatable="yes">Insert a username…</property>
<signal name="activate" handler="search" swapped="no"/>
<signal name="button-press-event" handler="clear_text" swapped="no"/>
<signal name="icon-press" handler="gtk_widget_grab_focus" swapped="no"/>
</object>
</child>
</object>
Expand Down Expand Up @@ -1599,17 +1592,15 @@ Unless the author name is valid, this field is ignored.</property>
<property name="left-padding">12</property>
<property name="right-padding">12</property>
<child>
<object class="GtkEntry" id="category_id_entry">
<object class="GtkSearchEntry" id="category_id_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Search in videos uploaded in a specific category.
Unless the categoryID is valid, this field is ignored.</property>
<property name="invisible-char">•</property>
<property name="text" translatable="yes">Insert a valid category ID...</property>
<property name="primary-icon-activatable">False</property>
<property name="secondary-icon-activatable">False</property>
<property name="placeholder-text" translatable="yes">Insert a category ID…</property>
<signal name="activate" handler="search" swapped="no"/>
<signal name="button-press-event" handler="clear_text" swapped="no"/>
<signal name="icon-press" handler="gtk_widget_grab_focus" swapped="no"/>
</object>
</child>
</object>
Expand Down Expand Up @@ -3387,7 +3378,6 @@ and others... https://github.com/trizen/youtube-viewer/graphs/contributors</prop
<property name="primary-icon-activatable">False</property>
<property name="secondary-icon-activatable">False</property>
<signal name="activate" handler="save_channel" swapped="no"/>
<signal name="button-press-event" handler="clear_text" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
Expand Down Expand Up @@ -3415,7 +3405,6 @@ and others... https://github.com/trizen/youtube-viewer/graphs/contributors</prop
<property name="primary-icon-activatable">False</property>
<property name="secondary-icon-activatable">False</property>
<signal name="activate" handler="save_channel" swapped="no"/>
<signal name="button-press-event" handler="clear_text" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
Expand Down

0 comments on commit e61d210

Please sign in to comment.