Rotate and change the font size of a GTK Label object

Although the PyGTK Reference Manual is extremely helpful in figuring out how to use gtk objects, there’s not a whole lot of information about setting properties on gtk.Label objects readily available.

Some hard-to-find yet simple tasks are setting the font size of a label and rotating the text. Pango is your friend, so don’t forget to include him.

Create a label

mylabel = gtk.Label(’Vertical Text Here?’)

Change the font and size

mylabel.modify_font(pango.FontDescription(”sans 18″))

Rotate the text

mylabel.props.angle = 90

print(gtk.Label.__doc__)

Printing the __doc__ can be helpful too… sometimes… but you still won’t find it in there.

Object GtkLabel

Signals from GtkLabel:
move-cursor (GtkMovementStep, gint, gboolean)
copy-clipboard ()
populate-popup (GtkMenu)
activate-current-link ()
activate-link (gchararray) -> gboolean

Properties from GtkLabel:
label -> gchararray: Label
The text of the label
attributes -> PangoAttrList: Attributes
A list of style attributes to apply to the text of the label
use-markup -> gboolean: Use markup
The text of the label includes XML markup. See pango_parse_markup()
use-underline -> gboolean: Use underline
If set, underline in text indicates next character used for mnemonic accelerator key
justify -> GtkJustification: Justification
The alignment of the lines in the text of the label relative to each other.
pattern -> gchararray: Pattern
A string with _ characters in positions correspond to characters in the text to underline
wrap -> gboolean: Line wrap
If set, wrap lines if the text becomes too wide
wrap-mode -> PangoWrapMode: Line wrap mode
If wrap is set, controls how linewrapping is done
selectable -> gboolean: Selectable
Whether the label text can be selected with the mouse
mnemonic-keyval -> guint: Mnemonic key
The mnemonic accelerator key for this label
mnemonic-widget -> GtkWidget: Mnemonic widget
The widget to be activated when the label’s mnemonic key is pressed
cursor-position -> gint: Cursor Position
The current position of the insertion cursor in chars
selection-bound -> gint: Selection Bound
The position of the opposite end of the selection from the cursor in chars
ellipsize -> PangoEllipsizeMode: Ellipsize
The preferred place to ellipsize the string, if the label has no room for entire string
width-chars -> gint: Width In Characters
The desired width of the label, in characters
single-line-mode -> gboolean: Single Line Mode
Whether the label is in single line mode
angle -> gdouble: Angle
Angle at which the label is rotated
max-width-chars -> gint: Maximum Width In Characters
The desired maximum width of the label, in characters
track-visited-links -> gboolean: Track visited links
Whether visited links should be tracked

Properties from GtkMisc:
xalign -> gfloat: X align
The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts.
yalign -> gfloat: Y align
The vertical alignment, from 0 (top) to 1 (bottom)
xpad -> gint: X pad
The amount of space to add on the left and right of the widget, in pixels
ypad -> gint: Y pad
The amount of space to add on the top and bottom of the widget, in pixels

