Python gi.repository.Pango.FontDescription() Examples
The following are 28
code examples of gi.repository.Pango.FontDescription().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gi.repository.Pango
, or try the search function
.
Example #1
Source File: ssh_host_key.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, application, hostname, key): """ :param application: The application to associate this popup dialog with. :type application: :py:class:`.KingPhisherClientApplication` :param str hostname: The hostname associated with the key. :param key: The host's SSH key. :type key: :py:class:`paramiko.pkey.PKey` """ super(BaseHostKeyDialog, self).__init__(application) self.hostname = hostname self.key = key textview = self.gobjects['textview_key_details'] textview.modify_font(Pango.FontDescription('monospace 9')) textview.get_buffer().set_text(self.key_details) if self.default_response is not None: button = self.dialog.get_widget_for_response(response_id=self.default_response) button.grab_default()
Example #2
Source File: exception.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, application, exc_info=None, error_uid=None): """ :param application: The parent application for this object. :type application: :py:class:`Gtk.Application` :param tuple exc_info: The exception information as provided by :py:func:`sys.exc_info`. :param str error_uid: An optional unique identifier for the exception that can be provided for tracking purposes. """ super(ExceptionDialog, self).__init__(application) self.error_description = self.gtk_builder_get('label_error_description') self.error_details = self.gtk_builder_get('textview_error_details') self.error_details.modify_font(Pango.FontDescription('monospace 9')) self.exc_info = exc_info or sys.exc_info() self.error_uid = error_uid linkbutton = self.gobjects['linkbutton_github_issues'] linkbutton.set_label('Project Issue Tracker') linkbutton.connect('activate-link', lambda _: utilities.open_uri(linkbutton.get_property('uri')))
Example #3
Source File: mail.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, *args, **kwargs): self.label = Gtk.Label(label='Send') """The :py:class:`Gtk.Label` representing this tabs name.""" super(MailSenderSendTab, self).__init__(*args, **kwargs) self.textview = self.gobjects['textview_mail_sender_progress'] """The :py:class:`Gtk.TextView` object that renders text status messages.""" self.textview.modify_font(Pango.FontDescription(self.config['text_font'])) self.textbuffer = self.textview.get_buffer() """The :py:class:`Gtk.TextBuffer` instance associated with :py:attr:`~.MailSenderSendTab.textview`.""" self.textbuffer_iter = self.textbuffer.get_start_iter() self.progressbar = self.gobjects['progressbar_mail_sender'] """The :py:class:`Gtk.ProgressBar` instance which is used to display progress of sending messages.""" self.pause_button = self.gobjects['togglebutton_mail_sender_pause'] self.sender_thread = None """The :py:class:`.MailSenderThread` instance that is being used to send messages.""" self.application.connect('exit', self.signal_kpc_exit) self.application.connect('exit-confirm', self.signal_kpc_exit_confirm) self.textview.connect('populate-popup', self.signal_textview_populate_popup)
Example #4
Source File: editor.py From rednotebook with GNU General Public License v2.0 | 6 votes |
def __init__(self, day_text_view): super().__init__() self.day_text_view = day_text_view self._connect_undo_signals() self.search_text = "" # spell checker self._spell_checker = None self.enable_spell_check(False) # Enable drag&drop self.day_text_view.connect("drag-data-received", self.on_drag_data_received) # Sometimes making the editor window very small causes the program to freeze # So we forbid that behaviour, by setting a minimum width self.day_text_view.set_size_request(1, -1) self.font = Pango.FontDescription(DEFAULT_FONT) self.default_size = self.font.get_size() / Pango.SCALE logging.debug("Default font: %s" % self.font.to_string()) logging.debug("Default size: %s" % self.default_size)
Example #5
Source File: libcairodoc.py From gprime with GNU General Public License v2.0 | 6 votes |
def fontstyle_to_fontdescription(font_style): """Convert a FontStyle instance to a Pango.FontDescription one. Font color and underline are not implemented in Pango.FontDescription, and have to be set with Pango.Layout.set_attributes(attrlist) method. """ if font_style.get_bold(): f_weight = Pango.Weight.BOLD else: f_weight = Pango.Weight.NORMAL if font_style.get_italic(): f_style = Pango.Style.ITALIC else: f_style = Pango.Style.NORMAL font_description = Pango.FontDescription(font_families[font_style.face]) font_description.set_size(int(round(font_style.get_size() * Pango.SCALE))) font_description.set_weight(f_weight) font_description.set_style(f_style) return font_description
Example #6
Source File: QuiltView.py From addons-source with GNU General Public License v2.0 | 6 votes |
def draw(self, canvas, cr): Gdk.cairo_set_source_rgba(cr, self.bg_color) cr.rectangle(self.x, self.y, self.width, self.height) cr.fill() Gdk.cairo_set_source_rgba(cr, self.fg_color) cr.rectangle(self.x, self.y, self.width, self.height) cr.stroke() layout = canvas.create_pango_layout('F') font = Pango.FontDescription('Sans') layout.set_font_description(font) width, height = layout.get_size() Gdk.cairo_set_source_rgba(cr, self.fg_color) cr.move_to(self.x, self.y) PangoCairo.show_layout(cr, layout) #------------------------------------------------------------------------- # # QuiltView # #-------------------------------------------------------------------------
Example #7
Source File: widgets.py From zim-desktop-wiki with GNU General Public License v2.0 | 6 votes |
def ScrolledTextView(text=None, monospace=False, **kwarg): '''Initializes a C{Gtk.TextView} with sane defaults for displaying a piece of multiline text and wraps it in a scrolled window @param text: initial text to show in the textview @param monospace: when C{True} the font will be set to monospaced and line wrapping disabled, use this to display log files etc. @param kwarg: arguments passed on to L{ScrolledWindow} @returns: a 2-tuple of the scrolled window and the textview ''' textview = Gtk.TextView() textview.set_editable(False) textview.set_left_margin(5) textview.set_right_margin(5) if monospace: font = Pango.FontDescription('Monospace') textview.modify_font(font) else: textview.set_wrap_mode(Gtk.WrapMode.WORD) if text: textview.get_buffer().set_text(text) window = ScrolledWindow(textview, **kwarg) return window, textview
Example #8
Source File: syntrax.py From syntrax with MIT License | 5 votes |
def cairo_font(tk_font): family, size, weight = tk_font return pango.FontDescription('{} {} {}'.format(family, weight, size))
Example #9
Source File: editor.py From rednotebook with GNU General Public License v2.0 | 5 votes |
def set_font(self, font_name): font = Pango.FontDescription(font_name) self.day_text_view.modify_font(font)
Example #10
Source File: main_window.py From rednotebook with GNU General Public License v2.0 | 5 votes |
def set_font(self, font_name): self.day_text_field.set_font(font_name) self.html_editor.set_font_size( Pango.FontDescription(font_name).get_size() / Pango.SCALE )
Example #11
Source File: widgets.py From zim-desktop-wiki with GNU General Public License v2.0 | 5 votes |
def ScrolledSourceView(text=None, syntax=None): '''If GTKSourceView was successfullly loaded, this generates a SourceView and initializes it. Otherwise ScrolledTextView will be used as a fallback. @param text: initial text to show in the view @param syntax: this will try to enable syntax highlighting for the given language. If None, no syntax highlighting will be enabled. @returns: a 2-tuple of a window and a view. ''' if GtkSource: gsvbuf = GtkSource.Buffer() if syntax: gsvbuf.set_highlight_syntax(True) language_manager = GtkSource.LanguageManager() gsvbuf.set_language(language_manager.get_language(syntax)) if text: gsvbuf.set_text(text) textview = GtkSource.View() textview.set_buffer(gsvbuf) textview.set_property("show-line-numbers", True) textview.set_property("auto-indent", True) font = Pango.FontDescription('Monospace') textview.modify_font(font) textview.set_property("smart-home-end", True) window = ScrolledWindow(textview) return (window, textview) else: return ScrolledTextView(text=text, monospace=True)
Example #12
Source File: gtk.py From bups with MIT License | 5 votes |
def __init__(self, manager, parent=None): Gtk.Window.__init__(self, title=_("Backup")) self.set_border_width(10) self.set_icon_name("drive-harddisk") self.set_position(Gtk.WindowPosition.CENTER) if parent is not None: self.set_transient_for(parent) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) self.add(vbox) self.label = Gtk.Label(_("Ready."), xalign=0) self.label.set_justify(Gtk.Justification.LEFT) vbox.pack_start(self.label, False, False, 0) self.progressbar = Gtk.ProgressBar() vbox.pack_start(self.progressbar, False, False, 0) self.textview = Gtk.TextView() #self.textview.modify_bg(Gtk.StateType.NORMAL, Gdk.Color(0, 0, 0)) #self.textview.modify_text(Gtk.StateType.NORMAL, Gdk.Color(255, 255, 255)) fontdesc = Pango.FontDescription("monospace") self.textview.modify_font(fontdesc) self.textview.set_editable(False) sw = Gtk.ScrolledWindow() sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) sw.set_min_content_height(200) sw.add(self.textview) exp = Gtk.Expander() exp.set_label(_("Details")) exp.add(sw) vbox.pack_start(exp, True, True, 0) hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50) vbox.add(hbox) self.close_button = Gtk.Button(_("Close")) self.close_button.connect("clicked", self.on_close_clicked) hbox.pack_end(self.close_button, False, False, 0) self.manager = manager
Example #13
Source File: gcode_view.py From hazzy with GNU General Public License v2.0 | 5 votes |
def __init__(self): GtkSource.Map.__init__(self) self.set_vexpand(True) self.props.font_desc = Pango.FontDescription('1')
Example #14
Source File: gap_draw_helper.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def get_text_layout(cairo_context, text, size): c = cairo_context layout = PangoCairo.create_layout(c) layout.set_text(text, -1) font_name = constants.INTERFACE_FONT font = FontDescription(font_name + " " + str(size)) layout.set_font_description(font) return layout
Example #15
Source File: RemarkableWindow.py From Remarkable with MIT License | 5 votes |
def font_dialog_ok(self, widget): self.font = self.font_chooser.get_font_name() self.remarkable_settings['font'] = self.font # Save prefs self.write_settings() self.text_view.override_font(Pango.FontDescription(self.font)) # Now adjust the size using TextTag self.font_dialog_destroyed(self)
Example #16
Source File: NoteGramplet.py From addons-source with GNU General Public License v2.0 | 5 votes |
def flow_changed(self, active): """ Changes the wrap/font of text flow. """ if active: # Set the text style to monospace self.texteditor.set_wrap_mode(Gtk.WrapMode.NONE) self.texteditor.modify_font(Pango.FontDescription("monospace")) else: # Set the text style to normal self.texteditor.set_wrap_mode(Gtk.WrapMode.WORD) self.texteditor.modify_font(Pango.FontDescription("normal"))
Example #17
Source File: QuiltView.py From addons-source with GNU General Public License v2.0 | 5 votes |
def draw(self, canvas, cr): if self.sex is not None: sex_char = self.symbols.get_symbol_for_string(self.sex) else: sex_char = '' if config.get('utf8.in-use'): if self.sex is not None: sex_char = self.symbols.get_symbol_for_string(self.sex) else: sex_char = '' label = sex_char + ' ' + self.dead + ' ' + self.name layout = canvas.create_pango_layout(label) if is_quartz(): PangoCairo.context_set_resolution(layout.get_context(), 72) font = Pango.FontDescription('Sans') layout.set_font_description(font) width, height = layout.get_size() self.width = width / 1024 # Set the name background depending on the sex Gdk.cairo_set_source_rgba(cr, self.bg_color) cr.rectangle(self.x + 1, self.y + 1, self.width - 2, self.height - 2) cr.fill() # Set the name border cr.set_source_rgb(0.50, 0.50, 0.50) cr.move_to(self.x, self.y) cr.line_to(self.x + self.width, self.y) cr.stroke() cr.move_to(self.x, self.y + self.height) cr.line_to(self.x + self.width, self.y + self.height) cr.stroke() Gdk.cairo_set_source_rgba(cr, self.fg_color) cr.move_to(self.x, self.y) PangoCairo.show_layout(cr, layout)
Example #18
Source File: gtk.py From encompass with GNU General Public License v3.0 | 5 votes |
def create_about_tab(self): from gi.repository import Pango page = Gtk.VBox() page.show() tv = Gtk.TextView() tv.set_editable(False) tv.set_cursor_visible(False) tv.modify_font(Pango.FontDescription(MONOSPACE_FONT)) scroll = Gtk.ScrolledWindow() scroll.add(tv) page.pack_start(scroll, True, True, 0) self.info = tv.get_buffer() self.add_tab(page, 'Wall')
Example #19
Source File: cairo_backend.py From symbolator with MIT License | 5 votes |
def cairo_font(tk_font): family, size, weight = tk_font return pango.FontDescription('{} {} {}'.format(family, weight, size))
Example #20
Source File: ports.py From RAFCON with Eclipse Public License 1.0 | 4 votes |
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 #21
Source File: BoardView.py From pychess with GNU General Public License v3.0 | 4 votes |
def drawCords(self, context, rectangle): thickness = 0.01 signsize = 0.02 if (not self.show_cords) and (not self.setup_position): return xc_loc, yc_loc, square, side = self.square if rectangle is not None and contains(rect((xc_loc, yc_loc, square)), rectangle): return thick = thickness * square sign_size = signsize * square pangoScale = float(Pango.SCALE) if self.no_frame: context.set_source_rgb(0.0, 0.0, 0.0) else: context.set_source_rgb(1.0, 1.0, 1.0) def paint(inv): for num in range(self.RANKS): rank = inv and num + 1 or self.RANKS - num layout = self.create_pango_layout("%d" % rank) layout.set_font_description( Pango.FontDescription("bold %d" % sign_size)) width = layout.get_extents()[1].width / pangoScale height = layout.get_extents()[0].height / pangoScale # Draw left side context.move_to(xc_loc - thick - width, side * num + yc_loc + height / 2 + thick * 3) PangoCairo.show_layout(context, layout) file = inv and self.FILES - num or num + 1 layout = self.create_pango_layout(chr(file + ord("A") - 1)) layout.set_font_description( Pango.FontDescription("bold %d" % sign_size)) # Draw bottom context.move_to(xc_loc + side * num + side / 2 - width / 2, yc_loc + square) PangoCairo.show_layout(context, layout) matrix, invmatrix = matrixAround(self.matrix_pi, xc_loc + square / 2, yc_loc + square / 2) if self.rotation == 0: paint(False) else: context.transform(matrix) paint(True) context.transform(invmatrix) if self.faceToFace: if self.rotation == 0: context.transform(matrix) paint(True) context.transform(invmatrix) else: paint(False)
Example #22
Source File: editor.py From king-phisher-plugins with BSD 3-Clause "New" or "Revised" License | 4 votes |
def __init__(self, application, file_path, directory): """ This class is used to set up the Gtk.SourceView instance to edit the file :param application: The main client application instance. :type application: :py:class:`Gtk.Application` :param str file_path: the path of the file to edit :param directory: the local or remote directory instance """ self.application = application # get editor tab objects self.file_location = directory.location self.file_path = file_path self.file_contents = None self.directory = directory config = self.application.config self.sourceview_editor = sftp_utilities.get_object('SFTPClient.notebook.page_editor.sourceview') self.save_button = sftp_utilities.get_object('SFTPClient.notebook.page_editor.toolbutton_save_html_file') self.template_button = sftp_utilities.get_object('SFTPClient.notebook.page_editor.toolbutton_template_wiki') self.template_button.connect('clicked', self.signal_template_help) self.statusbar = sftp_utilities.get_object('SFTPClient.notebook.page_editor.statusbar') # set up sourceview for editing self.sourceview_buffer = GtkSource.Buffer() self.sourceview_buffer.connect('changed', self.signal_buff_changed) self.sourceview_editor.set_buffer(self.sourceview_buffer) self.sourceview_editor.modify_font(Pango.FontDescription(config['text_font'])) language_manager = GtkSource.LanguageManager() self.sourceview_buffer.set_language(language_manager.get_language('html')) self.sourceview_buffer.set_highlight_syntax(True) self.sourceview_editor.set_property('highlight-current-line', config.get('text_source.highlight_line', True)) self.sourceview_editor.set_property('indent-width', config.get('text_source.tab_width', 4)) self.sourceview_editor.set_property('insert-spaces-instead-of-tabs', not config.get('text_source.hardtabs', False)) self.sourceview_editor.set_property('tab-width', config.get('text_source.tab_width', 4)) scheme_manager = GtkSource.StyleSchemeManager() style_scheme_name = config.get('text_source.theme', 'cobalt') style_scheme = scheme_manager.get_scheme(style_scheme_name) if style_scheme: self.sourceview_buffer.set_style_scheme(style_scheme) else: logger.error("invalid GTK source theme: '{0}'".format(style_scheme_name)) self.view_completion = self.sourceview_editor.get_completion() self.view_completion.set_property('accelerators', 0) self.view_completion.set_property('auto-complete-delay', 250) self.view_completion.set_property('show-icons', False) if not self.view_completion.get_providers(): self.view_completion.add_provider(completion_providers.HTMLCompletionProvider()) self.view_completion.add_provider(completion_providers.JinjaPageCompletionProvider()) logger.info('successfully loaded HTML and Jinja completion providers')
Example #23
Source File: printreport.py From amir with GNU General Public License v3.0 | 4 votes |
def formatHeader(self): LINE_HEIGHT = 2 * (share.config.namefont) # MARGIN = self.page_margin # cwidth = context.get_width() cwidth = self.page_setup.get_page_width(Gtk.Unit.POINTS) logging.info("Paper width: " + str(cwidth)) cr = self.cairo_context fontsize = share.config.namefont fdesc = Pango.FontDescription("Sans") fdesc.set_size(fontsize * Pango.SCALE) self.pangolayout.set_font_description(fdesc) if self.title != "": self.pangolayout.set_text(self.title, -1) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(Pango.Alignment.CENTER) cr.move_to((cwidth - width / Pango.SCALE) / 2, (LINE_HEIGHT - (height / Pango.SCALE))/2) PangoCairo.show_layout(cr, self.pangolayout) # cr.move_to((cwidth + width / Pango.SCALE) / 2, LINE_HEIGHT + config.topmargin) # cr.line_to((cwidth - width / Pango.SCALE) / 2, LINE_HEIGHT + config.topmargin) cr.move_to((cwidth + width / Pango.SCALE) / 2, LINE_HEIGHT + self.cell_margin) cr.line_to((cwidth - width / Pango.SCALE) / 2, LINE_HEIGHT + self.cell_margin) addh = LINE_HEIGHT + self.cell_margin LINE_HEIGHT = 2 * share.config.headerfont fontsize = share.config.headerfont fdesc.set_size(fontsize * Pango.SCALE) self.pangolayout.set_font_description(fdesc) flag = 1 for k, v in self.fields.items(): self.pangolayout.set_text(k + ": " + v, -1) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(Pango.Alignment.CENTER) if flag == 1: addh += LINE_HEIGHT cr.move_to(cwidth - (width / Pango.SCALE) - share.config.rightmargin, addh - (height / Pango.SCALE)/2) flag = 0 else: cr.move_to((width / Pango.SCALE) + share.config.leftmargin, addh - (height / Pango.SCALE)/2) flag = 1 PangoCairo.show_layout(cr, self.pangolayout) cr.stroke() self.header_height = addh + 8
Example #24
Source File: printreport.py From amir with GNU General Public License v3.0 | 4 votes |
def drawTrialReport(self, page_nr): self.formatHeader() RIGHT_EDGE = self.page_setup.get_page_width( Gtk.Unit.POINTS) - share.config.rightmargin HEADER_HEIGHT = self.header_height HEADING_HEIGHT = self.heading_height MARGIN = self.cell_margin TABLE_TOP = HEADER_HEIGHT + HEADING_HEIGHT + self.cell_margin ROW_HEIGHT = self.row_height LINE = self.line cr = self.cairo_context fontsize = share.config.contentfont fdesc = Pango.FontDescription("Sans") fdesc.set_size(fontsize * Pango.SCALE) self.pangolayout.set_font_description(fdesc) self.drawTableHeading() # Draw table data rindex = page_nr * self.lines_per_page offset = 0 addh = TABLE_TOP try: while offset < self.lines_per_page: row = self.content[rindex + offset] cr.move_to(RIGHT_EDGE, addh) cr.line_to(RIGHT_EDGE, addh+ROW_HEIGHT) right_txt = RIGHT_EDGE dindex = 0 for data in row: right_txt -= MARGIN+LINE self.pangolayout.set_text(data, -1) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(Pango.Alignment.RIGHT) cr.move_to(right_txt - (width / Pango.SCALE), addh + (ROW_HEIGHT-(height / Pango.SCALE))/2) PangoCairo.show_layout(cr, self.pangolayout) right_txt -= self.cols_width[dindex] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) dindex += 1 addh += ROW_HEIGHT offset += 1 except IndexError: pass # Table top line cr.move_to(right_txt, TABLE_TOP) cr.line_to(RIGHT_EDGE, TABLE_TOP) # Table bottom line cr.move_to(right_txt, addh) cr.line_to(RIGHT_EDGE, addh) cr.stroke()
Example #25
Source File: gremlin3dwidget.py From hazzy with GNU General Public License v2.0 | 4 votes |
def __init__(self, inifile, width, height): #GObject.__init__(self) gremlin3d.Gremlin3D.__init__(self, inifile) self.width = width self.height = height self.percent = 0 self.mouse_mode = None self.zoom_in_pressed = False self.zoom_out_pressed = False self.set_display_units('mm') # Gremlin3D width = width - 40 to allow room for the controls self.set_size_request(self.width - 40, self.height) # Add gremlin back-plot self.gremlin_view = Gtk.HBox() fixed = Gtk.Fixed() fixed.put(self, 0, 0) self.gremlin_view.add(fixed) self.connect('button_press_event', self.on_gremlin_clicked) # Add touchscreen controls gladefile = os.path.join(UIDIR, 'controls.glade') self.builder = Gtk.Builder() self.builder.add_from_file(gladefile) self.builder.connect_signals(self) controls = self.builder.get_object('controls') controls.set_size_request(40, self.height) self.gremlin_view.add(controls) # Add progress label self.label = Gtk.Label() # self.label.modify_font(Pango.FontDescription('FreeSans 11')) # self.label.modify_fg(Gtk.StateType.NORMAL, Gdk.Color('White')) # labelbox = Gtk.EventBox() # labelbox.modify_bg(Gtk.StateType.NORMAL, Gdk.Color('Black')) # labelbox.set_size_request(-1, 20) # labelbox.add(self.label) # fixed.put(labelbox, 0, self.height - 20) # def fileloading(self, current_line): # self.progressbar.show() # percent = current_line * 100 / self.line_count # if self.percent != percent: # self.percent = percent # msg = "Generating preview {}%".format(self.percent) # self.progressbar.set_text(msg) # self.progressbar.set_fraction(self.percent / 100) # log.debug(msg) # self.emit('loading_progress', percent)
Example #26
Source File: console_textview.py From bokken with GNU General Public License v2.0 | 4 votes |
def __init__(self, main): super(ConsoleTextView,self).__init__(False, 1) self.main = main self.uicore = self.main.uicore ################################################################# # Interactive Right Textview ################################################################# self.buffer = GtkSource.Buffer() self.buffer.create_tag("green-background", background="green", foreground="black") self.view = GtkSource.View.new_with_buffer(self.buffer) # FIXME options must be user-selectable (statusbar) self.view.set_editable(False) #self.view.set_highlight_current_line(True) # posible values: Gtk.WrapMode.NONE, Gtk.WrapMode.CHAR, Gtk.WrapMode.WORD... self.view.set_wrap_mode(Gtk.WrapMode.NONE) self.view.connect("populate-popup", self._populate_menu) # setup view font_desc = Pango.FontDescription('monospace 9') if font_desc: self.view.modify_font(font_desc) self.buffer.set_highlight_syntax(False) language = self.main.lm.get_language('asm') self.buffer.set_language(language) self.mgr = GtkSource.StyleSchemeManager.get_default() # Scrolled window self.console_scrolled_window = Gtk.ScrolledWindow() self.console_scrolled_window.set_shadow_type(Gtk.ShadowType.ETCHED_IN) self.console_scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.console_scrolled_window.show() # Add Textview to Scrolled Window self.console_scrolled_window.add(self.view) self.pack_start(self.console_scrolled_window, True, True, 0) #Always on bottom on change self.vajd = self.console_scrolled_window.get_vadjustment() self.vajd.connect('changed', lambda a, s=self.console_scrolled_window: self.rescroll(a,s)) # Comand line entry self.exec_entry = Gtk.Entry() self.exec_entry.set_max_length(100) self.exec_entry.set_icon_from_stock(1, Gtk.STOCK_EXECUTE) self.exec_entry.set_icon_tooltip_text(1, 'Execute') self.exec_entry.set_text('Radare console: type ? for help') self.exec_entry.connect("activate", self.r2_exec) self.exec_entry.connect("icon-press", self.r2_exec) self.exec_entry.connect('focus-in-event', self._clean, 'in') self.exec_entry.connect('focus-out-event', self._clean, 'out') self.pack_end(self.exec_entry, False, True, 0)
Example #27
Source File: sourceview.py From zim-desktop-wiki with GNU General Public License v2.0 | 4 votes |
def _init_view(self): self.buffer.object_attrib.connect('changed', self.on_attrib_changed) self.view = GtkSource.View() self.view.set_buffer(self.buffer) self.view.modify_font(Pango.FontDescription('monospace')) self.view.set_auto_indent(True) self.view.set_smart_home_end(True) self.view.set_highlight_current_line(True) self.view.set_right_margin_position(80) self.view.set_show_right_margin(True) self.view.set_tab_width(4) self.view.set_show_line_numbers(self.buffer.object_attrib['linenumbers']) self.view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR) self.WRAP_MODE = { WRAP_NONE: Gtk.WrapMode.NONE, WRAP_WORD_CHAR: Gtk.WrapMode.WORD_CHAR, WRAP_CHAR: Gtk.WrapMode.CHAR, WRAP_WORD: Gtk.WrapMode.WORD, } # simple toolbar #~ bar = Gtk.HBox() # FIXME: use Gtk.Toolbar stuff #~ lang_selector = Gtk.ComboBoxText() #~ lang_selector.append_text('(None)') #~ for l in lang_names: lang_selector.append_text(l) #~ try: #~ lang_selector.set_active(lang_ids.index(self._attrib['lang'])+1) #~ self.set_language(self._attrib['lang'] or None, False) #~ except (ValueError, KeyError): #~ lang_selector.set_active(0) #~ self.set_language(None, False) #~ lang_selector.connect('changed', self.on_lang_changed) #~ bar.pack_start(lang_selector, False, False) #~ line_numbers = Gtk.ToggleButton('Line numbers') #~ try: #~ line_numbers.set_active(self._attrib['linenumbers']=='true') #~ self.show_line_numbers(self._attrib['linenumbers'], False) #~ except (ValueError, KeyError): #~ line_numbers.set_active(True) #~ self.show_line_numbers(True, False) #~ line_numbers.connect('toggled', self.on_line_numbers_toggled) #~ bar.pack_start(line_numbers, False, False) #~ self.add_header(bar) # TODO: other toolbar options # TODO: autohide toolbar if textbuffer is not active win = ScrolledWindow(self.view, Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER, Gtk.ShadowType.NONE) self.add(win) self.view.connect('populate-popup', self.on_populate_popup)
Example #28
Source File: mail.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 4 votes |
def __init__(self, *args, **kwargs): self.label = Gtk.Label(label='Edit') """The :py:class:`Gtk.Label` representing this tabs name.""" super(MailSenderEditTab, self).__init__(*args, **kwargs) self.textview = self.gobjects['view_html_file'] """The :py:class:`Gtk.TextView` object of the editor.""" self.textbuffer = GtkSource.Buffer() """The :py:class:`Gtk.TextBuffer` used by the :py:attr:textview` attribute.""" self.textview.set_buffer(self.textbuffer) self.language_manager = GtkSource.LanguageManager() self.textbuffer.set_language(self.language_manager.get_language('html')) self.textbuffer.set_highlight_syntax(True) self.textview.modify_font(Pango.FontDescription(self.config['text_font'])) self.textview.set_property('highlight-current-line', self.config.get('text_source.highlight_line', True)) self.textview.set_property('indent-width', self.config.get('text_source.tab_width', 4)) self.textview.set_property('insert-spaces-instead-of-tabs', not self.config.get('text_source.hardtabs', False)) self.textview.set_property('tab-width', self.config.get('text_source.tab_width', 4)) wrap_mode = self.config.get('text_source.wrap_mode', 'NONE') if wrap_mode.startswith('GTK_WRAP_'): wrap_mode = wrap_mode[9:] if wrap_mode.upper() in ('CHAR', 'NONE', 'WORD', 'WORD_CHAR'): self.textview.set_property('wrap-mode', getattr(Gtk.WrapMode, wrap_mode.upper())) else: self.logger.warning("invalid GtkWrapMode: {0!r}".format(wrap_mode)) self.toolbutton_save_html_file = self.gobjects['toolbutton_save_html_file'] self.textview.connect('populate-popup', self.signal_textview_populate_popup) self.textview.connect('key-press-event', self.signal_textview_key_pressed) scheme_manager = GtkSource.StyleSchemeManager() style_scheme_name = self.config['text_source.theme'] style_scheme = scheme_manager.get_scheme(style_scheme_name) if style_scheme: self.textbuffer.set_style_scheme(style_scheme) else: self.logger.error("invalid GTK source theme: '{0}'".format(style_scheme_name)) self.file_monitor = None source_completion = self.textview.get_completion() source_completion.set_property('accelerators', 0) source_completion.set_property('auto-complete-delay', 250) source_completion.set_property('show-icons', False) source_completion.add_provider(completion_providers.HTMLCompletionProvider()) source_completion.add_provider(completion_providers.JinjaEmailCompletionProvider())