Skip to content

Instantly share code, notes, and snippets.

@mariocesar mariocesar/app_granite.py
Last active Apr 18, 2019

Embed
What would you like to do?
Python GTK3 desktop app and Granite App (Elementary OS Desktop)
import sys
from gi.repository import Granite
from gi.repository import Gtk
from gi.repository import Gio
class LightWindow(Gtk.Dialog):
def __init__(self):
super(LightWindow, self).__init__()
self.set_default_size(400, 300)
self.set_title('Demo')
self.set_position(Gtk.WindowPosition.CENTER)
class Application(Granite.Application):
def __init__(self):
Gtk.Application.__init__(self,
flags=Gio.ApplicationFlags.FLAGS_NONE)
self.license_type = Gtk.License.GPL_3_0
def do_activate(self):
light = LightWindow()
light.set_application (self);
light.connect("destroy", self.on_quit)
light.show()
def do_startup(self):
Gtk.Application.do_startup(self)
def do_shutdown(self):
Gtk.Application.do_shutdown(self)
def on_quit(self, widget, data):
self.quit()
if __name__ == '__main__':
application = Application()
application.run('', 1)
import sys
from gi.repository import Gtk
from gi.repository import Gio
class ApplicationWindow(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.ApplicationWindow.__init__(self, application=app)
self.set_default_size(400, 300)
self.set_title('Demo')
self.set_default_icon_name('document-properties')
self.set_position(Gtk.WindowPosition.CENTER)
class Application(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self,
flags=Gio.ApplicationFlags.FLAGS_NONE)
self.license_type = Gtk.License.GPL_3_0
def do_activate(self):
self.window = ApplicationWindow(app=self)
self.window.connect('destroy', self.on_quit)
self.window.show_all()
self.add_window(self.window)
def do_startup(self):
Gtk.Application.do_startup(self)
def do_shutdown(self):
Gtk.Application.do_shutdown(self)
def on_quit(self, widget, data):
self.quit()
if __name__ == '__main__':
application = Application()
application.run(None)
@clcneogeek325

This comment has been minimized.

Copy link

commented Nov 12, 2014

gracias

@elephantatech

This comment has been minimized.

Copy link

commented Oct 14, 2017

I cannot run the python code for the granite version I get error cannot import name granite. I already installed the python-gi using apt-get on elementaryOS. Any idea what I am missing.

Nevermind I installed the elementary sdk mentioned on https://elementary.io/docs/code/getting-started#developer-sdk and it works now.

great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.