Example #1
0
def font_description_to_dict(desc):
    from gi.repository.Pango import FontDescription, Style, Weight
    desc = FontDescription(desc)
    return {
        'name' : desc.get_family(),
        'size' : int(desc.get_size()/1024.0),
        'bold' : desc.get_weight() == Weight.BOLD,
        'italic' : desc.get_style() == Style.ITALIC,
        'underlined' : False
        # TODO
    }
Example #2
0
def dict_to_font_description(_dict):
    from gi.repository.Pango import FontDescription, Style, Weight
    desc = FontDescription()
    desc.set_family(_dict['name'])
    desc.set_size(_dict['size']*1024) # *1024? aha.
    if _dict['italic']:
        desc.set_style(Style.ITALIC)
    if _dict['bold']:
        desc.set_weight(Weight.BOLD)
    return desc
Example #3
0
    def generate_console(self):
        scrolled_window1 = Gtk.ScrolledWindow()
        scrolled_window1.set_border_width(2)
        self.grid.attach(scrolled_window1, 0, 2, 3, 1)
        # we scroll only if needed
        scrolled_window1.set_policy(
            Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)

        # a text buffer (stores text)
        self.bufferConsola = Gtk.TextBuffer()

        # a textview (displays the buffer)
        self.txtConsola = Gtk.TextView(buffer=self.bufferConsola)
        # textview is scrolled
        scrolled_window1.add(self.txtConsola)
        # wrap the text, if needed, breaking lines in between words
        self.txtConsola.set_wrap_mode(Gtk.WrapMode.WORD)

        self.bufferConsola.set_text('>')

        self.txtConsola.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse( "#014276" ));
        tag = self.bufferConsola.create_tag()
        tag.set_property("foreground",'yellow')
        start = self.bufferConsola.get_start_iter()
        end = self.bufferConsola.get_end_iter()
        self.bufferConsola.apply_tag(tag, start, end)
        self.fontConsola = FontDescription.from_string('Monospace')
        self.fontConsola.set_size(8 * 1000)
        self.txtConsola.override_font(self.fontConsola)
Example #4
0
    def __init__(self, preferences, action_name=None):
        super(SourceView, self).__init__()
        if action_name:
            self.action_name = action_name

        self.set_hexpand(True)
        self.set_vexpand(True)
        self.text_buffer = Buffer.new_with_language(
            LANGS['.%s' % preferences.parser])
        self.text_buffer.connect("changed", self.inc_changes)
        self.source_view = View.new_with_buffer(self.text_buffer)

        self.spellchecker = Checker()
        self.spellchecker.connect("language-changed", self.language_changed)

        self.source_view.override_font(
            FontDescription.from_string('Monospace'))
        # self.source_view.set_monospace(True) since 3.16
        self.add(self.source_view)

        editor_pref = preferences.editor
        self.set_period_save(editor_pref.period_save)
        self.set_check_spelling(editor_pref.check_spelling,
                                editor_pref.spell_lang)
        self.set_spaces_instead_of_tabs(editor_pref.spaces_instead_of_tabs)
        self.source_view.set_tab_width(editor_pref.tab_width)
        self.source_view.set_auto_indent(editor_pref.auto_indent)
        self.source_view.set_show_line_numbers(editor_pref.line_numbers)
        self.source_view.set_show_right_margin(editor_pref.right_margin)
        self.source_view.set_highlight_current_line(editor_pref.current_line)
        self.set_text_wrapping(editor_pref.text_wrapping)
        self.set_white_chars(editor_pref.white_chars)
Example #5
0
 def __init__(self, parent, traceback):
     super(TraceBackDialog, self).__init__(
         "Traceback error",
         parent,
         Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
         use_header_bar=True)
     box = self.get_content_area()
     label = Gtk.Label(traceback)
     label.override_font(FontDescription.from_string('Monospace'))
     label.show_all()
     box.add(label)
Example #6
0
    def generate_textview(self):
        scrolledwindow = Gtk.ScrolledWindow()
        scrolledwindow.set_hexpand(True)
        scrolledwindow.set_vexpand(True)
        self.grid.attach(scrolledwindow, 0, 1, 3, 1)

        self.textview = GtkSource.View()
        self.font = FontDescription.from_string('Monospace')
        self.font.set_size(12*1000)
        self.textview.override_font(self.font)
        self.textview.set_show_line_numbers(True)
        self.textview.set_auto_indent(True)
        self.textview.set_tab_width(4)
        #self.textview.set_show_right_margin(True) #muy python
        self.textview.set_highlight_current_line(True)
        self.set_text_wrapping(False)
        #self.set_white_chars(True) #pone los puntos en los espacios

        self.textbuffer = self.textview.get_buffer()
        self.textbuffer.new_with_language(self.LANGS['.%s' % 'py'])
        self.textbuffer.set_text('')
        self.workingFile = None
        self.do_file_type('.py')
        #/usr/share/gtksourceview-3.0/styles/
        #mas temas en https://wiki.gnome.org/Projects/GtkSourceView/StyleSchemes
        style_scheme = GtkSource.StyleSchemeManager.get_default().get_scheme('oblivion')
        #style_scheme = GtkSource.StyleSchemeManager.get_default().get_scheme('tango')
        self.textbuffer.set_style_scheme(style_scheme)

        scrolledwindow.add(self.textview)

        self.tag_bold = self.textbuffer.create_tag("bold",
            weight=Pango.Weight.BOLD)
        self.tag_italic = self.textbuffer.create_tag("italic",
            style=Pango.Style.ITALIC)
        self.tag_underline = self.textbuffer.create_tag("underline",
            underline=Pango.Underline.SINGLE)
        self.tag_found = self.textbuffer.create_tag("found",
            background="yellow")

        #scroll zoom raton
        self.textview.connect('scroll-event', self.on_scroll)
        self.connect("key-press-event", self.key_press_event)
