def __setDataBoxFont(self, font_button = None): font_button = font_button or self.box_editor.font_button font_description = FontDescription(font_button.get_font_name()) self.data_box.setFontFace(font_description.get_family()) self.data_box.setFontSize(font_description.get_size() / SCALE) self.data_box.setFontStyle(font_description.get_style()) self.data_box.setFontWeight(font_description.get_weight())
def __init__(self, mapsObj): gtk.Window.__init__(self) self.mapsObj = mapsObj self.gps_values = [] self.__stop = False vbox = gtk.VBox(False) vbox.pack_start(self._createLabels(FontDescription("16"))) self.add(vbox) self.set_title("GPS") self.set_border_width(10) self.update_widgets() self.set_position(gtk.WIN_POS_CENTER) self.set_gravity(gtk.gdk.GRAVITY_STATIC) self.placement = self.get_position() self.set_size_request(250, 300) self.connect('key-press-event', self.key_press) self.connect('delete-event', self.on_delete) self.connect('hide', self.on_hide) self.add_events(gtk.gdk.BUTTON_PRESS_MASK) menu = self.rclick_menu() self.connect('button_press_event', self.window_event, menu) self.show_all() self.set_transient_for(mapsObj) self.connect('show', self.on_show) timeout_add_seconds(1, self.update_widgets)
def default_font_toggled(self, client, connection_id, entry, data): """If the gconf var use_default_font be changed, this method will be called and will change the font style to the gnome default or to the chosen font in style/font/style in all terminals open. """ font_name = None if entry.value.get_bool(): # cannot directly use the Gio API since it requires to rework completely # the library inclusion, remove dependencies on gobject and so on. # Instead, issuing a direct command line request proc = subprocess.Popen([ 'gsettings', 'get', DCONF_MONOSPACE_FONT_PATH, DCONF_MONOSPACE_FONT_KEY ], stdout=subprocess.PIPE) font_name = proc.stdout.readline().replace("'", "") if font_name is None: # Back to gconf font_name = client.get_string(GCONF_MONOSPACE_FONT_PATH) proc.kill() else: key = KEY('/style/font/style') font_name = client.get_string(key) if not font_name: log.error("Error: unable to find font name !!!") return font = FontDescription(font_name) if not font: return for i in self.guake.notebook.iter_terminals(): i.set_font(font)
def make_msg_tab(self): def pack(txt, i): hb = gtk.HBox(False, 2) l = gtk.Label() l.set_markup('<span size="10000"><b>{}</b></span>'.format(txt)) hb.add(i) hb.add(l) return hb v = gtk.VBox(False, 1) v.pack_start(self.agtora, False, True, 5) vv = gtk.HBox(True, 5) tooltips = gtk.Tooltips() pixbuf = env.IconTheme.load_icon("kuser", 24, gtk.ICON_LOOKUP_GENERIC_FALLBACK) img = gtk.Image() img.set_from_pixbuf(pixbuf) bt = gtk.Button() bt.connect('clicked', self.on_add_agt) bt.add(pack('Adaugă', img)) tooltips.set_tip(bt, 'Adaugă un nou agent!') vv.add(bt) img = gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU) bt = gtk.Button() bt.connect('clicked', self.on_del_agt) tooltips.set_tip(bt, 'Șterge agentul selectat!') bt.add(pack('Șterge', img)) vv.add(bt) pixbuf = env.IconTheme.load_icon("gnome-settings-theme", 24, gtk.ICON_LOOKUP_GENERIC_FALLBACK) img = gtk.Image() img.set_from_pixbuf(pixbuf) bt = gtk.Button() bt.connect('clicked', self.on_edit_agt) tooltips.set_tip(bt, 'Modifică numele\nagentului selectat!') bt.add(pack('Modifică', img)) vv.add(bt) v.pack_start(vv, False, True) v.add( gtk.image_new_from_pixbuf( gtk.gdk.pixbuf_new_from_file_at_size('agt.png', 64, 64))) self.mesaj.set_editable(False) self.mesaj.modify_font(FontDescription('Segoe UI 9')) self.mesaj.set_wrap_mode(gtk.WRAP_WORD) # self.mesaj.set_justification(gtk.JUSTIFY_CENTER) self.mesaj.set_cursor_visible(False) self.mesaj.set_left_margin(2) self.mesaj.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ddd')) self.mesaj.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse('#000')) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add(self.mesaj) self.mesaj.set_size_request(-1, 80) v.add(sw) v.pack_end(self.userbt, False, True) return v
def fstyle_changed(self, client, connection_id, entry, data): """If the gconf var style/font/style be changed, this method will be called and will change the font style in all terminals open. """ font = FontDescription(entry.value.get_string()) for i in self.guake.notebook.iter_terminals(): i.set_font(font)
def show_end(self): """show and design end page.""" final = self.main_window.get_widget('final') final.set_bg_color(gtk.gdk.color_parse("#087021")) final.set_logo(gtk.gdk.pixbuf_new_from_file("pixmaps/logo.png")) final.modify_font(FontDescription('Helvetica 14')) final.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#087021")) final.show()
def get_text_layout(cairo_context, text, size): c = cairo_context layout = c.create_layout() layout.set_text(text) font_name = constants.INTERFACE_FONT font = FontDescription(font_name + " " + str(size)) layout.set_font_description(font) return layout
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 c.set_antialias(cairo.ANTIALIAS_SUBPIXEL) side_length = self.port_side_size layout = c.create_layout() 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) ink_extents, logical_extents = layout.get_extents() extents = [extent / float(SCALE) for extent in logical_extents] 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)) c.update_layout(layout) c.show_layout(layout) c.restore() return name_size_with_margin
def fontprevmodify(self, fontname=None): alloc = self.entry2.get_allocation() if alloc.width > 1 and alloc.height > 1 : self.entry2.set_size_request(alloc.width, alloc.height) size = self.spinbutton1.get_value_as_int()*SCALE if fontname: fontdesc = FontDescription(fontname) else: fontsel = self.treeview1.get_selection() fmodel, fitem = fontsel.get_selected_rows() stylsel = self.treeview2.get_selection() smodel, sitem = stylsel.get_selected_rows() if not fitem or not sitem: return font = fmodel[fitem[0][0]][0] styl = self.checkstyle(smodel[sitem[0][0]][0]) fullname = '%s, %s' % (font, styl) fontdesc = FontDescription(fullname) fontdesc.set_size(size) self.entry2.modify_font(fontdesc)
def __setDataBoxFont(self, font_button=None): font_button = font_button or self.box_editor.font_button font_description = FontDescription(font_button.get_font_name()) self.data_box.setFontFace(font_description.get_family()) self.data_box.setFontSize(font_description.get_size() / SCALE) self.data_box.setFontStyle(font_description.get_style()) self.data_box.setFontWeight(font_description.get_weight())
def __init__(self): gtksourceview2.View.__init__(self) self.archivo = False self.set_show_line_numbers(True) self.set_insert_spaces_instead_of_tabs(True) self.set_tab_width(4) self.set_auto_indent(True) font = "Monospace " + str(int(10/style.ZOOM_FACTOR)) self.modify_font(FontDescription(font)) self.show_all()
def on_add_obv(self, _): dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, None) dialog.set_alternative_button_order( [gtk.RESPONSE_CANCEL, gtk.RESPONSE_OK]) dialog.set_default_response(2) dialog.set_markup('Introduceți numele <i>noului</i> <b>obiectiv</b>:') dialog.set_position(gtk.WIN_POS_CENTER) entry = gtk.Entry() entry.connect("activate", resp_to_dialog, dialog, gtk.RESPONSE_OK) hbox = gtk.HBox() hbox.pack_start(gtk.Label("Nume:"), False, 5, 5) hbox.pack_end(entry) # dialog.format_secondary_markup("Adăugți un <i>obiectiv</i> nou") dialog.vbox.pack_end(hbox, True, True, 0) dialog.show_all() resp = dialog.run() text = entry.get_text().title() dialog.destroy() if resp == gtk.RESPONSE_OK: post = self.disp.add_post(text) self.cal.redraw(post) hh, ww = self.bt_tab.get_data('hh'), self.bt_tab.get_data('ww') if hh % 3 == 0: hh = 0 ww += 1 bt = gtk.Button('') bt.connect('clicked', self.toggled, post.id) bt.child.set_markup('<span size="%s">%s</span>' % (env.BT_FONT, post.nume)) bt.child.modify_font( FontDescription('Calibri %s' % int(env.BT_FONT / 1000))) self.bt_tab.attach(bt, hh, hh + 1, ww, ww + 1) bt.set_data('ord', post.id) bt.show_all() self.bt_tab.show_all() self.bt_frame.show_all() self.bt_frame.set_size_request(-1, -1) self.btlist[post.nume] = bt env.log('add_obiectiv', text.title(), text) self.check_unmark()
def update_demo_palette(self, palette): fgcolor = gtk.gdk.color_parse( self.client.get_string(KEY('/style/font/color'))) bgcolor = gtk.gdk.color_parse( self.client.get_string(KEY('/style/background/color'))) palette = [gtk.gdk.color_parse(color) for color in palette.split(':')] font_name = self.client.get_string(KEY('/style/font/style')) font = FontDescription(font_name) use_palette_font_and_background_color = self.client.get_bool( KEY('/general/use_palette_font_and_background_color')) if use_palette_font_and_background_color and len(palette) > 16: fgcolor = palette[16] bgcolor = palette[17] self.demo_terminal.set_color_dim(fgcolor) self.demo_terminal.set_color_foreground(fgcolor) self.demo_terminal.set_color_bold(fgcolor) self.demo_terminal.set_color_background(bgcolor) self.demo_terminal.set_background_tint_color(bgcolor) self.demo_terminal.set_colors(fgcolor, bgcolor, palette[:16]) self.demo_terminal.set_font(font)
def __update_view(self): language = self.__editor.language language = language if language else "plain text" from SCRIBES.TabWidthMetadata import get_value as tab_width self.__view.set_property("tab-width", tab_width(language)) from SCRIBES.MarginPositionMetadata import get_value as margin_position self.__view.set_property("right-margin-position", margin_position(language)) from SCRIBES.DisplayRightMarginMetadata import get_value as show_margin self.__view.set_property("show-right-margin", show_margin(language)) from SCRIBES.UseTabsMetadata import get_value as use_tabs self.__view.set_property("insert-spaces-instead-of-tabs", (not use_tabs(language))) from SCRIBES.FontMetadata import get_value as font_name from pango import FontDescription font = FontDescription(font_name(language)) self.__view.modify_font(font) from gtk import WRAP_WORD_CHAR, WRAP_NONE from SCRIBES.TextWrappingMetadata import get_value as wrap_mode_bool wrap_mode = self.__view.set_wrap_mode wrap_mode(WRAP_WORD_CHAR) if wrap_mode_bool(language) else wrap_mode( WRAP_NONE) self.__view.grab_focus() return False
def fontprevmodify(self, fontname=None): alloc = self.entry2.get_allocation() if alloc.width > 1 and alloc.height > 1: self.entry2.set_size_request(alloc.width, alloc.height) size = self.spinbutton1.get_value_as_int() * SCALE if fontname: fontdesc = FontDescription(fontname) else: fontsel = self.treeview1.get_selection() fmodel, fitem = fontsel.get_selected_rows() stylsel = self.treeview2.get_selection() smodel, sitem = stylsel.get_selected_rows() if not fitem or not sitem: return font = fmodel[fitem[0][0]][0] styl = self.checkstyle(smodel[sitem[0][0]][0]) fullname = '%s, %s' % (font, styl) fontdesc = FontDescription(fullname) fontdesc.set_size(size) self.entry2.modify_font(fontdesc)
def label_mod(l, col, font=False): l.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(col)) if font: l.modify_font(FontDescription(font))
def set_font_description(font_size): font = FontDescription(font_name + " " + str(font_size)) layout.set_font_description(font)
def __update(self): from pango import FontDescription from SCRIBES.FontMetadata import get_value new_font = FontDescription(get_value(self.__manager.get_language())) self.__view.modify_font(new_font) return False
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 c.set_antialias(ANTIALIAS_SUBPIXEL) 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 = c.create_layout() layout.set_text(text) 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] 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)) c.update_layout(layout) c.show_layout(layout) c.restore() if show_additional_value: value_text = limit_value_string_length(additional_value) value_layout = c.create_layout() value_layout.set_text(value_text) value_layout.set_font_description(font) ink_extents, logical_extents = value_layout.get_extents() extents = [extent / float(SCALE) for extent in logical_extents] 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_color(gui_config.gtk_colors['BLACK']) 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'])) c.update_layout(value_layout) c.show_layout(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
def set_font(self): font_name = self.client.get_string(GCONF_PATH + 'style/font/style') font = FontDescription(font_name) for i in self.term_list: i.set_font(font)