Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
This commit is contained in:
commit
f1aa2cf11a
@ -1,10 +1,9 @@
|
||||
SUBDIRS = lib po shell sugar services tools
|
||||
SUBDIRS = emulator lib po shell sugar services tools
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
bin_SCRIPTS = \
|
||||
sugar-emulator \
|
||||
sugar-emulator-shutdown
|
||||
sugar-emulator
|
||||
|
||||
DISTCLEANFILES = \
|
||||
intltool-extract \
|
||||
|
@ -104,6 +104,7 @@ AM_GLIB_GNU_GETTEXT
|
||||
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
emulator/Makefile
|
||||
lib/Makefile
|
||||
lib/data/Makefile
|
||||
lib/src/Makefile
|
||||
@ -116,7 +117,6 @@ services/clipboard/Makefile
|
||||
services/datastore/Makefile
|
||||
shell/Makefile
|
||||
shell/intro/Makefile
|
||||
shell/data/Makefile
|
||||
shell/hardware/Makefile
|
||||
shell/view/Makefile
|
||||
shell/view/devices/Makefile
|
||||
@ -138,7 +138,6 @@ services/console/interface/memphis/Makefile
|
||||
services/console/interface/logviewer/Makefile
|
||||
services/console/interface/terminal/Makefile
|
||||
sugar/Makefile
|
||||
sugar/__installed__.py
|
||||
sugar/activity/Makefile
|
||||
sugar/chat/Makefile
|
||||
sugar/chat/sketchpad/Makefile
|
||||
|
4
emulator/Makefile.am
Normal file
4
emulator/Makefile.am
Normal file
@ -0,0 +1,4 @@
|
||||
confdir = $(pkgdatadir)/emulator
|
||||
conf_DATA = kbdconfig
|
||||
|
||||
EXTRA_DIST = $(conf_DATA)
|
@ -5,5 +5,3 @@
|
||||
<Alt>n=next
|
||||
<Alt>p=prev
|
||||
<Alt>c=close
|
||||
|
||||
<Alt>q=!sugar-emulator-shutdown
|
@ -18,6 +18,7 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
|
||||
from sugar import logger
|
||||
@ -31,9 +32,9 @@ import dbus.glib
|
||||
|
||||
from sugar import env
|
||||
|
||||
sys.path.insert(0, env.get_services_dir())
|
||||
sys.path.insert(0, env.get_service_path('clipboard'))
|
||||
|
||||
from clipboard.clipboardservice import ClipboardService
|
||||
from clipboardservice import ClipboardService
|
||||
|
||||
logging.info('Starting clipboard service.')
|
||||
|
||||
|
@ -3,9 +3,10 @@
|
||||
import pygtk
|
||||
pygtk.require('2.0')
|
||||
|
||||
import os, sys
|
||||
import os
|
||||
import sys
|
||||
from sugar import env
|
||||
|
||||
sys.path.insert(0, env.get_services_dir())
|
||||
sys.path.insert(0, env.get_service_path('console'))
|
||||
|
||||
import console.console
|
||||
import console
|
||||
|
@ -18,16 +18,17 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
|
||||
from sugar import logger
|
||||
from sugar import env
|
||||
|
||||
sys.path.insert(0, env.get_services_dir())
|
||||
sys.path.insert(0, env.get_service_path('datastore'))
|
||||
|
||||
logger.start('data-store')
|
||||
logging.info('Starting the data store...')
|
||||
|
||||
from datastore import datastore
|
||||
import datastore
|
||||
|
||||
datastore.main()
|
||||
|
@ -24,11 +24,11 @@ import os
|
||||
from sugar import logger
|
||||
from sugar import env
|
||||
|
||||
sys.path.insert(0, env.get_services_dir())
|
||||
sys.path.insert(0, env.get_service_path('presence'))
|
||||
|
||||
logger.start('presenceservice')
|
||||
|
||||
from presence import PresenceService
|
||||
import PresenceService
|
||||
|
||||
logging.info('Starting presence service')
|
||||
|
||||
|
@ -24,11 +24,11 @@ import os
|
||||
from sugar import logger
|
||||
from sugar import env
|
||||
|
||||
sys.path.insert(0, env.get_services_dir())
|
||||
sys.path.insert(0, env.get_service_path('presence2'))
|
||||
|
||||
logger.start('presenceservice')
|
||||
|
||||
from presence2 import presenceservice
|
||||
import presenceservice
|
||||
|
||||
logging.info('Starting presence service')
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
SUBDIRS = data hardware model view intro
|
||||
SUBDIRS = hardware model view intro
|
||||
|
||||
bin_SCRIPTS = \
|
||||
sugar-activity \
|
||||
|
@ -1,7 +0,0 @@
|
||||
confdir = $(pkgdatadir)
|
||||
conf_DATA = kbdconfig
|
||||
|
||||
imagedir = $(pkgdatadir)
|
||||
image_DATA = default-picture.png
|
||||
|
||||
EXTRA_DIST = $(conf_DATA) $(image_DATA)
|
@ -1,3 +1,7 @@
|
||||
imagedir = $(pkgdatadir)/shell/intro
|
||||
image_DATA = default-picture.png
|
||||
|
||||
EXTRA_DIST = $(conf_DATA) $(image_DATA)
|
||||
sugardir = $(pkgdatadir)/shell/intro
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@ -143,7 +143,8 @@ class VideoBox(hippo.CanvasBox, hippo.CanvasItem):
|
||||
self._img_widget.props.widget = self._img
|
||||
|
||||
if not has_webcam:
|
||||
path = os.path.join(env.get_data_dir(),'default-picture.png')
|
||||
path = os.path.join(os.path.dirname(__file__),
|
||||
'default-picture.png')
|
||||
self._video.load_image(path)
|
||||
|
||||
def _clear_image_cb(self, widget, event):
|
||||
|
@ -36,7 +36,7 @@ logger.cleanup()
|
||||
logger.start('shell')
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
sys.path.insert(0, os.path.join(env.get_data_dir(), 'shell'))
|
||||
sys.path.insert(0, env.get_shell_path())
|
||||
|
||||
from view.Shell import Shell
|
||||
from model.ShellModel import ShellModel
|
||||
|
@ -1,3 +1,6 @@
|
||||
import os
|
||||
import signal
|
||||
|
||||
import dbus
|
||||
import gobject
|
||||
|
||||
@ -34,7 +37,8 @@ _actions_table = {
|
||||
'0xEB' : 'rotate',
|
||||
'<alt>r' : 'rotate',
|
||||
'0xEC' : 'keyboard_brightness',
|
||||
'<alt>Tab' : 'home'
|
||||
'<alt>Tab' : 'home',
|
||||
'<alt>q' : 'quit_emulator',
|
||||
}
|
||||
|
||||
class KeyHandler(object):
|
||||
@ -149,6 +153,11 @@ class KeyHandler(object):
|
||||
gobject.spawn_async(['xrandr', '-o', states[self._screen_rotation]],
|
||||
flags=gobject.SPAWN_SEARCH_PATH)
|
||||
|
||||
def handle_quit_emulator(self):
|
||||
if os.environ.has_key('SUGAR_EMULATOR_PID'):
|
||||
pid = int(os.environ['SUGAR_EMULATOR_PID'])
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
|
||||
def handle_home(self):
|
||||
# FIXME: finish alt+tab support
|
||||
pass
|
||||
|
@ -47,17 +47,21 @@ else:
|
||||
program = sys.argv[1]
|
||||
|
||||
if gtk.gdk.screen_width() < 1200 or gtk.gdk.screen_height() < 900:
|
||||
fullscreen = True
|
||||
width = -1
|
||||
height = -1
|
||||
else:
|
||||
fullscreen = False
|
||||
width = 1200
|
||||
height = 900
|
||||
|
||||
dpi = min(_sugar.get_screen_dpi(), 96)
|
||||
|
||||
emulator = Emulator(width, height, fullscreen, dpi)
|
||||
if sourcedir:
|
||||
kbd_config = os.path.join(sourcedir, 'emulator/kbdconfig')
|
||||
else:
|
||||
kbd_config = os.path.join(env.get_emulator_path('kbdconfig'))
|
||||
|
||||
emulator = Emulator(width, height, dpi)
|
||||
emulator.set_keyboard_config(kbd_config)
|
||||
emulator.start()
|
||||
|
||||
if sourcedir:
|
||||
|
@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (C) 2006, 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 signal
|
||||
|
||||
if os.environ.has_key('SUGAR_XEPHYR_PID'):
|
||||
pid = int(os.environ['SUGAR_XEPHYR_PID'])
|
||||
os.kill(pid, signal.SIGTERM)
|
@ -3,7 +3,6 @@ SUBDIRS = activity chat clipboard graphics p2p presence datastore
|
||||
sugardir = $(pythondir)/sugar
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
__installed__.py \
|
||||
date.py \
|
||||
emulator.py \
|
||||
env.py \
|
||||
@ -12,5 +11,3 @@ sugar_PYTHON = \
|
||||
simulator.py \
|
||||
TracebackUtils.py \
|
||||
util.py
|
||||
|
||||
EXTRA_DIST = __uninstalled__.py
|
||||
|
@ -1,5 +0,0 @@
|
||||
sugar_source_dir = None
|
||||
sugar_data_dir = '@prefix@/share/sugar'
|
||||
sugar_activity_info_dir = '@prefix@/share/sugar/activities'
|
||||
sugar_services_dir = '@prefix@/share/sugar/services'
|
||||
sugar_shell_bin_dir = '@prefix@/bin'
|
@ -1,7 +0,0 @@
|
||||
import os
|
||||
|
||||
_sourcedir = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
sugar_data_dir = os.path.join(_sourcedir, 'shell/data')
|
||||
sugar_services_dir = os.path.join(_sourcedir, 'services')
|
||||
sugar_shell_bin_dir = os.path.join(_sourcedir, 'shell')
|
@ -44,8 +44,7 @@ class Bundle:
|
||||
if cp.has_option(section, 'class'):
|
||||
self._class = cp.get(section, 'class')
|
||||
self._exec = '%s %s --bundle-path="%s"' % (
|
||||
os.path.join(env.get_shell_bin_dir(), _PYTHON_FACTORY),
|
||||
self._class, self.get_path())
|
||||
env.get_bin_path(_PYTHON_FACTORY), self._class, self.get_path())
|
||||
elif cp.has_option(section, 'exec'):
|
||||
self._class = None
|
||||
self._exec = cp.get(section, 'exec')
|
||||
|
@ -93,7 +93,7 @@ def _get_install_dir(prefix):
|
||||
return os.path.join(prefix, 'share/activities')
|
||||
|
||||
def _get_bundle_path():
|
||||
return os.path.join(env.get_user_activities_dir(), _get_bundle_dir())
|
||||
return os.path.join(env.get_user_activities_path(), _get_bundle_dir())
|
||||
|
||||
def _get_package_name():
|
||||
bundle = Bundle(_get_source_path())
|
||||
@ -120,7 +120,7 @@ setup.py help - print this message \n\
|
||||
'
|
||||
|
||||
def cmd_dev():
|
||||
bundle_path = os.path.join(env.get_user_activities_dir(), _get_bundle_dir())
|
||||
bundle_path = os.path.join(env.get_user_activities_path(), _get_bundle_dir())
|
||||
try:
|
||||
os.symlink(_get_source_path(), bundle_path)
|
||||
except OSError:
|
||||
|
@ -1,14 +1,26 @@
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
import gobject
|
||||
|
||||
from sugar.activity.bundle import Bundle
|
||||
from sugar import env
|
||||
from sugar import util
|
||||
|
||||
# http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
|
||||
def _get_data_dirs():
|
||||
if os.environ.has_key('XDG_DATA_DIRS'):
|
||||
return os.environ['XDG_DATA_DIRS'].split(':')
|
||||
else:
|
||||
return [ '/usr/local/share/', '/usr/share/' ]
|
||||
|
||||
class _ServiceManager(object):
|
||||
def __init__(self):
|
||||
self._path = env.get_user_service_dir()
|
||||
service_dir = os.path.expanduser('~/.local/share/dbus-1/services')
|
||||
if not os.path.isdir(service_dir):
|
||||
os.makedirs(service_dir)
|
||||
|
||||
self._path = service_dir
|
||||
|
||||
def add(self, bundle):
|
||||
util.write_service(bundle.get_service_name(),
|
||||
@ -74,8 +86,8 @@ def get_registry():
|
||||
|
||||
_bundle_registry = BundleRegistry()
|
||||
|
||||
for path in env.get_data_dirs():
|
||||
for path in _get_data_dirs():
|
||||
bundles_path = os.path.join(path, 'activities')
|
||||
_bundle_registry.add_search_path(bundles_path)
|
||||
|
||||
_bundle_registry.add_search_path(env.get_user_activities_dir())
|
||||
_bundle_registry.add_search_path(env.get_user_activities_path())
|
||||
|
@ -64,13 +64,13 @@ class Process:
|
||||
self._stdout = result[2]
|
||||
|
||||
class MatchboxProcess(Process):
|
||||
def __init__(self):
|
||||
kbd_config = os.path.join(env.get_data_dir(), 'kbdconfig')
|
||||
options = '-kbdconfig %s ' % kbd_config
|
||||
|
||||
options += '-use_titlebar no '
|
||||
def __init__(self, kbd_config):
|
||||
options = '-use_titlebar no '
|
||||
options += '-theme olpc '
|
||||
|
||||
if kbd_config:
|
||||
options += '-kbdconfig %s ' % kbd_config
|
||||
|
||||
command = 'matchbox-window-manager %s ' % options
|
||||
Process.__init__(self, command)
|
||||
|
||||
@ -78,15 +78,14 @@ class MatchboxProcess(Process):
|
||||
return 'Matchbox'
|
||||
|
||||
class XephyrProcess(Process):
|
||||
def __init__(self, width, height, fullscreen, dpi):
|
||||
def __init__(self, width, height, dpi):
|
||||
self._display = get_display_number()
|
||||
cmd = 'Xephyr :%d -ac ' % (self._display)
|
||||
|
||||
if fullscreen:
|
||||
cmd += ' -fullscreen '
|
||||
|
||||
if width > 0 and height > 0:
|
||||
cmd += ' -screen %dx%d' % (width, height)
|
||||
else:
|
||||
cmd += ' -fullscreen '
|
||||
|
||||
if dpi > 0:
|
||||
cmd += ' -dpi %d' % (dpi)
|
||||
@ -99,24 +98,26 @@ class XephyrProcess(Process):
|
||||
def start(self, standard_output=False):
|
||||
Process.start(self)
|
||||
os.environ['DISPLAY'] = ":%d" % (self._display)
|
||||
os.environ['SUGAR_XEPHYR_PID'] = '%d' % self.pid
|
||||
os.environ['SUGAR_EMULATOR_PID'] = '%d' % self.pid
|
||||
|
||||
class Emulator(object):
|
||||
"""The OLPC emulator"""
|
||||
def __init__(self, width, height, fullscreen, dpi):
|
||||
self._fullscreen = fullscreen
|
||||
def __init__(self, width, height, dpi):
|
||||
self._keyboard_config = None
|
||||
self._width = width
|
||||
self._height = height
|
||||
self._dpi = dpi
|
||||
|
||||
def set_keyboard_config(self, config):
|
||||
self._keyboard_config = config
|
||||
|
||||
def start(self):
|
||||
try:
|
||||
process = XephyrProcess(self._width, self._height,
|
||||
self._fullscreen, self._dpi)
|
||||
process = XephyrProcess(self._width, self._height, self._dpi)
|
||||
process.start()
|
||||
except:
|
||||
print 'Cannot run the emulator. You need to install Xephyr'
|
||||
sys.exit(0)
|
||||
|
||||
process = MatchboxProcess()
|
||||
process = MatchboxProcess(self._keyboard_config)
|
||||
process.start()
|
||||
|
51
sugar/env.py
51
sugar/env.py
@ -16,13 +16,17 @@
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import pwd
|
||||
|
||||
try:
|
||||
from sugar.__uninstalled__ import *
|
||||
except ImportError:
|
||||
from sugar.__installed__ import *
|
||||
def _get_prefix_path(base, path=None):
|
||||
if os.environ.has_key('SUGAR_PREFIX'):
|
||||
prefix = os.environ['SUGAR_PREFIX']
|
||||
else:
|
||||
prefix = '/usr'
|
||||
|
||||
if path:
|
||||
return os.path.join(prefix, base, path)
|
||||
else:
|
||||
return os.path.join(prefix, base)
|
||||
|
||||
def is_emulator():
|
||||
if os.environ.has_key('SUGAR_EMULATOR'):
|
||||
@ -45,31 +49,20 @@ def get_profile_path():
|
||||
|
||||
return path
|
||||
|
||||
def get_data_dir():
|
||||
return sugar_data_dir
|
||||
|
||||
def get_services_dir():
|
||||
return sugar_services_dir
|
||||
|
||||
def get_shell_bin_dir():
|
||||
return sugar_shell_bin_dir
|
||||
|
||||
# http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
|
||||
def get_data_dirs():
|
||||
if os.environ.has_key('XDG_DATA_DIRS'):
|
||||
return os.environ['XDG_DATA_DIRS'].split(':')
|
||||
else:
|
||||
return [ '/usr/local/share/', '/usr/share/' ]
|
||||
|
||||
def get_user_service_dir():
|
||||
service_dir = os.path.expanduser('~/.local/share/dbus-1/services')
|
||||
if not os.path.isdir(service_dir):
|
||||
os.makedirs(service_dir)
|
||||
return service_dir
|
||||
|
||||
def get_user_activities_dir():
|
||||
def get_user_activities_path():
|
||||
path = os.path.expanduser('~/Activities')
|
||||
if not os.path.isdir(path):
|
||||
os.mkdir(path)
|
||||
return path
|
||||
|
||||
def get_bin_path(path=None):
|
||||
return _get_prefix_path('bin', path)
|
||||
|
||||
def get_service_path(name):
|
||||
return _get_prefix_path('share/sugar/services', name)
|
||||
|
||||
def get_shell_path(path=None):
|
||||
return _get_prefix_path('share/sugar/shell', path)
|
||||
|
||||
def get_emulator_path(path=None):
|
||||
return _get_prefix_path('share/sugar/emulator', path)
|
||||
|
@ -20,6 +20,7 @@ sugar_PYTHON = \
|
||||
snowflakebox.py \
|
||||
spreadbox.py \
|
||||
timeline.py \
|
||||
toggleiconbutton.py \
|
||||
toolbar.py \
|
||||
units.py \
|
||||
window.py \
|
||||
|
@ -176,7 +176,6 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
|
||||
|
||||
hippo.CanvasBox.__init__(self, **kwargs)
|
||||
|
||||
self.connect_after('button-press-event', self._button_press_event_cb)
|
||||
self.connect_after('motion-notify-event', self._motion_notify_event_cb)
|
||||
|
||||
def _clear_buffers(self):
|
||||
@ -326,9 +325,9 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
|
||||
[width, height] = self._get_icon_size()
|
||||
return height
|
||||
|
||||
def _button_press_event_cb(self, item, event):
|
||||
item.emit_activated()
|
||||
return False
|
||||
def do_button_press_event(self, event):
|
||||
self.emit_activated()
|
||||
return True
|
||||
|
||||
def get_popup(self):
|
||||
if self._tooltip:
|
||||
|
@ -21,7 +21,8 @@ _system_colors = {
|
||||
'button-hover' : '#808080',
|
||||
'button-background-hover' : '#000000',
|
||||
'icon-stroke-inactive' : '#757575',
|
||||
'icon-fill-inactive' : '#9D9FA1'
|
||||
'icon-fill-inactive' : '#9D9FA1',
|
||||
'toggle-button-background' : '#A1A5A8'
|
||||
}
|
||||
|
||||
def _html_to_rgb(html_color):
|
||||
@ -100,3 +101,4 @@ BUTTON_HOVER = SystemColor('button-hover')
|
||||
BUTTON_BACKGROUND_HOVER = SystemColor('button-background-hover')
|
||||
ICON_FILL_INACTIVE = SystemColor('icon-fill-inactive')
|
||||
ICON_STROKE_INACTIVE = SystemColor('icon-stroke-inactive')
|
||||
TOGGLE_BUTTON_BACKGROUND = SystemColor('toggle-button-background')
|
||||
|
@ -27,7 +27,7 @@ from sugar.graphics import color
|
||||
STANDARD_SIZE = 0
|
||||
SMALL_SIZE = 1
|
||||
|
||||
class IconButton(CanvasIcon):
|
||||
class IconButton(CanvasIcon, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarIconButton'
|
||||
|
||||
__gproperties__ = {
|
||||
@ -45,9 +45,6 @@ class IconButton(CanvasIcon):
|
||||
|
||||
self._set_size(STANDARD_SIZE)
|
||||
|
||||
self.connect('button-press-event',
|
||||
self._icon_button_button_press_event_cb)
|
||||
|
||||
def _set_size(self, size):
|
||||
if size == SMALL_SIZE:
|
||||
self.props.box_width = -1
|
||||
@ -72,7 +69,7 @@ class IconButton(CanvasIcon):
|
||||
else:
|
||||
return CanvasIcon.do_get_property(self, pspec)
|
||||
|
||||
def _icon_button_button_press_event_cb(self, widget, event):
|
||||
def do_button_press_event(self, event):
|
||||
if self._active:
|
||||
self.emit_activated()
|
||||
return True
|
||||
|
69
sugar/graphics/toggleiconbutton.py
Normal file
69
sugar/graphics/toggleiconbutton.py
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright (C) 2007, Red Hat
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
import gobject
|
||||
import hippo
|
||||
|
||||
from sugar.graphics.iconbutton import IconButton
|
||||
from sugar.graphics import color
|
||||
|
||||
class ToggleIconButton(IconButton, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarToggleIconButton'
|
||||
|
||||
__gproperties__ = {
|
||||
'toggled' : (bool, None, None, False,
|
||||
gobject.PARAM_READWRITE)
|
||||
}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self._toggled = False
|
||||
|
||||
IconButton.__init__(self, **kwargs)
|
||||
|
||||
def _get_bg_color(self):
|
||||
if self._toggled:
|
||||
col = color.TOGGLE_BUTTON_BACKGROUND
|
||||
else:
|
||||
col = color.BUTTON_BACKGROUND_NORMAL
|
||||
|
||||
return col.get_int()
|
||||
|
||||
def _set_toggled(self, toggled):
|
||||
self._toggled = toggled
|
||||
self.props.background_color = self._get_bg_color()
|
||||
|
||||
def do_set_property(self, pspec, value):
|
||||
if pspec.name == 'toggled':
|
||||
self._set_toggled(value)
|
||||
else:
|
||||
IconButton.do_set_property(self, pspec, value)
|
||||
|
||||
def do_get_property(self, pspec):
|
||||
if pspec.name == 'toggled':
|
||||
return self._toggled
|
||||
|
||||
return IconButton.do_get_property(self, pspec)
|
||||
|
||||
def do_button_press_event(self, event):
|
||||
self.props.toggled = not self._toggled
|
||||
return True
|
||||
|
||||
def prelight(self, enter):
|
||||
if enter:
|
||||
IconButton.prelight(self, enter)
|
||||
else:
|
||||
self.props.background_color = self._get_bg_color()
|
@ -23,12 +23,16 @@ import hippo
|
||||
|
||||
from sugar.graphics.toolbar import Toolbar
|
||||
from sugar.graphics.iconbutton import IconButton
|
||||
from sugar.graphics.toggleiconbutton import ToggleIconButton
|
||||
from sugar.graphics.button import Button
|
||||
from sugar.graphics.entry import Entry
|
||||
|
||||
def _button_activated_cb(button):
|
||||
print "_button_activated_cb"
|
||||
|
||||
def _toggled_changed_cb(button, pspec):
|
||||
print "Toggle state: %d" % button.props.toggled
|
||||
|
||||
window = gtk.Window()
|
||||
window.connect("destroy", lambda w: gtk.main_quit())
|
||||
window.show()
|
||||
@ -48,6 +52,10 @@ for i in [1, 2]:
|
||||
icon_button = IconButton(icon_name='theme:stock-close')
|
||||
toolbar.append(icon_button)
|
||||
|
||||
toggle = ToggleIconButton(icon_name='theme:stock-back')
|
||||
toggle.connect('notify::toggled', _toggled_changed_cb)
|
||||
toolbar.append(toggle)
|
||||
|
||||
button = Button(text='Click me!', icon_name='theme:stock-close')
|
||||
button.connect('activated', _button_activated_cb)
|
||||
toolbar.append(button)
|
||||
|
@ -27,7 +27,7 @@ bus = dbus.SessionBus()
|
||||
proxy_obj = bus.get_object(DBUS_SERVICE, DBUS_PATH)
|
||||
dbus_service = dbus.Interface(proxy_obj, DBUS_SERVICE)
|
||||
|
||||
bundle_dir = env.get_user_activities_dir()
|
||||
bundle_dir = env.get_user_activities_path()
|
||||
|
||||
zip_file = zipfile.ZipFile(sys.argv[1])
|
||||
file_names = zip_file.namelist()
|
||||
|
Loading…
Reference in New Issue
Block a user