Guest User

Untitled

a guest
Feb 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. def setup_menus(self):
  2. ui_string = """
  3. <ui>
  4. <menubar name="menubarMain">
  5. <menu action="menuFile">
  6. <menuitem action="Capture"/>
  7. <menuitem action="Open"/>
  8. <menuitem action="Save"/>
  9. <menuitem action="Upload"/>
  10. <separator/>
  11. <menuitem action="Quit"/>
  12. </menu>
  13. <menu action="menuEdit">
  14. <menuitem action="Copy"/>
  15. <separator/>
  16. <menuitem action="Crop"/>
  17. </menu>
  18. <menu action="menuImage">
  19. </menu>
  20. <menu action="menuView">
  21. <menuitem action="ZoomIn"/>
  22. <menuitem action="ZoomOut"/>
  23. <menuitem action="NormalSize"/>
  24. </menu>
  25. <menu action="menuHelp">
  26. <menuitem action="About"/>
  27. </menu>
  28. </menubar>
  29. <toolbar name="toolbarMain">
  30. <toolitem action="Capture"/>
  31. <toolitem action="Open"/>
  32. <toolitem action="Save"/>
  33. <separator/>
  34. <toolitem action="Copy"/>
  35. <separator/>
  36. <toolitem action="Quit"/>
  37. </toolbar>
  38. <toolbar name="toolbarPalette">
  39. <toolitem action="toolPointer"/>
  40. <toolitem action="toolSelect"/>
  41. <toolitem action="toolPaint"/>
  42. <toolitem action="toolFill"/>
  43. <toolitem action="toolText"/>
  44. <toolitem action="toolRect"/>
  45. </toolbar>
  46. </ui>
  47. """
  48.  
  49. self.act_main = gtk.ActionGroup("Actions")
  50. self.act_main.add_actions([
  51. ("menuFile", None, "_File"),
  52. ("menuEdit", None, "_Edit"),
  53. ("menuImage", None, "_Image"),
  54. ("menuView", None, "_View"),
  55. ("menuHelp", None, "_Help"),
  56. ("Capture", None, "_Capture", "<ctrl>G", "Capture a screenshot", self.screen_capture),
  57. ("Open", gtk.STOCK_OPEN, None, None, "Open an existing file", self.on_open),
  58. ("Save", gtk.STOCK_SAVE, None, None, "Save the current file", self.on_save),
  59. ("Upload", gtk.STOCK_NETWORK, "_Upload", None, "Upload the current file", self.on_upload),
  60. ("Quit", gtk.STOCK_QUIT, None, None, "Quit the program", self.on_quit),
  61. ("Copy", gtk.STOCK_COPY, None, None, "Copy the image to the clipboard", self.on_copy),
  62. ("ZoomIn", gtk.STOCK_ZOOM_IN, None, None, "Enlarge the image view", self.on_zoom_in),
  63. ("ZoomOut", gtk.STOCK_ZOOM_OUT, None, None, "Shrink the image view", self.on_zoom_out),
  64. ("NormalSize", gtk.STOCK_ZOOM_100, None, None, "Show the image at its normal size", self.on_normal_size),
  65. ("About", gtk.STOCK_ABOUT, None, None, "View information about the program", self.on_about),
  66. ])
  67.  
  68. self.act_selected = gtk.ActionGroup("Selected")
  69. self.act_selected.add_actions([
  70. ("Crop", None, "_Crop", "<ctrl>R", "Crop the image", self.on_crop),
  71. ])
  72.  
  73. self.act_tools = gtk.ActionGroup("Tools")
  74. self.act_tools.add_radio_actions([
  75. ("toolPointer", None, "Pointer", None, "Select and manipulate items", 0),
  76. ("toolSelect", None, "Select", None, "Select regions of the canvas", 1),
  77. ("toolRect", None, "Rectangle", None, "Create rectangle shapes", 2),
  78. ("toolText", None, "Text", None, "Create text annotations", 3),
  79. ("toolPaint", None, "Paint", None, "Paint on the canvas", 4),
  80. ("toolFill", None, "Fill", None, "Fill an area with color", 5),
  81. ])
  82.  
  83. ui = gtk.UIManager()
  84. ui.insert_action_group(self.act_main, 0)
  85. ui.insert_action_group(self.act_selected, 0)
  86. ui.insert_action_group(self.act_tools, 0)
  87. ui.add_ui_from_string(ui_string)
  88.  
  89. set_icon_named("applets-screenshooter",
  90. ui.get_widget("/toolbarMain/Capture"))
  91.  
  92. set_icon_named(get_icon("transform-crop-and-resize.png"),
  93. ui.get_widget("/menubarMain/menuEdit/Crop"))
  94.  
  95. icons = {
  96. "toolRect": "draw-rectangle.png",
  97. "toolSelect": "select-rectangular.png",
  98. "toolText": "draw-text.png",
  99. "toolPointer": "selector.png",
  100. "toolPaint": "draw-brush.png",
  101. "toolFill": "color-fill.png",
  102. }
  103.  
  104. for n, f in icons.items():
  105. set_icon_named(get_icon(f), ui.get_widget("/toolbarPalette/%s" % n))
  106.  
  107. self.manage_enabled_widgets()
  108. self.canvas.act_select_change = self.manage_enabled_widgets
  109.  
  110. return ui
Add Comment
Please, Sign In to add comment