gstreamer/debug-viewer/GstDebugViewer/GUI/app.py

130 lines
3.6 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
from gi.repository import GObject
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
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)
2011-11-05 22:47:47 +00:00
zoom_level = Common.GUI.StateInt ("zoom-level")
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)
self.add_section_class (AppStateSection)
class App (object):
def __init__ (self):
self.attach ()
def load_plugins (self):
from GstDebugViewer import Plugins
plugin_classes = list (Plugins.load ([os.path.dirname (Plugins.__file__)]))
self.plugins = []
for plugin_class in plugin_classes:
plugin = plugin_class (self)
self.plugins.append (plugin)
def iter_plugin_features (self):
for plugin in self.plugins:
for feature in plugin.features:
yield feature
def attach (self):
config_home = Common.utils.XDG.CONFIG_HOME
state_filename = os.path.join (config_home, "gst-debug-viewer", "state")
self.state = AppState (state_filename)
self.state_section = self.state.sections["state"]
self.load_plugins ()
self.windows = []
# we override expander size because of:
# https://bugzilla.gnome.org/show_bug.cgi?id=615985
rcstring = """
style "no-expander-treeview-style" {
GtkTreeView::expander_size = 1
#GtkTreeView::vertical-separator = 0
GtkWidget::focus-line-width = 0
}
widget "*.log_view" style "no-expander-treeview-style"
"""
Gtk.rc_parse_string (rcstring)
2009-08-06 23:54:10 +00:00
self.open_window ()
def detach (self):
# TODO: If we take over deferred saving from the inspector, specify now
# = True here!
self.state.save ()
def run (self):
try:
Common.Main.MainLoopWrapper (Gtk.main, Gtk.main_quit).run ()
2009-08-06 23:54:10 +00:00
except:
raise
else:
self.detach ()
def open_window (self):
self.windows.append (Window (self))
def close_window (self, window):
self.windows.remove (window)
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 ()