Exemplo n.º 1
0
    def set_size(width=None, height=None, depth=32):
        """
        **Note: only works when the display mode is available**

        Set the primary Windows display to the specified mode

        Example
        --------
        >>> screen = Screen()                                  # Create a new screen instance
        >>> highest_size = screen.get_displaymodes()[-1]       # Gets the highest available display mode
        >>> screen.set_size(highest_size[0], highest_size[1])  # Sets the display mode to the highest available

        :param width: The screen width to set the display mode to
        :param height: The screen height to set the display mode to
        :param depth: The screen depth to set the display mode to
        :returns: Nothing
        """

        # Gave up on ctypes, the struct is really complicated
        # user32.ChangeDisplaySettingsW(None, 0)
        import win32api
        if width and height:

            if not depth:
                depth = 32

            mode = win32api.EnumDisplaySettings()
            mode.PelsWidth = width
            mode.PelsHeight = height
            mode.BitsPerPel = depth

            win32api.ChangeDisplaySettings(mode, 0)
        else:
            win32api.ChangeDisplaySettings(None, 0)
Exemplo n.º 2
0
    def tgFullScreen(self, e=None):
        self.fs = not self.fs
        self.root.attributes("-fullscreen", self.fs)

        if PLATFORM == "darwin":
            if self.fs:  # For easier zoom
                px = (self.root.winfo_screenwidth() - self.W) // 2
                py = (self.root.winfo_screenheight() - self.H) // 2
                self.d.grid(padx=px, pady=py)
            else:
                self.d.grid(padx=0, pady=0)
                self.root.geometry("{}x{}+0+0".format(self.W, self.H))
                self.root.title("AXI Combat")

        if PLATFORM != "win32": return
        if not self.activeFS: return

        if self.fs:
            res = sorted(self.getResolutions())
            w = self.W
            h = self.H
            for x in res:
                if (x[0] >= w) and (x[1] >= h):
                    w, h = x
                    break
            dm = pywintypes.DEVMODEType()
            dm.PelsWidth = w
            dm.PelsHeight = h
            dm.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
            win32api.ChangeDisplaySettings(dm, 0)
        else:
            win32api.ChangeDisplaySettings(None, 0)
Exemplo n.º 3
0
def set_display(width, height, orient=0, depth=32, hz=60):
    '''
        Attempts to set the display settings to given parameters.  If
        valid, they will take hold at next boot.
        Arguments:
            width           Resolution in pixels, as integer.
            height
        Options:
            orient          Orientation, 0:std, 1:90 deg, 2:180, 3:270.
            depth           Color depth.
            hz              Refresh rate in cycles/second.
        Note:
            The combination chosen may not be available; an error will be logged.
    '''
    import win32api as api, win32con as con, pywintypes
    retvals = dict((getattr(con, c), c) for c in dir(con)  # get names
                   if c.startswith('DISP_'))

    def get_display_modes():
        display_modes = {}
        n = 0
        while True:
            try:
                devmode = api.EnumDisplaySettings(None, n)
            except pywintypes.error:
                break
            else:
                key = (devmode.BitsPerPel, devmode.PelsWidth,
                       devmode.PelsHeight, devmode.DisplayFrequency,
                       devmode.DisplayOrientation)
                display_modes[key] = devmode
                n += 1
        return display_modes

    if orient in (0, 2):  # landscape
        mode_requested = (depth, width, height, hz, orient)
    else:  # portrait
        mode_requested = (depth, height, width, hz, orient)
    _log.info(
        'Attempting to set display resolution to: %s; deferred until ' +
        'next boot.', (width, height, orient, depth, hz))
    devmode = get_display_modes().get(mode_requested)
    if (devmode and api.ChangeDisplaySettings(devmode, con.CDS_TEST)
            == 0):  # check first
        r = api.ChangeDisplaySettings(
            devmode,  # defer until next boot
            con.CDS_UPDATEREGISTRY | con.CDS_NORESET | con.CDS_GLOBAL)
        _log.debug('win32api.ChangeDisplaySettings() returned: %s' %
                   retvals.get(r, r))
    else:
        _log.error('Display mode %s not supported.' % (mode_requested, ))