Example #7
0
 def set_font_description(font_size):
     font = FontDescription(font_name + " " + str(font_size))
     layout.set_font_description(font)
Example #8
0
    def draw_name(self, context, transparency, only_calculate_size=False):
        """Draws the name of the port

        Offers the option to only calculate the size of the name.

        :param context: The context to draw on
        :param transparency: The transparency of the text
        :param only_calculate_size: Whether to only calculate the size
        :return: Size of the name
        :rtype: float, float
        """
        c = context
        cairo_context = c
        if isinstance(c, CairoBoundingBoxContext):
            cairo_context = c._cairo
        # c.set_antialias(Antialias.GOOD)

        side_length = self.port_side_size

        layout = PangoCairo.create_layout(cairo_context)
        font_name = constants.INTERFACE_FONT
        font_size = gap_draw_helper.FONT_SIZE
        font = FontDescription(font_name + " " + str(font_size))
        layout.set_font_description(font)
        layout.set_text(self.name, -1)

        ink_extents, logical_extents = layout.get_extents()
        extents = [
            extent / float(SCALE) for extent in [
                logical_extents.x, logical_extents.y, logical_extents.width,
                logical_extents.height
            ]
        ]
        real_name_size = extents[2], extents[3]
        desired_height = side_length * 0.75
        scale_factor = real_name_size[1] / desired_height

        # Determine the size of the text, increase the width to have more margin left and right of the text
        margin = side_length / 4.
        name_size = real_name_size[0] / scale_factor, desired_height
        name_size_with_margin = name_size[0] + margin * 2, name_size[
            1] + margin * 2

        # Only the size is required, stop here
        if only_calculate_size:
            return name_size_with_margin

        # Current position is the center of the port rectangle
        c.save()
        if self.side is SnappedSide.RIGHT or self.side is SnappedSide.LEFT:
            c.rotate(deg2rad(-90))
        c.rel_move_to(-name_size[0] / 2, -name_size[1] / 2)
        c.scale(1. / scale_factor, 1. / scale_factor)
        c.rel_move_to(-extents[0], -extents[1])

        c.set_source_rgba(
            *gap_draw_helper.get_col_rgba(self.text_color, transparency))
        PangoCairo.update_layout(cairo_context, layout)
        PangoCairo.show_layout(cairo_context, layout)
        c.restore()

        return name_size_with_margin
