Created
December 29, 2008 04:03
-
-
Save segphault/41169 to your computer and use it in GitHub Desktop.
Menu setup in GrabberSnap
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
def setup_menus(self): | |
ui_string = """ | |
<ui> | |
<menubar name="menubarMain"> | |
<menu action="menuFile"> | |
<menuitem action="Capture"/> | |
<menuitem action="Open"/> | |
<menuitem action="Save"/> | |
<menuitem action="Upload"/> | |
<separator/> | |
<menuitem action="Quit"/> | |
</menu> | |
<menu action="menuEdit"> | |
<menuitem action="Copy"/> | |
<separator/> | |
<menuitem action="Crop"/> | |
</menu> | |
<menu action="menuImage"> | |
</menu> | |
<menu action="menuView"> | |
<menuitem action="ZoomIn"/> | |
<menuitem action="ZoomOut"/> | |
<menuitem action="NormalSize"/> | |
</menu> | |
<menu action="menuHelp"> | |
<menuitem action="About"/> | |
</menu> | |
</menubar> | |
<toolbar name="toolbarMain"> | |
<toolitem action="Capture"/> | |
<toolitem action="Open"/> | |
<toolitem action="Save"/> | |
<separator/> | |
<toolitem action="Copy"/> | |
<separator/> | |
<toolitem action="Quit"/> | |
</toolbar> | |
<toolbar name="toolbarPalette"> | |
<toolitem action="toolPointer"/> | |
<toolitem action="toolSelect"/> | |
<toolitem action="toolPaint"/> | |
<toolitem action="toolFill"/> | |
<toolitem action="toolText"/> | |
<toolitem action="toolRect"/> | |
</toolbar> | |
</ui> | |
""" | |
self.act_main = gtk.ActionGroup("Actions") | |
self.act_main.add_actions([ | |
("menuFile", None, "_File"), | |
("menuEdit", None, "_Edit"), | |
("menuImage", None, "_Image"), | |
("menuView", None, "_View"), | |
("menuHelp", None, "_Help"), | |
("Capture", None, "_Capture", "<ctrl>G", "Capture a screenshot", self.screen_capture), | |
("Open", gtk.STOCK_OPEN, None, None, "Open an existing file", self.on_open), | |
("Save", gtk.STOCK_SAVE, None, None, "Save the current file", self.on_save), | |
("Upload", gtk.STOCK_NETWORK, "_Upload", None, "Upload the current file", self.on_upload), | |
("Quit", gtk.STOCK_QUIT, None, None, "Quit the program", self.on_quit), | |
("Copy", gtk.STOCK_COPY, None, None, "Copy the image to the clipboard", self.on_copy), | |
("ZoomIn", gtk.STOCK_ZOOM_IN, None, None, "Enlarge the image view", self.on_zoom_in), | |
("ZoomOut", gtk.STOCK_ZOOM_OUT, None, None, "Shrink the image view", self.on_zoom_out), | |
("NormalSize", gtk.STOCK_ZOOM_100, None, None, "Show the image at its normal size", self.on_normal_size), | |
("About", gtk.STOCK_ABOUT, None, None, "View information about the program", self.on_about), | |
]) | |
self.act_selected = gtk.ActionGroup("Selected") | |
self.act_selected.add_actions([ | |
("Crop", None, "_Crop", "<ctrl>R", "Crop the image", self.on_crop), | |
]) | |
self.act_tools = gtk.ActionGroup("Tools") | |
self.act_tools.add_radio_actions([ | |
("toolPointer", None, "Pointer", None, "Select and manipulate items", 0), | |
("toolSelect", None, "Select", None, "Select regions of the canvas", 1), | |
("toolRect", None, "Rectangle", None, "Create rectangle shapes", 2), | |
("toolText", None, "Text", None, "Create text annotations", 3), | |
("toolPaint", None, "Paint", None, "Paint on the canvas", 4), | |
("toolFill", None, "Fill", None, "Fill an area with color", 5), | |
]) | |
ui = gtk.UIManager() | |
ui.insert_action_group(self.act_main, 0) | |
ui.insert_action_group(self.act_selected, 0) | |
ui.insert_action_group(self.act_tools, 0) | |
ui.add_ui_from_string(ui_string) | |
set_icon_named("applets-screenshooter", | |
ui.get_widget("/toolbarMain/Capture")) | |
set_icon_named(get_icon("transform-crop-and-resize.png"), | |
ui.get_widget("/menubarMain/menuEdit/Crop")) | |
icons = { | |
"toolRect": "draw-rectangle.png", | |
"toolSelect": "select-rectangular.png", | |
"toolText": "draw-text.png", | |
"toolPointer": "selector.png", | |
"toolPaint": "draw-brush.png", | |
"toolFill": "color-fill.png", | |
} | |
for n, f in icons.items(): | |
set_icon_named(get_icon(f), ui.get_widget("/toolbarPalette/%s" % n)) | |
self.manage_enabled_widgets() | |
self.canvas.act_select_change = self.manage_enabled_widgets | |
return ui | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment