fork download
  1. from gi.repository import Gtk as gtk
  2. from gi.repository import Gdk as gdk
  3. from functools import partial
  4. import json
  5. import os
  6.  
  7. class FlowBoxWindow:
  8.  
  9. def __init__(self):
  10.  
  11. self.window = gtk.Window()
  12. self.screen = gdk.Screen.get_default()
  13. self.icon_theme = gtk.IconTheme.get_default()
  14. self.window.set_size_request(self.screen.get_width(),
  15. self.screen.get_height())
  16. self.window.set_name("flow_box")
  17. self.window.move(0, 0)
  18. self.window.set_keep_above(False)
  19. self.window.set_resizable(False)
  20. self.window.set_decorated(False)
  21. self.window.set_border_width(0)
  22. self.window.connect("destroy", gtk.main_quit)
  23.  
  24. hbox_container = gtk.HBox()
  25.  
  26. scrolled_window_categories = gtk.ScrolledWindow()
  27. scrolled_window_categories.set_policy(gtk.PolicyType.AUTOMATIC,
  28. gtk.PolicyType.NEVER)
  29.  
  30. viewportv_categories = gtk.Viewport()
  31. viewportv_categories.add(hbox_container)
  32. scrolled_window_categories.add(viewportv_categories)
  33. self.window.add(scrolled_window_categories)
  34.  
  35. self.notebook_categories = gtk.Notebook()
  36. hbox_container.add(self.notebook_categories)
  37.  
  38. self.create_app_menu()
  39. self.window.show_all()
  40.  
  41. def run_cmd(self, command, widget):
  42. print ('run {}'.format(command))
  43. os.system(command)
  44.  
  45. def create_app_menu(self):
  46.  
  47. for category in json.load(open('settings.json')):
  48.  
  49. # create container for app buttons
  50. box_categories = gtk.Box()
  51. box_categories.set_name("scrolledwindow")
  52. box_categories.set_size_request(self.screen.get_width(),
  53. self.screen.get_height() - 101)
  54. pixbuffer = self.icon_theme.load_icon(category['icon-name'],
  55. int(category['icon-size']),
  56. 0)
  57. image = gtk.Image()
  58. image.set_from_pixbuf(pixbuffer)
  59.  
  60. # flowbox area
  61. app_window = gtk.ScrolledWindow()
  62. app_window.set_policy(gtk.PolicyType.NEVER,
  63. gtk.PolicyType.AUTOMATIC)
  64.  
  65. apps_container = gtk.FlowBox()
  66. apps_container.set_valign(gtk.Align.START)
  67. apps_container.set_max_children_per_line(30)
  68. apps_container.set_selection_mode(gtk.SelectionMode.NONE)
  69.  
  70. for app in category['apps']:
  71. command = partial(self.run_cmd, app["command"])
  72. button = gtk.Button(app['name'])
  73. button.connect("clicked", command)
  74. apps_container.add(button)
  75.  
  76. app_window.add(apps_container)
  77. box_categories.add(app_window)
  78.  
  79. self.notebook_categories.append_page(box_categories, image)
  80.  
  81. if __name__ == '__main__':
  82. app = FlowBoxWindow()
  83. gtk.main()
  84.  
Runtime error #stdin #stdout #stderr 0.02s 9936KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ImportError: No module named 'gi'