Languages

gtk

TreeView with ListStore

0
Your rating: None
using Gtk;
 
public class TreeViewSample : Window {
 
    public TreeViewSample () {
        this.title = "TreeView Sample";
        set_default_size (250, 100);
        var view = new TreeView ();
        setup_treeview (view);
        add (view);
        this.destroy += Gtk.main_quit;
    }
 
    private void setup_treeview (TreeView view) {
 
        /*
         * Use ListStore to hold accountname, accounttype, balance and
         * color attribute.

TreeView with TreeStore

0
Your rating: None
using Gtk;
 
public class TreeViewSample : Window {
 
    public TreeViewSample () {
        this.title = "TreeView Sample";
        set_default_size (250, 100);
        var view = new TreeView ();
        setup_treeview (view);
        add (view);
        this.destroy += Gtk.main_quit;
    }
 
    private void setup_treeview (TreeView view) {
 
        var store = new TreeStore (2, typeof (string), typeof (string));
        view.set_model (store);
 
        view.insert_column_with_attributes (-1, "Product", new CellRendererText (), "text", 0, null);
        view.insert_column_wi

Unit test using GTK+

0
Your rating: None
void add_foo_tests ()
{
  Test.add_func ("/vala/test", () => {
      var widget = new Gtk.Button ();
      assert (widget is Gtk.Button);
    }
  );
}
 
void main (string[] args)
{
  Gtk.init(ref args);
  Test.init(ref args);
 
  add_foo_tests ();
 
  Idle.add (() => {
      Test.run ();
      Gtk.main_quit ();
    }
  );
  Gtk.main ();
}

Gtk+ custom CellRenderer sample

4
Your rating: None Average: 4 (1 vote)
using Gtk;
using Gdk;
 
class MyCellRenderer : Gtk.CellRenderer
{
  /* icon property set by the tree column */
  public Gdk.Pixbuf icon { get; set; }
 
  /* dumb constructor */
  public MyCellRenderer () {}
 
  /* get_size method, always request a 50x50 area */
  public override void get_size (Gtk.Widget widget,
                                 Gdk.Rectangle?

Subclassing Gtk.Widget

0
Your rating: None
/*
 * Johan Dahlin 2008
 *
 * A quite simple Gtk.Widget subclass which demonstrates how to subclass
 * and do realizing, sizing and drawing. Based on widget.py in PyGTK
 */ 
 
using Gtk;
using Cairo;
 
public class ValaWidget : Widget {
 
    private static const string TEXT = "Hello World!";
    private static const int BORDER_WIDTH = 10;
    private Pango.Layout layout;
 
    construct {
        this.layout = create_pango_layout (TEXT);
    }
 
    /*
     * This method Gtk+ is calling on a widget to ask
     * the widget how large it wishes to be.

Egg Clock Sample

0
Your rating: None
using Gtk;
using Cairo;
 
namespace Egg {
 
    public class ClockFace : DrawingArea {
 
        private Time time;
        private int minute_offset;
        private bool dragging;
 
        public signal void time_changed (int hour, int minute);
 
        public ClockFace () {
            add_events (Gdk.EventMask.BUTTON_PRESS_MASK
                      | Gdk.EventMask.BUTTON_RELEASE_MASK
                      | Gdk.EventMask.POINTER_MOTION_MASK);
            update ();
 
            // update the clock once a second
            Timeout.add (1000, update);
        }
 

A Skeleton for subclassing Gtk.DrawingArea

0
Your rating: None
using Gtk;
 
public class CustomWidget : DrawingArea {
 
    public CustomWidget () {
 
        // Enable the events you wish to get notified about.
        // The 'expose' event is already enabled by the DrawingArea.
        add_events (Gdk.EventMask.BUTTON_PRESS_MASK
                  | Gdk.EventMask.BUTTON_RELEASE_MASK
                  | Gdk.EventMask.POINTER_MOTION_MASK);
 
        // Set favored widget size
        set_size_request (100, 100);
    }
 
    /* Widget is asked to draw itself */
    public override bool expose_event (Gdk.EventExpose event) {
 
        // Create 

GtkTreeView with GtkCellRendererToggle sample

0
Your rating: None
using Gtk;
 
public class ListSample : Gtk.Window
{
        private ListStore _list_store;
        private TreeView _tree_view;
 
        private enum Columns
        {
                TOGGLE,
                TEXT,
                N_COLUMNS
        }
 
        public ListSample ()
        {
                this.title = "List Sample";
                this.destroy.connect (Gtk.main_quit);
                this.set_size_request (200, 200);
 
                _list_store = new ListStore (Columns.N_COLUMNS, typeof (bool), typeof (string));
                _tree_view = new TreeVie

Creating a dialog

0
Your rating: None
using Gtk;
 
public class SearchDialog : Dialog {
 
    private Entry search_entry;
    private CheckButton match_case;
    private CheckButton find_backwards;
    private Widget find_button;
 
    public signal void find_next (string text, bool case_sensitivity);
    public signal void find_previous (string text, bool case_sensitivity);
 
    public SearchDialog () {
        this.title = "Find";
        this.has_separator = false;
        this.border_width = 5;
        set_default_size (350, 100);
        create_widgets ();
        connect_signals ();
    }
 
    private 

A simple text file viewer

0
Your rating: None
using Gtk;
 
public class TextFileViewer : Window {
 
    private TextView text_view;
 
    public TextFileViewer () {
        this.title = "Text File Viewer";
        this.position = WindowPosition.CENTER;
        set_default_size (400, 300);
 
        var toolbar = new Toolbar ();
        var open_button = new ToolButton.from_stock (STOCK_OPEN);
        toolbar.add (open_button);
        open_button.clicked += on_open_clicked;
 
        this.text_view = new TextView ();
        this.text_view.editable = false;
        this.text_view.cursor_visible = false;
 
        var scroll 
Syndicate content