public
Last active

granite-demo in python

  • Download Gist
granitedemo.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
import sys
from gi.repository import Gtk, Gdk, GdkPixbuf
from gi.repository import Granite
 
class DemoApp(Granite.Application):
application_id="demo.granite.org"
program_name="Granite Demo"
app_years= "2012"
build_version="1.0"
main_url = "https://launchpad.net/granite";
bug_url = "https://bugs.launchpad.net/granite";
help_url = "https://answers.launchpad.net/granite";
translate_url = "https://translations.launchpad.net/granite";
about_authors = {"Kekun",
None
};
about_documenters = {"Valadoc",
None
};
about_artists = {"Daniel P. Fore",
None
};
 
about_authors = {"Maxwell Barvian <mbarvian@gmail.com>",
"Daniel Fore <bunny@go-docky.com>",
"Avi Romanoff <aviromanoff@gmail.com>",
None
};
 
about_comments = "A demo of the Granite toolkit";
about_translators = "Launchpad Translators";
about_license_type = Gtk.License.GPL_3_0;
 
def do_activate(self):
win = Gtk.Window(application = self )
notebook = Gtk.Notebook()
#/* welcome */
 
#// These strings will be automatically corrected by the widget
win.add(notebook)
welcome = Granite.WidgetsWelcome()
welcome = welcome.new("Granite's Welcome Screen", "This is Granite's Welcome widget.")
 
notebook.append_page(welcome, Gtk.Label("Welcome"))
 
pixbuf = Gtk.IconTheme.get_default().load_icon("document-new",48, Gtk.IconLookupFlags.GENERIC_FALLBACK)
image = Gtk.Image.new_from_icon_name("document-open", Gtk.IconSize.DIALOG)
 
#Adding elements. Use the most convenient function to add an icon
welcome.append_with_pixbuf(pixbuf,"create", "Write a new document")
welcome.append_with_image(image, "open","select a file")
welcome.append("help-info", "Discover", "learn more about this app")
 
#modebutton
mode_button = Granite.WidgetsModeButton()
mode_button.valing = Gtk.Align.CENTER
mode_button.haling = Gtk.Align.CENTER
 
mode_button.append(Gtk.Label("Hardware"))
mode_button.append(Gtk.Label("Input"))
mode_button.append(Gtk.Label("Output"))
mode_button.append(Gtk.Label("Output"))
mode_button.append(Gtk.Label("Quite long"))
mode_button.append(Gtk.Label("Very Very long \n with line break"))
 
vbox = Gtk.Grid()
toolbar = Gtk.Toolbar()
toolbar.get_style_context().add_class("primary-toolbar")
toolbutton = Gtk.ToolItem()
tool_mode = Granite.WidgetsModeButton()
 
tool_mode.append_icon("view-list-column-symbolic", Gtk.IconSize.MENU)
tool_mode.append_icon("view-list-details-symbolic", Gtk.IconSize.MENU)
tool_mode.append_icon("view-list-icons-symbolic", Gtk.IconSize.MENU)
tool_mode.append_icon("view-list-video-symbolic", Gtk.IconSize.MENU)
toolbutton.add(tool_mode)
toolbar.insert(toolbutton,-1)
 
#Granite.Application.create_appmenu missing
menu = Gtk.Menu()
app_menu = Granite.WidgetsAppMenu.new_with_app(self,menu)
toolbar.insert(app_menu,-1)
 
 
vbox.attach(toolbar,0, 0, 1,1)
vbox.attach(mode_button,0,2,1,1)
notebook.append_page(vbox, Gtk.Label("ModeButton"))
 
win.resize(800,600)
win.show_all()
 
 
 
app= DemoApp()
app.run("",1)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.