def toggle_readonly(self, readonly): '''Menu action to toggle the read-only state of the application @emits: readonly-changed ''' if readonly and self.page and self.page.modified: # Save any modification now - will not be allowed after switch self.pageview.save_changes() for group in self.uimanager.get_action_groups(): for action in group.list_actions(): if hasattr(action, 'zim_readonly') \ and not action.zim_readonly: action.set_sensitive(not readonly) self.uistate['readonly'] = readonly self.emit('readonly-changed', readonly)
def __init__(self, widget, notebook, page, navigation): '''Constructor @param widget: owning gtk widget or C{None}, only used to determine parent window for dialogs @param notebook: L{Notebook} object for actions to act on @param page: L{Page} object that reflects the _default_ page for actions to act on. @param navigation: a L{NavigationModel} ''' self.widget = widget self.notebook = notebook self.page = page self.navigation = navigation self.notebook.properties.connect('changed', self.on_notebook_properties_changed) group = get_gtk_actiongroup(self) action = self.actiongroup.get_action('show_debug_log') action.set_sensitive(zim.debug_log_file is not None)
def init_uistate(self): # Initialize all the uistate parameters # delayed till show or show_all because all this needs real # uistate to be in place and plugins to be loaded # Run between loading plugins and actually presenting the window to the user if not self._geometry_set: # Ignore this if an explicit geometry was specified to the constructor if self.uistate['windowpos'] is not None: x, y = self.uistate['windowpos'] self.move(x, y) w, h = self.uistate['windowsize'] self.set_default_size(w, h) if self.uistate['windowmaximized']: self.maximize() # For these two "None" means system default, but we don't know what that default is :( self.preferences.setdefault( 'toolbar_style', None, (TOOLBAR_ICONS_ONLY, TOOLBAR_ICONS_AND_TEXT, TOOLBAR_TEXT_ONLY)) self.preferences.setdefault( 'toolbar_size', None, (TOOLBAR_ICONS_TINY, TOOLBAR_ICONS_SMALL, TOOLBAR_ICONS_LARGE)) self.toggle_toolbar(self.uistate['show_toolbar']) self.toggle_statusbar(self.uistate['show_statusbar']) Window.init_uistate(self) # takes care of sidepane positions etc if self.preferences['toolbar_style'] is not None: self.set_toolbar_style(self.preferences['toolbar_style']) if self.preferences['toolbar_size'] is not None: self.set_toolbar_icon_size(self.preferences['toolbar_size']) self.toggle_fullscreen(self._set_fullscreen) if self.notebook.readonly: self.toggle_editable(False) action = self.actiongroup.get_action('toggle_editable') action.set_sensitive(False) else: self.toggle_editable(not self.uistate['readonly']) # And hook to notebook properties self.on_notebook_properties_changed(self.notebook.properties) self.notebook.properties.connect('changed', self.on_notebook_properties_changed) # Hook up the statusbar self.connect('page-changed', self.do_update_statusbar) self.connect('readonly-changed', self.do_update_statusbar) self.pageview.connect('modified-changed', self.do_update_statusbar) self.notebook.connect_after('stored-page', self.do_update_statusbar) # Notify plugins self.emit('init-uistate') # Update menus etc. self.uimanager.ensure_update() # Prevent flashing when the toolbar is loaded after showing the window # and do this before connecting signal below for accelmap. # Add search bar onec toolbar is loaded space = Gtk.SeparatorToolItem() space.set_draw(False) space.set_expand(True) self.toolbar.insert(space, -1) from zim.gui.widgets import InputEntry entry = InputEntry(placeholder_text=_('Search')) entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_FIND) entry.set_icon_activatable(Gtk.EntryIconPosition.SECONDARY, True) entry.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, _('Search Pages...')) # T: label in search entry inline_search = lambda e, *a: self._uiactions.show_search( query=e.get_text() or None) entry.connect('activate', inline_search) entry.connect('icon-release', inline_search) entry.show() item = Gtk.ToolItem() item.add(entry) self.toolbar.insert(item, -1) # Load accelmap config and setup saving it # TODO - this probably belongs in the application class, not here accelmap = ConfigManager.get_config_file('accelmap').file logger.debug('Accelmap: %s', accelmap.path) if accelmap.exists(): Gtk.AccelMap.load(accelmap.path) def on_accel_map_changed(o, path, key, mod): logger.info('Accelerator changed for %s', path) Gtk.AccelMap.save(accelmap.path) Gtk.AccelMap.get().connect('changed', on_accel_map_changed) self.do_update_statusbar()
def on_notebook_properties_changed(self, propeties): group = get_gtk_actiongroup(self) action = self.actiongroup.get_action('open_document_root') action.set_sensitive(self.notebook.document_root is not None)