gstreamer/subprojects/gst-devtools/debug-viewer/GstDebugViewer/GUI/app.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
4.2 KiB
Python
Raw Normal View History

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
import gi
gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0')
from gi.repository import GObject
from gi.repository import Gdk
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
2009-08-06 23:54:10 +00:00
class AppStateSection (Common.GUI.StateSection):
_name = "state"
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
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):
def __init__(self, *a, **kw):
Common.GUI.State.__init__(self, *a, **kw)
2009-08-06 23:54:10 +00:00
self.add_section_class(AppStateSection)
2009-08-06 23:54:10 +00:00
class App (object):
def __init__(self):
2009-08-06 23:54:10 +00:00
self.attach()
2009-08-06 23:54:10 +00:00
def load_plugins(self):
2009-08-06 23:54:10 +00:00
from GstDebugViewer import Plugins
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:
plugin = plugin_class(self)
self.plugins.append(plugin)
2009-08-06 23:54:10 +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
def attach(self):
2009-08-06 23:54:10 +00:00
config_home = Common.utils.XDG.CONFIG_HOME
state_filename = os.path.join(
config_home, "gst-debug-viewer", "state")
2009-08-06 23:54:10 +00:00
self.state = AppState(state_filename)
2009-08-06 23:54:10 +00:00
self.state_section = self.state.sections["state"]
self.load_plugins()
2009-08-06 23:54:10 +00:00
self.windows = []
# Apply custom widget stying
# TODO: check for dark theme
css = b"""
@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;
}
"""
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
self.open_window()
2009-08-06 23:54:10 +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!
self.state.save()
2009-08-06 23:54:10 +00:00
def run(self):
2009-08-06 23:54:10 +00:00
try:
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:
self.detach()
2009-08-06 23:54:10 +00:00
def open_window(self):
2009-08-06 23:54:10 +00:00
self.windows.append(Window(self))
2009-08-06 23:54:10 +00:00
def close_window(self, window):
2009-08-06 23:54:10 +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:
GObject.idle_add(Gtk.main_quit)
Gtk.main()
2009-08-06 23:54:10 +00:00
Gtk.main_quit()