Example #1
0
    def test_temporary_chdir(self):
        dir1 = os.getcwd()
        with utils.temporary_chdir(utils.get_temp_directory()):
            dir2 = os.getcwd()
        dir3 = os.getcwd()
        self.assertPathEquals(dir1, dir3)
        self.assertPathEquals(dir2, utils.get_temp_directory())

        with self.assertRaises(RuntimeError):
            with utils.temporary_chdir(utils.get_temp_directory()):
                raise RuntimeError()
        dir4 = os.getcwd()
        self.assertPathEquals(dir1, dir4)
Example #2
0
 def set_theme_advanced(self,
                        theme_name,
                        brightness=1.0,
                        saturation=1.0,
                        hue=1.0,
                        preserve_transparency=True,
                        output_dir=None,
                        advanced_name="advanced"):
     """
     Load an advanced theme that is customized upon runtime. Requires
     write permission into a temporary directory that is used to
     temporarily store the custom theme. Only available with Img
     library support (Tk 8.6 or higher, Python 3 unless you have
     compiled Tk yourself).
     :param theme_name: pixmap theme name to base the new theme on
     :param brightness: brightness modifier for the pixmaps
     :param saturation: saturation modifier for the pixmaps
     :param hue: hue modifier for the pixmaps, limited to 0.0-2.0
     :param preserve_transparency: When True, all black pixels in the
         resulting images will be set to transparent instead, as
         transparency is lost during RGBA->HSV conversion. Has no
         effect when not changing hue.
     :param output_dir: directory to put the theme in. By default,
         a volatile temporary directory is used
     :param advanced_name: Name to give to the new theme
     :raises: RuntimeError when PNG images are not supported by Tk.
         This usually applies to Python 2 platforms.
     :raises: ValueError is theme is not available or valid
     :raises: RuntimeError when the same name is used twice
     """
     if not self.img_support:
         raise RuntimeError(
             "PNG images are not supported by your Tkinter installation")
     # Check if the theme is a pixmap theme
     if theme_name not in self.pixmap_themes:
         raise ValueError("Theme is not a valid pixmap theme")
     # Check if theme is available in the first place
     if theme_name not in self.themes:
         raise ValueError(
             "Theme to create new theme from is not available: {}".format(
                 theme_name))
     if advanced_name in self.themes:
         raise RuntimeError(
             "The same name for an advanced theme cannot be used twice")
     # Unload advanced if already loaded
     output_dir = os.path.join(
         utils.get_temp_directory(),
         advanced_name) if output_dir is None else output_dir
     self._setup_advanced_theme(theme_name, output_dir, advanced_name)
     # Perform image operations
     image_directory = os.path.join(output_dir, advanced_name,
                                    advanced_name)
     self._setup_images(image_directory, brightness, saturation, hue,
                        preserve_transparency)
     # Load the new theme
     with utils.temporary_chdir(output_dir):
         self.tk.call("lappend", "auto_path", "[{}]".format(output_dir))
         self.tk.eval("source pkgIndex.tcl")
         self.set_theme(advanced_name)
Example #3
0
 def test_get_temp_directory(self):
     self.assertTrue(os.path.exists(utils.get_temp_directory()))