示例#1
0
 def showCenter(self):
     screen = qApp.primaryScreen()
     geometry = screen.availableGeometry()
     x = geometry.x() + (geometry.width() - self.width())/2
     y = geometry.y() + (geometry.height() - self.height())/2
     self.move(x, y)
     self.show()
示例#2
0
 def showCenter(self):
     screen = qApp.primaryScreen()
     geometry = screen.availableGeometry()
     x = geometry.x() + (geometry.width() - self.width())/2
     y = geometry.y() + (geometry.height() - self.height())/2
     self.move(x, y)
     self.show()
示例#3
0
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        self.appendPlainText('修改分辨率后查看')
        # 记录最后一次的值(减少槽调用)
        self.m_rect = QRect()
        # 使用定时器来延迟触发最后一次变化
        self.m_timer = QTimer(self, timeout=self.onSolutionChanged)
        self.m_timer.setSingleShot(True)  # **重要** 保证多次信号尽量少的调用函数

        # 主要是多屏幕->无屏幕->有屏幕
        qApp.primaryScreenChanged.connect(lambda _: self.m_timer.start(1000))
        # 其它信号最终基本上都会调用该信号
        qApp.primaryScreen().virtualGeometryChanged.connect(
            lambda _: self.m_timer.start(1000))
        # DPI变化
        qApp.primaryScreen().logicalDotsPerInchChanged.connect(
            lambda _: self.m_timer.start(1000))
示例#4
0
	def shootScreen(self):
		#~ g = QRect(self.geometry())
		self.hide()
		time.sleep(1)
		pix = qApp.primaryScreen().grabWindow(QApplication.desktop().winId())
		#~ pix = QPixmap.grabWindow(QApplication.desktop().winId())
		self.show()
		#~ self.setGeometry(g)
		self.setPixmap(pix)
		self.status.showMessage('Use the crop tool and then decode the image')
示例#5
0
文件: qrshot.py 项目: thet0mmy/attic
 def shootScreen(self):
     #~ g = QRect(self.geometry())
     self.hide()
     time.sleep(1)
     pix = qApp.primaryScreen().grabWindow(QApplication.desktop().winId())
     #~ pix = QPixmap.grabWindow(QApplication.desktop().winId())
     self.show()
     #~ self.setGeometry(g)
     self.setPixmap(pix)
     self.status.showMessage('Use the crop tool and then decode the image')
 def move_cursor_to_corner(self):
     '''
     Move cursor to bottom right corner of screen.
     '''
     screen = qApp.primaryScreen()
     try:
         QCursor().setPos(screen, screen.size().width(), screen.size().height())
     except:
         # Moves the cursor the primary screen to the global screen position (x, y).
         # Sometimes, setPos(QScreen, Int, Int) API don't exists.
         QCursor().setPos(screen.size().width(), screen.size().height())
示例#7
0
def OpenVoiceInput():
    global VoiceInput
    screen = qApp.primaryScreen()
    rect = screen.availableGeometry()
    size = rect.size()
    rect.setX(rect.width() - 300)
    rect.setY(rect.height() - 200)
    VoiceInput = ShowVoiceText()
    VoiceInput.setGeometry(rect)
    VoiceInput.show()
    # qApp       . exec_                      (                         )
    return
