tintwizard.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:tintwizard 作者: vanadey 项目源码 文件源码
def apply(self, widget, event=None, confirmChange=True):
        """Applies the current config to tint2."""
        # Check if tint2 is running
        procs = os.popen('pgrep -x "tint2"')            # Check list of active processes for tint2
        pids = []                                       # List of process ids for tint2

        for proc in procs.readlines():
            pids += [int(proc.strip().split(" ")[0])]

        procs.close()

        if self.oneConfigFile:
            # Save and copy as default
            self.save()
            tmpSrc = self.filename
            tmpDest = os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc"
            try:
                shutil.copyfile(tmpSrc, tmpDest)
            except shutil.Error:
                pass
            # Ask tint2 to reload config
            for pid in pids:
                os.kill(pid, signal.SIGUSR1)
        else:
            if confirmDialog(self, "This will terminate all currently running instances of tint2 before applying config. Continue?") == gtk.RESPONSE_YES:
                if not self.save():
                    return

                #shutil.copyfile(self.filename, self.filename+".backup")        # Create backup

                # If it is - kill it
                for pid in pids:
                    os.kill(pid, signal.SIGTERM)

                # Lastly, start it
                os.spawnv(os.P_NOWAIT, self.tint2Bin, [self.tint2Bin, "-c", self.filename])

                if confirmChange and self.filename != (os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc") and confirmDialog(self, "Use this as default tint2 config?") == gtk.RESPONSE_YES:
                    tmp = self.filename
                    self.filename = os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc"
                    try:
                        shutil.copyfile(tmp, self.filename)
                    except shutil.Error:
                        pass

                #if confirmChange and confirmDialog(self, "Keep this config?") == gtk.RESPONSE_NO:
                #   shutil.copyfile(self.filename+".backup", self.filename)     # Create backup
                #   self.apply(widget, event, False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号