Exemplo n.º 4
0
def set_scrn_resol(width, height):
    # 利用win32api库修改屏幕分辨率
    dm = win32api.EnumDisplaySettings(None, 0)
    dm.PelsWidth = width
    dm.PelsHeight = height
    dm.BitsPerPel = 32
    dm.DisplayFixedOutput = 0
    win32api.ChangeDisplaySettings(dm, 0)
Exemplo n.º 5
0
def setScreenPx(width=1920, height=1080):
    width, height = int(width), int(height)
    dm = win32api.EnumDisplaySettings(None, 0)
    dm.PelsHeight = height
    dm.PelsWidth = width
    dm.BitsPerPel = 32
    dm.DisplayFixedOutput = 0
    win32api.ChangeDisplaySettings(dm, 0)
Exemplo n.º 6
0
def set_resolution(gamestream_width, gamestream_height):
    print("Switching resolution to {0}x{1}".format(gamestream_width,
                                                   gamestream_height))
    devmode = pywintypes.DEVMODEType()
    devmode.PelsWidth = int(gamestream_width)
    devmode.PelsHeight = int(gamestream_height)
    devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
    win32api.ChangeDisplaySettings(devmode, 0)
Exemplo n.º 7
0
    def _win32_set(width=None, height=None, depth=32):

        # Gave up on ctypes, the struct is really complicated
        import win32api
        if width and height:

            if not depth:
                depth = 32

            mode = win32api.EnumDisplaySettings()
            mode.PelsWidth = width
            mode.PelsHeight = height
            mode.BitsPerPel = depth

            win32api.ChangeDisplaySettings(mode, 0)
        else:
            win32api.ChangeDisplaySettings(None, 0)
Exemplo n.º 8
0
 def SetScreen(width, height, depth) -> None:
     '''需安装pywin32'''
     import win32api
     dm = win32api.EnumDisplaySettings(None, 0)
     dm.PelsHeight = height
     dm.PelsWidth = width
     dm.BitsPerPel = depth
     dm.DisplayFixedOutput = 0
     win32api.ChangeDisplaySettings(dm, 0)
    def _win32_set(width=None, height=None, depth=32):
        '''
        Set the primary windows display to the specified mode
        '''
        # Gave up on ctypes, the struct is really complicated
        #user32.ChangeDisplaySettingsW(None, 0)
        if width and height:
            if not depth:
                depth = 32

            mode = win32api.EnumDisplaySettings()
            mode.PelsWidth = width
            mode.PelsHeight = height
            mode.BitsPerPel = depth

            win32api.ChangeDisplaySettings(mode, 0)
        else:
            win32api.ChangeDisplaySettings(None, 0)
Exemplo n.º 10
0
        def _win32_set(
                width=None,
                height=None,
                depth=32
        ):  # Set the primary windows display to the specified mode
            # Gave up on ctypes, the struct is really complicated
            import win32api
            from pywintypes import DEVMODEType
            if width and height:

                if not depth:
                    depth = 32

                mode = win32api.EnumDisplaySettings()
                mode.PelsWidth = width
                mode.PelsHeight = height
                mode.BitsPerPel = depth

                win32api.ChangeDisplaySettings(mode, 0)
            else:
                win32api.ChangeDisplaySettings(None, 0)
Exemplo n.º 11
0
def rotateTO(rotateDic):
    display_num = 0  # display 1
    device = win32.EnumDisplayDevices(None, display_num)
    dm = win32.EnumDisplaySettings(device.DeviceName,
                                   win32con.ENUM_CURRENT_SETTINGS)
    if 0 != dm:
        dm.PelsWidth, dm.PelsHeight = dm.PelsHeight, dm.PelsWidth
        dm.DisplayOrientation = int(rotateDic / 90)
        iRet = win32.ChangeDisplaySettings(dm, 0)
    if win32con.DISP_CHANGE_SUCCESSFUL != iRet:
        print("Failed(Already) to rotate " + str(rotateDic) + " degrees")
    return win32.ChangeDisplaySettingsEx(device.DeviceName, dm)
