Example #1
0
    def set_image(self, buf, fill='#0000ff', stroke='#4d4c4f'):
        img = Gtk.Image()
        str_buf = StringIO.StringIO(buf)
        thumb_surface = cairo.ImageSurface.create_from_png(str_buf)

        bg_width, bg_height = style.zoom(120), style.zoom(110)
        bg_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, bg_width,
                                        bg_height)
        context = cairo.Context(bg_surface)
        # draw a rectangle in the background with the selected colors
        context.set_line_width(style.zoom(10))
        context.set_source_rgba(*style.Color(fill).get_rgba())
        context.rectangle(0, 0, bg_width, bg_height)
        context.fill_preserve()
        context.set_source_rgba(*style.Color(stroke).get_rgba())
        context.stroke()
        # add the screenshot
        dest_x = style.zoom(10)
        dest_y = style.zoom(20)
        context.set_source_surface(thumb_surface, dest_x, dest_y)
        thumb_width, thumb_height = style.zoom(100), style.zoom(80)
        context.rectangle(dest_x, dest_y, thumb_width, thumb_height)
        context.fill()

        pixbuf_bg = Gdk.pixbuf_get_from_surface(bg_surface, 0, 0, bg_width,
                                                bg_height)

        img.set_from_pixbuf(pixbuf_bg)
        self.set_icon_widget(img)
        img.show()
Example #2
0
    def _draw_simple_background(self, cr):
        """Draw the background of the simple clock.
        The simple clock background is a white disk, with hours and minutes
        ticks, and the hour numbers.
        """
        cr.set_line_width(4 * self._line_width)
        cr.set_line_cap(cairo.LINE_CAP_ROUND)

        # Simple clock background
        cr.set_source_rgba(*style.Color(self._COLOR_WHITE).get_rgba())
        cr.arc(self._radius, self._radius, self._radius - self._line_width * 2,
               0, 2 * math.pi)
        cr.fill_preserve()
        cr.set_source_rgba(*style.Color(self._COLOR_BLACK).get_rgba())
        cr.stroke()

        # Clock ticks
        for i in xrange(60):
            if i % 15 == 0:
                inset = 0.11 * self._radius
                cr.set_line_width(7 * self._line_width)
            elif i % 5 == 0:
                inset = 0.1 * self._radius
                cr.set_line_width(5 * self._line_width)
            else:
                inset = 0.05 * self._radius
                cr.set_line_width(4 * self._line_width)

            cos = math.cos(i * math.pi / 30.0)
            sin = math.sin(i * math.pi / 30.0)
            cr.move_to(int(self._radius + (self._radius - inset) * cos),
                       int(self._radius + (self._radius - inset) * sin))
            cr.line_to(int(self._radius + (self._radius - 6) * cos),
                       int(self._radius + (self._radius - 6) * sin))
            cr.stroke()
