Skip to content

Instantly share code, notes, and snippets.

@vkolev
Created September 17, 2012 17:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkolev/3738745 to your computer and use it in GitHub Desktop.
Save vkolev/3738745 to your computer and use it in GitHub Desktop.
gi.repository Granite with Python
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
#
# app.py
#
# Copyright 2012 Vladimir Kolev <vladi@elementos>
#
# This is a semple application using the Granite widgets
# from the ElementaryOS project
#
# The problem is how to make it more Object-orientated and
# wrapt the Application class as main class for the application
#
import sys
from gi.repository import Gtk, Gdk, GdkPixbuf
from gi.repository import Granite
def show_about(sender = None):
about = Granite.WidgetsAboutDialog.new()
about.set_program_name("gSharkDown")
about.set_comments("""A simple application for downloading\n
and listening to music from grooveshark.com""")
about.set_logo(GdkPixbuf.Pixbuf.new_from_file_at_size("gsharkdown_64.png", 64, 64))
about.set_website("http://gsharkdown.bultux.org")
about.set_website_label("http://gsharkdown.bultux.org")
about.set_version("1.0")
about.run()
about.destroy()
def page_changed(sender, info):
sender.set_page(info)
def show_window(sender):
light = Granite.WidgetsLightWindow.new("Example Window")
lightlabel = Granite.WidgetsWrapLabel.new("Just an example label for the window")
light.add(lightlabel)
light.set_default_size(300, 300)
light.set_position(Gtk.WindowPosition.CENTER)
light.show_all()
window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
window.set_position(Gtk.WindowPosition.CENTER)
window.set_default_size(300, 400)
box = Gtk.VBox()
toolbar = Gtk.Toolbar.new()
pager = Granite.WidgetsStaticNotebook.new(0)
pager.connect('page-changed', page_changed)
welcome = Granite.WidgetsWelcome.new('Just example', 'Simple example for testing')
pager.append_page(welcome, Gtk.Label("Welcome"))
pager.append_page(Gtk.Label("Page 2"), Gtk.Label("pg2"))
date_picker = Granite.WidgetsDatePicker.new()
pager.append_page(date_picker, Gtk.Label("Date/Time"))
button = Gtk.Button("Test Window")
button.connect('clicked', show_window)
box.pack_start(toolbar, False, True, 0)
box.pack_start(pager, True, True, 0)
box.pack_end(button, False, False, 3)
menu = Gtk.Menu.new()
about_item = Gtk.MenuItem.new_with_label("About Dialog")
about_item.connect('activate', show_about)
menu_item = Gtk.MenuItem.new_with_label("Quit")
menu_item.connect('activate', Gtk.main_quit)
menu.append(about_item)
menu.append(menu_item)
appmenu = Granite.WidgetsAppMenu.new(menu)
toolbar.insert(appmenu, -1)
window.add(box)
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
@clcneogeek325
Copy link

gracias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment