def message(self, message, style="error", timeout=5): """Push a message to the statusbar. Args: message: Message to push. style: One of error, warning and info. timeout: Time until the message shall be removed by update info. """ if self._app.debug: self._app["log"].write_message(style, message) self._errors = True styles = {"error": "#CC0000", "warning": "#FA9E21", "info": "#6699FF"} message = "<b><span foreground='" + styles[style] + "'>" + \ style.upper() + ": </span></b>" + message self._timer_id = GLib.timeout_add(timeout * 1000, self.update_info) # Show if is was hidden if not settings["display_bar"].get_value(): settings.override("display_bar", "true") self._was_hidden = True self._left_label.set_markup(message) # CSS to style bar according to message css_provider = Gtk.CssProvider() css_str = "#OverLay { border-top: solid 2px " + styles[style] + ";}" css_provider.load_from_data(css_str.encode()) Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
def toggle(self): """Toggle the slideshow or update the delay.""" if not self._app.get_paths(): message = "No valid paths, starting slideshow failed" self._app["statusbar"].message(message, "error") return if self._app["thumbnail"].toggled: message = "Slideshow makes no sense in thumbnail mode" self._app["statusbar"].message(message, "warning") return # Delay changed via vimiv["eventhandler"].num_str? number = self._app["eventhandler"].get_num_str() if number: settings.override("slideshow_delay", number) self._app["eventhandler"].num_clear() # If the delay wasn't changed in any way just toggle the slideshow else: self.running = not self.running if self.running: delay = 1000 * settings["slideshow_delay"].get_value() self._start_index = self._app.get_index() self._timer_id = GLib.timeout_add(delay, self._next) else: self._app["statusbar"].lock = False GLib.source_remove(self._timer_id) self._app["statusbar"].update_info()
def parse_config(commandline_config=None, running_tests=False): """Check each configfile for settings and apply them. Args: commandline_config: Configfile given by command line flag to parse. running_tests: If True, running from testsuite. Return: Dictionary of modified settings. """ configfiles = [] # We do not want to parse user configuration files when running the test # suite if not running_tests: configfiles += [ "/etc/vimiv/vimivrc", os.path.join(get_user_config_dir(), "vimiv/vimivrc"), os.path.expanduser("~/.vimiv/vimivrc")] if commandline_config: configfiles.append(commandline_config) # Error message, gets filled with invalid sections in the user's configfile. # If any exist, a popup is displayed at startup. message = "" # Let ConfigParser parse the list of configuration files config = configparser.ConfigParser() try: config.read(configfiles) except UnicodeDecodeError as e: message += "Could not decode configfile.\n" + str(e) except configparser.MissingSectionHeaderError as e: message += "Invalid configfile.\n" + str(e) except configparser.ParsingError as e: message += str(e) # Override settings with settings in config for header in ["GENERAL", "LIBRARY", "EDIT"]: if header not in config: continue section = config[header] for setting in section: try: settings.override(setting, section[setting]) except StringConversionError as e: message += str(e) + "\n" except SettingNotFoundError: message += "Unknown setting %s\n" % (setting) # Receive aliases aliases, partial_message = get_aliases(config) settings.set_aliases(aliases) message += partial_message if message: error_message(message, running_tests=running_tests) return settings
def _on_settings_changed(self, new_settings, setting): if setting == "library_width": width = settings["library_width"].get_value() # Set some reasonable limits to the library size width = min(width, self._app["window"].winsize[0]) width = max(width, 100) if width != settings["library_width"].get_value(): settings.override("library_width", str(width)) return else: self.set_size_request(width, 10) self._app.emit("widget-layout-changed", self) elif setting == "show_hidden" and self.is_visible(): self.reload(".")
def _on_settings_changed(self, new_settings, setting): if setting == "slideshow_delay": delay = settings["slideshow_delay"].get_value() # Set a minimum if delay < 0.5: settings.override("slideshow_delay", "0.5") self._app["statusbar"].message( "Delays shorter than 0.5 s are not allowed", "warning") return # If slideshow was running reload it if self.running: GLib.source_remove(self._timer_id) self._timer_id = GLib.timeout_add(1000 * delay, self._next) self._app["statusbar"].update_info()
def set_option(name, setting, value=0): """Set a setting in settings according to commandline option. Args: name: Name of the commandline option setting: Name of setting in settings to modify. value: One of 0, 1 or 2. 0: Set setting to False. 1: Set setting to True. 2: Set setting to value given in the commandline. """ if options.contains(name): valuedict = {0: "false", 1: "true"} if value == 2: valuedict[2] = options.lookup_value(name).unpack() settings.override(setting, valuedict[value])
def update_info(self): """Update the statusbar and the window title.""" # Return if it is locked if self.lock: return # Hide again if it was shown due to an error message if self._was_hidden: self._was_hidden = False settings.override("display_bar", "false") # Strip error messages if any if self._errors: self._error_false() # Get mode first mode = self._get_mode() # Update all relevant widgets self._set_left_status(mode) self._set_center_status(mode) self._set_right_status(mode) self._set_window_title()
def set(self, setting, value=None): """Wrapper for settings.override catching errors.""" # Allow passing multipliers via keybinding multiplier = self._app["eventhandler"].get_num_str() if multiplier: self._app["eventhandler"].num_clear() else: multiplier = "1" try: # Toggle boolean settings if setting.endswith("!"): setting = setting.rstrip("!") settings.toggle(setting) # Add to number settings elif value and value.startswith("+") or value.startswith("-"): settings.add_to(setting, value, multiplier) else: settings.override(setting, value) except (StringConversionError, SettingNotFoundError, NotABoolean, NotANumber) as e: self._app["statusbar"].message(str(e), "error")
def setUpClass(cls): settings.override("incsearch", "false") settings.override("search_case_sensitive", "true") cls.search = Search(None) cls.filelist = []