Example #3
0
    def set_empty_image(self, page, fill='#0000ff', stroke='#4d4c4f'):
        img = Gtk.Image()

        bg_width, bg_height = style.zoom(120), style.zoom(110)
        bg_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, bg_width,
                                        bg_height)
        context = cairo.Context(bg_surface)
        # draw a rectangle in the background with the selected colors
        context.set_line_width(style.zoom(10))
        context.set_source_rgba(*style.Color(fill).get_rgba())
        context.rectangle(0, 0, bg_width, bg_height)
        context.fill_preserve()
        context.set_source_rgba(*style.Color(stroke).get_rgba())
        context.stroke()

        # add the page number
        context.set_font_size(style.zoom(60))
        text = str(page)
        x, y = bg_width / 2, bg_height / 2

        xbearing, ybearing, width, height, xadvance, yadvance = \
            context.text_extents(text)
        context.move_to(x - width / 2, y + height / 2)
        context.show_text(text)
        context.stroke()

        pixbuf_bg = Gdk.pixbuf_get_from_surface(bg_surface, 0, 0, bg_width,
                                                bg_height)

        img.set_from_pixbuf(pixbuf_bg)
        self.set_icon_widget(img)
        img.show()
    def _create_right_toolbar(self):
        """
        This is a vertical toolbar for this page
        Elements are
        --Install Button
        --Edit Button
        --Delete Button
        """
        frame = Gtk.Frame()
        grid = Gtk.Grid()
        # grid.set_border_color(style.Color('# 34495E').get_gdk_color())

        # GRID_HEIGHT= 3  # number of rows # not used
        # GRID_WIDTH = 1  # number of columns # not used
        # GRID_BOX_SIZE = 40  # not used
        GRID_ROW_SPACING = 20
        GRID_COLUMN_SPACING = 5

        frame.set_border_width(5)
        frame.add(grid)
        grid.set_column_spacing(GRID_COLUMN_SPACING)
        grid.set_row_spacing(GRID_ROW_SPACING)

        # Install Button
        image_icon = Icon(pixel_size=style.zoom(55 * 1.5),
                          icon_name='install',
                          stroke_color=style.COLOR_BLACK.get_svg(),
                          fill_color=style.COLOR_WHITE.get_svg())
        installButton = Gtk.Button()
        installButton.set_image(image_icon)
        installButton.modify_bg(Gtk.StateType.NORMAL,
                                style.Color('#34495E').get_gdk_color())
        installButton.props.relief = Gtk.ReliefStyle.NONE
        installButton.connect("clicked", self._clickInstall)
        grid.attach(installButton, 0, 0, 1, 1)

        # Edit Button
        image_icon = Icon(pixel_size=style.MEDIUM_ICON_SIZE,
                          icon_name='edit',
                          stroke_color=style.COLOR_BLACK.get_svg(),
                          fill_color=style.COLOR_WHITE.get_svg())
        editButton = Gtk.Button()
        editButton.add(image_icon)
        editButton.props.relief = Gtk.ReliefStyle.NONE
        editButton.connect("clicked", self._clickEdit)
        grid.attach(editButton, 0, 1, 1, 1)

        # Delete Button
        image_icon = Icon(pixel_size=style.MEDIUM_ICON_SIZE,
                          icon_name='delete',
                          stroke_color=style.COLOR_BLACK.get_svg(),
                          fill_color=style.Color('#E74C3C').get_svg())

        deleteButton = Gtk.Button()
        deleteButton.add(image_icon)
        deleteButton.props.relief = Gtk.ReliefStyle.NONE
        deleteButton.connect("clicked", self._clickDelete)
        grid.attach(deleteButton, 0, 2, 1, 1)

        return frame
Example #5
0
    def _draw_time_scale(self, cr):

        p_length = int(self._bio[0] * self._scale)
        e_length = int(self._bio[1] * self._scale)
        i_length = int(self._bio[2] * self._scale)

        # Fill background
        width = 70
        x = self._center_x
        y = self._center_y

        cr.set_source_rgba(*style.Color(self._COLOR_WHITE).get_rgba())
        cr.rectangle(self._center_x - (width + 30) - 35,
                     (self._center_y - self._scale - 10),
                     3 * width + 2 * 20 + 20, self._scale * 2 + 20)
        cr.fill()

        # Physical cycle
        cr.set_source_rgba(*style.Color(self._COLOR_P).get_rgba())
        cr.rectangle(x - (width + 20) - 35, y, width, p_length)
        cr.fill()

        # Emotional cycle
        cr.set_source_rgba(*style.Color(self._COLOR_E).get_rgba())
        cr.rectangle(x - 35, y, width, e_length)
        cr.fill()

        # Intellectual cycle
        cr.set_source_rgba(*style.Color(self._COLOR_I).get_rgba())
        cr.rectangle(x - 35 + (width + 20), y, width, i_length)
        cr.fill()