def main():
    global view
    global settings
    global windoInfo
    global menu_controller

    cursor_pos = QCursor.pos()
    desktop = qApp.desktop()
    screen_num = desktop.screenNumber(cursor_pos)
    screen_geo = desktop.screenGeometry(screen_num)
    pixmap = qApp.primaryScreen().grabWindow(0)
    pixmap = pixmap.copy(screen_geo.x(), screen_geo.y(), screen_geo.width(), screen_geo.height())
    pixmap.save(TMP_IMAGE_FILE)

    settings.showOSD = startFromDesktopValue
    settings.tmpImageFile = TMP_IMAGE_FILE
    menu_controller = MenuController()
    windoInfo = WindowInfo(screen_num)

    notificationsInterface.ActionInvoked.connect(_actionInvoked)
    notificationsInterface.NotificationClosed.connect(_notificationClosed)

    if fullscreenValue:
        saveScreenshot(pixmap)
    elif topWindowValue:
        wInfos = windoInfo.get_windows_info()
        if len(wInfos) > 0:
            wInfo = wInfos[0]
            pix = pixmap.copy(wInfo[0] - screen_geo.x(), wInfo[1] - screen_geo.y(), wInfo[2], wInfo[3])
            saveScreenshot(pix)
    else:
        view = Window(settings, windoInfo)
        view.setX(screen_geo.x())
        view.setY(screen_geo.y())
        view.setWidth(screen_geo.width())
        view.setHeight(screen_geo.height())
        view.visibleChanged.connect(_windowVisibleChanged)

        qml_context = view.rootContext()
        qml_context.setContextProperty("windowView", view)
        qml_context.setContextProperty("qApp", qApp)
        qml_context.setContextProperty("screenWidth", view.window_info.screen_width)
        qml_context.setContextProperty("screenHeight", view.window_info.screen_height)
        qml_context.setContextProperty("_menu_controller", menu_controller)

        view.setSource(QUrl.fromLocalFile(MAIN_QML))
        view.disable_zone()
        view.showWindow()

        menu_controller.preMenuShow.connect(view.ungrabFocus)
        menu_controller.postMenuHide.connect(view.grabFocus)
示例#9
0
 def onSolutionChanged(self):
     # 获取主屏幕
     screen = qApp.primaryScreen()
     if self.m_rect == screen.availableVirtualGeometry():
         return
     self.m_rect = screen.availableVirtualGeometry()
     # 所有屏幕可用大小
     self.appendPlainText('\navailableVirtualGeometry: {0}'.format(
         str(screen.availableVirtualGeometry())))
     # 获取所有屏幕
     screens = qApp.screens()
     for screen in screens:
         self.appendPlainText(
             'screen: {0}, geometry({1}), availableGeometry({2}), logicalDotsPerInch({3}), '
             'physicalDotsPerInch({4}), refreshRate({5})'.format(
                 screen.name(), screen.geometry(),
                 screen.availableGeometry(), screen.logicalDotsPerInch(),
                 screen.physicalDotsPerInch(), screen.refreshRate()))
示例#10
0
    def main(self):
        fullscreenValue = self.argValues["fullscreen"]
        topWindowValue = self.argValues["topWindow"]
        startFromDesktopValue = self.argValues["startFromDesktop"]
        savePathValue = self.argValues["savePath"]
        noNotificationValue = self.argValues["noNotification"]

        cursor_pos = QCursor.pos()
        desktop = qApp.desktop()
        screen_num = desktop.screenNumber(cursor_pos)
        screen_geo = desktop.screenGeometry(screen_num)
        pixmap = qApp.primaryScreen().grabWindow(0)
        pixmap = pixmap.copy(screen_geo.x(), screen_geo.y(),
                             screen_geo.width(), screen_geo.height())
        pixmap.save(self.settings.tmpImageFile)

        show_osd = self.settings.getOption("showOSD", "show")
        if show_osd == True or show_osd == "true":
            self.settings.showOSD = startFromDesktopValue
            if self.settings.showOSD:
                self.settings.setOption("showOSD", "show", QVariant(False))
        else:
            self.settings.showOSD = False
        self.menu_controller = MenuController()
        self.windowInfo = WindowInfo(screen_num)

        if not noNotificationValue:
            notificationsInterface.ActionInvoked.connect(
                self._actionInvoked)
            notificationsInterface.NotificationClosed.connect(
                self._notificationClosed)

        self.pixmap = pixmap
        self.window = Window(ref(self)())

        if fullscreenValue:
            self.saveScreenshot(pixmap)
        elif topWindowValue:
            wInfo = self.windowInfo.get_active_window_info()
            pix = pixmap.copy(wInfo[0], wInfo[1], wInfo[2], wInfo[3])
            self.saveScreenshot(pix)
        else:
            self.window.setX(screen_geo.x())
            self.window.setY(screen_geo.y())
            self.window.setWidth(screen_geo.width())
            self.window.setHeight(screen_geo.height())
            self.window.windowClosing.connect(self._windowClosing)
            self.window.visibleChanged.connect(self._windowVisibleChanged)

            # NOTE: make sure that all the objects that are set as context
            # property are always referenced by others through the lifetime
            # of this application, otherwise it'll cause problems.
            qml_context = self.window.rootContext()
            qml_context.setContextProperty("windowView", self.window)
            qml_context.setContextProperty("qApp", qApp)
            qml_context.setContextProperty("screenWidth",
                self.window.window_info.screen_width)
            qml_context.setContextProperty("screenHeight",
                self.window.window_info.screen_height)
            qml_context.setContextProperty("tmpImageFile",
                self.settings.tmpImageFile)
            qml_context.setContextProperty("blurImageFile",
                self.settings.tmpBlurFile)
            qml_context.setContextProperty("mosaicImageFile",
                self.settings.tmpMosaiceFile)
            qml_context.setContextProperty("_menu_controller",
                self.menu_controller)

            self.window.setSource(QUrl.fromLocalFile(MAIN_QML))
            self.window.showWindow()
            rootObject = self.window.rootObject()
            rootObject.helpView.connect(self.helpManual)
            rootObject.setProperty("saveSpecifiedPath", savePathValue)

            self.menu_controller.preMenuShow.connect(self.window.ungrabFocus)
            self.menu_controller.postMenuHide.connect(self.window.grabFocus)