Signals from GtkWidget:
composited-changed ()
show ()
hide ()
map ()
unmap ()
realize ()
unrealize ()
size-request (GtkRequisition)
size-allocate (GdkRectangle)
state-changed (GtkStateType)
parent-set (GtkWidget)
hierarchy-changed (GtkWidget)
style-set (GtkStyle)
direction-changed (GtkTextDirection)
grab-notify (gboolean)
child-notify (GParam)
mnemonic-activate (gboolean) -> gboolean
grab-focus ()
focus (GtkDirectionType) -> gboolean
move-focus (GtkDirectionType)
event (GdkEvent) -> gboolean
event-after (GdkEvent)
button-press-event (GdkEvent) -> gboolean
button-release-event (GdkEvent) -> gboolean
scroll-event (GdkEvent) -> gboolean
motion-notify-event (GdkEvent) -> gboolean
keynav-failed (GtkDirectionType) -> gboolean
delete-event (GdkEvent) -> gboolean
destroy-event (GdkEvent) -> gboolean
expose-event (GdkEvent) -> gboolean
key-press-event (GdkEvent) -> gboolean
key-release-event (GdkEvent) -> gboolean
enter-notify-event (GdkEvent) -> gboolean
leave-notify-event (GdkEvent) -> gboolean
configure-event (GdkEvent) -> gboolean
focus-in-event (GdkEvent) -> gboolean
focus-out-event (GdkEvent) -> gboolean
map-event (GdkEvent) -> gboolean
unmap-event (GdkEvent) -> gboolean
property-notify-event (GdkEvent) -> gboolean
selection-clear-event (GdkEvent) -> gboolean
selection-request-event (GdkEvent) -> gboolean
selection-notify-event (GdkEvent) -> gboolean
selection-received (GtkSelectionData, guint)
selection-get (GtkSelectionData, guint, guint)
proximity-in-event (GdkEvent) -> gboolean
proximity-out-event (GdkEvent) -> gboolean
drag-leave (GdkDragContext, guint)
drag-begin (GdkDragContext)
drag-end (GdkDragContext)
drag-data-delete (GdkDragContext)
drag-failed (GdkDragContext, GtkDragResult) -> gboolean
drag-motion (GdkDragContext, gint, gint, guint) -> gboolean
drag-drop (GdkDragContext, gint, gint, guint) -> gboolean
drag-data-get (GdkDragContext, GtkSelectionData, guint, guint)
drag-data-received (GdkDragContext, gint, gint, GtkSelectionData, guint, guint)
visibility-notify-event (GdkEvent) -> gboolean
client-event (GdkEvent) -> gboolean
no-expose-event (GdkEvent) -> gboolean
window-state-event (GdkEvent) -> gboolean
damage-event (GdkEvent) -> gboolean
grab-broken-event (GdkEvent) -> gboolean
query-tooltip (gint, gint, gboolean, GtkTooltip) -> gboolean
popup-menu () -> gboolean
show-help (GtkWidgetHelpType) -> gboolean
accel-closures-changed ()
screen-changed (GdkScreen)
can-activate-accel (guint) -> gboolean

Properties from GtkWidget:
name -> gchararray: Widget name
The name of the widget
parent -> GtkContainer: Parent widget
The parent widget of this widget. Must be a Container widget
width-request -> gint: Width request
Override for width request of the widget, or -1 if natural request should be used
height-request -> gint: Height request
Override for height request of the widget, or -1 if natural request should be used
visible -> gboolean: Visible
Whether the widget is visible
sensitive -> gboolean: Sensitive
Whether the widget responds to input
app-paintable -> gboolean: Application paintable
Whether the application will paint directly on the widget
can-focus -> gboolean: Can focus
Whether the widget can accept the input focus
has-focus -> gboolean: Has focus
Whether the widget has the input focus
is-focus -> gboolean: Is focus
Whether the widget is the focus widget within the toplevel
can-default -> gboolean: Can default
Whether the widget can be the default widget
has-default -> gboolean: Has default
Whether the widget is the default widget
receives-default -> gboolean: Receives default
If TRUE, the widget will receive the default action when it is focused
composite-child -> gboolean: Composite child
Whether the widget is part of a composite widget
style -> GtkStyle: Style
The style of the widget, which contains information about how it will look (colors etc)
events -> GdkEventMask: Events
The event mask that decides what kind of GdkEvents this widget gets
extension-events -> GdkExtensionMode: Extension events
The mask that decides what kind of extension events this widget gets
no-show-all -> gboolean: No show all
Whether gtk_widget_show_all() should not affect this widget
has-tooltip -> gboolean: Has tooltip
Whether this widget has a tooltip
tooltip-markup -> gchararray: Tooltip markup
The contents of the tooltip for this widget
tooltip-text -> gchararray: Tooltip Text
The contents of the tooltip for this widget
window -> GdkWindow: Window
The widget’s window if it is realized
double-buffered -> gboolean: Double Buffered
Whether or not the widget is double buffered

Signals from GtkObject:
destroy ()

Properties from GtkObject:
user-data -> gpointer: User Data
Anonymous User Data Pointer

Signals from GObject:
notify (GParam)

Posted by admica   @   30 April 2010

Related Posts

Like this post? Share it!

Digg Twitter StumbleUpon Delicious Technorati Facebook RSS

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Ubuntu 10.04 LTS Lucid Lynx is here
Next Post
Convert wordpress xml export file into a python dictionary »
Powered by Wordpress   |   Lunated designed by ZenVerse