Example #6
0
    def __init__(self, parent,
                 name_color, text_color, bg_color, highlight_color,
                 lang_rtl, nick_name=None, text=None):
        Gtk.TextView.__init__(self)
        self._parent = parent
        self._buffer = Gtk.TextBuffer()
        self._empty_buffer = Gtk.TextBuffer()
        self._empty_buffer.set_text('')
        self._empty = True
        self._name_tag = self._buffer.create_tag(
            'name', foreground=name_color.get_html(), weight=Pango.Weight.BOLD)
        self._fg_tag = self._buffer.create_tag(
            'foreground_color', foreground=text_color.get_html())
        self._subscript_tag = self.get_buffer().create_tag(
            'subscript', foreground=text_color.get_html(),
            rise=-7 * Pango.SCALE)  # in pixels

        # Initialise each TextView object with a default set of pattern tags
        self._pattern_tag_hilite = self._buffer.create_tag(
            'pattern-hilite', background=style.Color('#D80A0A').get_html())
        self._pattern_tag_select = self._buffer.create_tag(
            'pattern-select', background=style.Color('#09C3F7').get_html())
        if nick_name:
            self._add_name(nick_name)
            self.add_text(text, newline=False)
        elif text:
            self.add_text(text)

        self.resize_box()

        self._lang_rtl = lang_rtl
        self.set_editable(False)
        self.set_cursor_visible(False)
        self.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)

        self.palette = None

        self._mouse_detector = MouseSpeedDetector(200, 5)
        self._mouse_detector.connect('motion-slow', self.__mouse_slow_cb)

        self.modify_bg(0, bg_color.get_gdk_color())

        rgba = Gdk.RGBA()
        rgba.red, rgba.green, rgba.blue, rgba.alpha = \
            highlight_color.get_rgba()
        self.override_background_color(Gtk.StateFlags.SELECTED, rgba)

        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK |
                        Gdk.EventMask.BUTTON_RELEASE_MASK |
                        Gdk.EventMask.LEAVE_NOTIFY_MASK)

        self.connect('event-after', self.__event_after_cb)
        self.connect('button-press-event', self.__button_press_cb)
        self.motion_notify_id = \
            self.connect('motion-notify-event', self.__motion_notify_cb)
        self.connect('visibility-notify-event', self.__visibility_notify_cb)
        self.connect('leave-notify-event', self.__leave_notify_event_cb)
        self.connect('size-allocate', self.__size_allocate_cb)
Example #7
0
    def _editor_selected_cb(self, editor, data=None):
        last_editor = self._editors[self._selected]
        last_editor.modify_bg(Gtk.StateType.NORMAL,
                              style.Color('#FFFFFF').get_gdk_color())

        self._selected = self._editors.index(editor)
        editor.modify_bg(Gtk.StateType.NORMAL,
                         style.Color('#FF0000').get_gdk_color())

        logging.error('_last_selected is %d', self._selected)
    def _print_text(self,
                    context,
                    x,
                    y,
                    text,
                    font_size,
                    max_width=0,
                    alignment=None,
                    color=None):
        if text is None:
            return
        context.save()
        context.translate(x, y)
        layout = self.create_pango_layout(text)
        if max_width > 0:
            layout.set_width(max_width * Pango.SCALE)
            layout.set_wrap(Pango.WrapMode.WORD_CHAR)
        if alignment is not None:
            layout.set_alignment(alignment)
        font_desc = Pango.FontDescription("Sans %s" % font_size)
        layout.set_font_description(font_desc)

        if color is None:
            context.set_source_rgb(0, 0, 0)
        else:
            context.set_source_rgba(*style.Color(color).get_rgba())

        PangoCairo.update_layout(context, layout)
        PangoCairo.show_layout(context, layout)
        context.fill()

        context.restore()
Example #9
0
    def update_summary(self):
        # Calculate starting balance.
        start = 0.0
        for t in self.data['transactions']:
            d = t['date']
            if d < self.period_start.toordinal():
                if t['type'] == 'credit':
                    start += t['amount']
                else:
                    start -= t['amount']

        # Calculate totals for this period.
        credit_count = 0
        credit_total = 0.0
        debit_count = 0
        debit_total = 0.0
        total = start
        for t in self.visible_transactions:
            if t['type'] == 'credit':
                credit_count += 1
                credit_total += t['amount']
                total += t['amount']
            else:
                debit_count += 1
                debit_total += t['amount']
                total -= t['amount']

        # Update Balance.
        if total >= 0.0:
            balancecolor = colors.CREDIT_COLOR
        else:
            balancecolor = colors.DEBIT_COLOR
        balance = \
            "<span size='xx-large' foreground='white'><b>%s %s</b></span>" % \
            (_('Balance: '), locale.currency(total))
        self.balancelabel.set_markup(balance)

        self.balance_evbox.modify_bg(Gtk.StateType.NORMAL,
                                     style.Color(balancecolor).get_gdk_color())

        self.startlabel.set_markup(
            "<span foreground='white'><b>%s</b></span>" %
            _('Starting Balance:'))
        self.startamountlabel.set_markup(
            "<span foreground='white'><b>%s</b></span>" %
            locale.currency(start))

        self.creditslabel.set_markup(
            "<span foreground='white'><b>%s</b></span>" %
            (_('%(credit_total)s in %(credit_count)d credits') % {
                'credit_total': locale.currency(credit_total),
                'credit_count': credit_count
            }))

        self.debitslabel.set_markup(
            "<span foreground='white'><b>%s</b></span>" %
            (_('%(debit_total)s in %(debit_count)d debits') % {
                'debit_total': locale.currency(debit_total),
                'debit_count': debit_count
            }))