示例#11
0
    def __init__(self, theParent):

        self.mainConf = nw.CONFIG
        self.theParent = theParent
        self.theIcons = GuiIcons(self.theParent)
        self.guiPalette = QPalette()
        self.guiPath = "gui"
        self.fontPath = "fonts"
        self.syntaxPath = "syntax"
        self.cssName = "style.qss"
        self.confName = "theme.conf"
        self.themeList = []
        self.syntaxList = []

        # Loaded Theme Settings

        ## Theme
        self.themeName = ""
        self.themeDescription = ""
        self.themeAuthor = ""
        self.themeCredit = ""
        self.themeUrl = ""
        self.themeLicense = ""
        self.themeLicenseUrl = ""

        ## GUI
        self.statNone = [120, 120, 120]
        self.statUnsaved = [200, 15, 39]
        self.statSaved = [2, 133, 37]
        self.helpText = [0, 0, 0]

        # Loaded Syntax Settings

        ## Main
        self.syntaxName = ""
        self.syntaxDescription = ""
        self.syntaxAuthor = ""
        self.syntaxCredit = ""
        self.syntaxUrl = ""
        self.syntaxLicense = ""
        self.syntaxLicenseUrl = ""

        ## Colours
        self.colBack = [255, 255, 255]
        self.colText = [0, 0, 0]
        self.colLink = [0, 0, 0]
        self.colHead = [0, 0, 0]
        self.colHeadH = [0, 0, 0]
        self.colEmph = [0, 0, 0]
        self.colDialN = [0, 0, 0]
        self.colDialD = [0, 0, 0]
        self.colDialS = [0, 0, 0]
        self.colHidden = [0, 0, 0]
        self.colKey = [0, 0, 0]
        self.colVal = [0, 0, 0]
        self.colSpell = [0, 0, 0]
        self.colTagErr = [0, 0, 0]
        self.colRepTag = [0, 0, 0]
        self.colMod = [0, 0, 0]

        # Changeable Settings
        self.guiTheme = None
        self.guiSyntax = None
        self.themeRoot = None
        self.themePath = None
        self.syntaxFile = None
        self.confFile = None
        self.cssFile = None
        self.guiFontDB = QFontDatabase()

        self.loadFonts()
        self.updateFont()
        self.updateTheme()
        self.theIcons.updateTheme()

        self.getIcon = self.theIcons.getIcon
        self.getPixmap = self.theIcons.getPixmap
        self.loadDecoration = self.theIcons.loadDecoration

        # Extract Other Info
        self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX()
        self.guiScale = qApp.primaryScreen().logicalDotsPerInchX() / 96.0
        self.mainConf.guiScale = self.guiScale
        logger.verbose("GUI DPI: %.1f" % self.guiDPI)
        logger.verbose("GUI Scale: %.2f" % self.guiScale)

        # Fonts
        self.guiFont = qApp.font()

        qMetric = QFontMetrics(self.guiFont)
        self.fontPointSize = self.guiFont.pointSizeF()
        self.fontPixelSize = int(round(qMetric.height()))
        self.baseIconSize = int(round(qMetric.ascent()))
        self.textNHeight = qMetric.boundingRect("N").height()
        self.textNWidth = qMetric.boundingRect("N").width()

        # Monospace Font
        self.guiFontFixed = QFont()
        self.guiFontFixed.setPointSizeF(0.95 * self.fontPointSize)
        self.guiFontFixed.setFamily(
            QFontDatabase.systemFont(QFontDatabase.FixedFont).family())

        logger.verbose("GUI Font Family: %s" % self.guiFont.family())
        logger.verbose("GUI Font Point Size: %.2f" % self.fontPointSize)
        logger.verbose("GUI Font Pixel Size: %d" % self.fontPixelSize)
        logger.verbose("GUI Base Icon Size: %d" % self.baseIconSize)
        logger.verbose("Text 'N' Height: %d" % self.textNHeight)
        logger.verbose("Text 'N' Width: %d" % self.textNWidth)

        # Internal Mapping
        self.makeAlert = self.theParent.makeAlert
        self.tr = partial(QCoreApplication.translate, "GuiTheme")

        return