Exemplo n.º 12
0
    def _win32_set(width=None, height=None, depth=32):
        '''
        Set the primary windows display to the specified mode
        '''
        import win32api
        import win32con

        if not depth:
            depth = 32

        if not width or not height:
            win32api.ChangeDisplaySettings(None, 0)
            return

        mode = win32api.EnumDisplaySettings()
        mode.PelsWidth = width
        mode.PelsHeight = height
        mode.BitsPerPel = depth
        mode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT

        win32api.ChangeDisplaySettings(mode, 0)
Exemplo n.º 13
0
def set_resolution(gamestream_width, gamestream_height, refresh_rate=None):
    if refresh_rate is None:
        print("Switching resolution to {0}x{1}".format(gamestream_width,
                                                       gamestream_height))
    else:
        print("Switching resolution to {0}x{1} at {2}Hz".format(
            gamestream_width, gamestream_height, refresh_rate))
    devmode = pywintypes.DEVMODEType()
    devmode.PelsWidth = int(gamestream_width)
    devmode.PelsHeight = int(gamestream_height)
    devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
    if refresh_rate is not None:
        devmode.DisplayFrequency = refresh_rate
        devmode.Fields |= win32con.DM_DISPLAYFREQUENCY
    win32api.ChangeDisplaySettings(devmode, 0)
Exemplo n.º 14
0
def runGUI(P, *args):
    try:
        app = ThreeDVisualizer(P, *args)
        if PLATFORM == "win32": writeRes(app)
        app.mainloop()
        if PLATFORM == "win32": win32api.ChangeDisplaySettings(None, 0)
        time.sleep(0.2)
        app.finish()
    except Exception as e:
        logError(e, "main")
        raise
    finally:
        print("UI closed")
        if hasattr(app, "selfServe"):
            app.selfServe.terminate()
Exemplo n.º 15
0
 def set_display_resolution(size, display=None):
     """
 @param  size  (int w, int h)
 @return  bool
 """
     try:
         if not display:
             display = get_display()
         if size == (display.PelsWidth, display.PelsHeight):
             return True
         display.PelsWidth, display.PelsHeight = size
         return win32con.DISP_CHANGE_SUCCESSFUL == win32api.ChangeDisplaySettings(
             display, 0)  # 0 means do change
     except Exception, e:
         dwarn(e)
         return False
import win32api
import win32con
import pywintypes
devmode = pywintypes.DEVMODEType()
devmode.PelsWidth = 640
devmode.PelsHeight = 480
devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode, 0)
Exemplo n.º 17
0
import win32api
dm = win32api.EnumDisplaySettings(None, 0)
dm.PelsHeight = 1080
dm.PelsWidth = 1920
dm.BitsPerPel = 32
dm.DisplayFixedOutput = 0
win32api.ChangeDisplaySettings(dm, 0)
Exemplo n.º 18
0
resolution_list = [[3840, 2160], [2556, 1440], [1920, 1080], [1680, 1050],
                   [1600, 1024], [1600, 900]]

depth = 32
response = -2
resItem = 0
attempts = 10

while response != 0 and attempts != 0:
    width = resolution_list[resItem][0]
    height = resolution_list[resItem][1]

    mode1 = win32api.EnumDisplaySettings()
    mode1.PelsWidth = width
    mode1.PelsHeight = height
    mode1.BitsPerPel = depth

    response = win32api.ChangeDisplaySettings(mode1, 0)

    outcome = "failed"
    if response == 0:
        outcome = "success"

    message = "trying resolution %d x %d....%s code: %d" % (width, height,
                                                            outcome, response)
    logger.info(message)
    print(message)

    resItem += 1
    attempts -= 1
Exemplo n.º 19
0
import sys
import win32api
from pywintypes import DEVMODEType

resolution_list = [[1920,1080], [1680,1050], [1600,1024], [1600,900]]

depth = 32
success = -2
resItem = 0
attempts = 5