Example #10
0
    def __init__(self, activity):
        GObject.GObject.__init__(self)

        self.activity = activity

        self.category_total = {}
        self.sorted_categories = []
        self._graph_mode = self.CHART_DEBIT

        header = Gtk.EventBox()
        header.modify_bg(Gtk.StateType.NORMAL,
                         style.Color('#666666').get_gdk_color())
        header.set_size_request(-1, style.GRID_CELL_SIZE)

        self._title_label = Gtk.Label()
        self._title_label.set_halign(Gtk.Align.START)
        self._title_label.props.margin_left = style.GRID_CELL_SIZE / 2
        header.add(self._title_label)

        self.area = Gtk.DrawingArea()
        self.area.connect('draw', self.chart_draw_cb)

        self.pack_start(header, False, False, 0)
        self.pack_start(self.area, True, True, 0)

        self.show_all()
    def _draw_box(self, glyphName, i, j):

        eventBox = Gtk.EventBox()
        self.grid.attach(eventBox, i, j, 1, 1)
        eventBox.connect("button-press-event", self._glyph_clicked, glyphName)
        eventBox.modify_bg(
            Gtk.StateType.NORMAL,
            style.Color(globals.GLYPH_BOX_COLOR).get_gdk_color())

        box = Gtk.VBox()
        eventBox.add(box)
        unicode_lable = FormatLabel(glyphName, globals.TEXT_STYLE['LABEL'])

        unicode_lable.set_max_width_chars(9)
        unicode_lable.set_ellipsize(Pango.EllipsizeMode.END)
        unicode_lable.set_halign(Gtk.Align.CENTER)
        box.pack_start(unicode_lable, False, False, 2)

        alignment = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0, yscale=0)
        box.pack_start(alignment, True, False, 0)

        glyphBox = RenderGlyph(glyphName, globals.GRID_BOX_SIZE,
                               globals.GRID_BOX_SIZE, self.h, self.b)
        eventBox.connect("button-press-event", self._glyph_clicked, glyphName)

        alignment.add(glyphBox)
Example #12
0
    def _draw_time(self):
        """Draw the time in colors (digital display).
        """
        # TRANS: The format used to display the time for digital clock
        # You can add AM/PM indicator or use 12/24 format, for example
        # "%I:%M:%S %p".  See
        # http://docs.python.org/lib/module-time.html for available
        # strftime formats If the display of the time is moving
        # horizontally, it means that the glyphs of the digits used in
        # the font don't have the same width. Try to use a Monospace
        # font.  xgettext:no-python-format
        markup = _('<markup>\
<span lang="en" font_desc="Sans,Monospace Bold 96">\
<span foreground="#005FE4">%I</span>:\
<span foreground="#00B20D">%M</span>:\
<span foreground="#E6000A">%S</span>%p</span></markup>')
        # BUG: The following line kills Python 2.5 but is valid in 2.4
        markup_time = self._time.strftime(markup)
        # markup_time = time.strftime(markup)

        cr = self.window.cairo_create()
        cr.set_source_rgba(*style.Color(self._COLOR_BLACK).get_rgba())
        pango_layout = PangoCairo.create_layout(
            PangoCairo.create_context(cr))
        d = int(self._center_y + 0.3 * self._radius)
        pango_layout.set_markup(markup_time)
        dx, dy = pango_layout.get_pixel_size()
        pango_layout.set_alignment(Pango.Alignment.CENTER)
        cr.translate(self._center_x - dx / 2.0, d - dy / 2.0)
        PangoCairo.show_layout(cr, pango_layout)
Example #13
0
    def _validate(self, page):

        failed_items = []

        if page == 0:
            box = self._first_page
            if self._poll.title == '':
                failed_items.append('title')

            if self._poll.question == '':
                failed_items.append('question')

        if page == 1:
            box = self._maxvoters_page
            if self._poll.maxvoters == 0:
                failed_items.append('maxvoters')

        if page == 2:
            box = self._options_page
            if self._poll.options[0] == '':
                failed_items.append(0)

            if self._poll.options[1] == '':
                failed_items.append(1)

            if self._poll.options[3] != '' and self._poll.options[2] == '':
                failed_items.append(2)

            if self._poll.options[4] != '' and self._poll.options[3] == '':
                failed_items.append(3)

            if self._poll.options[2] == '':
                self._poll.number_of_options = 2

            elif self._poll.options[3] == '':
                self._poll.number_of_options = 3

            elif self._poll.options[4] == '':
                self._poll.number_of_options = 4

            else:
                self._poll.number_of_options = 5

            # if there are images loaded, request a description
            for field in range(0, 5):
                image_loaded = self._poll.images_ds_objects[field] != {}
                if image_loaded and self._poll.options[field] == '':
                    failed_items.append(field)

        # paint the obligatory entries without value

        for child in box:
            if (type(child) is ItemNewPoll or
                type(child) is ItemOptionNewPoll) \
                    and child.field in failed_items:
                child.entry.modify_bg(Gtk.StateType.NORMAL,
                                      style.Color('#FFFF00').get_gdk_color())

        return failed_items
