diff options
-rw-r--r-- | NEWS | 9 | ||||
-rw-r--r-- | RulerActivity.py | 317 | ||||
-rw-r--r-- | activity/activity.info | 7 | ||||
-rw-r--r-- | icons/angles-180.svg | 12 | ||||
-rw-r--r-- | icons/angles-360.svg | 54 | ||||
-rw-r--r-- | icons/angles-90.svg | 47 | ||||
-rw-r--r-- | icons/checker.svg | 47 | ||||
-rw-r--r-- | icons/grid-a.svg | 64 | ||||
-rw-r--r-- | icons/grid-c.svg | 106 | ||||
-rw-r--r-- | icons/ruler.svg | 54 | ||||
-rwxr-xr-x | setup.py | 2 | ||||
-rw-r--r-- | show_grids.py | 1 | ||||
-rw-r--r-- | util.py | 79 |
13 files changed, 472 insertions, 327 deletions
@@ -1,3 +1,12 @@ +21 + +* GTK-3 conversion by Flavio Danesse +* New translations + +20 + +* Remove deprecated code (commands) + 19 * New translations diff --git a/RulerActivity.py b/RulerActivity.py index 5396726..7479753 100644 --- a/RulerActivity.py +++ b/RulerActivity.py @@ -1,5 +1,6 @@ # Copyright (c) 2007 Mitchell N. Charity -# Copyright (c) 2009-2011 Walter Bender +# Copyright (c) 2009-2012 Walter Bender +# Copyright (c) 2012 Flavio Danesse # # This file is part of Ruler. # @@ -16,39 +17,29 @@ # You should have received a copy of the GNU General Public License # along with Ruler. If not, see <http://www.gnu.org/licenses/> -import pygtk -pygtk.require('2.0') -import gtk -import gobject +import gi +from gi.repository import Gtk +from gi.repository import GObject +from gi.repository import GdkX11 import cairo import os.path -import sugar -from sugar.activity import activity -try: # 0.86+ toolbar widgets - from sugar.graphics.toolbarbox import ToolbarBox - HAS_TOOLARBOX = True -except ImportError: - HAS_TOOLARBOX = False - -if HAS_TOOLARBOX: - from sugar.bundle.activitybundle import ActivityBundle - from sugar.activity.widgets import ActivityToolbarButton - from sugar.activity.widgets import StopButton - from sugar.graphics.toolbarbox import ToolbarButton - -from sugar.graphics.radiotoolbutton import RadioToolButton -from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.menuitem import MenuItem -from sugar.graphics.icon import Icon -from sugar.datastore import datastore -try: - from sugar.graphics import style - GRID_CELL_SIZE = style.GRID_CELL_SIZE -except ImportError: - GRID_CELL_SIZE = 0 +import sugar3 +from sugar3.activity import activity +from sugar3.graphics.toolbarbox import ToolbarBox +from sugar3.bundle.activitybundle import ActivityBundle +from sugar3.activity.widgets import ActivityToolbarButton +from sugar3.activity.widgets import StopButton +from sugar3.graphics.toolbarbox import ToolbarButton +from sugar3.graphics.radiotoolbutton import RadioToolButton +from sugar3.graphics.toolbutton import ToolButton +from sugar3.graphics.menuitem import MenuItem +from sugar3.graphics.icon import Icon +from sugar3.datastore import datastore +from sugar3.graphics import style +GRID_CELL_SIZE = style.GRID_CELL_SIZE import logging _logger = logging.getLogger("ruler-activity") @@ -61,26 +52,26 @@ import show_grids import show_checkers import show_angles +from sugar3.graphics import style -class MyCanvas(gtk.DrawingArea): +class MyCanvas(Gtk.DrawingArea): ''' Create a GTK+ widget on which we will draw using Cairo ''' def __init__(self): - gtk.DrawingArea.__init__(self) + + Gtk.DrawingArea.__init__(self) + self._draw_ruler = False self._object = None - self.connect('expose-event', self.__expose_event_cb) + self.connect('draw', self.__expose_event_cb) self._dpi = 96 def __expose_event_cb(self, drawing_area, event): - cr = self.window.cairo_create() + cr = self.get_property('window').cairo_create() if self._draw_ruler: self._object.draw(cr, self._dpi) - - # Restrict Cairo to the exposed area; avoid extra work - cr.rectangle(event.area.x, event.area.y, - event.area.width, event.area.height) + cr.clip() def add_a_ruler(self, r): @@ -117,8 +108,9 @@ class RulerActivity(activity.Activity): self.set_canvas(self._canvas) self._canvas.show() - width = gtk.gdk.screen_width() - height = gtk.gdk.screen_height() - GRID_CELL_SIZE + screen = GdkX11.X11Screen() + width = screen.width() + height = screen.height() - GRID_CELL_SIZE dpi, self.known_dpi = calc_dpi() self._canvas.set_dpi(dpi) @@ -144,84 +136,67 @@ class RulerActivity(activity.Activity): # self.max_participants = 1 - if HAS_TOOLARBOX: - # Use 0.86 toolbar design - toolbar_box = ToolbarBox() - - # Buttons added to the Activity toolbar - activity_button = ActivityToolbarButton(self) - toolbar_box.toolbar.insert(activity_button, 0) - activity_button.show() - - self.rulers = MyButton(self, 'ruler', - icon_name='ruler', - callback=self._rulers_cb, - tooltip=_('Ruler')) - toolbar_box.toolbar.insert(self.rulers, -1) - - self.grids = MyButton(self, 'grids', - icon_name='grid-a', - callback=self._grids_cb, - tooltip=_('Grid'), - group=self.rulers) - toolbar_box.toolbar.insert(self.grids, -1) - - self.angles = MyButton(self, 'angles', - icon_name='angles-90', - callback=self._angles_cb, - tooltip=_('Angles'), - group=self.rulers) - toolbar_box.toolbar.insert(self.angles, -1) - - self.checker = MyButton(self, 'checker', - icon_name='checker', - callback=self._checker_cb, - tooltip=_('Checker'), - group=self.rulers) - toolbar_box.toolbar.insert(self.checker, -1) - - if not self.known_dpi: - print self.known_dpi - separator = gtk.SeparatorToolItem() - separator.show() - toolbar_box.toolbar.insert(separator, -1) - dpi = self._canvas.get_dpi() - self._dpi_spin_adj = gtk.Adjustment(dpi, 72, 200, 2, 32, 0) - self._dpi_spin = gtk.SpinButton(self._dpi_spin_adj, 0, 0) - self._dpi_spin_id = self._dpi_spin.connect('value-changed', - self._dpi_spin_cb) - self._dpi_spin.set_numeric(True) - self._dpi_spin.show() - self.tool_item_dpi = gtk.ToolItem() - self.tool_item_dpi.add(self._dpi_spin) - toolbar_box.toolbar.insert(self.tool_item_dpi, -1) - self.tool_item_dpi.show() - - separator = gtk.SeparatorToolItem() - separator.props.draw = False - separator.set_expand(True) - separator.show() - toolbar_box.toolbar.insert(separator, -1) + toolbar_box = ToolbarBox() - # The ever-present Stop Button - stop_button = StopButton(self) - stop_button.props.accelerator = '<Ctrl>Q' - toolbar_box.toolbar.insert(stop_button, -1) - stop_button.show() + # Buttons added to the Activity toolbar + activity_button = ActivityToolbarButton(self) + toolbar_box.toolbar.insert(activity_button, 0) + activity_button.show() - self.set_toolbar_box(toolbar_box) - toolbar_box.show() + self.rulers = radio_factory('ruler', + toolbar_box.toolbar, + self._rulers_cb, + tooltip=_('Ruler'), + group=None) - else: - # Use pre-0.86 toolbar design - toolbox = activity.ActivityToolbox(self) - self.set_toolbox(toolbox) + self.grids = radio_factory('grid-a', + toolbar_box.toolbar, + self._grids_cb, + tooltip=_('Grid'), + group=self.rulers) - self.projectToolbar = ProjectToolbar(self) - toolbox.add_toolbar(_('Rulers'), self.projectToolbar) + self.angles = radio_factory('angles-90', + toolbar_box.toolbar, + self._angles_cb, + tooltip=_('Angles'), + group=self.rulers) - toolbox.show() - toolbox.set_current_toolbar(1) + self.checker = radio_factory('checker', + toolbar_box.toolbar, + self._checker_cb, + tooltip=_('Checker'), + group=self.rulers) + + if not self.known_dpi: + separator = Gtk.SeparatorToolItem() + separator.show() + toolbar_box.toolbar.insert(separator, -1) + dpi = self._canvas.get_dpi() + self._dpi_spin_adj = Gtk.Adjustment(dpi, 72, 200, 2, 32, 0) + self._dpi_spin = Gtk.SpinButton(self._dpi_spin_adj, 0, 0) + self._dpi_spin_id = self._dpi_spin.connect('value-changed', + self._dpi_spin_cb) + self._dpi_spin.set_numeric(True) + self._dpi_spin.show() + self.tool_item_dpi = Gtk.ToolItem() + self.tool_item_dpi.add(self._dpi_spin) + toolbar_box.toolbar.insert(self.tool_item_dpi, -1) + self.tool_item_dpi.show() + + separator = Gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + separator.show() + toolbar_box.toolbar.insert(separator, -1) + + # The ever-present Stop Button + stop_button = StopButton(self) + stop_button.props.accelerator = '<Ctrl>Q' + toolbar_box.toolbar.insert(stop_button, -1) + stop_button.show() + + self.set_toolbar_box(toolbar_box) + toolbar_box.show() self.show_all() @@ -230,13 +205,11 @@ class RulerActivity(activity.Activity): if 'ruler' in self.metadata and \ self.metadata['ruler'] in self.button_dict: _logger.debug('restoring %s', self.metadata['ruler']) - if HAS_TOOLARBOX: - self.button_dict[self.metadata['ruler']].set_active(True) + self.button_dict[self.metadata['ruler']].set_active(True) self.callback_dict[self.metadata['ruler']] else: self._rulers_cb() - if HAS_TOOLARBOX: - self.rulers.set_active(True) + self.rulers.set_active(True) # # Button callbacks @@ -254,12 +227,12 @@ class RulerActivity(activity.Activity): if self._grids_mode == "cm": self._current = self._gcm if hasattr(self, 'grids'): - self.grids.set_icon("grid-c") + self.grids.set_icon_name("grid-c") self._grids_mode = "mm" else: self._current = self._gmm if hasattr(self, 'grids'): - self.grids.set_icon("grid-a") + self.grids.set_icon_name("grid-a") self._grids_mode = "cm" self._canvas.add_a_ruler(self._current) _logger.debug('selecting grids') @@ -271,12 +244,12 @@ class RulerActivity(activity.Activity): if self._angles_mode == "90": self._current = self._a90 if hasattr(self, 'angles'): - self.angles.set_icon("angles-360") + self.angles.set_icon_name("angles-360") self._angles_mode = "360" else: self._current = self._a360 if hasattr(self, 'angles'): - self.angles.set_icon("angles-90") + self.angles.set_icon_name("angles-90") self._angles_mode = "90" self._canvas.add_a_ruler(self._current) _logger.debug('selecting angles') @@ -303,90 +276,20 @@ class RulerActivity(activity.Activity): self.metadata['dpi'] = str(dpi) -class ProjectToolbar(gtk.Toolbar): - ''' Project toolbar for pre-0.86 toolbars ''' - - def __init__(self, pc): - gtk.Toolbar.__init__(self) - self.activity = pc - - # Ruler - self.activity.rulers = ToolButton("ruler") - self.activity.rulers.set_tooltip(_('Ruler')) - self.activity.rulers.props.sensitive = True - self.activity.rulers.connect('clicked', self.activity._rulers_cb) - self.insert(self.activity.rulers, -1) - self.activity.rulers.show() - - # Grid - self.activity.grids = ToolButton("grid-a") - self.activity.grids.set_tooltip(_('Grid')) - self.activity.grids.props.sensitive = True - self.activity.grids.connect('clicked', self.activity._grids_cb) - self.insert(self.activity.grids, -1) - self.activity.grids.show() - - # Angles - self.activity.angles = ToolButton("angles-90") - self.activity.angles.set_tooltip(_('Angles')) - self.activity.angles.props.sensitive = True - self.activity.angles.connect('clicked', self.activity._angles_cb) - self.insert(self.activity.angles, -1) - self.activity.angles.show() - - # Checker - self.activity.checker = ToolButton("checker") - self.activity.checker.set_tooltip(_('Checker')) - self.activity.checker.props.sensitive = True - self.activity.checker.connect('clicked', self.activity._checker_cb) - self.insert(self.activity.checker, -1) - self.activity.checker.show() - - if not self.activity.known_dpi: - separator = gtk.SeparatorToolItem() - separator.set_draw(True) - self.insert(separator, -1) - separator.show() - - dpi = self.activity._canvas.get_dpi() - self.activity._dpi_spin_adj = gtk.Adjustment( - dpi, 72, 200, 2, 32, 0) - self.activity._dpi_spin = \ - gtk.SpinButton(self.activity._dpi_spin_adj, 0, 0) - self.activity._dpi_spin_id = self.activity._dpi_spin.connect( - 'value-changed', self.activity._dpi_spin_cb) - self.activity._dpi_spin.set_numeric(True) - self.activity._dpi_spin.show() - self.activity.tool_item_dpi = gtk.ToolItem() - self.activity.tool_item_dpi.add(self.activity._dpi_spin) - self.insert(self.activity.tool_item_dpi, -1) - self.activity.tool_item_dpi.show() - - -class MyButton(RadioToolButton): - - def __init__(self, parent, name, icon_name='', callback=None, - tooltip=None, group=None): - RadioToolButton.__init__(self) - - if icon_name == '': - icon_name = 'computer-xo' - icon = Icon(icon_name=icon_name, - icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) - self.set_icon_widget(icon) - icon.show() - if tooltip is not None: - self.set_tooltip(tooltip) - self.props.sensitive = True - self.connect('clicked', callback) - self.set_group(group) - self.show() - - parent.button_dict[name] = self - parent.callback_dict[name] = callback - - def set_icon(self, name): - icon = Icon(icon_name=name, - icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) - self.set_icon_widget(icon) - icon.show() +def radio_factory(icon_name, toolbar, callback, cb_arg=None, + tooltip=None, group=None): + ''' Add a radio button to a toolbar ''' + button = RadioToolButton(group=group) + button.set_icon_name(icon_name) + if tooltip is not None: + button.set_tooltip(tooltip) + if cb_arg is None: + button.connect('clicked', callback) + else: + button.connect('clicked', callback, cb_arg) + if hasattr(toolbar, 'insert'): # the main toolbar + toolbar.insert(button, -1) + else: # or a secondary toolbar + toolbar.props.page.insert(button, -1) + button.show() + return button diff --git a/activity/activity.info b/activity/activity.info index cfa2cde..a15d945 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -3,6 +3,11 @@ name = Ruler bundle_id = com.laptop.Ruler exec = sugar-activity RulerActivity.RulerActivity icon = activity-ruler -activity_version = 19 +<<<<<<< HEAD +activity_version = 20 +======= +activity_version = 21 +>>>>>>> c1ae3b7b6eedf94357961f25ad764802154ac360 show_launcher = yes license = GPLv3+ +summary = scaled images of a ruler, protractor, and a checker board diff --git a/icons/angles-180.svg b/icons/angles-180.svg deleted file mode 100644 index a988926..0000000 --- a/icons/angles-180.svg +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ - <!ENTITY fill_color "none"> - <!ENTITY stroke_color "#FFFFFF"> -]> -<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45"> - <line x1="0" y1="42" x2="44" y2="42" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="22" y1="42" x2="22" y2="20" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="22" y1="42" x2="6.4" y2="26.4" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="22" y1="42" x2="37.6" y2="26.4" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> -</svg> diff --git a/icons/angles-360.svg b/icons/angles-360.svg index e3b8ff8..96c9e66 100644 --- a/icons/angles-360.svg +++ b/icons/angles-360.svg @@ -1,12 +1,44 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ - <!ENTITY fill_color "none"> - <!ENTITY stroke_color "#FFFFFF"> -]> -<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45"> - <line x1="0" y1="22" x2="44" y2="22" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="22" y1="0" x2="22" y2="44" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="6.4" y1="6.4" x2="37.6" y2="37.6" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="6.4" y1="37.6" x2="37.6" y2="6.4" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="55" + height="55"> + <rect + width="55" + height="55" + x="0" + y="0" + style="fill:#000000;fill-opacity:1;stroke:none" /> + <g + transform="translate(5.5,5.5)"> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="22" + x2="44" + y1="22" + x1="0" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="44" + x2="22" + y1="0" + x1="22" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="37.6" + x2="37.6" + y1="6.4" + x1="6.4" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="6.4" + x2="37.6" + y1="37.6" + x1="6.4" /> + </g> </svg> diff --git a/icons/angles-90.svg b/icons/angles-90.svg index b8db8fb..a8faf03 100644 --- a/icons/angles-90.svg +++ b/icons/angles-90.svg @@ -1,11 +1,38 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ - <!ENTITY fill_color "none"> - <!ENTITY stroke_color "#FFFFFF"> -]> -<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45"> - <line x1="3" y1="44" x2="3" y2="0" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="3" y1="42" x2="45" y2="42" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="3" y1="42" x2="32.7" y2="12.3" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="55" + height="55"> + <rect + width="55" + height="55" + x="0" + y="0" + style="fill:#000000;fill-opacity:1;stroke:none" /> + <g + transform="translate(3.5,5.5)"> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="0" + x2="3" + y1="44" + x1="3" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="42" + x2="45" + y1="42" + x1="3" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="12.3" + x2="32.7" + y1="42" + x1="3" /> + </g> </svg> diff --git a/icons/checker.svg b/icons/checker.svg index b58c66a..4a0629b 100644 --- a/icons/checker.svg +++ b/icons/checker.svg @@ -1,11 +1,38 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ - <!ENTITY fill_color "none"> - <!ENTITY stroke_color "#FFFFFF"> -]> -<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45"> - <rect x="0" y="0" width="45" height="45" style="fill:&fill_color;;stroke:&fill_color;;stroke-width:0"/> - <rect x="0" y="0" width="22" height="22" style="fill:&stroke_color;;stroke:none;stroke-width:0"/> - <rect x="22" y="22" width="44" height="44" style="fill:&stroke_color;;stroke:none;stroke-width:0"/> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="55" + height="55"> + <rect + width="55" + height="55" + x="0" + y="0" + style="fill:#000000;fill-opacity:1;stroke:none" /> + <rect + width="45" + height="45" + x="0" + y="10" + style="fill:none;stroke:none" /> + <g + transform="translate(0.45328999,0.6546607)"> + <rect + width="22" + height="22" + x="4.9577274" + y="4.8516951" + style="fill:#ffffff;stroke:none" /> + <rect + width="22" + height="22" + x="27.135693" + y="26.838984" + style="fill:#ffffff;stroke:none" /> + </g> </svg> diff --git a/icons/grid-a.svg b/icons/grid-a.svg index 8810486..e0de4de 100644 --- a/icons/grid-a.svg +++ b/icons/grid-a.svg @@ -1,16 +1,50 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ - <!ENTITY fill_color "none"> - <!ENTITY stroke_color "#FFFFFF"> -]> -<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45"> - <rect x="0" y="0" width="45" height="45" style="fill:&fill_color;;stroke:&fill_color;;stroke-width:0"/> - - <line x1="0" x2="45" y1="6" y2="6" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="0" x2="45" y1="39" y2="39" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - - <line y1="0" y2="45" x1="6" x2="6" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line y1="0" y2="45" x1="39" x2="39" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="55" + height="55"> + <rect + width="55" + height="55" + x="0" + y="0" + style="fill:#000000;fill-opacity:1;stroke:none" /> + <g + transform="translate(5,-5)"> + <rect + width="45" + height="45" + x="0" + y="10" + style="fill:none;stroke:none" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="16" + y1="16" + x2="45" + x1="0" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="49" + y1="49" + x2="45" + x1="0" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="6" + x1="6" + y2="55" + y1="10" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="39" + x1="39" + y2="55" + y1="10" /> + </g> </svg> diff --git a/icons/grid-c.svg b/icons/grid-c.svg index ba785bf..b1f4796 100644 --- a/icons/grid-c.svg +++ b/icons/grid-c.svg @@ -1,22 +1,86 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ - <!ENTITY fill_color "none"> - <!ENTITY stroke_color "#FFFFFF"> -]> -<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45"> - <rect x="0" y="0" width="44" height="44" style="fill:&fill_color;;stroke:&fill_color;;stroke-width:0"/> - - <line x1="0" x2="44" y1="2" y2="2" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="0" x2="44" y1="12" y2="12" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="0" x2="44" y1="22" y2="22" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="0" x2="44" y1="32" y2="32" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line x1="0" x2="44" y1="42" y2="42" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - - <line y1="0" y2="44" x1="2" x2="2" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line y1="0" y2="44" x1="12" x2="12" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line y1="0" y2="44" x1="22" x2="22" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line y1="0" y2="44" x1="32" x2="32" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line y1="0" y2="44" x1="42" x2="42" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="55" + height="55"> + <rect + width="55" + height="55" + x="0" + y="0" + style="fill:#000000;fill-opacity:1;stroke:none" /> + <g + transform="translate(5.5,-4.5)"> + <rect + width="44" + height="44" + x="0" + y="10" + style="fill:none;stroke:none" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="12" + y1="12" + x2="44" + x1="0" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="22" + y1="22" + x2="44" + x1="0" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="32" + y1="32" + x2="44" + x1="0" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="42" + y1="42" + x2="44" + x1="0" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + y2="52" + y1="52" + x2="44" + x1="0" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="2" + x1="2" + y2="54" + y1="10" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="12" + x1="12" + y2="54" + y1="10" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="22" + x1="22" + y2="54" + y1="10" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="32" + x1="32" + y2="54" + y1="10" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="42" + x1="42" + y2="54" + y1="10" /> + </g> </svg> diff --git a/icons/ruler.svg b/icons/ruler.svg index b6240f9..06dc7d3 100644 --- a/icons/ruler.svg +++ b/icons/ruler.svg @@ -1,12 +1,44 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ - <!ENTITY fill_color "none"> - <!ENTITY stroke_color "#FFFFFF"> -]> -<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45"> - <rect x="13" y="3" width="20" height="40" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line y1="13" y2="13" x1="25" x2="33" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line y1="23" y2="23" x1="25" x2="33" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> - <line y1="33" y2="33" x1="25" x2="33" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:4"/> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="55" + height="55"> + <rect + width="55" + height="55" + x="0" + y="0" + style="fill:#000000;fill-opacity:1;stroke:none" /> + <g + transform="translate(4.5,-5.5)"> + <rect + width="20" + height="40" + x="13" + y="13" + style="fill:none;stroke:#ffffff;stroke-width:4" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="33" + x1="25" + y2="23" + y1="23" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="33" + x1="25" + y2="33" + y1="33" /> + <line + style="fill:none;stroke:#ffffff;stroke-width:4" + x2="33" + x1="25" + y2="43" + y1="43" /> + </g> </svg> @@ -1,5 +1,5 @@ #!/usr/bin/env python -from sugar.activity import bundlebuilder +from sugar3.activity import bundlebuilder if __name__ == "__main__": bundlebuilder.start() diff --git a/show_grids.py b/show_grids.py index 0795be7..f050e50 100644 --- a/show_grids.py +++ b/show_grids.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with Ruler. If not, see <http://www.gnu.org/licenses/> -import gtk import cairo from util import mm, dimensions_mm, set_background_color, write @@ -1,5 +1,6 @@ # Copyright 2007 Mitchell N. Charity -# Copyright 2009 Walter Bender +# Copyright 2009, 2012 Walter Bender +# Copyright 2012 Flavio Danesse # # This file is part of Ruler. # @@ -16,19 +17,19 @@ # You should have received a copy of the GNU General Public License # along with Ruler. If not, see <http://www.gnu.org/licenses/> -import pygtk -pygtk.require('2.0') -import gtk -import gobject +import gi +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GObject import dbus import os -import commands +import subprocess from string import find -import pango -import pangocairo +from gi.repository import Pango +from gi.repository import PangoCairo XO1 = 'xo1' XO15 = 'xo1.5' @@ -81,14 +82,13 @@ def dimensions_mm(dpi, w, h): def calc_dpi(): '''Looking for 'dimensions' line in xdpyinfo dimensions: 1280x800 pixels (339x212 millimeters)''' - (status, output) = commands.getstatusoutput('/usr/bin/xdpyinfo') - if status == 0: + output = check_output('/usr/bin/xdpyinfo', 'xdpyinfo failed') + if output is not None: strings = output[find(output, 'dimensions:'):].split() w = int(strings[1].split('x')[0]) # e.g., 1280x800 mm = int(strings[3][1:].split('x')[0]) # e.g., (339x212) return int((w * 25.4 / mm) + 0.5), True else: - # just in case the above fails return 96, False @@ -98,38 +98,63 @@ def calc_dpi(): def set_background_color(c, w, h): c.save() c.rectangle(0, 0, w, h) - c.set_source_color(gtk.gdk.color_parse('white')) + Gdk.cairo_set_source_color(c, Gdk.color_parse('white')) c.fill() c.restore() def set_color(c, name): - c.set_source_color(gtk.gdk.color_parse(name)) + Gdk.cairo_set_source_color(c, Gdk.color_parse(name)) def write(c, text, name, size, centered=False, at_top=False): - pc = pangocairo.CairoContext(c) + pc = PangoCairo.create_context(c) - font = pango.FontDescription(name) - font.set_size(int(round(size * pango.SCALE))) - lo = pc.create_layout() + font = Pango.FontDescription(name) + font.set_size(int(round(size * Pango.SCALE))) + lo = PangoCairo.create_layout(pc) lo.set_font_description(font) - lo.set_text('X') - extent = [x / pango.SCALE for x in lo.get_extents()[1]] - ex, ey = extent[2], extent[3] - baseline_offset = -ey + lo.set_text('X', -1) + baseline_offset = lo.get_baseline() / Pango.SCALE if not at_top: - c.rel_move_to(0, baseline_offset) + c.rel_move_to(0, -baseline_offset) - lo = pc.create_layout() lo.set_font_description(font) - lo.set_text(text) - extent = [x / pango.SCALE for x in lo.get_extents()[1]] - ex, ey = extent[2], extent[3] + lo.set_text(text, -1) + if hasattr(lo, 'get_logical_extents'): + extents = lo.get_logical_extents() + ex = extents.get_width() / Pango.SCALE + else: + ex = size + ex *= len(text) + if centered: c.rel_move_to(-ex / 2, 0) - pc.show_layout(lo) + PangoCairo.update_layout(c, lo) + PangoCairo.show_layout(c, lo) c.rel_move_to(ex, 0) if not at_top: c.rel_move_to(0, -baseline_offset) + + +def check_output(command, warning): + ''' Workaround for old systems without subprocess.check_output''' + if hasattr(subprocess, 'check_output'): + try: + output = subprocess.check_output(command) + except subprocess.CalledProcessError: + log.warning(warning) + return None + else: + import commands + + cmd = '' + for c in command: + cmd += c + cmd += ' ' + (status, output) = commands.getstatusoutput(cmd) + if status != 0: + log.warning(warning) + return None + return output |