-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathkickoff_player.py
executable file
·113 lines (78 loc) · 3.21 KB
/
kickoff_player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#! /usr/bin/python3
import gi
import signal
import argparse
gi.require_version('Gtk', '3.0')
gi.require_version('GLib', '2.0')
from gi.repository import Gtk, GLib
from handlers.data import DataHandler, StaticStream
from handlers.cache import CacheHandler
from handlers.match import MatchHandler
from handlers.channel import ChannelHandler
from handlers.player import PlayerHandler
from apis.scores import ScoresApi
from apis.streams import StreamsApi
from helpers.gtk import add_custom_css, relative_path
class KickoffPlayer(object):
def __init__(self, cache, data):
GLib.set_prgname('kickoff-player')
GLib.set_application_name('Kickoff Player')
add_custom_css('ui/styles.css')
self.argparse = argparse.ArgumentParser(prog='kickoff-player')
self.argparse.add_argument('url', metavar='URL', nargs='?', default=None)
self.cache = cache
self.data = data
self.scores_api = ScoresApi(self.data, self.cache)
self.streams_api = StreamsApi(self.data, self.cache)
self.main = Gtk.Builder()
self.main.add_from_file(relative_path('ui/main.ui'))
self.main.connect_signals(self)
self.window = self.main.get_object('window_main')
self.header_back = self.main.get_object('header_button_back')
self.header_reload = self.main.get_object('header_button_reload')
self.main_stack = self.main.get_object('stack_main')
self.player_stack = self.main.get_object('stack_player')
self.matches_stack = self.main.get_object('stack_matches')
self.channels_stack = self.main.get_object('stack_channels')
self.matches = MatchHandler(self)
self.channels = ChannelHandler(self)
self.player = PlayerHandler(self)
GLib.timeout_add(2000, self.toggle_reload, True)
self.open_stream_url()
def run(self):
self.window.show_all()
Gtk.main()
def quit(self):
self.player.close()
Gtk.main_quit()
def open_stream_url(self):
url = self.argparse.parse_args().url
if url is not None:
stream = StaticStream(url)
self.player.open_stream(stream)
self.set_stack_visible_child(self.player_stack)
def toggle_reload(self, show):
self.header_reload.set_sensitive(show)
def get_stack_visible_child(self):
return self.main_stack.get_visible_child()
def set_stack_visible_child(self, widget):
self.main_stack.set_visible_child(widget)
def on_window_main_destroy(self, _event):
self.quit()
def on_window_main_key_release_event(self, widget, event):
self.player.on_window_main_key_release_event(widget, event)
def on_header_button_back_clicked(self, widget):
self.matches.on_header_button_back_clicked(widget)
def on_header_button_reload_clicked(self, widget):
self.player.on_header_button_reload_clicked(widget)
self.matches.on_header_button_reload_clicked(widget)
self.channels.on_header_button_reload_clicked(widget)
def on_stack_main_visible_child_notify(self, widget, params):
self.matches.on_stack_main_visible_child_notify(widget, params)
self.channels.on_stack_main_visible_child_notify(widget, params)
if __name__ == '__main__':
signal.signal(signal.SIGINT, signal.SIG_DFL)
cache = CacheHandler()
data = DataHandler()
player = KickoffPlayer(cache, data)
player.run()