Example #14
0
    def __init__(self):
        Gtk.EventBox.__init__(self)
        self.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE * 2)
        self._xo_color = profile.get_color()
        self._fill_color = style.Color(self._xo_color.get_fill_color())
        self._stroke_color = style.Color(self._xo_color.get_stroke_color())

        self._box = Gtk.VButtonBox()
        self._box.set_layout(Gtk.ButtonBoxStyle.CENTER)
        self.add(self._box)
        self._box.show()

        self._bookmark_icon = None
        self._bookmark_manager = None
        self._is_showing_local_bookmark = False
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self._box.connect('draw', self.__draw_cb)
Example #15
0
    def __init__(self,
                 icon_name,
                 stroke_color=globals.USER_COLOR[0],
                 fill_color=globals.USER_COLOR[1],
                 bg_color=globals.ACTIVITY_BG,
                 pixel_size=82.5):

        super(ImageButton, self).__init__()
        self.icon = Icon(icon_name=icon_name,
                         pixel_size=style.zoom(pixel_size),
                         stroke_color=style.Color(stroke_color).get_svg(),
                         fill_color=style.Color(fill_color).get_svg())

        self.set_image(self.icon)
        self.props.relief = Gtk.ReliefStyle.NONE
        self.modify_bg(Gtk.StateType.NORMAL,
                       style.Color(bg_color).get_gdk_color())
Example #16
0
    def __init__(self, buddy, look='centre'):
        self.buddy = buddy
        name = buddy.props.nick.decode('utf-8')
        self.nick = unicodedata.normalize('NFC', name)
        colors = buddy.props.color.split(",")
        self.fg = style.Color(colors[0])
        self.bg = style.Color(colors[1])
        self.victories = 0

        # this field is None when the activity is not shared and when
        # the user shared it this field will become to
        # "olpcgames.mesh.my_handle()"
        self.uid = None

        self.look = look
        self.hidden = False
        self.bonusplayers = None
        self.reset()
    def __init__(self, game, editor_index):
        Gtk.EventBox.__init__(self)
        self._game = game
        self.snd = None
        self.editor_index = editor_index
        self.temp_folder = None

        box = Gtk.Grid()
        box.set_column_spacing(style.DEFAULT_SPACING)
        box.set_row_spacing(style.DEFAULT_SPACING)
        box.props.margin = style.DEFAULT_SPACING

        self.card = svgcard.SvgCard(-1, {
            'front_text': {
                'card_text': '',
                'text_color': style.Color('#ffffff')
            }
        }, None, PAIR_SIZE, '#c0c0c0')
        self.card.flip()
        card_align = Gtk.Alignment.new(.5, .5, 0, 0)
        card_align.add(self.card)
        box.attach(card_align, 0, 0, 1, 1)

        self.textentry = Gtk.Entry()
        self.textentry.connect('changed', self.update_text)
        self.textentry.set_valign(Gtk.Align.START)
        box.attach(self.textentry, 0, 1, 1, 1)

        toolbar = Gtk.VBox()
        toolbar.set_valign(Gtk.Align.CENTER)

        browsepicture = ToolButton(icon_name='import_picture',
                                   tooltip=_('Insert picture'))
        toolbar.add(browsepicture)

        browsesound = ToolButton(icon_name='import_sound',
                                 tooltip=_('Insert sound'))
        toolbar.add(browsesound)

        browsepicture.connect('clicked', self._load_image)
        browsesound.connect('clicked', self._load_audio)

        if speak.espeak.supported:
            self.usespeak = ToggleToolButton(icon_name='speak')
            self.usespeak.set_palette(SpeakPalette(self))
            toolbar.add(self.usespeak)
            self.usespeak.connect('toggled', self._usespeak_cb)
        else:
            self.usespeak = None

        self.fontbutton = FontButton()
        toolbar.add(self.fontbutton)
        self.id_font_changed = self.fontbutton.connect('changed',
                                                       self.__font_changed_cb)
        box.attach(toolbar, 1, 0, 1, 2)

        self.add(box)