示例#12
0
    def main(self):
        fullscreenValue = self.argValues["fullscreen"]
        topWindowValue = self.argValues["topWindow"]
        startFromDesktopValue = self.argValues["startFromDesktop"]

        cursor_pos = QCursor.pos()
        desktop = qApp.desktop()
        screen_num = desktop.screenNumber(cursor_pos)
        screen_geo = desktop.screenGeometry(screen_num)
        pixmap = qApp.primaryScreen().grabWindow(0)
        pixmap = pixmap.copy(screen_geo.x(), screen_geo.y(),
                             screen_geo.width(), screen_geo.height())
        pixmap.save(self.settings.tmpImageFile)

        show_osd = self.settings.getOption("showOSD", "show")
        if show_osd == True or show_osd == "true":
            self.settings.showOSD = startFromDesktopValue
            if self.settings.showOSD:
                self.settings.setOption("showOSD", "show", QVariant(False))
        else:
            self.settings.showOSD = False
        self.menu_controller = MenuController()
        self.windowInfo = WindowInfo(screen_num)

        notificationsInterface.ActionInvoked.connect(self._actionInvoked)
        notificationsInterface.NotificationClosed.connect(
            self._notificationClosed)

        if fullscreenValue:
            self.saveScreenshot(pixmap)
        elif topWindowValue:
            wInfos = self.windowInfo.get_windows_info()
            if len(wInfos) > 0:
                wInfo = wInfos[0]
                pix = pixmap.copy(wInfo[0] - screen_geo.x(),
                                  wInfo[1] - screen_geo.y(), wInfo[2],
                                  wInfo[3])
                self.saveScreenshot(pix)
        else:
            self.window = Window(ref(self)())
            self.window.setX(screen_geo.x())
            self.window.setY(screen_geo.y())
            self.window.setWidth(screen_geo.width())
            self.window.setHeight(screen_geo.height())
            self.window.windowClosing.connect(self._windowClosing)
            self.window.visibleChanged.connect(self._windowVisibleChanged)

            # NOTE: make sure that all the objects that are set as context
            # property are always referenced by others through the lifetime
            # of this application, otherwise it'll cause problems.
            qml_context = self.window.rootContext()
            qml_context.setContextProperty("windowView", self.window)
            qml_context.setContextProperty("qApp", qApp)
            qml_context.setContextProperty(
                "screenWidth", self.window.window_info.screen_width)
            qml_context.setContextProperty(
                "screenHeight", self.window.window_info.screen_height)
            qml_context.setContextProperty("tmpImageFile",
                                           self.settings.tmpImageFile)
            qml_context.setContextProperty("blurImageFile",
                                           self.settings.tmpBlurFile)
            qml_context.setContextProperty("mosaicImageFile",
                                           self.settings.tmpMosaiceFile)
            qml_context.setContextProperty("_menu_controller",
                                           self.menu_controller)

            self.window.setSource(QUrl.fromLocalFile(MAIN_QML))
            self.window.showWindow()

            self.menu_controller.preMenuShow.connect(self.window.ungrabFocus)
            self.menu_controller.postMenuHide.connect(self.window.grabFocus)
示例#13
0
 def move_cursor_to_corner(self):
     '''
     Move cursor to bottom right corner of screen.
     '''
     screen = qApp.primaryScreen()
     QCursor().setPos(screen, screen.size().width(), screen.size().height())