Example #9
0
def draw_port_label(context,
                    port,
                    transparency,
                    fill,
                    label_position,
                    show_additional_value=False,
                    additional_value=None,
                    only_extent_calculations=False):
    """Draws a normal label indicating the port name.

    :param context: Draw Context
    :param port: The PortView
    :param transparency: Transparency of the text
    :param fill: Whether the label should be filled or not
    :param label_position: Side on which the label should be drawn
    :param show_additional_value: Whether to show an additional value (for data ports)
    :param additional_value: The additional value to be shown
    :param only_extent_calculations: Calculate only the extends and do not actually draw
    """
    c = context
    cairo_context = c
    if isinstance(c, CairoBoundingBoxContext):
        cairo_context = c._cairo

    text = port.name
    label_color = get_col_rgba(port.fill_color, transparency)
    text_color = port.text_color
    port_height = port.port_size[1]

    port_position = c.get_current_point()

    layout = PangoCairo.create_layout(cairo_context)
    layout.set_text(text, -1)

    font_name = constants.INTERFACE_FONT
    font = FontDescription(font_name + " " + str(FONT_SIZE))
    layout.set_font_description(font)

    ink_extents, logical_extents = layout.get_extents()
    extents = [
        extent / float(SCALE) for extent in [
            logical_extents.x, logical_extents.y, logical_extents.width,
            logical_extents.height
        ]
    ]
    real_text_size = extents[2], extents[3]
    desired_height = port_height
    scale_factor = real_text_size[1] / desired_height

    # margin is the distance between the text and the border line
    margin = desired_height / 2.5
    arrow_height = desired_height
    # The real_text_size dimensions are rotated by 90 deg compared to the label, as the label is drawn upright
    text_size = desired_height, real_text_size[0] / scale_factor,
    text_size_with_margin = text_size[0] + 2 * margin, text_size[
        1] + 2 * margin + arrow_height
    port_distance = desired_height
    port_offset = desired_height / 2.

    if label_position is SnappedSide.RIGHT:
        label_angle = deg2rad(-90)
        text_angle = 0
    elif label_position is SnappedSide.BOTTOM:
        label_angle = 0
        text_angle = deg2rad(-90)
    elif label_position is SnappedSide.LEFT:
        label_angle = deg2rad(90)
        text_angle = 0
    else:  # label_position is SnappedSide.TOP:
        label_angle = deg2rad(180)
        text_angle = deg2rad(90)

    # Draw (filled) outline of label
    c.move_to(*port_position)
    c.save()
    c.rotate(label_angle)
    draw_label_path(c, text_size_with_margin[0], text_size_with_margin[1],
                    arrow_height, port_distance, port_offset)
    c.restore()

    c.set_line_width(port_height * .03)
    c.set_source_rgba(*label_color)
    label_extents = c.stroke_extents()
    if label_extents[0] == 0:
        label_extents = c.fill_extents()

    if only_extent_calculations:
        c.new_path()
    else:
        if fill:
            c.fill_preserve()
        c.stroke()

        # Move to the upper left corner of the desired text position
        c.save()
        c.move_to(*port_position)
        c.rotate(label_angle)
        c.rel_move_to(0, port_distance + arrow_height + 2 * margin)
        c.scale(1. / scale_factor, 1. / scale_factor)
        c.rel_move_to(-real_text_size[1] / 2 - extents[1],
                      real_text_size[0] - extents[0])
        c.restore()

        # Show text in correct orientation
        c.save()
        c.rotate(text_angle)
        c.scale(1. / scale_factor, 1. / scale_factor)
        # Correction for labels positioned right: as the text is mirrored, the anchor point must be moved
        if label_position is SnappedSide.RIGHT:
            c.rel_move_to(-real_text_size[0], -real_text_size[1])
        c.set_source_rgba(*get_col_rgba(text_color, transparency))
        PangoCairo.update_layout(cairo_context, layout)
        PangoCairo.show_layout(cairo_context, layout)
        c.restore()

    if show_additional_value:
        value_text = limit_value_string_length(additional_value)
        value_layout = PangoCairo.create_layout(cairo_context)
        value_layout.set_text(value_text, -1)
        value_layout.set_font_description(font)

        ink_extents, logical_extents = value_layout.get_extents()
        extents = [
            extent / float(SCALE) for extent in [
                logical_extents.x, logical_extents.y, logical_extents.width,
                logical_extents.height
            ]
        ]
        value_text_size = extents[2], real_text_size[1]

        # Move to the upper left corner of the additional value box
        c.save()
        c.move_to(*port_position)
        c.rotate(label_angle)
        c.rel_move_to(-text_size_with_margin[0] / 2.,
                      text_size_with_margin[1] + port_distance)
        # Draw rectangular path
        c.rel_line_to(text_size_with_margin[0], 0)
        c.rel_line_to(0, value_text_size[0] / scale_factor + 2 * margin)
        c.rel_line_to(-text_size_with_margin[0], 0)
        c.close_path()
        c.restore()

        value_extents = c.stroke_extents()

        if only_extent_calculations:
            c.new_path()
        else:
            # Draw filled outline
            c.set_source_rgba(
                *get_col_rgba(gui_config.gtk_colors['DATA_VALUE_BACKGROUND']))
            c.fill_preserve()
            c.set_source_rgb(*gui_config.gtk_colors['BLACK'].to_floats())
            c.stroke()

            # Move to the upper left corner of the desired text position
            c.save()
            c.move_to(*port_position)
            c.rotate(label_angle)
            c.rel_move_to(0, margin + text_size_with_margin[1] + port_distance)
            c.scale(1. / scale_factor, 1. / scale_factor)
            c.rel_move_to(-real_text_size[1] / 2., value_text_size[0])
            c.restore()

            # Show text in correct orientation
            c.save()
            c.rotate(text_angle)
            c.scale(1. / scale_factor, 1. / scale_factor)
            # Correction for labels positioned right: as the text is mirrored, the anchor point must be moved
            if label_position is SnappedSide.RIGHT:
                c.rel_move_to(-value_text_size[0] - margin * scale_factor,
                              -real_text_size[1])
            c.set_source_rgba(
                *get_col_rgba(gui_config.gtk_colors['SCOPED_VARIABLE_TEXT']))
            PangoCairo.update_layout(cairo_context, value_layout)
            PangoCairo.show_layout(cairo_context, value_layout)
            c.restore()

        label_extents = min(label_extents[0], value_extents[0]), min(label_extents[1], value_extents[1]), \
                        max(label_extents[2], value_extents[2]), max(label_extents[3], value_extents[3])

    return label_extents