Example #18
0
    def _add_bookmark_icon(self, bookmark):
        self._xo_color = XoColor(str(bookmark.color))
        self._fill_color = style.Color(self._xo_color.get_fill_color())
        self._stroke_color = style.Color(self._xo_color.get_stroke_color())
        self._bookmark_icon = Icon(icon_name='emblem-favorite',
                                   xo_color=self._xo_color,
                                   pixel_size=style.STANDARD_ICON_SIZE)
        self._bookmark_icon.set_valign(Gtk.Align.START)

        self._box.props.has_tooltip = True
        self.__box_query_tooltip_cb_id = self._box.connect(
            'query_tooltip', self.__bookmark_query_tooltip_cb)

        self._box.pack_start(self._bookmark_icon, False, False, 0)
        self._bookmark_icon.show_all()

        if bookmark.is_local():
            self._is_showing_local_bookmark = True
Example #19
0
    def set_border(self, stroke_color, fill_color, full_animation=False):
        """
        style_color, fill_color: str with format #RRGGBB
        """
        self.props['front'].update({'fill_color': style.Color(fill_color),
                                    'stroke_color': style.Color(stroke_color)})
        self._cached_surface[True] = None

        if full_animation:
            if self.get_speak():
                # If we displayed the robot face, displayed the text
                self.jpeg = None
                self.props['front_text']['speak'] = False

        if not self.is_flipped():
            self.flip(full_animation)
        else:
            self.queue_draw()
    def draw_label(self, ctx, piece, text, xIni, yIni):

        stroke_r, stroke_g, stroke_b = 0, 0, 0
        alpha = 1
        if piece.player.color is not None:
            xocolor = piece.player.color
            stroke_r, stroke_g, stroke_b, alpha = style.Color(
                xocolor.get_stroke_color(), 1.0).get_rgba()
        ctx.set_source_rgb(stroke_r, stroke_g, stroke_b)

        xCenter = xIni + (dominoview.SIZE / 2)
        yCenter = yIni + (dominoview.SIZE / 2)

        separa = (dominoview.SIZE / 4)
        radio = 4

        #
        #   *1    *2
        #   *3 *4 *5
        #   *6    *7
        #

        # 1
        if text in ("2", "3", "4", "5", "6"):
            ctx.arc(xCenter - separa, yCenter - separa, radio, 0, 2 * M_PI)
            ctx.fill()

        # 2
        if text in ("4", "5", "6"):
            ctx.arc(xCenter + separa, yCenter - separa, radio, 0, 2 * M_PI)
            ctx.fill()

        # 3
        if text == "6":
            ctx.arc(xCenter - separa, yCenter, radio, 0, 2 * M_PI)
            ctx.fill()

        # 4
        if text in ("1", "3", "5"):
            ctx.arc(xCenter, yCenter, radio, 0, 2 * M_PI)
            ctx.fill()

        # 5
        if text == "6":
            ctx.arc(xCenter + separa, yCenter, radio, 0, 2 * M_PI)
            ctx.fill()

        # 6
        if text in ("4", "5", "6"):
            ctx.arc(xCenter - separa, yCenter + separa, radio, 0, 2 * M_PI)
            ctx.fill()

        # 7
        if text in ("2", "3", "4", "5", "6"):
            ctx.arc(xCenter + separa, yCenter + separa, radio, 0, 2 * M_PI)
            ctx.fill()
Example #21
0
    def __init__(self):
        Gtk.EventBox.__init__(self)

        self.modify_bg(Gtk.StateType.NORMAL, style.COLOR_BLACK.get_gdk_color())

        self.face = speak.face.View(style.Color('#4b4c4e'))
        self.face.set_border_width(style.DEFAULT_SPACING)
        self.add(self.face)
        self.show_all()

        self.set_app_paintable(True)
        self.connect('unrealize', self._unrealize_cb)
