GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Apr 19, 2014 4:22 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: GTK+3 , Python, Vte, gpointer, 'decrease-font-size'
PostPosted: Wed Jun 12, 2013 12:41 pm 
Offline

Joined: Tue Jun 11, 2013 11:37 pm
Posts: 2
Hi,
I want to change the font size of a terminal with Vte. The doc says something like:
https://developer.gnome.org/vte/0.26/VteTerminal.html
terminal.connect('decrease-font-size', gpointer user data)
Whats a gpointer? How can I use this correctly?

Here is the code:
Code:
#!/usr/bin/python shells.py

from gi.repository import Gtk, Vte, Gdk
from gi.repository import GLib
import os

class TableWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="shells")
        self.resize(600, 400)

        table = Gtk.Table(2, 2, True)
        self.add(table)
        palette = [Gdk.color_parse('red')] * 16
        terminal1 = Vte.Terminal()
        terminal2 = Vte.Terminal()
        terminal3 = Vte.Terminal()
        terminal4 = Vte.Terminal()
       
        scrolledwindow1 = Gtk.ScrolledWindow()
        scrolledwindow1.add(terminal1)
       
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.add(terminal2)
       
        scrolledwindow3 = Gtk.ScrolledWindow()
        scrolledwindow3.add(terminal3)
       
        scrolledwindow4 = Gtk.ScrolledWindow()
        scrolledwindow4.add(terminal4)
       
        terminal1.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                       [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal2.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                       [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal3.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                       [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal4.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                       [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
                                       
        terminal1.set_colors(Gdk.color_parse('red'), Gdk.color_parse('black'), palette)
        terminal2.set_colors(Gdk.color_parse('yellow'), Gdk.color_parse('black'), palette)
        terminal3.set_colors(Gdk.color_parse('green'), Gdk.color_parse('black'), palette)
        terminal4.set_colors(Gdk.color_parse('blue'), Gdk.color_parse('black'), palette)
       
        table.attach(scrolledwindow1, 0, 1, 0, 1)
        table.attach(scrolledwindow2, 1, 2, 0, 1)
        table.attach(scrolledwindow3, 0, 1, 1, 2)
        table.attach(scrolledwindow4, 1, 2, 1, 2)
       
win = TableWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()



Greets


Top
 Profile  
 
 Post subject: Re: GTK+3 , Python, Vte, gpointer, 'decrease-font-size'
PostPosted: Wed Jun 12, 2013 4:34 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Hello,

A gpointer is just a general pointer and used in signal call-back functions to pass user data around. Under C it is defined as
Code:
typedef void * gpointer;


Under other language bindings the gpointer is generally not exposed to the API of the binding and the passing of extra parameters or class data is done by the binding often using the gpointer user_data.

The signal that you mentioned actually does not do the resizing of the text. All it does is call a call-back function when the user request the size to be made smaller. The C functions that you need is
Code:
void                vte_terminal_set_font               (VteTerminal *terminal,
                                                         const PangoFontDescription *font_desc);

_________________
E.


Top
 Profile  
 
 Post subject: Re: GTK+3 , Python, Vte, gpointer, 'decrease-font-size'
PostPosted: Wed Jun 12, 2013 7:30 pm 
Offline

Joined: Tue Jun 11, 2013 11:37 pm
Posts: 2
Hi errol, thx for reply :)

I did something like

Code:
import pango
font = pango.FontDescription()
terminal1.set_font(font)


But I get:

Code:
/usr/lib/python2.7/dist-packages/gobject/constants.py:24: Warning: g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
  import gobject._gobject
Traceback (most recent call last):
  File "shells.py", line 57, in <module>
    win = MainWindow()
  File "shells.py", line 24, in __init__
    terminal1.set_font(font)
  File "/usr/lib/python2.7/dist-packages/gi/types.py", line 43, in function
    return info.invoke(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/gi/importer.py", line 76, in load_module
    dynamic_module._load()
  File "/usr/lib/python2.7/dist-packages/gi/module.py", line 224, in _load
    overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
  File "/usr/lib/python2.7/dist-packages/gi/overrides/Pango.py", line 33, in <module>
    Context = override(Context)
  File "/usr/lib/python2.7/dist-packages/gi/overrides/__init__.py", line 63, in override
    registry.register(type_)
  File "/usr/lib/python2.7/dist-packages/gi/overrides/__init__.py", line 38, in register
    self[override_class] = override_class
  File "/usr/lib/python2.7/dist-packages/gi/overrides/__init__.py", line 20, in __setitem__
    info = getattr(value, '__info__')
AttributeError: type object 'Context' has no attribute '__info__'



Hhhm, can you give me a hint what this means??
Greets


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Gunner and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group