parent
6345da8e07
commit
aa8a5e70c4
@ -1 +1 @@
|
||||
dist_bin_SCRIPTS = sugar-activity sugar-activity-web
|
||||
dist_bin_SCRIPTS = sugar-activity sugar-activity-web sugar-activity3
|
||||
|
@ -1,219 +1,5 @@
|
||||
#!/usr/bin/env python2
|
||||
|
||||
# Copyright (C) 2006-2008, Red Hat, Inc.
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
from sugar3.activity import activityinstance
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Change the default encoding to avoid UnicodeDecodeError
|
||||
# http://lists.sugarlabs.org/archive/sugar-devel/2012-August/038928.html
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
|
||||
import gettext
|
||||
from optparse import OptionParser
|
||||
|
||||
import dbus
|
||||
import dbus.service
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
|
||||
from sugar3.activity import activityhandle
|
||||
from sugar3 import config
|
||||
from sugar3.bundle.activitybundle import ActivityBundle
|
||||
from sugar3 import logger
|
||||
|
||||
from sugar3.bundle.bundle import MalformedBundleException
|
||||
|
||||
from distutils.dir_util import mkpath
|
||||
import time
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
def create_activity_instance(constructor, handle):
|
||||
activity = constructor(handle)
|
||||
activity.show()
|
||||
return activity
|
||||
|
||||
|
||||
def get_single_process_name(bundle_id):
|
||||
return bundle_id
|
||||
|
||||
|
||||
def get_single_process_path(bundle_id):
|
||||
return '/' + bundle_id.replace('.', '/')
|
||||
|
||||
|
||||
class SingleProcess(dbus.service.Object):
|
||||
|
||||
def __init__(self, name_service, constructor):
|
||||
self.constructor = constructor
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
bus_name = dbus.service.BusName(name_service, bus=bus)
|
||||
object_path = get_single_process_path(name_service)
|
||||
dbus.service.Object.__init__(self, bus_name, object_path)
|
||||
|
||||
@dbus.service.method('org.laptop.SingleProcess', in_signature='a{sv}')
|
||||
def create(self, handle_dict):
|
||||
handle = activityhandle.create_from_dict(handle_dict)
|
||||
create_activity_instance(self.constructor, handle)
|
||||
|
||||
|
||||
def main():
|
||||
usage = 'usage: %prog [options] [activity dir] [python class]'
|
||||
epilog = 'If you are running from a directory containing an Activity, ' \
|
||||
'the argument may be omitted. Otherwise please provide either '\
|
||||
'a directory containing a Sugar Activity [activity dir], a '\
|
||||
'[python_class], or both.'
|
||||
|
||||
parser = OptionParser(usage=usage, epilog=epilog)
|
||||
parser.add_option('-b', '--bundle-id', dest='bundle_id',
|
||||
help='identifier of the activity bundle')
|
||||
parser.add_option('-a', '--activity-id', dest='activity_id',
|
||||
help='identifier of the activity instance')
|
||||
parser.add_option('-o', '--object-id', dest='object_id',
|
||||
help='identifier of the associated datastore object')
|
||||
parser.add_option('-u', '--uri', dest='uri',
|
||||
help='URI to load')
|
||||
parser.add_option('-s', '--single-process', dest='single_process',
|
||||
action='store_true',
|
||||
help='start all the instances in the same process')
|
||||
parser.add_option('-i', '--invited', dest='invited',
|
||||
action='store_true', default=False,
|
||||
help='the activity is being launched for handling an '
|
||||
'invite from the network')
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
logger.start()
|
||||
|
||||
activity_class = None
|
||||
if len(args) == 2:
|
||||
activity_class = args[1]
|
||||
os.chdir(args[0])
|
||||
elif len(args) == 1:
|
||||
if os.path.isdir(args[0]):
|
||||
os.chdir(args[0])
|
||||
else:
|
||||
activity_class = args[0]
|
||||
|
||||
os.environ['SUGAR_BUNDLE_PATH'] = os.path.abspath(os.curdir)
|
||||
|
||||
bundle_path = os.environ['SUGAR_BUNDLE_PATH']
|
||||
sys.path.insert(0, bundle_path)
|
||||
|
||||
try:
|
||||
bundle = ActivityBundle(bundle_path)
|
||||
except MalformedBundleException:
|
||||
parser.print_help()
|
||||
exit(0)
|
||||
|
||||
if not activity_class:
|
||||
if bundle.get_command().startswith('sugar-activity'):
|
||||
activity_class = bundle.get_command().split(" ")[1]
|
||||
|
||||
if 'SUGAR_VERSION' not in os.environ:
|
||||
profile_id = os.environ.get('SUGAR_PROFILE', 'default')
|
||||
home_dir = os.environ.get('SUGAR_HOME', os.path.expanduser('~/.sugar'))
|
||||
base = os.path.join(home_dir, profile_id)
|
||||
activity_root = os.path.join(base, bundle.get_bundle_id())
|
||||
|
||||
instance_dir = os.path.join(activity_root, 'instance')
|
||||
mkpath(instance_dir)
|
||||
|
||||
data_dir = os.path.join(activity_root, 'data')
|
||||
mkpath(data_dir)
|
||||
|
||||
tmp_dir = os.path.join(activity_root, 'tmp')
|
||||
mkpath(tmp_dir)
|
||||
|
||||
os.environ['SUGAR_ACTIVITY_ROOT'] = activity_root
|
||||
os.environ['SUGAR_BUNDLE_PATH'] = bundle.get_path()
|
||||
|
||||
os.environ['SUGAR_BUNDLE_ID'] = bundle.get_bundle_id()
|
||||
os.environ['SUGAR_BUNDLE_NAME'] = bundle.get_name()
|
||||
os.environ['SUGAR_BUNDLE_VERSION'] = str(bundle.get_activity_version())
|
||||
|
||||
# must be done early, some activities set translations globally, SL #3654
|
||||
activity_locale_path = os.environ.get("SUGAR_LOCALEDIR",
|
||||
config.locale_path)
|
||||
|
||||
gettext.bindtextdomain(bundle.get_bundle_id(), activity_locale_path)
|
||||
gettext.bindtextdomain('sugar-toolkit-gtk3', config.locale_path)
|
||||
gettext.textdomain(bundle.get_bundle_id())
|
||||
|
||||
splitted_module = activity_class.rsplit('.', 1)
|
||||
module_name = splitted_module[0]
|
||||
class_name = splitted_module[1]
|
||||
|
||||
module = __import__(module_name)
|
||||
for comp in module_name.split('.')[1:]:
|
||||
module = getattr(module, comp)
|
||||
|
||||
activity_constructor = getattr(module, class_name)
|
||||
|
||||
if not options.activity_id:
|
||||
# Generate random hash
|
||||
data = '%s%s' % (time.time(), random.randint(10000, 100000))
|
||||
random_hash = hashlib.sha1(data).hexdigest()
|
||||
options.activity_id = random_hash
|
||||
options.bundle_id = bundle.get_bundle_id()
|
||||
|
||||
activity_handle = activityhandle.ActivityHandle(
|
||||
activity_id=options.activity_id,
|
||||
object_id=options.object_id, uri=options.uri,
|
||||
invited=options.invited)
|
||||
|
||||
if options.single_process is True:
|
||||
sessionbus = dbus.SessionBus()
|
||||
|
||||
service_name = get_single_process_name(options.bundle_id)
|
||||
service_path = get_single_process_path(options.bundle_id)
|
||||
|
||||
bus_object = sessionbus.get_object(
|
||||
'org.freedesktop.DBus', '/org/freedesktop/DBus')
|
||||
try:
|
||||
name = bus_object.GetNameOwner(
|
||||
service_name, dbus_interface='org.freedesktop.DBus')
|
||||
except dbus.DBusException:
|
||||
name = None
|
||||
|
||||
if not name:
|
||||
SingleProcess(service_name, activity_constructor)
|
||||
else:
|
||||
try:
|
||||
single_process = sessionbus.get_object(service_name,
|
||||
service_path)
|
||||
single_process.create(
|
||||
activity_handle.get_dict(),
|
||||
dbus_interface='org.laptop.SingleProcess')
|
||||
|
||||
print 'Created %s in a single process.' % service_name
|
||||
sys.exit(0)
|
||||
except (TypeError, dbus.DBusException):
|
||||
print 'Could not communicate with the instance process,' \
|
||||
'launching a new process'
|
||||
|
||||
if hasattr(module, 'start'):
|
||||
module.start()
|
||||
|
||||
instance = create_activity_instance(activity_constructor, activity_handle)
|
||||
|
||||
if hasattr(instance, 'run_main_loop'):
|
||||
instance.run_main_loop()
|
||||
|
||||
main()
|
||||
activityinstance.main()
|
||||
|
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from sugar3.activity import activityinstance
|
||||
|
||||
activityinstance.main()
|
@ -0,0 +1,222 @@
|
||||
# Copyright (C) 2006-2008, Red Hat, Inc.
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import os
|
||||
import sys
|
||||
import six
|
||||
import logging
|
||||
|
||||
# Change the default encoding to avoid UnicodeDecodeError
|
||||
# http://lists.sugarlabs.org/archive/sugar-devel/2012-August/038928.html
|
||||
if six.PY2:
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
|
||||
import gettext
|
||||
from optparse import OptionParser
|
||||
|
||||
import dbus
|
||||
import dbus.service
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
|
||||
from sugar3.activity import activityhandle
|
||||
from sugar3 import config
|
||||
from sugar3.bundle.activitybundle import ActivityBundle
|
||||
from sugar3 import logger
|
||||
|
||||
from sugar3.bundle.bundle import MalformedBundleException
|
||||
|
||||
from distutils.dir_util import mkpath
|
||||
import time
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
|
||||
def create_activity_instance(constructor, handle):
|
||||
activity = constructor(handle)
|
||||
activity.show()
|
||||
return activity
|
||||
|
||||
|
||||
def get_single_process_name(bundle_id):
|
||||
return bundle_id
|
||||
|
||||
|
||||
def get_single_process_path(bundle_id):
|
||||
return '/' + bundle_id.replace('.', '/')
|
||||
|
||||
|
||||
class SingleProcess(dbus.service.Object):
|
||||
|
||||
def __init__(self, name_service, constructor):
|
||||
self.constructor = constructor
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
bus_name = dbus.service.BusName(name_service, bus=bus)
|
||||
object_path = get_single_process_path(name_service)
|
||||
dbus.service.Object.__init__(self, bus_name, object_path)
|
||||
|
||||
@dbus.service.method('org.laptop.SingleProcess', in_signature='a{sv}')
|
||||
def create(self, handle_dict):
|
||||
handle = activityhandle.create_from_dict(handle_dict)
|
||||
create_activity_instance(self.constructor, handle)
|
||||
|
||||
|
||||
def main():
|
||||
usage = 'usage: %prog [options] [activity dir] [python class]'
|
||||
epilog = 'If you are running from a directory containing an Activity, ' \
|
||||
'the argument may be omitted. Otherwise please provide either '\
|
||||
'a directory containing a Sugar Activity [activity dir], a '\
|
||||
'[python_class], or both.'
|
||||
|
||||
parser = OptionParser(usage=usage, epilog=epilog)
|
||||
parser.add_option('-b', '--bundle-id', dest='bundle_id',
|
||||
help='identifier of the activity bundle')
|
||||
parser.add_option('-a', '--activity-id', dest='activity_id',
|
||||
help='identifier of the activity instance')
|
||||
parser.add_option('-o', '--object-id', dest='object_id',
|
||||
help='identifier of the associated datastore object')
|
||||
parser.add_option('-u', '--uri', dest='uri',
|
||||
help='URI to load')
|
||||
parser.add_option('-s', '--single-process', dest='single_process',
|
||||
action='store_true',
|
||||
help='start all the instances in the same process')
|
||||
parser.add_option('-i', '--invited', dest='invited',
|
||||
action='store_true', default=False,
|
||||
help='the activity is being launched for handling an '
|
||||
'invite from the network')
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
logger.start()
|
||||
|
||||
activity_class = None
|
||||
if len(args) == 2:
|
||||
activity_class = args[1]
|
||||
os.chdir(args[0])
|
||||
elif len(args) == 1:
|
||||
if os.path.isdir(args[0]):
|
||||
os.chdir(args[0])
|
||||
else:
|
||||
activity_class = args[0]
|
||||
|
||||
os.environ['SUGAR_BUNDLE_PATH'] = os.path.abspath(os.curdir)
|
||||
|
||||
bundle_path = os.environ['SUGAR_BUNDLE_PATH']
|
||||
sys.path.insert(0, bundle_path)
|
||||
|
||||
try:
|
||||
bundle = ActivityBundle(bundle_path)
|
||||
except MalformedBundleException:
|
||||
parser.print_help()
|
||||
exit(0)
|
||||
|
||||
if not activity_class:
|
||||
command = bundle.get_command()
|
||||
if command.startswith('sugar-activity'):
|
||||
if not command.startswith('sugar-activity3'):
|
||||
logging.warning("Activity written for Python 2, consider porting to Python 3.")
|
||||
activity_class = command.split(" ")[1]
|
||||
|
||||
if 'SUGAR_VERSION' not in os.environ:
|
||||
profile_id = os.environ.get('SUGAR_PROFILE', 'default')
|
||||
home_dir = os.environ.get('SUGAR_HOME', os.path.expanduser('~/.sugar'))
|
||||
base = os.path.join(home_dir, profile_id)
|
||||
activity_root = os.path.join(base, bundle.get_bundle_id())
|
||||
|
||||
instance_dir = os.path.join(activity_root, 'instance')
|
||||
mkpath(instance_dir)
|
||||
|
||||
data_dir = os.path.join(activity_root, 'data')
|
||||
mkpath(data_dir)
|
||||
|
||||
tmp_dir = os.path.join(activity_root, 'tmp')
|
||||
mkpath(tmp_dir)
|
||||
|
||||
os.environ['SUGAR_ACTIVITY_ROOT'] = activity_root
|
||||
os.environ['SUGAR_BUNDLE_PATH'] = bundle.get_path()
|
||||
|
||||
os.environ['SUGAR_BUNDLE_ID'] = bundle.get_bundle_id()
|
||||
os.environ['SUGAR_BUNDLE_NAME'] = bundle.get_name()
|
||||
os.environ['SUGAR_BUNDLE_VERSION'] = str(bundle.get_activity_version())
|
||||
|
||||
# must be done early, some activities set translations globally, SL #3654
|
||||
activity_locale_path = os.environ.get("SUGAR_LOCALEDIR",
|
||||
config.locale_path)
|
||||
|
||||
gettext.bindtextdomain(bundle.get_bundle_id(), activity_locale_path)
|
||||
gettext.bindtextdomain('sugar-toolkit-gtk3', config.locale_path)
|
||||
gettext.textdomain(bundle.get_bundle_id())
|
||||
|
||||
splitted_module = activity_class.rsplit('.', 1)
|
||||
module_name = splitted_module[0]
|
||||
class_name = splitted_module[1]
|
||||
|
||||
module = __import__(module_name)
|
||||
for comp in module_name.split('.')[1:]:
|
||||
module = getattr(module, comp)
|
||||
|
||||
activity_constructor = getattr(module, class_name)
|
||||
|
||||
if not options.activity_id:
|
||||
# Generate random hash
|
||||
data = '%s%s' % (time.time(), random.randint(10000, 100000))
|
||||
random_hash = hashlib.sha1(data.encode()).hexdigest()
|
||||
options.activity_id = random_hash
|
||||
options.bundle_id = bundle.get_bundle_id()
|
||||
|
||||
activity_handle = activityhandle.ActivityHandle(
|
||||
activity_id=options.activity_id,
|
||||
object_id=options.object_id, uri=options.uri,
|
||||
invited=options.invited)
|
||||
|
||||
if options.single_process is True:
|
||||
sessionbus = dbus.SessionBus()
|
||||
|
||||
service_name = get_single_process_name(options.bundle_id)
|
||||
service_path = get_single_process_path(options.bundle_id)
|
||||
|
||||
bus_object = sessionbus.get_object(
|
||||
'org.freedesktop.DBus', '/org/freedesktop/DBus')
|
||||
try:
|
||||
name = bus_object.GetNameOwner(
|
||||
service_name, dbus_interface='org.freedesktop.DBus')
|
||||
except dbus.DBusException:
|
||||
name = None
|
||||
|
||||
if not name:
|
||||
SingleProcess(service_name, activity_constructor)
|
||||
else:
|
||||
try:
|
||||
single_process = sessionbus.get_object(service_name,
|
||||
service_path)
|
||||
single_process.create(
|
||||
activity_handle.get_dict(),
|
||||
dbus_interface='org.laptop.SingleProcess')
|
||||
|
||||
print('Created %s in a single process.' % service_name)
|
||||
sys.exit(0)
|
||||
except (TypeError, dbus.DBusException):
|
||||
print('Could not communicate with the instance process,'
|
||||
'launching a new process')
|
||||
|
||||
if hasattr(module, 'start'):
|
||||
module.start()
|
||||
|
||||
instance = create_activity_instance(activity_constructor, activity_handle)
|
||||
|
||||
if hasattr(instance, 'run_main_loop'):
|
||||
instance.run_main_loop()
|
@ -1,202 +0,0 @@
|
||||
# Copyright (C) 2016 Abhijit Patel
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
'''
|
||||
Provide a PopWindow class for pop-up windows.
|
||||
Making PopWindow containing Gtk.Toolbar which also contains Gtk.Label
|
||||
and Toolbutton at the end of the Gtk.Toolbar.
|
||||
|
||||
It is possible to change props like size and add more widgets PopWindow
|
||||
and also to Gtk.Toolbar.
|
||||
|
||||
Example:
|
||||
.. literalinclude: ..sugar/src/jarabe/view/viewsource.py
|
||||
.. literalinclude: ..sugar/src/jarabe/view/viewhelp.py
|
||||
'''
|
||||
from gettext import gettext as _
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GdkX11
|
||||
from gi.repository import GObject
|
||||
|
||||
from sugar3.graphics import style
|
||||
from sugar3.graphics.toolbutton import ToolButton
|
||||
|
||||
from jarabe.model import shell
|
||||
|
||||
|
||||
class PopWindow(Gtk.Window):
|
||||
"""
|
||||
UI interface for activity Pop-up Windows.
|
||||
PopWindows are the windows that open on the top of the current window.
|
||||
These pop-up windows don't cover the whole screen.
|
||||
They contain canvas content, alerts messages, a tray and a
|
||||
toolbar.
|
||||
|
||||
FULLSCREEN and HALF_WIDTH for setting size of the window.
|
||||
|
||||
Kwargs:
|
||||
size (int,int): size to be set of the window
|
||||
window_xid (xlib.Window): xid of the parent window
|
||||
"""
|
||||
FULLSCREEN = (Gdk.Screen.width() - style.GRID_CELL_SIZE * 3,
|
||||
Gdk.Screen.height() - style.GRID_CELL_SIZE * 2)
|
||||
|
||||
HALF_WIDTH = ((Gdk.Screen.height() - style.GRID_CELL_SIZE * 3)/2,
|
||||
(Gdk.Screen.height() - style.GRID_CELL_SIZE * 2))
|
||||
|
||||
def __init__(self, window_xid=None, **kwargs):
|
||||
Gtk.Window.__init__(self, **kwargs)
|
||||
self._parent_window_xid = window_xid
|
||||
|
||||
self.set_decorated(False)
|
||||
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
|
||||
self.set_border_width(style.LINE_WIDTH)
|
||||
self.set_has_resize_grip(False)
|
||||
self.props.size = self.FULLSCREEN
|
||||
|
||||
self.connect('realize', self.__realize_cb)
|
||||
self.connect('key-press-event', self.__key_press_event_cb)
|
||||
self.connect('hide', self.__hide_cb)
|
||||
|
||||
self._vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
self.add(self._vbox)
|
||||
self._vbox.show()
|
||||
|
||||
self._title_box = TitleBox()
|
||||
self._title_box.close_button.connect(
|
||||
'clicked',
|
||||
self.__close_button_clicked_cb)
|
||||
self._title_box.set_size_request(-1, style.GRID_CELL_SIZE)
|
||||
|
||||
self._vbox.pack_start(self._title_box, False, True, 0)
|
||||
self._title_box.show()
|
||||
|
||||
# Note:
|
||||
# Not displaying the pop-up from here instead allowing
|
||||
# the child class to display the window after modifications
|
||||
# like chaninging window size, decorating, changing position.
|
||||
|
||||
def set_size(self, size):
|
||||
width, height = size
|
||||
self.set_size_request(width, height)
|
||||
|
||||
size = GObject.Property(type=None, setter=set_size)
|
||||
|
||||
def get_title_box(self):
|
||||
'''
|
||||
Getter method for title-box
|
||||
|
||||
Returns:
|
||||
self._title_box (): Title or Tool Box
|
||||
'''
|
||||
return self._title_box
|
||||
|
||||
title_box = GObject.Property(type=str, getter=get_title_box)
|
||||
|
||||
def get_vbox(self):
|
||||
'''
|
||||
Getter method for canvas
|
||||
|
||||
Returns:
|
||||
self._vbox (Gtk.Box): canvas
|
||||
'''
|
||||
return self._vbox
|
||||
vbox = GObject.Property(type=str, getter=get_vbox)
|
||||
|
||||
def __close_button_clicked_cb(self, button):
|
||||
self.destroy()
|
||||
|
||||
def __key_press_event_cb(self, window, event):
|
||||
keyname = Gdk.keyval_name(event.keyval)
|
||||
if keyname == 'Escape':
|
||||
self.destroy()
|
||||
|
||||
def __realize_cb(self, widget):
|
||||
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
|
||||
window = self.get_window()
|
||||
window.set_accept_focus(True)
|
||||
|
||||
if self._parent_window_xid is not None:
|
||||
display = Gdk.Display.get_default()
|
||||
parent = GdkX11.X11Window.foreign_new_for_display(
|
||||
display, self._parent_window_xid)
|
||||
window.set_transient_for(parent)
|
||||
shell.get_model().push_modal()
|
||||
|
||||
def __hide_cb(self, widget):
|
||||
shell.get_model().pop_modal()
|
||||
|
||||
def add_view(self, widget, expand=True, fill=True, padding=0):
|
||||
'''
|
||||
Adds child to the vbox.
|
||||
|
||||
Args:
|
||||
widget (Gtk.Widget): widget to be added
|
||||
|
||||
expand (bool): True if child is to be given extra space allocated
|
||||
to vbox.
|
||||
|
||||
fill (bool): True if space given to child by the expand option is
|
||||
actually allocated to child, rather than just padding it.
|
||||
|
||||
padding (int): extra space in pixels to put between child and its
|
||||
neighbors, over and above the global amount specified
|
||||
by spacing in vbox.
|
||||
|
||||
Returns:
|
||||
None
|
||||
'''
|
||||
self._vbox.pack_start(widget, expand, fill, padding)
|
||||
|
||||
|
||||
class TitleBox(Gtk.Toolbar):
|
||||
'''
|
||||
Title box at the top of the pop-up window.
|
||||
Title and close button are added to the box and as needed more widgets
|
||||
can be added using self.add_widget method.
|
||||
This box is optional as the inherited class can remove this block by
|
||||
setting the self._set_title_box to False.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
Gtk.Toolbar.__init__(self)
|
||||
|
||||
self.close_button = ToolButton(icon_name='dialog-cancel')
|
||||
self.close_button.set_tooltip(_('Close'))
|
||||
self.insert(self.close_button, -1)
|
||||
self.close_button.show()
|
||||
|
||||
self._label = Gtk.Label()
|
||||
self._label.set_alignment(0, 0.5)
|
||||
|
||||
tool_item = Gtk.ToolItem()
|
||||
tool_item.set_expand(True)
|
||||
tool_item.add(self._label)
|
||||
self._label.show()
|
||||
self.insert(tool_item, 0)
|
||||
tool_item.show()
|
||||
|
||||
def set_title(self, title):
|
||||
'''
|
||||
setter function for 'title' property.
|
||||
Args:
|
||||
title (str): title for the pop-up window
|
||||
'''
|
||||
self._label.set_markup('<b>%s</b>' % title)
|
||||
self._label.show()
|
||||
|
||||
title = GObject.Property(type=str, setter=set_title)
|
Loading…
Reference in New Issue