2007-11-14 08:30:19 +00:00
|
|
|
# -*- coding: utf-8; mode: python; -*-
|
|
|
|
#
|
|
|
|
# GStreamer Development Utilities
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2007-11-22 08:47:06 +00:00
|
|
|
"""GStreamer Development Utilities Common GUI module."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
import os
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import pygtk
|
|
|
|
pygtk.require ("2.0")
|
|
|
|
del pygtk
|
|
|
|
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
import GstDebugViewer
|
2007-11-14 08:30:19 +00:00
|
|
|
from GstDebugViewer.Common import utils
|
|
|
|
|
2007-12-07 14:24:01 +00:00
|
|
|
def widget_add_popup_menu (widget, menu, button = 3):
|
|
|
|
|
|
|
|
def popup_callback (widget, event):
|
|
|
|
|
|
|
|
if event.button == button:
|
|
|
|
menu.popup (None, None, None, event.button, event.get_time ())
|
2007-12-11 08:44:20 +00:00
|
|
|
return False
|
2007-12-07 14:24:01 +00:00
|
|
|
|
|
|
|
widget.connect ("button-press-event", popup_callback)
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
class Actions (dict):
|
|
|
|
|
|
|
|
def __init__ (self):
|
|
|
|
|
|
|
|
dict.__init__ (self)
|
|
|
|
|
2007-11-28 09:27:26 +00:00
|
|
|
self.groups = {}
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
def __getattr__ (self, name):
|
|
|
|
|
|
|
|
try:
|
|
|
|
return self[name]
|
|
|
|
except KeyError:
|
|
|
|
if "_" in name:
|
|
|
|
try:
|
|
|
|
return self[name.replace ("_", "-")]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
raise AttributeError ("no action with name %r" % (name,))
|
|
|
|
|
|
|
|
def add_group (self, group):
|
|
|
|
|
2007-11-28 09:27:26 +00:00
|
|
|
name = group.props.name
|
|
|
|
if name in self.groups:
|
|
|
|
raise ValueError ("already have a group named %s", name)
|
|
|
|
self.groups[name] = group
|
2007-11-14 08:30:19 +00:00
|
|
|
for action in group.list_actions ():
|
|
|
|
self[action.props.name] = action
|
|
|
|
|
|
|
|
class Widgets (dict):
|
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
def __init__ (self, builder):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
widgets = (obj for obj in builder.get_objects ()
|
2010-07-02 20:03:39 +00:00
|
|
|
if isinstance(obj, gtk.Buildable))
|
|
|
|
# gtk.Widget.get_name() shadows out the GtkBuildable interface method
|
|
|
|
# of the same name, hence calling the unbound interface method here:
|
|
|
|
items = ((gtk.Buildable.get_name (w), w,) for w in widgets)
|
|
|
|
|
|
|
|
dict.__init__ (self, items)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
def __getattr__ (self, name):
|
|
|
|
|
|
|
|
try:
|
|
|
|
return self[name]
|
|
|
|
except KeyError:
|
|
|
|
if "_" in name:
|
|
|
|
try:
|
|
|
|
return self[name.replace ("_", "-")]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
raise AttributeError ("no widget with name %r" % (name,))
|
|
|
|
|
|
|
|
class WidgetFactory (object):
|
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
def __init__ (self, directory):
|
|
|
|
|
|
|
|
self.directory = directory
|
|
|
|
|
|
|
|
def get_builder (self, filename):
|
|
|
|
|
|
|
|
builder_filename = os.path.join (self.directory, filename)
|
|
|
|
|
|
|
|
builder = gtk.Builder ()
|
|
|
|
builder.set_translation_domain (GstDebugViewer.GETTEXT_DOMAIN)
|
|
|
|
builder.add_from_file (builder_filename)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
return builder
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
def make (self, filename, widget_name, autoconnect = None):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
builder = self.get_builder (filename)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if autoconnect is not None:
|
2009-03-14 17:38:36 +00:00
|
|
|
builder.connect_signals (autoconnect)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
return Widgets (builder)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
def make_one (self, filename, widget_name):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
builder = self.get_builder (filename)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2009-03-14 17:38:36 +00:00
|
|
|
return builder.get_object (widget_name)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
class UIFactory (object):
|
|
|
|
|
|
|
|
def __init__ (self, ui_filename, actions = None):
|
|
|
|
|
|
|
|
self.filename = ui_filename
|
|
|
|
if actions:
|
|
|
|
self.action_groups = actions.groups
|
|
|
|
else:
|
|
|
|
self.action_groups = ()
|
|
|
|
|
|
|
|
def make (self, extra_actions = None):
|
|
|
|
|
|
|
|
ui_manager = gtk.UIManager ()
|
2007-11-28 09:27:26 +00:00
|
|
|
for action_group in self.action_groups.values ():
|
2007-11-14 08:30:19 +00:00
|
|
|
ui_manager.insert_action_group (action_group, 0)
|
|
|
|
if extra_actions:
|
|
|
|
for action_group in extra_actions.groups:
|
|
|
|
ui_manager.insert_action_group (action_group, 0)
|
|
|
|
ui_manager.add_ui_from_file (self.filename)
|
|
|
|
ui_manager.ensure_update ()
|
|
|
|
|
|
|
|
return ui_manager
|
|
|
|
|
|
|
|
class MetaModel (gobject.GObjectMeta):
|
|
|
|
|
|
|
|
"""Meta class for easy setup of gtk tree models.
|
|
|
|
|
|
|
|
Looks for a class attribute named `columns' which must be set to a
|
|
|
|
sequence of the form name1, type1, name2, type2, ..., where the
|
|
|
|
names are strings. This metaclass adds the following attributes
|
|
|
|
to created classes:
|
|
|
|
|
|
|
|
cls.column_types = (type1, type2, ...)
|
|
|
|
cls.column_ids = (0, 1, ...)
|
|
|
|
cls.name1 = 0
|
|
|
|
cls.name2 = 1
|
|
|
|
...
|
|
|
|
|
|
|
|
Example: A gtk.ListStore derived model can use
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
columns = ("COL_NAME", str, "COL_VALUE", str)
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
and use this in __init__:
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
gtk.ListStore.__init__ (self, *self.column_types)
|
|
|
|
|
|
|
|
Then insert data like this:
|
|
|
|
|
|
|
|
self.set (self.append (),
|
|
|
|
self.COL_NAME, "spam",
|
|
|
|
self.COL_VALUE, "ham")
|
|
|
|
"""
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
def __init__ (cls, name, bases, dict):
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
super (MetaModel, cls).__init__ (name, bases, dict)
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
spec = tuple (cls.columns)
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
column_names = spec[::2]
|
|
|
|
column_types = spec[1::2]
|
|
|
|
column_indices = range (len (column_names))
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
for col_index, col_name, in zip (column_indices, column_names):
|
|
|
|
setattr (cls, col_name, col_index)
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
cls.column_types = column_types
|
|
|
|
cls.column_ids = tuple (column_indices)
|
|
|
|
|
|
|
|
class Manager (object):
|
|
|
|
|
|
|
|
"""GUI Manager base class."""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def iter_item_classes (cls):
|
|
|
|
|
|
|
|
msg = "%s class does not support manager item class access"
|
|
|
|
raise NotImplementedError (msg % (cls.__name__,))
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def find_item_class (self, **kw):
|
|
|
|
|
|
|
|
return self.__find_by_attrs (self.iter_item_classes (), kw)
|
|
|
|
|
|
|
|
def iter_items (self):
|
|
|
|
|
|
|
|
msg = "%s object does not support manager item access"
|
|
|
|
raise NotImplementedError (msg % (type (self).__name__,))
|
|
|
|
|
|
|
|
def find_item (self, **kw):
|
|
|
|
|
|
|
|
return self.__find_by_attrs (self.iter_items (), kw)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def __find_by_attrs (i, kw):
|
|
|
|
|
|
|
|
from operator import attrgetter
|
|
|
|
|
|
|
|
if len (kw) != 1:
|
|
|
|
raise ValueError ("need exactly one keyword argument")
|
|
|
|
|
|
|
|
attr, value = kw.items ()[0]
|
|
|
|
getter = attrgetter (attr)
|
|
|
|
|
|
|
|
for item in i:
|
|
|
|
if getter (item) == value:
|
|
|
|
return item
|
|
|
|
else:
|
|
|
|
raise KeyError ("no item such that item.%s == %r" % (attr, value,))
|
|
|
|
|
|
|
|
class StateString (object):
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
"""Descriptor for binding to StateSection classes."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 12:42:46 +00:00
|
|
|
def __init__ (self, option, default = None):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
self.option = option
|
2007-11-26 12:42:46 +00:00
|
|
|
self.default = default
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def __get__ (self, section, section_class = None):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
import ConfigParser
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
if section is None:
|
2007-11-14 08:30:19 +00:00
|
|
|
return self
|
|
|
|
|
|
|
|
try:
|
2007-11-26 11:55:03 +00:00
|
|
|
return self.get (section)
|
2007-11-14 08:30:19 +00:00
|
|
|
except (ConfigParser.NoSectionError,
|
|
|
|
ConfigParser.NoOptionError,):
|
2007-11-26 11:55:03 +00:00
|
|
|
return self.get_default (section)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def __set__ (self, section, value):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
import ConfigParser
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
self.set (section, value)
|
|
|
|
|
|
|
|
def get (self, section):
|
|
|
|
|
|
|
|
return section.get (self)
|
|
|
|
|
|
|
|
def get_default (self, section):
|
|
|
|
|
2007-11-26 12:42:46 +00:00
|
|
|
return self.default
|
2007-11-26 11:55:03 +00:00
|
|
|
|
|
|
|
def set (self, section, value):
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
if value is None:
|
|
|
|
value = ""
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
section.set (self, str (value))
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
class StateBool (StateString):
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
"""Descriptor for binding to StateSection classes."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def get (self, section):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
return section.state._parser.getboolean (section._name, self.option)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
class StateInt (StateString):
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
"""Descriptor for binding to StateSection classes."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def get (self, section):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
return section.state._parser.getint (section._name, self.option)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
class StateInt4 (StateString):
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
"""Descriptor for binding to StateSection classes. This implements storing
|
|
|
|
a tuple of 4 integers."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def get (self, section):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
value = StateString.get (self, section)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
l = value.split (",")
|
|
|
|
if len (l) != 4:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return tuple ((int (v) for v in l))
|
|
|
|
except (AttributeError, TypeError, ValueError,):
|
|
|
|
return None
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def set (self, section, value):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if value is None:
|
|
|
|
svalue = ""
|
|
|
|
elif len (value) != 4:
|
|
|
|
raise ValueError ("value needs to be a 4-sequence, or None")
|
|
|
|
else:
|
|
|
|
svalue = ", ".join ((str (v) for v in value))
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
return StateString.set (self, section, svalue)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
class StateItem (StateString):
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
"""Descriptor for binding to StateSection classes. This implements storing
|
|
|
|
a class controlled by a Manager class."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 12:42:46 +00:00
|
|
|
def __init__ (self, option, manager_class, default = None):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 12:42:46 +00:00
|
|
|
StateString.__init__ (self, option, default = default)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
self.manager = manager_class
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def get (self, section):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
value = SectionString.get (self, section)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if not value:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return self.parse_item (value)
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def set (self, section, value):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if value is None:
|
|
|
|
svalue = ""
|
|
|
|
else:
|
|
|
|
svalue = value.name
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
StateString.set (self, section, svalue)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
def parse_item (self, value):
|
|
|
|
|
|
|
|
name = value.strip ()
|
|
|
|
|
|
|
|
try:
|
|
|
|
return self.manager.find_item_class (name = name)
|
|
|
|
except KeyError:
|
2009-03-14 21:02:45 +00:00
|
|
|
return None
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
class StateItemList (StateItem):
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
"""Descriptor for binding to StateSection classes. This implements storing
|
|
|
|
an ordered set of Manager items."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def get (self, section):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
value = StateString.get (self, section)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if not value:
|
|
|
|
return []
|
|
|
|
|
|
|
|
classes = []
|
|
|
|
for name in value.split (","):
|
|
|
|
item_class = self.parse_item (name)
|
|
|
|
if item_class is None:
|
|
|
|
continue
|
|
|
|
if not item_class in classes:
|
|
|
|
classes.append (item_class)
|
|
|
|
|
|
|
|
return classes
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def get_default (self, section):
|
|
|
|
|
2007-11-26 12:42:46 +00:00
|
|
|
default = StateItem.get_default (self, section)
|
|
|
|
if default is None:
|
|
|
|
return []
|
|
|
|
else:
|
|
|
|
return default
|
2007-11-26 11:55:03 +00:00
|
|
|
|
|
|
|
def set (self, section, value):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if value is None:
|
|
|
|
svalue = ""
|
|
|
|
else:
|
|
|
|
svalue = ", ".join ((v.name for v in value))
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
StateString.set (self, section, svalue)
|
|
|
|
|
|
|
|
class StateSection (object):
|
|
|
|
|
|
|
|
_name = None
|
|
|
|
|
|
|
|
def __init__ (self, state):
|
|
|
|
|
|
|
|
self.state = state
|
|
|
|
|
|
|
|
if self._name is None:
|
|
|
|
raise NotImplementedError ("subclasses must override the _name attribute")
|
|
|
|
|
|
|
|
def get (self, state_string):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
return self.state._parser.get (self._name, state_string.option)
|
|
|
|
|
|
|
|
def set (self, state_string, value):
|
|
|
|
|
|
|
|
import ConfigParser
|
|
|
|
|
|
|
|
parser = self.state._parser
|
|
|
|
|
|
|
|
try:
|
|
|
|
parser.set (self._name, state_string.option, value)
|
|
|
|
except ConfigParser.NoSectionError:
|
|
|
|
parser.add_section (self._name)
|
|
|
|
parser.set (self._name, state_string.option, value)
|
|
|
|
|
|
|
|
class State (object):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
def __init__ (self, filename, old_filenames = ()):
|
|
|
|
|
|
|
|
import ConfigParser
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
self.sections = {}
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
self._filename = filename
|
|
|
|
self._parser = ConfigParser.RawConfigParser ()
|
|
|
|
success = self._parser.read ([filename])
|
|
|
|
if not success:
|
|
|
|
for old_filename in old_filenames:
|
|
|
|
success = self._parser.read ([old_filename])
|
|
|
|
if success:
|
|
|
|
break
|
|
|
|
|
2007-11-26 11:55:03 +00:00
|
|
|
def add_section_class (self, section_class):
|
|
|
|
|
|
|
|
self.sections[section_class._name] = section_class (self)
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
def save (self):
|
|
|
|
|
2011-11-16 18:50:06 +00:00
|
|
|
with utils.SaveWriteFile (self._filename, "wt") as fp:
|
2007-11-14 08:30:19 +00:00
|
|
|
self._parser.write (fp)
|
|
|
|
|
|
|
|
class WindowState (object):
|
|
|
|
|
|
|
|
def __init__ (self):
|
|
|
|
|
|
|
|
self.logger = logging.getLogger ("ui.window-state")
|
|
|
|
|
|
|
|
self.is_maximized = False
|
|
|
|
|
|
|
|
def attach (self, window, state):
|
|
|
|
|
|
|
|
self.window = window
|
|
|
|
self.state = state
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
self.window.connect ("window-state-event",
|
|
|
|
self.handle_window_state_event)
|
|
|
|
|
|
|
|
geometry = self.state.geometry
|
|
|
|
if geometry:
|
|
|
|
self.window.move (*geometry[:2])
|
|
|
|
self.window.set_default_size (*geometry[2:])
|
|
|
|
|
|
|
|
if self.state.maximized:
|
|
|
|
self.logger.debug ("initially maximized")
|
|
|
|
self.window.maximize ()
|
|
|
|
|
|
|
|
def detach (self):
|
|
|
|
|
|
|
|
window = self.window
|
|
|
|
|
|
|
|
self.state.maximized = self.is_maximized
|
|
|
|
if not self.is_maximized:
|
|
|
|
position = tuple (window.get_position ())
|
|
|
|
size = tuple (window.get_size ())
|
|
|
|
self.state.geometry = position + size
|
|
|
|
|
|
|
|
self.window.disconnect_by_func (self.handle_window_state_event)
|
|
|
|
self.window = None
|
|
|
|
|
|
|
|
def handle_window_state_event (self, window, event):
|
|
|
|
|
|
|
|
if not event.changed_mask & gtk.gdk.WINDOW_STATE_MAXIMIZED:
|
|
|
|
return
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
if event.new_window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED:
|
|
|
|
self.logger.debug ("maximized")
|
|
|
|
self.is_maximized = True
|
|
|
|
else:
|
|
|
|
self.logger.debug ("unmaximized")
|
|
|
|
self.is_maximized = False
|