Example #22
0
    def _new_face(self, buddy, color):
        colors = buddy.props.color.split(',')
        lighter = style.Color(colors[_lighter_color(colors)])

        buddy_face = face.View(lighter)
        # FIXME: omit set_border_state causes main face alignment problems
        buddy_face.set_border_state(False)
        # FIXME: non-me faces have no mouth

        buddy_face.show_all()

        return buddy_face
    def __init__(self, handle):
        """Set up the HelloWorld activity."""
        activity.Activity.__init__(self, handle)

        # Change the following number to change max participants
        self.max_participants = 1

        toolbar_box = ToolbarBox()

        activity_button = ActivityToolbarButton(self)
        toolbar_box.toolbar.insert(activity_button, 0)
        activity_button.show()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbar_box.toolbar.insert(separator, -1)
        separator.show()

        stop_button = StopButton(self)
        toolbar_box.toolbar.insert(stop_button, -1)
        stop_button.show()

        self.set_toolbar_box(toolbar_box)
        toolbar_box.show()

        self._boards = []

        background = Gtk.EventBox()
        background.modify_bg(Gtk.StateType.NORMAL,
                             style.Color('#FFFFFF').get_gdk_color())
        self.set_canvas(background)

        # canvas
        hbox = Gtk.HBox()
        background.add(hbox)

        # treeview with pictograms
        self._create_picto_treeview()
        scrolled = Gtk.ScrolledWindow()
        scrolled.props.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.props.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.set_size_request(Gdk.Screen.width() / 4, -1)
        scrolled.add_with_viewport(self._picto_tree_view)
        hbox.pack_start(scrolled, False, False, 0)

        self._board_edit_panel = BoardEditPanel()
        hbox.pack_start(self._board_edit_panel, True, True, 0)

        self._load_pictograms()

        self.show_all()
Example #24
0
    def _draw_time_scale(self, cr):
        """Draw a time scale for digital clock.
        """
        # Draw scales of hours, minutes and seconds, to give the children
        # an appreciation of the time flowing...
        cr.save()
        hours_length = 2 * self._radius / 24 * self._time.hour
        minutes_length = 2 * self._radius / 60 * self._time.minute
        seconds_length = 2 * self._radius / 60 * self._time.second

        # Fill background
        cr.set_source_rgba(*style.Color(self._COLOR_WHITE).get_rgba())
        cr.rectangle(round(self._center_x - 1.1 * self._radius),
                     round(self._center_y - 0.85 * self._radius),
                     round(2.2 * self._radius),
                     round(0.65 * self._radius))
        cr.fill()

        h = round(0.15 * self._radius)
        x = round(self._center_x - self._radius)

        # Hours scale
        cr.set_source_rgba(*style.Color(self._COLOR_HOURS).get_rgba())
        y = round(self._center_y - 0.75 * self._radius)
        cr.rectangle(x, y, hours_length, h)
        cr.fill()

        # Minutes scale
        cr.set_source_rgba(*style.Color(self._COLOR_MINUTES).get_rgba())
        y = round(self._center_y - 0.60 * self._radius)
        cr.rectangle(x, y, minutes_length, h)
        cr.fill()

        # Seconds scale
        cr.set_source_rgba(*style.Color(self._COLOR_SECONDS).get_rgba())
        y = round(self._center_y - 0.45 * self._radius)
        cr.rectangle(x, y, seconds_length, h)
        cr.fill()
        cr.restore()
