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


Python Surface.dispose方法代码示例

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


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

示例1: trayApp

# 需要导入模块: from surface import Surface [as 别名]
# 或者: from surface.Surface import dispose [as 别名]
class trayApp(QSystemTrayIcon):
    def __init__(self, parent=None):
        super(trayApp, self).__init__(parent)
        self.loadSettings()
        self.setIcon(QIcon("icon.png"))
        self.createSysTrayMenu()
        self.setGlobalHotkeys()
        self.imgurClient = Imgur("", "")
        self.clipboard = QApplication.clipboard()

    def createSysTrayMenu(self):
        self.sysTrayMenu = QMenu()
        self.setContextMenu(self.sysTrayMenu)
        self.createSysTrayActions()

    def createSysTrayActions(self):
        self.sysTrayMenuRegionAction = self.createAction("&Capture region", self.createDrawSurface, self.hotkey)
        self.sysTrayMenuHotkeyAction = self.createAction("&Change hotkey...", self.createKeySequenceDialog)
        self.sysTrayMenuUploadAction = self.createAction("&Upload to imgur", checkable=True)
        self.sysTrayMenuUploadAction.setChecked(self.upload)
        self.sysTrayMenuSaveAction = self.createAction("&Save locally", checkable=True)
        self.sysTrayMenuSaveAction.setChecked(self.save)
        self.sysTrayMenuExitAction = self.createAction("&Exit", self.quit)

        self.addActions(self.sysTrayMenu, (self.sysTrayMenuRegionAction,
                                           None,
                                           self.sysTrayMenuHotkeyAction,
                                           self.sysTrayMenuUploadAction,
                                           self.sysTrayMenuSaveAction,
                                           self.sysTrayMenuExitAction))

    def createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False):
        action = QAction(text, self)
        if slot is not None:
            action.triggered.connect(slot)
        if shortcut is not None:
            action.setShortcut(shortcut)
        if icon is not None:
            action.setIcon(QIcon(":/{}.png".format(icon)))
        if tip is not None:
            action.setToolTip(tip)
            action.setStatusTip(tip)
        if checkable:
            action.setCheckable(True)
        return action

    def addActions(self, target, actions):
        for action in actions:
            if action is None:
                target.addSeparator()
            else:
                target.addAction(action)

    def createKeySequenceDialog(self):
        self.keySequenceDialog = KeySequenceDialog(self.hotkey)
        self.keySequenceDialog.accepted.connect(self.changeHotkey)
        self.keySequenceDialog.show()

    def changeHotkey(self):
        text = self.keySequenceDialog.keySequenceLineEdit.text()
        if text:
            self.hotkey = text
            self.sysTrayMenuRegionAction.setShortcut(self.hotkey)
            self.sysTrayMenuRegionGlobalHotkey.setShortcut(QKeySequence(self.hotkey))

    def loadSettings(self):
        settings = QSettings("ninjapic", "settings")
        self.upload = settings.value("upload").toBool()
        self.save = settings.value("save").toBool()
        self.hotkey = settings.value("hotkey").toString()
        if not self.hotkey:
            self.hotkey = "Alt+C"

    def saveSettings(self):
        settings = QSettings("ninjapic", "settings")
        settings.setValue("upload", self.sysTrayMenuUploadAction.isChecked())
        settings.setValue("save", self.sysTrayMenuSaveAction.isChecked())
        settings.setValue("hotkey", self.hotkey)

    def createDrawSurface(self):
        self.surface = Surface()
        self.surface.imageReady.connect(self.storeImage)
        self.surface.show()

    def setGlobalHotkeys(self):
        self.sysTrayMenuRegionGlobalHotkey = QxtGlobalShortcut()
        self.sysTrayMenuRegionGlobalHotkey.setShortcut(QKeySequence(self.hotkey))
        self.sysTrayMenuRegionGlobalHotkey.activated.connect(self.createDrawSurface)

    def storeImage(self):
        if not self.surface.image.save("screenshot.png", "PNG", -1):
            QMessageBox.warning(None, "Image Error", "The image couldn't be saved.")
            return
        if self.sysTrayMenuUploadAction.isChecked():
            try:
                uploaded_image = self.imgurClient.upload_image("screenshot.png")
                self.clipboard.setText(uploaded_image.link)
                webbrowser.open(uploaded_image.link)
            except HTTPError, e:
                self.surface.dispose()
#.........这里部分代码省略.........
开发者ID:Catgroove,项目名称:ninjapic,代码行数:103,代码来源:__main__.py


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