Python pango.FontDescription() Examples

The following are 30 code examples of 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 pango , or try the search function .
Example #1
Source File: core.py    From ns3-802.11ad with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.ipython = ipython_view.IPythonView()
        self.ipython.modify_font(pango.FontDescription(SHELL_FONT))
        self.ipython.set_wrap_mode(gtk.WRAP_CHAR)
        self.ipython.show()
        scrolled_window.add(self.ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        self.ipython.updateNamespace({'viz': self}) 
Example #2
Source File: ipython_view.py    From CRE-NS3 with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in ansi_colors:
      self.text_buffer.create_tag(code,
                                  foreground=ansi_colors[code],
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
                self.text_buffer.create_mark('line_start',
                        self.text_buffer.get_end_iter(), True
                )
    self.connect('key-press-event', self._onKeypress)
    self.last_cursor_pos = 0 
Example #3
Source File: core.py    From CRE-NS3 with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        ipython = ipython_view.IPythonView()
        ipython.modify_font(pango.FontDescription(SHELL_FONT))
        ipython.set_wrap_mode(gtk.WRAP_CHAR)
        ipython.show()
        scrolled_window.add(ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        __IPYTHON__.user_ns['viz'] = self 
Example #4
Source File: core.py    From ns3-ecn-sharp with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.ipython = ipython_view.IPythonView()
        self.ipython.modify_font(pango.FontDescription(SHELL_FONT))
        self.ipython.set_wrap_mode(gtk.WRAP_CHAR)
        self.ipython.show()
        scrolled_window.add(self.ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        self.ipython.updateNamespace({'viz': self}) 
Example #5
Source File: ipython_view.py    From ns-3-dev-git with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    '''
    Initialize console view.
    '''
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in self.ANSI_COLORS:
      self.text_buffer.create_tag(code, 
                                  foreground=self.ANSI_COLORS[code], 
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
        self.text_buffer.create_mark('line_start', 
                                     self.text_buffer.get_end_iter(), True)
    self.connect('key-press-event', self.onKeyPress) 
Example #6
Source File: core.py    From ns-3-dev-git with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.ipython = ipython_view.IPythonView()
        self.ipython.modify_font(pango.FontDescription(SHELL_FONT))
        self.ipython.set_wrap_mode(gtk.WRAP_CHAR)
        self.ipython.show()
        scrolled_window.add(self.ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        self.ipython.updateNamespace({'viz': self}) 
Example #7
Source File: ipython_view.py    From ns3-ecn-sharp with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    '''
    Initialize console view.
    '''
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in self.ANSI_COLORS:
      self.text_buffer.create_tag(code, 
                                  foreground=self.ANSI_COLORS[code], 
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
        self.text_buffer.create_mark('line_start', 
                                     self.text_buffer.get_end_iter(), True)
    self.connect('key-press-event', self.onKeyPress) 
Example #8
Source File: ipython_view.py    From royal-chaos with MIT License 6 votes vote down vote up
def __init__(self):
    """
    Initialize console view.
    """
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in self.ANSI_COLORS:
      self.text_buffer.create_tag(code, 
                                  foreground=self.ANSI_COLORS[code], 
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
        self.text_buffer.create_mark('line_start', 
                                     self.text_buffer.get_end_iter(), True)
    self.connect('key-press-event', self.onKeyPress) 
Example #9
Source File: core.py    From royal-chaos with MIT License 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.ipython = ipython_view.IPythonView()
        self.ipython.modify_font(pango.FontDescription(SHELL_FONT))
        self.ipython.set_wrap_mode(gtk.WRAP_CHAR)
        self.ipython.show()
        scrolled_window.add(self.ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        self.ipython.updateNamespace({'viz': self}) 
Example #10
Source File: ipython_view.py    From ns3-rdma with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in ansi_colors:
      self.text_buffer.create_tag(code,
                                  foreground=ansi_colors[code],
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
                self.text_buffer.create_mark('line_start',
                        self.text_buffer.get_end_iter(), True
                )
    self.connect('key-press-event', self._onKeypress)
    self.last_cursor_pos = 0 
Example #11
Source File: core.py    From ns3-rdma with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        ipython = ipython_view.IPythonView()
        ipython.modify_font(pango.FontDescription(SHELL_FONT))
        ipython.set_wrap_mode(gtk.WRAP_CHAR)
        ipython.show()
        scrolled_window.add(ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        __IPYTHON__.user_ns['viz'] = self 
Example #12
Source File: ipython_view.py    From 802.11ah-ns3 with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    '''
    Initialize console view.
    '''
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in self.ANSI_COLORS:
      self.text_buffer.create_tag(code, 
                                  foreground=self.ANSI_COLORS[code], 
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
        self.text_buffer.create_mark('line_start', 
                                     self.text_buffer.get_end_iter(), True)
    self.connect('key-press-event', self.onKeyPress) 
Example #13
Source File: core.py    From 802.11ah-ns3 with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.ipython = ipython_view.IPythonView()
        self.ipython.modify_font(pango.FontDescription(SHELL_FONT))
        self.ipython.set_wrap_mode(gtk.WRAP_CHAR)
        self.ipython.show()
        scrolled_window.add(self.ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        self.ipython.updateNamespace({'viz': self}) 
Example #14
Source File: ipython_view.py    From ns3-load-balance with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    '''
    Initialize console view.
    '''
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in self.ANSI_COLORS:
      self.text_buffer.create_tag(code, 
                                  foreground=self.ANSI_COLORS[code], 
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
        self.text_buffer.create_mark('line_start', 
                                     self.text_buffer.get_end_iter(), True)
    self.connect('key-press-event', self.onKeyPress) 
Example #15
Source File: core.py    From ns3-load-balance with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.ipython = ipython_view.IPythonView()
        self.ipython.modify_font(pango.FontDescription(SHELL_FONT))
        self.ipython.set_wrap_mode(gtk.WRAP_CHAR)
        self.ipython.show()
        scrolled_window.add(self.ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        self.ipython.updateNamespace({'viz': self}) 
Example #16
Source File: ipython_view.py    From ns3-802.11ad with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    """
    Initialize console view.
    """
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in self.ANSI_COLORS:
      self.text_buffer.create_tag(code, 
                                  foreground=self.ANSI_COLORS[code], 
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
        self.text_buffer.create_mark('line_start', 
                                     self.text_buffer.get_end_iter(), True)
    self.connect('key-press-event', self.onKeyPress) 
Example #17
Source File: core.py    From Tocino with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.ipython = ipython_view.IPythonView()
        self.ipython.modify_font(pango.FontDescription(SHELL_FONT))
        self.ipython.set_wrap_mode(gtk.WRAP_CHAR)
        self.ipython.show()
        scrolled_window.add(self.ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        self.ipython.updateNamespace({'viz': self}) 
Example #18
Source File: ipython_view.py    From Tocino with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    '''
    Initialize console view.
    '''
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in self.ANSI_COLORS:
      self.text_buffer.create_tag(code, 
                                  foreground=self.ANSI_COLORS[code], 
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
        self.text_buffer.create_mark('line_start', 
                                     self.text_buffer.get_end_iter(), True)
    self.connect('key-press-event', self.onKeyPress) 
Example #19
Source File: ipython_view.py    From IEEE-802.11ah-ns-3 with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    '''
    Initialize console view.
    '''
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in self.ANSI_COLORS:
      self.text_buffer.create_tag(code, 
                                  foreground=self.ANSI_COLORS[code], 
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
        self.text_buffer.create_mark('line_start', 
                                     self.text_buffer.get_end_iter(), True)
    self.connect('key-press-event', self.onKeyPress) 
Example #20
Source File: core.py    From IEEE-802.11ah-ns-3 with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.ipython = ipython_view.IPythonView()
        self.ipython.modify_font(pango.FontDescription(SHELL_FONT))
        self.ipython.set_wrap_mode(gtk.WRAP_CHAR)
        self.ipython.show()
        scrolled_window.add(self.ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        self.ipython.updateNamespace({'viz': self}) 
Example #21
Source File: ipython_view.py    From ntu-dsi-dcn with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self):
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in ansi_colors:
      self.text_buffer.create_tag(code,
                                  foreground=ansi_colors[code],
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
                self.text_buffer.create_mark('line_start',
                        self.text_buffer.get_end_iter(), True
                )
    self.connect('key-press-event', self._onKeypress)
    self.last_cursor_pos = 0 
Example #22
Source File: core.py    From ntu-dsi-dcn with GNU General Public License v2.0 6 votes vote down vote up
def _start_shell(self, dummy_button):
        if self.shell_window is not None:
            self.shell_window.present()
            return
        
        self.shell_window = gtk.Window()
        self.shell_window.set_size_request(750,550)
        self.shell_window.set_resizable(True)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        ipython = ipython_view.IPythonView()
        ipython.modify_font(pango.FontDescription(SHELL_FONT))
        ipython.set_wrap_mode(gtk.WRAP_CHAR)
        ipython.show()
        scrolled_window.add(ipython)
        scrolled_window.show()
        self.shell_window.add(scrolled_window)
        self.shell_window.show()
        self.shell_window.connect('destroy', self._on_shell_window_destroy)

        self._update_ipython_selected_node()
        __IPYTHON__.user_ns['viz'] = self 
Example #23
Source File: __init__.py    From nightmare with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, db, gui):

        trace = vdb.VdbTrace(db)
        self.db = db

        # The vdb instance *is* the cli object.
        vw_windows.MainWindow.__init__(self, db, trace, syms=trace)

        self.gui = gui
        self.set_title("Vdb")
        self.menubar.addField("File.Save.Layout", self.file_save_layout)
        self.menubar.addField("File.Save.Snapshot", self.file_save_snapshot)
        self.menubar.addField("File.Quit", self.file_quit)
        self.menubar.addField("Edit.Copy", self.file_edit_copy)
        self.menubar.addField("View.Memory Window", self.file_view_memwin)
        self.menubar.addField("View.Memory Maps", self.file_view_memmaps)
        self.menubar.addField("View.Registers", self.file_view_registers)
        self.menubar.addField("View.File Descriptors", self.file_view_filedesc)
        self.menubar.addField("Tools.Python", self.tools_python)

        # On delete, lets save off the layout...
        self.connect('delete_event', self._mainDelete)

        #descr = pango.FontDescription("Monospace 12")
        #entry.modify_font(descr) 
Example #24
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 6 votes vote down vote up
def show_font_dialog(parent, title, button):
    if not hasattr(parent, 'dlgFont'):
        parent.dlgFont = None
        
    if parent.dlgFont == None:
        parent.dlgFont = gtk.FontSelectionDialog(title)
    fontsel = parent.dlgFont.fontsel
    fontsel.set_font_name(button.selected_font.to_string())    

    response = parent.dlgFont.run()

    if response == gtk.RESPONSE_OK:        
        button.selected_font = pango.FontDescription(fontsel.get_font_name())        
        button.set_label(button.selected_font.to_string())
        button.get_child().modify_font(button.selected_font)
    parent.dlgFont.hide() 
Example #25
Source File: backend_gdk.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def _get_pango_layout(self, s, prop):
        """
        Create a pango layout instance for Text 's' with properties 'prop'.
        Return - pango layout (from cache if already exists)

        Note that pango assumes a logical DPI of 96
        Ref: pango/fonts.c/pango_font_description_set_size() manual page
        """
        # problem? - cache gets bigger and bigger, is never cleared out
        # two (not one) layouts are created for every text item s (then they
        # are cached) - why?

        key = self.dpi, s, hash(prop)
        value = self.layoutd.get(key)
        if value != None:
            return value

        size = prop.get_size_in_points() * self.dpi / 96.0
        size = np.round(size)

        font_str = '%s, %s %i' % (prop.get_name(), prop.get_style(), size,)
        font = pango.FontDescription(font_str)

        # later - add fontweight to font_str
        font.set_weight(self.fontweights[prop.get_weight()])

        layout = self.gtkDA.create_pango_layout(s)
        layout.set_font_description(font)
        inkRect, logicalRect = layout.get_pixel_extents()

        self.layoutd[key] = layout, inkRect, logicalRect
        return layout, inkRect, logicalRect 
Example #26
Source File: indic_scribe_python2.py    From chamanti_ocr with Apache License 2.0 5 votes vote down vote up
def scribe(text, fontname, ten=10, style=0,
           sz=48, spc=1, movex=10, movey=0, twist=0):
    lines = text.split('\n')
    n_lines = len(lines)
    n_letters = max(len(line) for line in lines)

    size_x = 3 * ten * n_letters + 5 * ten
    size_y = 5 * ten * n_lines + 5 * ten

    # print("Lines: {} Letters:{} Size:{}x{}".format(
    #     n_lines, n_letters, size_x, size_y))

    data = np.zeros((size_y, size_x, 4), dtype=np.uint8)
    surf = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_ARGB32,
                                              size_x, size_y)
    cr = cairo.Context(surf)
    pc = pangocairo.CairoContext(cr)
    pc.set_antialias(cairo.ANTIALIAS_SUBPIXEL)

    layout = pc.create_layout()
    layout.set_text(text)

    style = styles[style]
    font_style = "{} {} {}".format(fontname, style, (sz * ten)//10)
    layout.set_font_description(pango.FontDescription(font_style))
    layout.set_spacing(spc * 32)

    cr.rectangle(0, 0, size_x, size_y)
    cr.set_source_rgb(1, 1, 1)
    cr.fill()
    cr.translate(ten, 0)
    cr.set_source_rgb(0, 0, 0)

    pc.update_layout(layout)
    pc.show_layout(layout)

    return data[:, :, 0] < 128 
Example #27
Source File: gtkbase.py    From gui-o-matic with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _font_setup(self):
        for name, style in self.config.get('font_styles', {}).iteritems():
            pfd = pango.FontDescription()
            pfd.set_family(style.get('family', 'normal'))
            pfd.set_size(style.get('points', 12) * pango.SCALE)
            if style.get('italic'): pfd.set_style(pango.STYLE_ITALIC)
            if style.get('bold'): pfd.set_weight(pango.WEIGHT_BOLD)
            self.font_styles[name] = pfd 
Example #28
Source File: cairo_backend.py    From symbolator with MIT License 5 votes vote down vote up
def cairo_font(tk_font):
  family, size, weight = tk_font
  return pango.FontDescription('{} {} {}'.format(family, weight, size)) 
Example #29
Source File: backend_gdk.py    From ImageFusion with MIT License 5 votes vote down vote up
def _get_pango_layout(self, s, prop):
        """
        Create a pango layout instance for Text 's' with properties 'prop'.
        Return - pango layout (from cache if already exists)

        Note that pango assumes a logical DPI of 96
        Ref: pango/fonts.c/pango_font_description_set_size() manual page
        """
        # problem? - cache gets bigger and bigger, is never cleared out
        # two (not one) layouts are created for every text item s (then they
        # are cached) - why?

        key = self.dpi, s, hash(prop)
        value = self.layoutd.get(key)
        if value != None:
            return value

        size = prop.get_size_in_points() * self.dpi / 96.0
        size = round(size)

        font_str = '%s, %s %i' % (prop.get_name(), prop.get_style(), size,)
        font = pango.FontDescription(font_str)

        # later - add fontweight to font_str
        font.set_weight(self.fontweights[prop.get_weight()])

        layout = self.gtkDA.create_pango_layout(s)
        layout.set_font_description(font)
        inkRect, logicalRect = layout.get_pixel_extents()

        self.layoutd[key] = layout, inkRect, logicalRect
        return layout, inkRect, logicalRect 
Example #30
Source File: punchcard.py    From Punchcard with MIT License 5 votes vote down vote up
def set_font(self, name, size, bold):
        weight = ' bold ' if bold else ' '
        fd = pango.FontDescription('%s%s%d' % (name, weight, size))
        self.layout.set_font_description(fd)