示例#14
0
    def __init__(self):

        self.mainConf = novelwriter.CONFIG
        self.iconCache = GuiIcons(self)

        # Loaded Theme Settings
        # =====================

        # Theme
        self.themeName = ""
        self.themeDescription = ""
        self.themeAuthor = ""
        self.themeCredit = ""
        self.themeUrl = ""
        self.themeLicense = ""
        self.themeLicenseUrl = ""

        # GUI
        self.statNone = [120, 120, 120]
        self.statUnsaved = [200, 15, 39]
        self.statSaved = [2, 133, 37]
        self.helpText = [0, 0, 0]

        # Loaded Syntax Settings
        # ======================

        # Main
        self.syntaxName = ""
        self.syntaxDescription = ""
        self.syntaxAuthor = ""
        self.syntaxCredit = ""
        self.syntaxUrl = ""
        self.syntaxLicense = ""
        self.syntaxLicenseUrl = ""

        # Colours
        self.colBack = [255, 255, 255]
        self.colText = [0, 0, 0]
        self.colLink = [0, 0, 0]
        self.colHead = [0, 0, 0]
        self.colHeadH = [0, 0, 0]
        self.colEmph = [0, 0, 0]
        self.colDialN = [0, 0, 0]
        self.colDialD = [0, 0, 0]
        self.colDialS = [0, 0, 0]
        self.colHidden = [0, 0, 0]
        self.colKey = [0, 0, 0]
        self.colVal = [0, 0, 0]
        self.colSpell = [0, 0, 0]
        self.colError = [0, 0, 0]
        self.colRepTag = [0, 0, 0]
        self.colMod = [0, 0, 0]

        # Changeable Settings
        self.guiTheme = None
        self.guiSyntax = None
        self.syntaxFile = None
        self.cssFile = None
        self.guiFontDB = QFontDatabase()

        # Class Setup
        # ===========

        self._guiPalette = QPalette()
        self._themeList = []
        self._syntaxList = []
        self._availThemes = {}
        self._availSyntax = {}

        self._listConf(self._availSyntax,
                       os.path.join(self.mainConf.dataPath, "syntax"))
        self._listConf(self._availSyntax,
                       os.path.join(self.mainConf.assetPath, "syntax"))
        self._listConf(self._availThemes,
                       os.path.join(self.mainConf.dataPath, "themes"))
        self._listConf(self._availThemes,
                       os.path.join(self.mainConf.assetPath, "themes"))

        self.updateFont()
        self.updateTheme()
        self.iconCache.updateTheme()

        # Icon Functions
        self.getIcon = self.iconCache.getIcon
        self.getPixmap = self.iconCache.getPixmap
        self.getItemIcon = self.iconCache.getItemIcon
        self.loadDecoration = self.iconCache.loadDecoration

        # Extract Other Info
        self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX()
        self.guiScale = qApp.primaryScreen().logicalDotsPerInchX() / 96.0
        self.mainConf.guiScale = self.guiScale
        logger.verbose("GUI DPI: %.1f", self.guiDPI)
        logger.verbose("GUI Scale: %.2f", self.guiScale)

        # Fonts
        self.guiFont = qApp.font()

        qMetric = QFontMetrics(self.guiFont)
        self.fontPointSize = self.guiFont.pointSizeF()
        self.fontPixelSize = int(round(qMetric.height()))
        self.baseIconSize = int(round(qMetric.ascent()))
        self.textNHeight = qMetric.boundingRect("N").height()
        self.textNWidth = qMetric.boundingRect("N").width()

        # Monospace Font
        self.guiFontFixed = QFont()
        self.guiFontFixed.setPointSizeF(0.95 * self.fontPointSize)
        self.guiFontFixed.setFamily(
            QFontDatabase.systemFont(QFontDatabase.FixedFont).family())

        logger.verbose("GUI Font Family: %s", self.guiFont.family())
        logger.verbose("GUI Font Point Size: %.2f", self.fontPointSize)
        logger.verbose("GUI Font Pixel Size: %d", self.fontPixelSize)
        logger.verbose("GUI Base Icon Size: %d", self.baseIconSize)
        logger.verbose("Text 'N' Height: %d", self.textNHeight)
        logger.verbose("Text 'N' Width: %d", self.textNWidth)

        return
示例#15
0
def defaultDpiY():
    screen = qApp.primaryScreen()
    if screen:
        return round(screen.logicalDotsPerInchY())

    return 96.0