while success != 0 and attempts != 0:
    width = resolution_list[resItem][0]
    height = resolution_list[resItem][1]
    
    print("trying resolution ", width, " x ", height)
    
    mode1 = win32api.EnumDisplaySettings()
    mode1.PelsWidth = width
    mode1.PelsHeight = height
    mode1.BitsPerPel = depth

    success = win32api.ChangeDisplaySettings(mode1, 0)
    print(success)
    resItem += 1
    attempts -= 1
Exemplo n.º 20
0
    def _set_mode_windows(self, mode):
        print("REFRESH RATE TOOL: setting mode", mode)
        if not win32api:
            print("win32api not available, returning")
            return False
        k = 0
        while True:
            try:
                settings = win32api.EnumDisplaySettingsEx(None, k, EDS_RAWMODE)
            except win32api.error:
                break
            refresh = float(settings.DisplayFrequency)
            width = int(settings.PelsWidth)
            height = int(settings.PelsHeight)
            bpp = int(settings.BitsPerPel)
            flags = int(settings.DisplayFlags)
            # print(width, height, refresh, bpp, flags)
            # modes.append({'width': width, 'height': height,
            #        'refresh': refresh, 'bpp': bpp, 'flags': flags})
            if (width == mode["width"] and height == mode["height"]
                    and refresh == mode["refresh"] and bpp == mode["bpp"]
                    and flags == mode["flags"]):

                # print("trying to override with refresh", int(round(self.game_refresh)))
                # #refresh == mode['refresh'] and \
                # settings.DisplayFrequency = int(round(self.game_refresh))
                # result = win32api.ChangeDisplaySettings(settings,
                #         win32con.CDS_UPDATEREGISTRY) #win32con.CDS_FULLSCREEN)
                #         #0) #win32con.CDS_FULLSCREEN)
                # if result == win32con.DISP_CHANGE_SUCCESSFUL:
                #     print("display change was successful")
                #     return True
                # print("failed, falling back to ", mode['refresh'])
                # settings.DisplayFrequency = mode['refresh']
                print("found windows mode, changing display settings")
                result = win32api.ChangeDisplaySettings(
                    settings, win32con.CDS_UPDATEREGISTRY)
                # win32con.CDS_FULLSCREEN)

                if result == win32con.DISP_CHANGE_SUCCESSFUL:
                    print("display change was successful")
                    return True
                else:
                    print("display change failed, result =", result)
                    return False
            k += 1

        # for omode in self.get_override_modes():
        #     print("trying override mode", omode)
        #     if omode['width'] == mode['width'] and \
        #             omode['height'] == mode['height'] and \
        #             omode['refresh'] == mode['refresh'] and \
        #             omode['bpp'] == mode['bpp'] and \
        #             omode['flags'] == mode['flags']:
        #         settings.PelsWidth = omode['width']
        #         settings.PelsHeight = omode['height']
        #         settings.BitsPerPel = omode['bpp']
        #         settings.DisplayFlags = omode['flags']
        #         settings.DisplayFrequency = omode['refresh']
        #         result = win32api.ChangeDisplaySettings(settings,
        #                 win32con.CDS_UPDATEREGISTRY) #win32con.CDS_FULLSCREEN)
        #                 #0) #win32con.CDS_FULLSCREEN)
        #         if result == win32con.DISP_CHANGE_SUCCESSFUL:
        #             print("display change was successful")
        #             return True
        #         else:
        #             print("display change failed, result =", result)
        #             return False
        return False
Exemplo n.º 21
0
        win32api.CloseHandle(playnite_mutex_handle)

    else:
        print(
            "No valid close_watch_method in the config. Press Enter when you're done."
        )
        input()

# Terminate background and launch session_end programs, if they're available
kill_processes(cfg_bg_paths)
launch_processes(cfg_end_paths)

# Restore original resolution
if skip_res_reset == False:
    print('Restoring original resolution.')
    win32api.ChangeDisplaySettings(None, 0)

# Kill gamestream
if no_nv_kill == False:
    print("Terminating GameStream session.")
    if "nvstreamer.exe" in (get_process_name(p)
                            for p in psutil.process_iter()):
        os.system('taskkill /f /im nvstreamer.exe')

if sleep_on_exit == '1':
    # Put computer to sleep
    print("Going to sleep")
    os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")

if debug == '1':
    # Leave window open for debugging