Example #1
0
    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()

        Window.init_uistate(self)  # takes care of sidepane positions etc

        self.toggle_fullscreen(self._set_fullscreen)

        # And hook to notebook properties
        self.on_notebook_properties_changed(self.notebook.properties)
        self.notebook.properties.connect('changed',
                                         self.on_notebook_properties_changed)

        # 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.

        # 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)
    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()