Exemple #1
0
    def add(self, value, multiplier):
        """Add a value to the currently stored integer.

        Args:
            value: The integer value to add.
            multiplier: Integer to multiply value with.
        """
        value = get_int(value, allow_sign=True)
        multiplier = get_int(multiplier, allow_sign=False)
        self._value += value * multiplier
Exemple #2
0
    def override(self, new_value):
        """Override the setting with a new geometry.

        Args:
            new_value: String in the form of "WIDTHxHEIGHT" for the new value.
        """
        geometry = new_value.split("x")
        if len(geometry) != 2:
            error = "Geometry must be of the form WIDTHxHEIGHT"
            raise StringConversionError(error)
        self._value = (get_int(geometry[0]), get_int(geometry[1]))
Exemple #3
0
    def flip(self, horizontal):
        """Flip the displayed image and call thread to flip files.

        Args:
            horizontal: If True, flip horizontally. Else vertically.
        """
        try:
            self._is_transformable()
            horizontal = get_int(horizontal)
        except NotTransformable as e:
            self._app["statusbar"].message(str(e) + " flip", "error")
            return
        except StringConversionError as e:
            self._app["statusbar"].message(str(e), "error")
            return
        images = self.get_images("Flipped")
        # Apply changes
        for fil in images:
            if fil not in self._changes:
                self._changes[fil] = [0, 0, 0]
            if horizontal:
                self._changes[fil][1] = \
                    (self._changes[fil][1] + 1) % 2
            else:
                self._changes[fil][2] = \
                    (self._changes[fil][2] + 1) % 2
        # Flip the image shown
        if self._app.get_path() in images:
            self.emit("changed", "flip", horizontal)
        # Reload thumbnails of flipped images immediately
        if self._app["thumbnail"].toggled:
            self.apply()
Exemple #4
0
    def rotate(self, cwise):
        """Rotate the displayed image and call thread to rotate files.

        Args:
            cwise: Rotate image 90 * cwise degrees.
        """
        try:
            self._is_transformable()
            cwise = get_int(cwise, allow_sign=True)
        except NotTransformable as e:
            self._app["statusbar"].message(str(e) + " rotate", "error")
            return
        except StringConversionError as e:
            self._app["statusbar"].message(str(e), "error")
            return
        images = self.get_images("Rotated")
        cwise = cwise % 4
        # Update properties
        for fil in images:
            if fil in self._changes:
                self._changes[fil][0] = \
                    (self._changes[fil][0] + cwise) % 4
            else:
                self._changes[fil] = [cwise, 0, 0]
        # Rotate the image shown
        if self._app.get_path() in images:
            self.emit("changed", "rotate", cwise)
        # Reload thumbnails of rotated images immediately
        if self._app["thumbnail"].toggled:
            self.apply()
Exemple #5
0
    def override(self, new_value):
        """Override the setting with a new thumbnail size.

        Args:
            new_value: String in the form of "(val, val)" for the new value.
        """
        new_value = new_value.lstrip("(").rstrip(")")
        int_tuple = new_value.split(",")
        if len(int_tuple) != 2:
            error = "Tuple must be of the form (val, val)"
            raise StringConversionError(error)
        int_tuple = (get_int(int_tuple[0]), get_int(int_tuple[1]))
        if int_tuple[0] != int_tuple[1]:
            error = "Thumbnail width and height must be equal"
            raise StringConversionError(error)
        if int_tuple[0] not in [64, 128, 256, 512]:
            error = "Thumbnail size must be one of 64, 128, 256 and 512"
            raise StringConversionError(error)
        self._value = tuple(int_tuple)
Exemple #6
0
    def num_receive(self, number=1, to_float=False):
        """Receive self._num_str and clear it.

        Args:
            number: Number to return if self._num_str is empty.
            to_float: If True, convert num_str to float. Else to int.
        Return:
            The received number or default.
        """
        if self._num_str:
            number = get_float(self._num_str) \
                if to_float else get_int(self._num_str)
            self.num_clear()
        return number
Exemple #7
0
    def change_slider(self, step="1"):
        """Change the value of the currently focused slider.

        Args:
            step: Step to edit the slider by.
        """
        try:
            step = get_int(step, allow_sign=True)
        except StringConversionError as e:
            self._app["statusbar"].message(str(e), "error")
            return
        for slider in self.sliders.values():
            if slider.is_focus():
                val = slider.get_value()
                step = self._app["eventhandler"].num_receive() * step
                val += step
                slider.set_value(val)
Exemple #8
0
 def override(self, new_value):
     self._value = get_int(new_value)