Verified Commit 0bc2781f authored by Todd Weaver's avatar Todd Weaver
Browse files

Adding in initial templates for menu/help/about

parent d3e17b7f
# about.py
#
# Copyright 2021 Todd Weaver
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# 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 this program. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
@Gtk.Template(resource_path="/sm/puri/Stream/ui/about.ui")
class About(Gtk.AboutDialog):
__gtype_name__ = 'About'
def __init__(self, **kwargs):
super().__init__(**kwargs)
# help.py
#
# Copyright 2021 Todd Weaver
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# 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 this program. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
@Gtk.Template(resource_path="/sm/puri/Stream/ui/help.ui")
class Help(Gtk.ShortcutsWindow):
__gtype_name__ = 'Help'
def __init__(self, **kwargs):
super().__init__(**kwargs)
......@@ -36,7 +36,6 @@ class Instances:
# get urls of instances from api.invidious.io
uri = f"https://api.invidious.io/instances.json?sort_by=health"
print("0: " + uri)
session = Soup.Session.new()
session.set_property("timeout", 10)
message = Soup.Message.new("GET", uri)
......@@ -68,7 +67,6 @@ class Instances:
# /api/v1/search?q=query
# /api/v1/search?q=Librem%205;fields=type
search_uri = f"{uri}/api/v1/search?q=Librem%205;fields=type"
print("1: " + search_uri)
session = Soup.Session.new()
session.set_property("timeout", 2)
message = Soup.Message.new("GET", search_uri)
......@@ -95,7 +93,6 @@ class Instances:
# /api/v1/videos/{videoId}
# /api/v1/videos/cAUNrY_qPCg?fields=type
fs_uri = f"{uri}/api/v1/videos/cAUNrY_qPCg?fields=formatStreams"
print("2: " + fs_uri)
session = Soup.Session.new()
session.set_property("timeout", 2)
message = Soup.Message.new("GET", fs_uri)
......@@ -124,7 +121,6 @@ class Instances:
session.queue_message(message, self.check_video_valid_cb, uri)
def check_video_valid_cb(self, session, results, uri):
print(results.status_code)
if results.status_code != 200:
return False
......
# menu.py
#
# Copyright 2021 Todd Weaver
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# 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 this program. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from .about import About
from .help import Help
@Gtk.Template(resource_path="/sm/puri/Stream/ui/menu.ui")
class Menu(Gtk.PopoverMenu):
__gtype_name__ = 'Menu'
def __init__(self, app_window, **kwargs):
super().__init__(**kwargs)
self.app_window = app_window
@Gtk.Template.Callback()
def show_about(self, data):
about = About()
about.props.transient_for = self.app_window
about.present()
@Gtk.Template.Callback()
def show_help(self, data):
help = Help()
help.props.transient_for = self.app_window
help.present()
......@@ -27,10 +27,13 @@ configure_file(
stream_sources = [
'__init__.py',
'help.py',
'main.py',
'menu.py',
'about.py',
'window.py',
'results.py',
'search.py',
'results.py',
'instances.py',
]
......
......@@ -26,8 +26,8 @@ from gi.repository import Gdk, GdkPixbuf, Gio, GLib, Gst, Gtk, Handy, Soup
import json
Gst.init()
Gst.init_check()
Gst.init(None)
Gst.init_check(None)
Handy.init()
import time
......
......@@ -38,8 +38,6 @@ class Search:
esc_query = GLib.uri_escape_string(query, None, None)
uri = f"{self.app_window.strong_instances[0]}/api/v1/search?q={esc_query};fields=title,videoId,author,lengthSeconds,videoThumbnails"
print(uri)
self.session = Soup.Session.new()
self.session.set_property("timeout", 5)
message = Soup.Message.new("GET", uri)
......
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/sm/puri/Stream">
<file>ui/help.ui</file>
<file>ui/menu.ui</file>
<file>ui/about.ui</file>
<file>ui/window.ui</file>
<file>ui/results.ui</file>
<file>ui/stream.css</file>
<file>ui/video-placeholder-332x186.png</file>
<file alias="gtk/help-overlay.ui">ui/help-overlay.ui</file>
</gresource>
</gresources>
</gresources>
......@@ -9,6 +9,7 @@
<property name="vexpand">True</property>
<property name="default-width">882</property>
<property name="default-height">652</property>
<property name="icon-name">sm.puri.Stream</property>
<signal name="key-press-event" handler="keypress_listener" swapped="no"/>
<child>
<object class="GtkBox">
......@@ -25,7 +26,6 @@
<object class="GtkToggleButton" id="search_bar_toggle">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="tooltip-text" translatable="yes">Search</property>
<property name="valign">center</property>
<property name="active">True</property>
......@@ -44,11 +44,56 @@
</object>
</child>
<child>
<object class="GtkMenuButton">
<object class="GtkButton" id="results_previous">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="action-name">win.open-primary-menu</property>
<property name="tooltip-text" translatable="yes">Previous</property>
<property name="valign">center</property>
<property name="sensitive">False</property>
<signal name="clicked" handler="show_previous_results" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">go-previous-symbolic</property>
<property name="icon_size">1</property>
</object>
</child>
<style>
<class name="image-button"/>
</style>
</object>
</child>
<child>
<object class="GtkButton" id="results_next">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Next</property>
<property name="valign">center</property>
<property name="sensitive">False</property>
<signal name="clicked" handler="show_next_results" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">go-next-symbolic</property>
<property name="icon_size">1</property>
</object>
</child>
<style>
<class name="image-button"/>
</style>
</object>
<packing>
<property name="pack-type">end</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="menu_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Menu</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
......
......@@ -27,6 +27,7 @@ import json
from .search import Search
from .instances import Instances
from .menu import Menu
@Gtk.Template(resource_path='/sm/puri/Stream/ui/window.ui')
class StreamWindow(Handy.ApplicationWindow):
......@@ -37,6 +38,8 @@ class StreamWindow(Handy.ApplicationWindow):
search_bar_toggle = Gtk.Template.Child()
search_bar = Gtk.Template.Child()
menu_button = Gtk.Template.Child()
status_page = Gtk.Template.Child()
spinner = Gtk.Template.Child()
error_box = Gtk.Template.Child()
......@@ -78,6 +81,10 @@ class StreamWindow(Handy.ApplicationWindow):
else:
focus_child.get_child().play_button(None)
# @Gtk.Template.Callback()
# def open_primary_menu(self, widget, ev):
# print("in open primary menu")
@Gtk.Template.Callback()
def keypress_listener(self, widget, ev):
key = Gdk.keyval_name(ev.keyval)
......@@ -120,6 +127,9 @@ class StreamWindow(Handy.ApplicationWindow):
instances = Instances(app_window = self)
instances.get_strong_instances()
menu = Menu(app_window = self)
self.menu_button.set_popover(menu)
provider = Gtk.CssProvider()
provider.load_from_resource('/sm/puri/Stream/ui/stream.css')
styleContext = Gtk.StyleContext()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment