Last active
June 29, 2021 08:35
-
-
Save mariocesar/11290827 to your computer and use it in GitHub Desktop.
Python GTK3 desktop app and Granite App (Elementary OS Desktop)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.