def __init__(self, font, font_bold, w, h): self.font = font self.font_bold = font_bold self.w = w self.h = h self.custom_unit_in_mm = 24.5 # precise upto 2 decimal places self.hw = get_hardware() self.offset_of_xo_side_from_screen = 0 self.dpi = 0 self.c = None
def __init__(self, font, font_bold, w, h): self.font = font self.font_bold = font_bold self.w = w self.h = h self.hw = get_hardware()
def __init__(self, handle): super(RulerActivity, self).__init__(handle) self.button_dict = {} self.callback_dict = {} self._ready = False _font = 'helvetica 12' _font_bold = 'helvetica bold 12' # # We need a canvas # self._canvas = MyCanvas() self.set_canvas(self._canvas) self._canvas.show() _width = gtk.gdk.screen_width() _height = gtk.gdk.screen_height() - GRID_CELL_SIZE # Read the dpi from the Journal if get_hardware()[0:2] == 'XO': self._canvas.set_dpi(200) # OLPC XO self.known_dpi = True else: self.known_dpi = False try: dpi = self.metadata['dpi'] _logger.debug("Read dpi: " + str(dpi)) self._canvas.set_dpi(int(dpi)) except KeyError: self._canvas.set_dpi(96) # Just a guess # Create instances of our graphics self._r = show_rulers.ScreenOfRulers(_font, _font_bold, _width, _height) self._gcm = show_grids.ScreenGrid_cm(_font, _font_bold, _width, _height) self._gmm = show_grids.ScreenGrid_mm(_font, _font_bold, _width, _height) self._a90 = show_angles.Angles90(_font, _font_bold, _width, _height) self._a360 = show_angles.Angles360(_font, _font_bold, _width, _height) self._c = show_checkers.ScreenOfCircles(_font, _font_bold, _width, _height) # start with a ruler self._current = self._r self._canvas.add_a_ruler(self._current) # other settings self._grids_mode = "cm" self._angles_mode = "90" # # We need some toolbars # 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: 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() else: # Use pre-0.86 toolbar design toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) self.projectToolbar = ProjectToolbar(self) toolbox.add_toolbar(_('Rulers'), self.projectToolbar) toolbox.show() toolbox.set_current_toolbar(1) self.show_all() # Restore state if previously saved self._ready = True 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.callback_dict[self.metadata['ruler']] else: self._rulers_cb() if HAS_TOOLARBOX: self.rulers.set_active(True)