2009-08-06 23:54:10 +00:00
|
|
|
# -*- coding: utf-8; mode: python; -*-
|
|
|
|
#
|
|
|
|
# GStreamer Debug Viewer - View and analyze GStreamer debug log files
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 René Stadler <mail@renestadler.de>
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
"""GStreamer Debug Viewer GUI module."""
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
|
2018-04-14 13:22:11 +00:00
|
|
|
import gi
|
|
|
|
gi.require_version('Gdk', '3.0')
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
from gi.repository import GObject
|
2016-10-08 20:23:39 +00:00
|
|
|
from gi.repository import Gdk
|
2015-10-20 13:21:01 +00:00
|
|
|
from gi.repository import Gtk
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
from GstDebugViewer import Common
|
|
|
|
from GstDebugViewer.GUI.columns import ViewColumnManager
|
|
|
|
from GstDebugViewer.GUI.window import Window
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2009-08-06 23:54:10 +00:00
|
|
|
class AppStateSection (Common.GUI.StateSection):
|
|
|
|
|
|
|
|
_name = "state"
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
geometry = Common.GUI.StateInt4("window-geometry")
|
|
|
|
maximized = Common.GUI.StateBool("window-maximized")
|
|
|
|
|
|
|
|
column_order = Common.GUI.StateItemList("column-order", ViewColumnManager)
|
|
|
|
columns_visible = Common.GUI.StateItemList(
|
|
|
|
"columns-visible", ViewColumnManager)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
zoom_level = Common.GUI.StateInt("zoom-level")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2011-11-05 22:47:47 +00:00
|
|
|
|
2009-08-06 23:54:10 +00:00
|
|
|
class AppState (Common.GUI.State):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, *a, **kw):
|
|
|
|
|
|
|
|
Common.GUI.State.__init__(self, *a, **kw)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.add_section_class(AppStateSection)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class App (object):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.attach()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def load_plugins(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
from GstDebugViewer import Plugins
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
plugin_classes = list(
|
|
|
|
Plugins.load([os.path.dirname(Plugins.__file__)]))
|
2009-08-06 23:54:10 +00:00
|
|
|
self.plugins = []
|
|
|
|
for plugin_class in plugin_classes:
|
2016-09-28 18:38:55 +00:00
|
|
|
plugin = plugin_class(self)
|
|
|
|
self.plugins.append(plugin)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def iter_plugin_features(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
for plugin in self.plugins:
|
|
|
|
for feature in plugin.features:
|
|
|
|
yield feature
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def attach(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
config_home = Common.utils.XDG.CONFIG_HOME
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
state_filename = os.path.join(
|
|
|
|
config_home, "gst-debug-viewer", "state")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.state = AppState(state_filename)
|
2009-08-06 23:54:10 +00:00
|
|
|
self.state_section = self.state.sections["state"]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.load_plugins()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.windows = []
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2016-10-08 20:23:39 +00:00
|
|
|
# Apply custom widget stying
|
|
|
|
# TODO: check for dark theme
|
2018-04-14 13:22:11 +00:00
|
|
|
css = b"""
|
2016-10-08 20:23:39 +00:00
|
|
|
@define-color normal_bg_color #FFFFFF;
|
|
|
|
@define-color shade_bg_color shade(@normal_bg_color, 0.95);
|
|
|
|
#log_view row:nth-child(even) {
|
|
|
|
background-color: @normal_bg_color;
|
|
|
|
}
|
|
|
|
#log_view row:nth-child(odd) {
|
|
|
|
background-color: @shade_bg_color;
|
|
|
|
}
|
|
|
|
#log_view row:selected {
|
|
|
|
background-color: #4488FF;
|
|
|
|
}
|
|
|
|
#log_view {
|
|
|
|
-GtkTreeView-horizontal-separator: 0;
|
|
|
|
-GtkTreeView-vertical-separator: 1;
|
|
|
|
outline-width: 0;
|
|
|
|
outline-offset: 0;
|
2010-04-16 15:26:26 +00:00
|
|
|
}
|
|
|
|
"""
|
2016-10-08 20:23:39 +00:00
|
|
|
|
|
|
|
style_provider = Gtk.CssProvider()
|
|
|
|
style_provider.load_from_data(css)
|
|
|
|
|
|
|
|
Gtk.StyleContext.add_provider_for_screen(
|
|
|
|
Gdk.Screen.get_default(),
|
|
|
|
style_provider,
|
|
|
|
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
|
|
|
)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.open_window()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def detach(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
# TODO: If we take over deferred saving from the inspector, specify now
|
|
|
|
# = True here!
|
2016-09-28 18:38:55 +00:00
|
|
|
self.state.save()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def run(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
try:
|
2016-09-28 18:38:55 +00:00
|
|
|
Common.Main.MainLoopWrapper(Gtk.main, Gtk.main_quit).run()
|
2019-03-16 15:21:34 +00:00
|
|
|
except BaseException:
|
2009-08-06 23:54:10 +00:00
|
|
|
raise
|
|
|
|
else:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.detach()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def open_window(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.windows.append(Window(self))
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def close_window(self, window):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.windows.remove(window)
|
2009-08-06 23:54:10 +00:00
|
|
|
if not self.windows:
|
|
|
|
# GtkTreeView takes some time to go down for large files. Let's block
|
|
|
|
# until the window is hidden:
|
2016-09-28 18:38:55 +00:00
|
|
|
GObject.idle_add(Gtk.main_quit)
|
|
|
|
Gtk.main()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
Gtk.main_quit()
|