def _init_uim(self): """Initialize the UI manager.""" self.uim = gtk.UIManager() safe_group = gtk.ActionGroup("main-safe") unsafe_group = gtk.ActionGroup("main-unsafe") for name in gaupol.actions.__all__: action = getattr(gaupol.actions, name)() args = (action, action.accelerator) if action.action_group == "main-safe": safe_group.add_action_with_accel(*args) if action.action_group == "main-unsafe": unsafe_group.add_action_with_accel(*args) self._init_uim_radio_groups(safe_group) self._init_uim_radio_groups(unsafe_group) self.uim.insert_action_group(safe_group, 0) self.uim.insert_action_group(unsafe_group, 1) action_group = gtk.ActionGroup("projects") self.uim.insert_action_group(action_group, -1) ui_xml_file = os.path.join(aeidon.DATA_DIR, "ui", "ui.xml") self.uim.add_ui_from_file(ui_xml_file) self.window.add_accel_group(self.uim.get_accel_group()) path = os.path.join(aeidon.CONFIG_HOME_DIR, "accels.conf") if os.path.isfile(path): gtk.accel_map_load(path) atexit.register(gtk.accel_map_save, path) self.uim.ensure_update()
def load_accel_map(): """ Load the user accelerator map from the gaphor user home directory """ filename = _get_accel_map_filename() if os.path.exists(filename) and os.path.isfile(filename): gtk.accel_map_load(filename)
def startgtkloop(errors, argparser): """ We start the gtk loop and run the function to start up GRAMPS """ gobject.threads_init() gobject.timeout_add(100, __startgramps, errors, argparser, priority=100) if os.path.exists(os.path.join(const.DATA_DIR, "gramps.accel")): gtk.accel_map_load(os.path.join(const.DATA_DIR, "gramps.accel")) gtk.main()
def state_restore(self): """Restore window state.""" conf = self.app.config action = self._get_action('instance-toggle-statusbar') action.set_active(conf.get('win.statusbar_visible', True)) self.on_toggle_statusbar(action) action = self._get_action('instance-toggle-toolbar') action.set_active(conf.get('win.toolbar_visible', True)) self.on_toggle_toolbar(action) self.side_pane.state_restore() self.bottom_pane.state_restore() width = conf.get('gui.width') height = conf.get('gui.height') if not width or width == -1: width = 800 if not height or height == -1: height = 600 self.resize(width, height) if conf.get('gui.maximized', False): self.maximize() fname = os.path.join(USER_CONFIG_DIR, 'shortcuts.map') if os.path.isfile(fname): gtk.accel_map_load(fname)
def __init__(self, datapath, extradata, confpath, filenames): """Construct, but do not run. :`datapath`: Usually ``$PREFIX/share/mypaint``. Where MyPaint should find its app-specific read-only data, e.g. UI definition XML, backgrounds and brush defintions. :`extradata`: Where to find the defaults for MyPaint's themeable UI icons. This will be effectively used in addition to ``$XDG_DATA_DIRS`` for the purposes of icon lookup. Normally it's ``$PREFIX/share``, to support unusual installations outside the usual locations. It should contain an ``icons/`` subdirectory. :`confpath`: Where the user's configuration is stored. ``$HOME/.mypaint`` is typical on Unix-like OSes. """ self.confpath = confpath self.datapath = datapath # create config directory, and subdirs where the user might drop files # TODO make scratchpad dir something pulled from preferences #PALETTE1 for d in ['', 'backgrounds', 'brushes', 'scratchpads']: d = os.path.join(self.confpath, d) if not os.path.isdir(d): os.mkdir(d) print 'Created', d # Default location for our icons. The user's theme can override these. icon_theme = gtk.icon_theme_get_default() icon_theme.append_search_path(join(extradata, "icons")) # Icon sanity check if not icon_theme.has_icon('mypaint') \ or not icon_theme.has_icon('mypaint-tool-brush'): print 'Error: Where have my icons gone?' print 'Icon search path:', icon_theme.get_search_path() print "Mypaint can't run sensibly without its icons; " \ + "please check your installation." print 'see https://gna.org/bugs/?18460 for possible solutions' sys.exit(1) gtk.window_set_default_icon_name('mypaint') stock.init_custom_stock_items() self.ui_manager = gtk.UIManager() gdk.set_program_class('MyPaint') self.pixmaps = PixbufDirectory(join(self.datapath, 'pixmaps')) self.cursor_color_picker = gdk.Cursor(gdk.display_get_default(), self.pixmaps.cursor_color_picker, 1, 30) # unmanaged main brush; always the same instance (we can attach settings_observers) # this brush is where temporary changes (color, size...) happen self.brush = brush.BrushInfo() self.brush.load_defaults() self.preferences = {} self.load_settings() self.scratchpad_filename = "" self.kbm = keyboard.KeyboardManager() self.doc = document.Document(self) self.scratchpad_doc = document.Document(self, leader=self.doc) self.brushmanager = brushmanager.BrushManager(join(datapath, 'brushes'), join(confpath, 'brushes'), self) self.filehandler = filehandling.FileHandler(self) self.brushmodifier = brushmodifier.BrushModifier(self) self.linemode = linemode.LineMode(self) if not self.preferences.get("scratchpad.last_opened_scratchpad", None): self.preferences["scratchpad.last_opened_scratchpad"] = self.filehandler.get_scratchpad_autosave() self.scratchpad_filename = self.preferences["scratchpad.last_opened_scratchpad"] self.brush.set_color_hsv((0, 0, 0)) self.init_brush_adjustments() self.init_line_mode_adjustments() self.ch = colorhistory.ColorHistory(self) self.layout_manager = layout.LayoutManager( prefs=self.preferences["layout.window_positions"], factory=windowing.window_factory, factory_opts=[self] ) self.drawWindow = self.layout_manager.get_widget_by_role("main-window") self.layout_manager.show_all() self.kbm.start_listening() self.filehandler.doc = self.doc self.filehandler.filename = None gtk.accel_map_load(join(self.confpath, 'accelmap.conf')) # Load the background settings window. # FIXME: this line shouldn't be needed, but we need to load this up # front to get any non-default background that the user has configured # from the preferences. self.layout_manager.get_subwindow_by_role("backgroundWindow") # And the brush settings window, or things like eraser mode will break. # FIXME: brush_adjustments should not be dependent on this self.layout_manager.get_subwindow_by_role("brushSettingsWindow") def at_application_start(*junk): self.brushmanager.select_initial_brush() if filenames: # Open only the first file, no matter how many has been specified # If the file does not exist just set it as the file to save to fn = filenames[0].replace('file:///', '/') # some filebrowsers do this (should only happen with outdated mypaint.desktop) if not os.path.exists(fn): self.filehandler.filename = fn else: self.filehandler.open_file(fn) # Load last scratchpad if not self.preferences["scratchpad.last_opened_scratchpad"]: self.preferences["scratchpad.last_opened_scratchpad"] = self.filehandler.get_scratchpad_autosave() self.scratchpad_filename = self.preferences["scratchpad.last_opened_scratchpad"] if os.path.isfile(self.scratchpad_filename): try: self.filehandler.open_scratchpad(self.scratchpad_filename) except AttributeError, e: print "Scratchpad widget isn't initialised yet, so cannot centre" self.apply_settings() if not self.pressure_devices: print 'No pressure sensitive devices found.' self.drawWindow.present()
def do_activate(self): if self.window: self.window.present() return self.window = Gtk.ApplicationWindow(application=self, title="Tryton") self.window.set_default_size(960, 720) self.window.maximize() self.window.set_position(Gtk.WIN_POS_CENTER) self.window.set_resizable(True) self.window.set_icon(TRYTON_ICON) self.window.connect("destroy", self.on_quit) self.window.connect("delete_event", self.on_quit) self.header = Gtk.HeaderBar.new() self.header.set_show_close_button(True) self.window.set_titlebar(self.header) self.set_title() menu = Gtk.Button.new() menu.set_relief(Gtk.ReliefStyle.NONE) icon = Gtk.Image.new() icon.set_from_stock('gtk-home', Gtk.IconSize.BUTTON) menu.set_image(icon) menu.connect('clicked', self.menu_toggle) self.header.pack_start(menu) favorite = Gtk.MenuButton.new() favorite.set_relief(Gtk.ReliefStyle.NONE) icon = Gtk.Image.new() icon.set_from_stock('tryton-bookmark', Gtk.IconSize.BUTTON) favorite.set_image(icon) self.menu_favorite = Gtk.Menu.new() favorite.set_popup(self.menu_favorite) favorite.connect('clicked', self.favorite_set) self.header.pack_start(favorite) self.set_global_search() self.header.pack_start(self.global_search_entry) self.accel_group = Gtk.AccelGroup() self.window.add_accel_group(self.accel_group) gtk.accel_map_add_entry('<tryton>/Form/New', gtk.keysyms.I, gtk.gdk.CONTROL_MASK) gtk.accel_map_add_entry('<tryton>/Form/Save', gtk.keysyms.S, gtk.gdk.CONTROL_MASK) gtk.accel_map_add_entry('<tryton>/Form/Duplicate', gtk.keysyms.D, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK) gtk.accel_map_add_entry('<tryton>/Form/Delete', gtk.keysyms.D, gtk.gdk.CONTROL_MASK) gtk.accel_map_add_entry('<tryton>/Form/Next', gtk.keysyms.Page_Down, 0) gtk.accel_map_add_entry('<tryton>/Form/Previous', gtk.keysyms.Page_Up, 0) gtk.accel_map_add_entry('<tryton>/Form/Switch View', gtk.keysyms.L, gtk.gdk.CONTROL_MASK) gtk.accel_map_add_entry('<tryton>/Form/Close', gtk.keysyms.W, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK) gtk.accel_map_add_entry('<tryton>/Form/Reload', gtk.keysyms.R, gtk.gdk.CONTROL_MASK) gtk.accel_map_add_entry('<tryton>/Form/Attachments', gtk.keysyms.T, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK) gtk.accel_map_add_entry('<tryton>/Form/Notes', gtk.keysyms.O, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK) gtk.accel_map_add_entry('<tryton>/Form/Relate', gtk.keysyms.R, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK) gtk.accel_map_add_entry('<tryton>/Form/Actions', gtk.keysyms.E, gtk.gdk.CONTROL_MASK) gtk.accel_map_add_entry('<tryton>/Form/Report', gtk.keysyms.P, gtk.gdk.CONTROL_MASK) gtk.accel_map_add_entry('<tryton>/Form/Search', gtk.keysyms.F, gtk.gdk.CONTROL_MASK) gtk.accel_map_load(os.path.join(get_config_dir(), 'accel.map')) self.tooltips = common.Tooltips() self.vbox = gtk.VBox() self.window.add(self.vbox) self.buttons = {} self.info = gtk.VBox() self.vbox.pack_start(self.info, expand=False) if CONFIG['client.check_version']: common.check_version(self.info) GLib.timeout_add_seconds(int(CONFIG['download.frequency']), common.check_version, self.info) self.pane = gtk.HPaned() self.vbox.pack_start(self.pane, True, True) self.pane.set_position(int(CONFIG['menu.pane'])) self.menu_screen = None self.menu = gtk.VBox() self.menu.set_vexpand(True) self.pane.add1(self.menu) self.notebook = gtk.Notebook() self.notebook.popup_enable() self.notebook.set_scrollable(True) self.notebook.connect_after('switch-page', self._sig_page_changt) self.pane.add2(self.notebook) self.window.show_all() self.pages = [] self.previous_pages = {} self.current_page = 0 self.last_page = 0 self.dialogs = [] # Register plugins tryton.plugins.register() self.set_title() # Adds username/profile while password is asked try: common.Login() except Exception as exception: if (not isinstance(exception, TrytonError) or exception.faultCode != 'QueryCanceled'): common.error(str(exception), traceback.format_exc()) return self.quit() self.get_preferences()
def __init__(self, window): gtk.UIManager.__init__(self) self._window = window self._tooltipstatus = status.TooltipStatusHelper( self, window.statusbar) # ---------------------------------------------------------------- # Create actions for the menus. # ---------------------------------------------------------------- self._actiongroup = gtk.ActionGroup('mcomix-main') self._actiongroup.add_actions([ ('copy_page', gtk.STOCK_COPY, _('_Copy'), None, _('Copies the current page to clipboard.'), window.clipboard.copy_page), ('delete', gtk.STOCK_DELETE, _('_Delete'), 'Delete', _('Deletes the current file or archive from disk.'), window.delete), ('next_page', 'mcomix-next-page', _('_Next page'), 'Page_Down', _('Next page'), window.next_page), ('previous_page', 'mcomix-previous-page', _('_Previous page'), 'Page_Up', _('Previous page'), window.previous_page), ('first_page', 'mcomix-goto-first-page', _('_First page'), 'Home', _('First page'), window.first_page), ('last_page', 'mcomix-goto-last-page', _('_Last page'), 'End', _('Last page'), window.last_page), ('go_to', gtk.STOCK_JUMP_TO, _('_Go to page...'), 'G', _('Go to page...'), window.page_select), ('refresh_archive', gtk.STOCK_REFRESH, _('Re_fresh'), '<control><shift>R', _('Reloads the currently opened files or archive.'), window.filehandler.refresh_file), ('next_archive', 'mcomix-next-archive', _('Next _archive'), '<control><shift>N', _('Next archive'), window.filehandler._open_next_archive), ('previous_archive', 'mcomix-previous-archive', _('Previous a_rchive'), '<control><shift>P', _('Previous archive'), window.filehandler._open_previous_archive), ('next_directory', 'mcomix-next-directory', _('Next directory'), '<control>N', _('Next directory'), window.filehandler.open_next_directory), ('previous_directory', 'mcomix-previous-directory', _('Previous directory'), '<control>P', _('Previous directory'), window.filehandler.open_previous_directory), ('zoom_in', gtk.STOCK_ZOOM_IN, _('Zoom _In'), 'KP_Add', None, window.manual_zoom_in), ('zoom_out', gtk.STOCK_ZOOM_OUT, _('Zoom _Out'), 'KP_Subtract', None, window.manual_zoom_out), ('zoom_original', gtk.STOCK_ZOOM_100, _('_Normal Size'), '<Control>0', None, window.manual_zoom_original), ('close', gtk.STOCK_CLOSE, _('_Close'), None, _('Closes all opened files.'), window.filehandler.close_file), ('quit', gtk.STOCK_QUIT, _('_Quit'), None, None, window.close_program), ('save_and_quit', gtk.STOCK_QUIT, _('_Save and quit'), '<Control><shift>q', _('Quits and restores the currently opened file next time the program starts.' ), window.save_and_terminate_program), ('rotate_90', 'mcomix-rotate-90', _('_Rotate 90 degrees CW'), 'r', None, window.rotate_90), ('rotate_180', 'mcomix-rotate-180', _('Rotate 180 de_grees'), None, None, window.rotate_180), ('rotate_270', 'mcomix-rotate-270', _('Rotat_e 90 degrees CCW'), '<Shift>r', None, window.rotate_270), ('flip_horiz', 'mcomix-flip-horizontal', _('Fli_p horizontally'), None, None, window.flip_horizontally), ('flip_vert', 'mcomix-flip-vertical', _('Flip _vertically'), None, None, window.flip_vertically), ('extract_page', gtk.STOCK_SAVE_AS, _('Save _As'), '<Control><Shift>s', None, window.extract_page), ('menu_zoom', 'mcomix-zoom', _('_Zoom')), ('menu_recent', gtk.STOCK_DND_MULTIPLE, _('_Recent')), ('menu_bookmarks_popup', 'comix-add-bookmark', _('_Bookmarks')), ('menu_bookmarks', None, _('_Bookmarks')), ('menu_toolbars', None, _('T_oolbars')), ('menu_edit', None, _('_Edit')), ('menu_file', None, _('_File')), ('menu_view', None, _('_View')), ('menu_view_popup', 'comix-image', _('_View')), ('menu_go', None, _('_Go')), ('menu_go_popup', gtk.STOCK_GO_FORWARD, _('_Go')), ('menu_tools', None, _('_Tools')), ('menu_help', None, _('_Help')), ('menu_transform', 'mcomix-transform', _('_Transform image')), ('expander', None, None, None, None, None) ]) self._actiongroup.add_toggle_actions([ ('fullscreen', gtk.STOCK_FULLSCREEN, _('_Fullscreen'), 'f', _('Fullscreen mode'), window.change_fullscreen), ('double_page', 'mcomix-double-page', _('_Double page mode'), 'd', _('Double page mode'), window.change_double_page), ('toolbar', None, _('_Toolbar'), None, None, window.change_toolbar_visibility), ('menubar', None, _('_Menubar'), '<Control>M', None, window.change_menubar_visibility), ('statusbar', None, _('St_atusbar'), None, None, window.change_statusbar_visibility), ('scrollbar', None, _('S_crollbars'), None, None, window.change_scrollbar_visibility), ('thumbnails', None, _('Th_umbnails'), 'F9', None, window.change_thumbnails_visibility), ('hide all', None, _('H_ide all'), 'i', None, window.change_hide_all), ('manga_mode', 'mcomix-manga', _('_Manga mode'), 'm', _('Manga mode'), window.change_manga_mode), ('invert_scroll', gtk.STOCK_UNDO, _('Invert smart scroll'), 'x', _('Invert smart scrolling direction.'), window.change_invert_scroll), ('keep_transformation', None, _('_Keep transformation'), 'k', _('Keeps the currently selected transformation for the next pages.' ), window.change_keep_transformation), ('slideshow', gtk.STOCK_MEDIA_PLAY, _('Start _slideshow'), '<Control>S', _('Start slideshow'), window.slideshow.toggle), ('lens', 'mcomix-lens', _('Magnifying _lens'), '<Shift>l', _('Magnifying lens'), window.lens.toggle), ('stretch', None, _('Stretch small images'), 'y', _('Stretch images to fit to the screen, depending on zoom mode.'), window.change_stretch) ]) # Note: Don't change the default value for the radio buttons unless # also fixing the code for setting the correct one on start-up in main.py. self._actiongroup.add_radio_actions( [('best_fit_mode', 'mcomix-fitbest', _('_Best fit mode'), 'b', _('Best fit mode'), constants.ZOOM_MODE_BEST), ('fit_width_mode', 'mcomix-fitwidth', _('Fit _width mode'), 'w', _('Fit width mode'), constants.ZOOM_MODE_WIDTH), ('fit_height_mode', 'mcomix-fitheight', _('Fit _height mode'), '<Shift>h', _('Fit height mode'), constants.ZOOM_MODE_HEIGHT), ('fit_manual_mode', 'mcomix-fitmanual', _('M_anual zoom mode'), 'a', _('Manual zoom mode'), constants.ZOOM_MODE_MANUAL)], 3, window.change_zoom_mode) self._actiongroup.add_actions( [('about', gtk.STOCK_ABOUT, _('_About'), None, None, dialog_handler.open_dialog)], (window, 'about-dialog')) self._actiongroup.add_actions( [('comments', 'mcomix-comments', _('Co_mments...'), 'c', None, dialog_handler.open_dialog)], (window, 'comments-dialog')) self._actiongroup.add_actions( [('properties', gtk.STOCK_PROPERTIES, _('Proper_ties'), '<Alt>Return', None, dialog_handler.open_dialog)], (window, 'properties-dialog')) self._actiongroup.add_actions( [('preferences', gtk.STOCK_PREFERENCES, _('Pr_eferences'), 'F12', None, preferences_dialog.open_dialog)], (window)) # Some actions added separately since they need extra arguments. self._actiongroup.add_actions( [('edit_archive', gtk.STOCK_EDIT, _('_Edit archive...'), None, _('Opens the archive editor.'), edit_dialog.open_dialog), ('open', gtk.STOCK_OPEN, _('_Open...'), None, None, file_chooser_main_dialog.open_main_filechooser_dialog), ('enhance_image', 'mcomix-enhance-image', _('En_hance image...'), 'e', None, enhance_dialog.open_dialog)], window) self._actiongroup.add_actions( [('library', 'mcomix-library', _('_Library...'), '<Control>L', None, library_main_dialog.open_dialog)], window) ui_description = """ <ui> <toolbar name="Tool"> <toolitem action="previous_archive" /> <toolitem action="first_page" /> <toolitem action="previous_page" /> <toolitem action="go_to" /> <toolitem action="next_page" /> <toolitem action="last_page" /> <toolitem action="next_archive" /> <separator /> <toolitem action="slideshow" /> <toolitem action="expander" /> <toolitem action="best_fit_mode" /> <toolitem action="fit_width_mode" /> <toolitem action="fit_height_mode" /> <toolitem action="fit_manual_mode" /> <separator /> <toolitem action="double_page" /> <toolitem action="manga_mode" /> <separator /> <toolitem action="lens" /> </toolbar> <menubar name="Menu"> <menu action="menu_file"> <menuitem action="open" /> <menu action="menu_recent" /> <menuitem action="library" /> <separator /> <menuitem action="extract_page" /> <menuitem action="refresh_archive" /> <menuitem action="properties" /> <separator /> <menuitem action="delete" /> <separator /> <menuitem action="close" /> <menuitem action="save_and_quit" /> <menuitem action="quit" /> </menu> <menu action="menu_edit"> <menuitem action="copy_page" /> <separator /> <menuitem action="edit_archive" /> <menuitem action="comments" /> <separator /> <menuitem action="preferences" /> </menu> <menu action="menu_view"> <menuitem action="fullscreen" /> <menuitem action="double_page" /> <menuitem action="manga_mode" /> <separator /> <menuitem action="best_fit_mode" /> <menuitem action="fit_width_mode" /> <menuitem action="fit_height_mode" /> <menuitem action="fit_manual_mode" /> <separator /> <menuitem action="slideshow" /> <separator /> <menuitem action="stretch" /> <menuitem action="invert_scroll" /> <menuitem action="lens" /> <menu action="menu_zoom"> <menuitem action="zoom_in" /> <menuitem action="zoom_out" /> <menuitem action="zoom_original" /> </menu> <separator /> <menu action="menu_toolbars"> <menuitem action="menubar" /> <menuitem action="toolbar" /> <menuitem action="statusbar" /> <menuitem action="scrollbar" /> <menuitem action="thumbnails" /> <separator /> <menuitem action="hide all" /> </menu> </menu> <menu action="menu_go"> <menuitem action="next_page" /> <menuitem action="previous_page" /> <menuitem action="go_to" /> <menuitem action="first_page" /> <menuitem action="last_page" /> <separator /> <menuitem action="next_archive" /> <menuitem action="previous_archive" /> <separator /> <menuitem action="next_directory" /> <menuitem action="previous_directory" /> </menu> <menu action="menu_bookmarks"> </menu> <menu action="menu_tools"> <menuitem action="enhance_image" /> <menu action="menu_transform"> <menuitem action="rotate_90" /> <menuitem action="rotate_270" /> <menuitem action="rotate_180" /> <separator /> <menuitem action="flip_horiz" /> <menuitem action="flip_vert" /> <separator /> <menuitem action="keep_transformation" /> </menu> </menu> <menu action="menu_help"> <menuitem action="about" /> </menu> </menubar> <popup name="Popup"> <menu action="menu_go_popup"> <menuitem action="next_page" /> <menuitem action="previous_page" /> <menuitem action="go_to" /> <menuitem action="first_page" /> <menuitem action="last_page" /> <separator /> <menuitem action="next_archive" /> <menuitem action="previous_archive" /> <separator /> <menuitem action="next_directory" /> <menuitem action="previous_directory" /> </menu> <menu action="menu_view_popup"> <menuitem action="fullscreen" /> <menuitem action="double_page" /> <menuitem action="manga_mode" /> <separator /> <menuitem action="best_fit_mode" /> <menuitem action="fit_width_mode" /> <menuitem action="fit_height_mode" /> <menuitem action="fit_manual_mode" /> <separator /> <menuitem action="slideshow" /> <separator /> <menuitem action="enhance_image" /> <separator /> <menuitem action="stretch" /> <menuitem action="invert_scroll" /> <menuitem action="lens" /> <menu action="menu_zoom"> <menuitem action="zoom_in" /> <menuitem action="zoom_out" /> <menuitem action="zoom_original" /> </menu> <separator /> <menu action="menu_toolbars"> <menuitem action="menubar" /> <menuitem action="toolbar" /> <menuitem action="statusbar" /> <menuitem action="scrollbar" /> <menuitem action="thumbnails" /> <separator /> <menuitem action="hide all" /> </menu> </menu> <menu action="menu_bookmarks_popup"> </menu> <separator /> <menuitem action="open" /> <menu action="menu_recent" /> <menuitem action="library" /> <separator /> <menuitem action="preferences" /> <separator /> <menuitem action="close" /> <menuitem action="quit" /> </popup> </ui> """ self.add_ui_from_string(ui_description) self.insert_action_group(self._actiongroup, 0) self.bookmarks = bookmark_menu.BookmarksMenu(self, window) self.get_widget('/Menu/menu_bookmarks').set_submenu(self.bookmarks) self.get_widget('/Menu/menu_bookmarks').show() self.bookmarks_popup = bookmark_menu.BookmarksMenu(self, window) self.get_widget('/Popup/menu_bookmarks_popup').set_submenu( self.bookmarks_popup) self.get_widget('/Popup/menu_bookmarks_popup').show() self.recent = recent.RecentFilesMenu(self, window) self.get_widget('/Menu/menu_file/menu_recent').set_submenu(self.recent) self.get_widget('/Menu/menu_file/menu_recent').show() self.recentPopup = recent.RecentFilesMenu(self, window) self.get_widget('/Popup/menu_recent').set_submenu(self.recentPopup) self.get_widget('/Popup/menu_recent').show() # Load keyboard accelerator map if os.path.isfile(constants.KEYBINDINGS_PATH): gtk.accel_map_load(constants.KEYBINDINGS_PATH) window.add_accel_group(self.get_accel_group()) # Is there no built-in way to do this? self.get_widget('/Tool/expander').set_expand(True) self.get_widget('/Tool/expander').set_sensitive(False)
def __init__(self): gedit.Plugin.__init__(self) self._instances = dict() gtk.accel_map_load(accel_map_file)
def __init__(self, window): gtk.UIManager.__init__(self) self._window = window self._tooltipstatus = status.TooltipStatusHelper(self, window.statusbar) # ---------------------------------------------------------------- # Create actions for the menus. # ---------------------------------------------------------------- self._actiongroup = gtk.ActionGroup('mcomix-main') self._actiongroup.add_actions([ ('copy_page', gtk.STOCK_COPY, _('_Copy'), None, _('Copies the current page to clipboard.'), window.clipboard.copy_page), ('delete', gtk.STOCK_DELETE, _('_Delete'), 'Delete', _('Deletes the current file or archive from disk.'), window.delete), ('next_page', 'mcomix-next-page', _('_Next page'), 'Page_Down', _('Next page'), window.next_page), ('previous_page', 'mcomix-previous-page', _('_Previous page'), 'Page_Up', _('Previous page'), window.previous_page), ('first_page', 'mcomix-goto-first-page', _('_First page'), 'Home', _('First page'), window.first_page), ('last_page', 'mcomix-goto-last-page', _('_Last page'), 'End', _('Last page'), window.last_page), ('go_to', gtk.STOCK_JUMP_TO, _('_Go to page...'), 'G', _('Go to page...'), window.page_select), ('refresh_archive', gtk.STOCK_REFRESH, _('Re_fresh'), '<control><shift>R', _('Reloads the currently opened files or archive.'), window.filehandler.refresh_file), ('next_archive', 'mcomix-next-archive', _('Next _archive'), '<control><shift>N', _('Next archive'), window.filehandler._open_next_archive), ('previous_archive', 'mcomix-previous-archive', _('Previous a_rchive'), '<control><shift>P', _('Previous archive'), window.filehandler._open_previous_archive), ('next_directory', 'mcomix-next-directory', _('Next directory'), '<control>N', _('Next directory'), window.filehandler.open_next_directory), ('previous_directory', 'mcomix-previous-directory', _('Previous directory'), '<control>P', _('Previous directory'), window.filehandler.open_previous_directory), ('zoom_in', gtk.STOCK_ZOOM_IN, _('Zoom _In'), 'KP_Add', None, window.manual_zoom_in), ('zoom_out', gtk.STOCK_ZOOM_OUT, _('Zoom _Out'), 'KP_Subtract', None, window.manual_zoom_out), ('zoom_original', gtk.STOCK_ZOOM_100, _('_Normal Size'), '<Control>0', None, window.manual_zoom_original), ('close', gtk.STOCK_CLOSE, _('_Close'), None, _('Closes all opened files.'), window.filehandler.close_file), ('quit', gtk.STOCK_QUIT, _('_Quit'), None, None, window.close_program), ('save_and_quit', gtk.STOCK_QUIT, _('_Save and quit'), '<Control><shift>q', _('Quits and restores the currently opened file next time the program starts.'), window.save_and_terminate_program), ('rotate_90', 'mcomix-rotate-90', _('_Rotate 90 degrees CW'), 'r', None, window.rotate_90), ('rotate_180','mcomix-rotate-180', _('Rotate 180 de_grees'), None, None, window.rotate_180), ('rotate_270', 'mcomix-rotate-270', _('Rotat_e 90 degrees CCW'), '<Shift>r', None, window.rotate_270), ('flip_horiz', 'mcomix-flip-horizontal', _('Fli_p horizontally'), None, None, window.flip_horizontally), ('flip_vert', 'mcomix-flip-vertical', _('Flip _vertically'), None, None, window.flip_vertically), ('extract_page', gtk.STOCK_SAVE_AS, _('Save _As'), '<Control><Shift>s', None, window.extract_page), ('menu_zoom', 'mcomix-zoom', _('_Zoom')), ('menu_recent', gtk.STOCK_DND_MULTIPLE, _('_Recent')), ('menu_bookmarks_popup', 'comix-add-bookmark', _('_Bookmarks')), ('menu_bookmarks', None, _('_Bookmarks')), ('menu_toolbars', None, _('T_oolbars')), ('menu_edit', None, _('_Edit')), ('menu_file', None, _('_File')), ('menu_view', None, _('_View')), ('menu_view_popup', 'comix-image', _('_View')), ('menu_go', None, _('_Go')), ('menu_go_popup', gtk.STOCK_GO_FORWARD, _('_Go')), ('menu_tools', None, _('_Tools')), ('menu_help', None, _('_Help')), ('menu_transform', 'mcomix-transform', _('_Transform image')), ('expander', None, None, None, None, None)]) self._actiongroup.add_toggle_actions([ ('fullscreen', gtk.STOCK_FULLSCREEN, _('_Fullscreen'), 'f', _('Fullscreen mode'), window.change_fullscreen), ('double_page', 'mcomix-double-page', _('_Double page mode'), 'd', _('Double page mode'), window.change_double_page), ('toolbar', None, _('_Toolbar'), None, None, window.change_toolbar_visibility), ('menubar', None, _('_Menubar'), '<Control>M', None, window.change_menubar_visibility), ('statusbar', None, _('St_atusbar'), None, None, window.change_statusbar_visibility), ('scrollbar', None, _('S_crollbars'), None, None, window.change_scrollbar_visibility), ('thumbnails', None, _('Th_umbnails'), 'F9', None, window.change_thumbnails_visibility), ('hide all', None, _('H_ide all'), 'i', None, window.change_hide_all), ('manga_mode', 'mcomix-manga', _('_Manga mode'), 'm', _('Manga mode'), window.change_manga_mode), ('invert_scroll', gtk.STOCK_UNDO, _('Invert smart scroll'), 'x', _('Invert smart scrolling direction.'), window.change_invert_scroll), ('keep_transformation', None, _('_Keep transformation'), 'k', _('Keeps the currently selected transformation for the next pages.'), window.change_keep_transformation), ('slideshow', gtk.STOCK_MEDIA_PLAY, _('Start _slideshow'), '<Control>S', _('Start slideshow'), window.slideshow.toggle), ('lens', 'mcomix-lens', _('Magnifying _lens'), 'l', _('Magnifying lens'), window.lens.toggle), ('stretch', None, _('Stretch small images'), 'y', _('Stretch images to fit to the screen, depending on zoom mode.'), window.change_stretch)]) # Note: Don't change the default value for the radio buttons unless # also fixing the code for setting the correct one on start-up in main.py. self._actiongroup.add_radio_actions([ ('best_fit_mode', 'mcomix-fitbest', _('_Best fit mode'), 'b', _('Best fit mode'), constants.ZOOM_MODE_BEST), ('fit_width_mode', 'mcomix-fitwidth', _('Fit _width mode'), 'w', _('Fit width mode'), constants.ZOOM_MODE_WIDTH), ('fit_height_mode', 'mcomix-fitheight', _('Fit _height mode'), 'h', _('Fit height mode'), constants.ZOOM_MODE_HEIGHT), ('fit_manual_mode', 'mcomix-fitmanual', _('M_anual zoom mode'), 'a', _('Manual zoom mode'), constants.ZOOM_MODE_MANUAL)], 3, window.change_zoom_mode) self._actiongroup.add_actions([ ('about', gtk.STOCK_ABOUT, _('_About'), None, None, dialog_handler.open_dialog)], (window, 'about-dialog')) self._actiongroup.add_actions([ ('comments', 'mcomix-comments', _('Co_mments...'), 'c', None, dialog_handler.open_dialog)], (window, 'comments-dialog')) self._actiongroup.add_actions([ ('properties', gtk.STOCK_PROPERTIES, _('Proper_ties'), '<Alt>Return', None, dialog_handler.open_dialog)], (window,'properties-dialog')) self._actiongroup.add_actions([ ('preferences', gtk.STOCK_PREFERENCES, _('Pr_eferences'), 'F12', None, preferences_dialog.open_dialog)], (window)) # Some actions added separately since they need extra arguments. self._actiongroup.add_actions([ ('edit_archive', gtk.STOCK_EDIT, _('_Edit archive...'), None, _('Opens the archive editor.'), edit_dialog.open_dialog), ('open', gtk.STOCK_OPEN, _('_Open...'), None, None, file_chooser_main_dialog.open_main_filechooser_dialog), ('enhance_image', 'mcomix-enhance-image', _('En_hance image...'), 'e', None, enhance_dialog.open_dialog)], window) self._actiongroup.add_actions([ ('library', 'mcomix-library', _('_Library...'), '<Control>L', None, library_main_dialog.open_dialog)], window) ui_description = """ <ui> <toolbar name="Tool"> <toolitem action="previous_archive" /> <toolitem action="first_page" /> <toolitem action="previous_page" /> <toolitem action="go_to" /> <toolitem action="next_page" /> <toolitem action="last_page" /> <toolitem action="next_archive" /> <separator /> <toolitem action="slideshow" /> <toolitem action="expander" /> <toolitem action="best_fit_mode" /> <toolitem action="fit_width_mode" /> <toolitem action="fit_height_mode" /> <toolitem action="fit_manual_mode" /> <separator /> <toolitem action="double_page" /> <toolitem action="manga_mode" /> <separator /> <toolitem action="lens" /> </toolbar> <menubar name="Menu"> <menu action="menu_file"> <menuitem action="open" /> <menu action="menu_recent" /> <menuitem action="library" /> <separator /> <menuitem action="extract_page" /> <menuitem action="refresh_archive" /> <menuitem action="properties" /> <separator /> <menuitem action="delete" /> <separator /> <menuitem action="close" /> <menuitem action="save_and_quit" /> <menuitem action="quit" /> </menu> <menu action="menu_edit"> <menuitem action="copy_page" /> <separator /> <menuitem action="edit_archive" /> <menuitem action="comments" /> <separator /> <menuitem action="preferences" /> </menu> <menu action="menu_view"> <menuitem action="fullscreen" /> <menuitem action="double_page" /> <menuitem action="manga_mode" /> <separator /> <menuitem action="best_fit_mode" /> <menuitem action="fit_width_mode" /> <menuitem action="fit_height_mode" /> <menuitem action="fit_manual_mode" /> <separator /> <menuitem action="slideshow" /> <separator /> <menuitem action="stretch" /> <menuitem action="invert_scroll" /> <menuitem action="lens" /> <menu action="menu_zoom"> <menuitem action="zoom_in" /> <menuitem action="zoom_out" /> <menuitem action="zoom_original" /> </menu> <separator /> <menu action="menu_toolbars"> <menuitem action="menubar" /> <menuitem action="toolbar" /> <menuitem action="statusbar" /> <menuitem action="scrollbar" /> <menuitem action="thumbnails" /> <separator /> <menuitem action="hide all" /> </menu> </menu> <menu action="menu_go"> <menuitem action="next_page" /> <menuitem action="previous_page" /> <menuitem action="go_to" /> <menuitem action="first_page" /> <menuitem action="last_page" /> <separator /> <menuitem action="next_archive" /> <menuitem action="previous_archive" /> <separator /> <menuitem action="next_directory" /> <menuitem action="previous_directory" /> </menu> <menu action="menu_bookmarks"> </menu> <menu action="menu_tools"> <menuitem action="enhance_image" /> <menu action="menu_transform"> <menuitem action="rotate_90" /> <menuitem action="rotate_270" /> <menuitem action="rotate_180" /> <separator /> <menuitem action="flip_horiz" /> <menuitem action="flip_vert" /> <separator /> <menuitem action="keep_transformation" /> </menu> </menu> <menu action="menu_help"> <menuitem action="about" /> </menu> </menubar> <popup name="Popup"> <menu action="menu_go_popup"> <menuitem action="next_page" /> <menuitem action="previous_page" /> <menuitem action="go_to" /> <menuitem action="first_page" /> <menuitem action="last_page" /> <separator /> <menuitem action="next_archive" /> <menuitem action="previous_archive" /> <separator /> <menuitem action="next_directory" /> <menuitem action="previous_directory" /> </menu> <menu action="menu_view_popup"> <menuitem action="fullscreen" /> <menuitem action="double_page" /> <menuitem action="manga_mode" /> <separator /> <menuitem action="best_fit_mode" /> <menuitem action="fit_width_mode" /> <menuitem action="fit_height_mode" /> <menuitem action="fit_manual_mode" /> <separator /> <menuitem action="slideshow" /> <separator /> <menuitem action="enhance_image" /> <separator /> <menuitem action="stretch" /> <menuitem action="invert_scroll" /> <menuitem action="lens" /> <menu action="menu_zoom"> <menuitem action="zoom_in" /> <menuitem action="zoom_out" /> <menuitem action="zoom_original" /> </menu> <separator /> <menu action="menu_toolbars"> <menuitem action="menubar" /> <menuitem action="toolbar" /> <menuitem action="statusbar" /> <menuitem action="scrollbar" /> <menuitem action="thumbnails" /> <separator /> <menuitem action="hide all" /> </menu> </menu> <menu action="menu_bookmarks_popup"> </menu> <separator /> <menuitem action="open" /> <menu action="menu_recent" /> <menuitem action="library" /> <separator /> <menuitem action="preferences" /> <separator /> <menuitem action="close" /> <menuitem action="quit" /> </popup> </ui> """ self.add_ui_from_string(ui_description) self.insert_action_group(self._actiongroup, 0) self.bookmarks = bookmark_menu.BookmarksMenu(self, window) self.get_widget('/Menu/menu_bookmarks').set_submenu(self.bookmarks) self.get_widget('/Menu/menu_bookmarks').show() self.bookmarks_popup = bookmark_menu.BookmarksMenu(self, window) self.get_widget('/Popup/menu_bookmarks_popup').set_submenu(self.bookmarks_popup) self.get_widget('/Popup/menu_bookmarks_popup').show() self.recent = recent.RecentFilesMenu(self, window) self.get_widget('/Menu/menu_file/menu_recent').set_submenu(self.recent) self.get_widget('/Menu/menu_file/menu_recent').show() self.recentPopup = recent.RecentFilesMenu(self, window) self.get_widget('/Popup/menu_recent').set_submenu(self.recentPopup) self.get_widget('/Popup/menu_recent').show() # Load keyboard accelerator map if os.path.isfile(constants.KEYBINDINGS_PATH): gtk.accel_map_load(constants.KEYBINDINGS_PATH) window.add_accel_group(self.get_accel_group()) # Is there no built-in way to do this? self.get_widget('/Tool/expander').set_expand(True) self.get_widget('/Tool/expander').set_sensitive(False)
def __init__(self, datapath, confpath, filenames): self.confpath = confpath self.datapath = datapath # create config directory, and subdirs where the user might drop files for d in ['', 'backgrounds', 'brushes']: d = os.path.join(self.confpath, d) if not os.path.isdir(d): os.mkdir(d) print 'Created', d self.ui_manager = gtk.UIManager() # if we are not installed, use the icons from the source theme = gtk.icon_theme_get_default() themedir_src = join(self.datapath, 'desktop/icons') theme.prepend_search_path(themedir_src) if not theme.has_icon('mypaint'): print 'Warning: Where have all my icons gone?' print 'Theme search path:', theme.get_search_path() gtk.window_set_default_icon_name('mypaint') gdk.set_program_class('MyPaint') self.pixmaps = PixbufDirectory(join(self.datapath, 'pixmaps')) self.cursor_color_picker = gdk.Cursor(gdk.display_get_default(), self.pixmaps.cursor_color_picker, 1, 30) # unmanaged main brush; always the same instance (we can attach settings_observers) # this brush is where temporary changes (color, size...) happen self.brush = brush.BrushInfo() self.brush.load_defaults() self.preferences = {} self.load_settings() self.brushmanager = brushmanager.BrushManager(join(datapath, 'brushes'), join(confpath, 'brushes'), self) self.kbm = keyboard.KeyboardManager() self.filehandler = filehandling.FileHandler(self) self.brushmodifier = brushmodifier.BrushModifier(self) self.doc = document.Document(self) self.brush.set_color_hsv((0, 0, 0)) self.init_brush_adjustments() self.ch = colorhistory.ColorHistory(self) self.layout_manager = layout.LayoutManager( app=self, prefs=self.preferences["layout.window_positions"], factory=windowing.window_factory, factory_opts=[self] ) self.drawWindow = self.layout_manager.get_widget_by_role("main-window") self.layout_manager.show_all() self.kbm.start_listening() self.filehandler.doc = self.doc self.filehandler.filename = None gtk.accel_map_load(join(self.confpath, 'accelmap.conf')) # Load the background settings window. # FIXME: this line shouldn't be needed, but we need to load this up # front to get any non-default background that the user has configured # from the preferences. self.layout_manager.get_subwindow_by_role("backgroundWindow") # And the brush settings window, or things like eraser mode will break. # FIXME: brush_adjustments should not be dependent on this self.layout_manager.get_subwindow_by_role("brushSettingsWindow") def at_application_start(*trash): self.brushmanager.select_initial_brush() if filenames: # Open only the first file, no matter how many has been specified # If the file does not exist just set it as the file to save to fn = filenames[0].replace('file:///', '/') # some filebrowsers do this (should only happen with outdated mypaint.desktop) if not os.path.exists(fn): self.filehandler.filename = fn else: self.filehandler.open_file(fn) self.apply_settings() if not self.pressure_devices: print 'No pressure sensitive devices found.' self.drawWindow.present() gobject.idle_add(at_application_start)
def __init__(self): self.mainWindow = MainWindow(self) self.mainWindow.show_all() gtk.accel_map_load('accelmap.conf')
def __init__(self, library, player): super(QuodLibetWindow, self).__init__() self.last_dir = const.HOME self.__update_title(player) self.set_default_size(550, 450) main_box = gtk.VBox() self.add(main_box) # create test instance of the MPD backend self._mpd = quodmpd.QuodMpd() # create main menubar, load/restore accelerator groups self.__library = library self.__create_menu(player, library) self.add_accel_group(self.ui.get_accel_group()) accel_fn = os.path.join(const.USERDIR, "accels") gtk.accel_map_load(accel_fn) accelgroup = gtk.accel_groups_from_object(self)[0] accelgroup.connect('accel-changed', lambda *args: gtk.accel_map_save(accel_fn)) main_box.pack_start(self.ui.get_widget("/Menu"), expand=False) # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.show_all() self.add_accel_group(self.songlist.accelerators) self.songlist.connect_after( 'drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = SongListScroller( self.ui.get_widget("/Menu/View/SongList")) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander( self.ui.get_widget("/Menu/View/Queue"), library, player) self.playlist = PlaylistMux( player, self.qexpander.model, self.songlist.model) top_bar = TopBar(self, player, library) top_align = Alignment(top_bar, border=3, bottom=-3) main_box.pack_start(top_align, expand=False) self.__browserbox = Alignment(top=3, bottom=3) main_box.pack_start(self.__browserbox) statusbox = StatusBarBox(self.songlist.model, player) self.order = statusbox.order self.repeat = statusbox.repeat self.statusbar = statusbox.statusbar main_box.pack_start(Alignment(statusbox, border=3, top=-3), expand=False) self.songpane = gtk.VPaned() self.songpane.pack1(self.song_scroller, resize=True, shrink=False) self.songpane.pack2(self.qexpander, resize=True, shrink=False) self.__handle_position = self.songpane.get_property("position") self.song_scroller.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::expanded', self.__expand_or) self.qexpander.connect('size-allocate', self.__qex_size_allocate) self.songpane.connect('notify', self.__moved_pane_handle) sort = config.get('memory', 'sortby') self.songlist.set_sort_by(None, sort[1:], order=int(sort[0])) self.browser = None main_box.show_all() try: self.select_browser( self, config.get("memory", "browser"), library, player, True) except: config.set("memory", "browser", browsers.name(0)) config.save(const.CONFIG) raise # set at least the playlist before the mainloop starts.. player.setup(self.playlist, None, 0) def delayed_song_set(): song = library.get(config.get("memory", "song")) seek_pos = config.getint("memory", "seek") config.set("memory", "seek", 0) player.setup(self.playlist, song, seek_pos) gobject.idle_add(delayed_song_set) self.showhide_playlist(self.ui.get_widget("/Menu/View/SongList")) self.showhide_playqueue(self.ui.get_widget("/Menu/View/Queue")) self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.get_selection().connect( 'changed', util.DeferredSignal(self.__set_time)) lib = library.librarian gobject_weak(lib.connect, 'removed', self.__set_time, parent=self) gobject_weak(lib.connect, 'added', self.__set_time, parent=self) gobject_weak(lib.connect_object, 'changed', self.__song_changed, player, parent=self) player_sigs = [ ('song-ended', self.__song_ended), ('song-started', self.__song_started), ('paused', self.__update_paused, True), ('unpaused', self.__update_paused, False), ] for sig in player_sigs: gobject_weak(player.connect, *sig, **{"parent": self}) targets = [("text/uri-list", 0, 1)] self.drag_dest_set( gtk.DEST_DEFAULT_ALL, targets, gtk.gdk.ACTION_DEFAULT) self.connect_object('drag-motion', QuodLibetWindow.__drag_motion, self) self.connect_object('drag-leave', QuodLibetWindow.__drag_leave, self) self.connect_object( 'drag-data-received', QuodLibetWindow.__drag_data_received, self) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect_object("key-press-event", self.__key_pressed, player) self.connect("delete-event", self.__save_browser) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet")
def _on_reload_config(self, action): print(_("reloading shortcuts from config file: %s") % accel_map_file) gtk.accel_map_load(accel_map_file)
""" Set up accelerator path in code but load shortcut from file. """ import gtk builder = gtk.Builder() builder.add_from_file("managed.ui") actiongroup = gtk.ActionGroup("MainWindow") actiongroup.add_action(builder.get_object("file")) action = builder.get_object("save") action.connect("activate", gtk.main_quit) PATH = "<Actions>/MainWindow/save" gtk.accel_map_load("accel.map") action.set_accel_path(PATH) actiongroup.add_action(action) manager = gtk.UIManager() manager.insert_action_group(actiongroup) manager.add_ui_from_file("managed.xml") window = gtk.Window() window.add_accel_group(manager.get_accel_group()) window.show_all() gtk.main()
def load_shortcuts(): config = get_settings_path('keys.conf') if os.path.exists(config): gtk.accel_map_load(config)