Test out a GtkApplication with a GMenu and some styling CSS with python3. Ok, might need a little more work but it is a start.
If you change colors with CSS be careful because people are using different themes and the new colors might not work so well with some of the themes. To get a general idea you can test with the Adwaita dark and light themes.
Eric
#!/usr/bin/python3
'''
Test some different themes along with styling with CSS.
GTK_THEME=Adwaita:dark python3 program.py
GTK_THEME=Adwaita:light python3 program.py
'''
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gio, Gtk, Gdk
class Application(Gtk.Application):
def __init__(self):
Gtk.ApplicationWindow.__init__(self, application_id="test.menu", flags=Gio.ApplicationFlags.FLAGS_NONE)
self.connect("startup", self.startup_menu)
self.connect("activate", self.activate_window)
def startup_menu(self, *args):
action=Gio.SimpleAction.new("open_file", None)
action.connect("activate", self.open_file)
self.add_action(action)
action=Gio.SimpleAction.new("save_file", None)
action.connect("activate", self.save_file)
self.add_action(action)
menu = Gio.Menu()
# The "open file" menu item
open_item = Gio.MenuItem()
open_item.set_label("Open File")
open_item.set_detailed_action("app.open_file")
# The "save file" menu item
save_item = Gio.MenuItem()
save_item.set_label("Save File")
save_item.set_detailed_action("app.save_file")
# The open and save menu items are part of a "section"; sections are used
# to tell the component that will render the menu to visually/semantically
# separate the items
section_menu = Gio.Menu()
section_menu.append_item(open_item)
section_menu.append_item(save_item)
# Put the section in a sub-menu, without a label
submenu = Gio.Menu()
submenu.append_section(None, section_menu)
# Put the sub-menu in the main menu, with a label
menu.append_submenu("File", submenu)
self.set_menubar(menu)
def activate_window(self, *args):
window=Gtk.ApplicationWindow(application=self, title="Menu")
window.set_default_size(200, 200)
window.set_position(Gtk.WindowPosition.CENTER)
label1=Gtk.Label("Green Label")
label1.set_vexpand(True)
label1.set_hexpand(True)
label1.set_name("green_label")
entry1=Gtk.Entry()
entry1.set_text("entry1")
#entry1.set_vexpand(True)
entry1.set_hexpand(True)
label2=Gtk.Label("Cyan Label")
label2.set_vexpand(True)
label2.set_hexpand(True)
label2.set_name("cyan_label")
entry2=Gtk.Entry()
entry2.set_text("entry2")
entry2.set_vexpand(True)
entry2.set_hexpand(True)
grid=Gtk.Grid()
grid.attach(label1, 0, 0, 1, 1)
grid.attach(entry1, 0, 1, 1, 1)
grid.attach(label2, 0, 2, 1, 1)
grid.attach(entry2, 0, 3, 1, 1)
window.add(grid)
style_provider=Gtk.CssProvider()
css=b'#green_label{background: rgba(0,255,0,1.0);} #cyan_label{background: rgba(0,255,255,1.0);}'
style_provider.load_from_data(css)
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
window.show_all()
def open_file(self, *args):
print("Open File")
def save_file(self, *args):
print("Save File")
if __name__ == "__main__":
app=Application()
app.run(None)