from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from functools import partial
import json
import os
class FlowBoxWindow:
def __init__(self):
self.window = gtk.Window()
self.screen = gdk.Screen.get_default()
self.icon_theme = gtk.IconTheme.get_default()
self.window.set_size_request(self.screen.get_width(),
self.screen.get_height())
self.window.set_name("flow_box")
self.window.move(0, 0)
self.window.set_keep_above(False)
self.window.set_resizable(False)
self.window.set_decorated(False)
self.window.set_border_width(0)
self.window.connect("destroy", gtk.main_quit)
hbox_container = gtk.HBox()
scrolled_window_categories = gtk.ScrolledWindow()
scrolled_window_categories.set_policy(gtk.PolicyType.AUTOMATIC,
gtk.PolicyType.NEVER)
viewportv_categories = gtk.Viewport()
viewportv_categories.add(hbox_container)
scrolled_window_categories.add(viewportv_categories)
self.window.add(scrolled_window_categories)
self.notebook_categories = gtk.Notebook()
hbox_container.add(self.notebook_categories)
self.create_app_menu()
self.window.show_all()
def run_cmd(self, command, widget):
print ('run {}'.format(command))
os.system(command)
def create_app_menu(self):
for category in json.load(open('settings.json')):
# create container for app buttons
box_categories = gtk.Box()
box_categories.set_name("scrolledwindow")
box_categories.set_size_request(self.screen.get_width(),
self.screen.get_height() - 101)
pixbuffer = self.icon_theme.load_icon(category['icon-name'],
int(category['icon-size']),
0)
image = gtk.Image()
image.set_from_pixbuf(pixbuffer)
# flowbox area
app_window = gtk.ScrolledWindow()
app_window.set_policy(gtk.PolicyType.NEVER,
gtk.PolicyType.AUTOMATIC)
apps_container = gtk.FlowBox()
apps_container.set_valign(gtk.Align.START)
apps_container.set_max_children_per_line(30)
apps_container.set_selection_mode(gtk.SelectionMode.NONE)
for app in category['apps']:
command = partial(self.run_cmd, app["command"])
button = gtk.Button(app['name'])
button.connect("clicked", command)
apps_container.add(button)
app_window.add(apps_container)
box_categories.add(app_window)
self.notebook_categories.append_page(box_categories, image)
if __name__ == '__main__':
app = FlowBoxWindow()
gtk.main()