当前位置: 首页>>代码示例>>Python>>正文


Python QMenu.setFont方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QMenu.setFont方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.setFont方法的具体用法?Python QMenu.setFont怎么用?Python QMenu.setFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QMenu的用法示例。


在下文中一共展示了QMenu.setFont方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import setFont [as 别名]
class MainWindow(QSystemTrayIcon):

    """Main widget for Vacap, not really a window since not needed."""

    def __init__(self, icon, parent=None):
        """Tray icon main widget."""
        super(MainWindow, self).__init__(icon, parent)
        log.info("Iniciando el programa Vacap...")
        global config
        get_or_set_config()
        self.origins = config["MAKE_BACKUP_FROM"]
        self.destination = config["SAVE_BACKUP_TO"]
        self.setToolTip(__doc__ + "\n1 Click y 'Hacer Backup'!")
        self.traymenu = QMenu("Backup")
        self.traymenu.setIcon(icon)
        self.traymenu.addAction(icon, "Hacer Backup", lambda: self.backup())
        self.traymenu.setFont(QFont("Verdana", 10, QFont.Bold))
        self.setContextMenu(self.traymenu)
        self.activated.connect(self.click_trap)
        self.contextMenu().setStyleSheet(CSS_STYLE)
        add_to_startup()
        log.info("Inicio el programa Vacap.")
        self.show()
        self.showMessage("Vacap", "Copia de Seguridad Backup funcionando.")
        if config["MAKE_BACKUP_ON_STARTUP"]:
            log.info("Running Backup on Start-Up.")
            self.backup()
        if config["MAKE_BACKUP_AT_THIS_HOUR"]:
            log.info("Running Automatic Backup by Scheduled Hours.")
            self.timer = QTimer(self)
            self.timer.timeout.connect(self.run_backup_by_hour)
            self.timer.start(3600000)  # 1 Hour on Milliseconds

    def click_trap(self, value):
        """Trap the mouse tight click."""
        if value == self.Trigger:  # left click
            self.traymenu.exec_(QCursor.pos())

    def run_backup_by_hour(self):
        """Run Automatic Backup if the actual Hour equals Scheduled Hour."""
        if int(datetime.now().hour) == int(config["MAKE_BACKUP_AT_THIS_HOUR"]):
            log.info("Running Automatic Backup by Scheduled Hour.")
            _day = day_name[datetime.today().weekday()].lower()
            if config["MAKE_BACKUP_ON_WEEK_DAY"] != _day:
                log.info("Skipping Automatic Backup by Scheduled Week Day.")
                return  # if backup on weeke day not equals today, then return
            self.backup()

    def check_destination_folder(self):
        """Check destination folder."""
        log.info("Checking destination folder {}.".format(self.destination))
        # What if destination folder been removed.
        if not os.path.isdir(self.destination):
            log.critical("Folder {} does not exist, saving to {}!.".format(
                self.destination, gettempdir()))
            self.destination = gettempdir()
        # What if destination folder is not Writable by the user.
        if not os.access(self.destination, os.W_OK):
            log.critical("Folder {} permission denied (Not Writable).".format(
                self.destination))
            self.destination = gettempdir()
        # get date and time for folder name
        t = datetime.now().isoformat().lower().split(".")[0].replace(":", "_")
        # prepare a new folder with date-time inside destination folder
        log.info("Folder {} is OK for BackUp.".format(self.destination))
        self.destination = os.path.join(self.destination, t)
        if not os.path.isdir(self.destination):
            os.mkdir(self.destination)
            log.info("Created New Folder {}.".format(self.destination))

    def check_origins_folders(self):
        """Check origin folders."""
        log.info("Checking origins folders {}.".format(self.origins))
        # remove repeated items if any
        self.origins = list(set(self.origins))
        for folder_to_check in self.origins:
            # if folder is not a folder
            if not os.path.isdir(folder_to_check):
                log.critical("Folder {} dont exist.".format(folder_to_check))
                self.origins.remove(folder_to_check)
            # if folder is not readable
            elif not os.access(folder_to_check, os.R_OK):
                log.critical("Folder {} not Readable.".format(folder_to_check))
                self.origins.remove(folder_to_check)
            else:  # folder is ok
                log.info("Folder {} is OK to BackUp.".format(folder_to_check))
        return bool(len(self.origins))

    def backup(self):
        """Backup desde MAKE_BACKUP_FROM hacia SAVE_BACKUP_TO."""
        if not config["MAKE_BACKUP_WHEN_RUNNING_ON_BATTERY"]:
            if windows_is_running_on_battery():  # if is windows on battery ?
                return  # if on battery and should not make backup, then return
        self.contextMenu().setDisabled(True)
        self.check_destination_folder()
        if self.check_origins_folders():
            log.info("Starting to BackUp folders...")
            Backuper(destination=self.destination, origins=self.origins)
            self.contextMenu().setDisabled(False)
            self.showMessage("Vacap", "Copia de Seguridad Backup Termino bien")
#.........这里部分代码省略.........
开发者ID:juancarlospaco,项目名称:vacap,代码行数:103,代码来源:vacap.py


注:本文中的PyQt5.QtWidgets.QMenu.setFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。