Example #25
0
    def _draw_time(self, cr):

        markup = _('<markup>\
<span lang="en" font_desc="Sans,Monospace Bold 12">\
<span foreground="#E6000A">%s</span></span></markup>')

        cr.set_source_rgba(*style.Color(self._COLOR_E).get_rgba())
        pango_layout = pangocairo.create_layout(cr)
        d = int(self._center_y + self._scale + 20)
        markup_f = markup % "Physical Emotional Intellectual"
        pango_layout.set_markup(markup_f)
        dx, dy = pango_layout.get_pixel_size()
        pango_layout.set_alignment(pango.Alignment.CENTER)
        cr.translate(self._center_x - dx / 2.0, d - dy / 2.0 + 5)
        pangocairo.show_layout(cr, pango_layout)
    def __init__(self, id='EDITOR', mode=['edit']):
        super(GlyphBox, self).__init__()

        # Generate a random indentifier for this GlyphBox
        # self.id = makeRandomIdentifier([])

        self.mode = mode
        self.id = id

        self.param = globals.GLYPH_BOX[self.id]
        self.set_size_request(
            self.param['width'],  # noqa
            self.param['height'])  # noqa

        self.fixed = Gtk.Fixed()
        self.fixed.set_size_request(
            self.param['width'],  # noqa
            self.param['height'])  # noqa
        self.add(self.fixed)

        self.da = Gtk.DrawingArea()
        self.da.set_size_request(
            self.param['width'],  # noqa
            self.param['height'])  # noqa

        self.da.modify_bg(Gtk.StateType.NORMAL,
                          style.Color(self.param['bg-color']).get_gdk_color())

        self.fixed.put(self.da, 0, 0)

        # The Glyph that will be displayed in the drawing box
        self.glyph = self.param['glyph']

        # declare the list for storing the drag points in the editing session
        self.points = []

        self.update_control_points()

        self.show_all()

        # connect the drawing area to the required events
        self.da.connect('draw', self._draw)

        self.connect("button-press-event", self._on_point_press)
        '''
    def draw_label(self, ctx, piece, text, xIni, yIni):
        stroke_r, stroke_g, stroke_b = 0, 0, 0
        alpha = 1
        if piece.player.color is not None:
            xocolor = piece.player.color
            stroke_r, stroke_g, stroke_b, alpha = style.Color(
                xocolor.get_stroke_color(), 1.0).get_rgba()
        ctx.set_source_rgb(stroke_r, stroke_g, stroke_b)

        ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)
        ctx.set_font_size(20)
        x_bearing, y_bearing, width, height, x_advance, y_advance = \
            ctx.text_extents(text)
        x = 0.5 - (width / 2 + x_bearing)
        y = 0.5 - (height / 2 + y_bearing)
        ctx.move_to(xIni + x + (dominoview.SIZE / 2),
                    yIni + y + (dominoview.SIZE / 2))
        ctx.show_text(text)
Example #28
0
    def _draw_box(self, glyphName, i, j):

        eventBox = Gtk.EventBox()
        self.grid.attach(eventBox, i, j, 1, 1)
        eventBox.connect("button-press-event", self._glyph_clicked, glyphName)
        eventBox.modify_bg(Gtk.StateType.NORMAL,
                           style.Color('#5DADE2').get_gdk_color())

        box = Gtk.VBox()
        eventBox.add(box)

        unicodeLable = Gtk.Label(glyphName)
        unicodeLable.set_max_width_chars(6)
        unicodeLable.set_property('ellipsize', Pango.ELLIPSIZE_END)
        box.pack_start(unicodeLable, False, False, 2)

        alignment = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0, yscale=0)
        box.pack_start(alignment, True, False, 0)

        glyphBox = RenderGlyph(self.font[glyphName], self.GRID_BOX_SIZE,
                               self.GRID_BOX_SIZE, self.h, self.b)
        alignment.add(glyphBox)
Example #29
0
    def _draw_numbers(self, cr):
        """Draw the numbers of the hours.
        """
        cr = PangoCairo.CairoContext(cr)
        cr.set_source_rgba(*style.Color(self._COLOR_HOURS).get_rgba())
        pango_layout = cr.create_layout()

        for i in xrange(12):
            # TRANS: The format of the font used to print hour
            # numbers, from 1 to 12.
            hour_number = _('<markup><span lang="en" \
font_desc="Sans Bold 40">%d</span></markup>') % (i + 1)
            cr.save()
            pango_layout.set_markup(hour_number)
            dx, dy = pango_layout.get_pixel_size()
            cr.translate(- dx / 2.0 + self._radius + 0.75 *
                         self._radius * math.cos((i - 2) * math.pi / 6.0),
                         - dy / 2.0 + self._radius + 0.75 * self._radius *
                         math.sin((i - 2) * math.pi / 6.0))
            cr.update_layout(pango_layout)
            cr.show_layout(pango_layout)
            cr.restore()
Example #30
0
    def loadToolbar(self):
        self.toolbarBox = Gtk.HBox()

        scrollbox = HScrolledBox(scroll_policy=Gtk.PolicyType.NEVER)
        scrollbox.set_viewport(self.toolbarBox)
        scrollbox.modify_bg(
            Gtk.StateType.NORMAL,
            style.Color(Config.PANEL_BCK_COLOR).get_gdk_color())
        self.mainVBox.pack_start(scrollbox, False, False, 0)

        self.firstTbBtn = None

        for i in range(len(Config.CATEGORIES)):
            category = Config.CATEGORIES[i]

            btn = ImageRadioButton(self.firstTbBtn, category + '.png',
                                   category + 'sel.png', category + 'sel.png')

            if self.firstTbBtn == None:
                self.firstTbBtn = btn
            btn.connect('clicked', self.handleToolbarBtnPress, category)
            btn.set_tooltip_text(str(category))
            self.toolbarBox.pack_start(btn, False, False, 0)