Re: [pygame] how do I maximize the window?
Hi, here's a minimal example that works for me. Pressing 'm' toggles between maximized and restored. It shows a dark red background with a single pixel wide yellow border to show the new screen area. ## import pygame from pygame.locals import * from ctypes import windll user32 = windll.user32 ShowWindow = user32.ShowWindow IsZoomed= user32.IsZoomed SW_MAXIMIZE = 3 SW_RESTORE = 9 def getSDLWindow(): return pygame.display.get_wm_info()['window'] def SDL_Maximize(): return ShowWindow(getSDLWindow(), SW_MAXIMIZE) def SDL_Restore(): return ShowWindow(getSDLWindow(), SW_RESTORE) def SDL_IsMaximized(): return IsZoomed(getSDLWindow()) def run(): video_flags = RESIZABLE size = (640, 480) screen = pygame.display.set_mode(size, video_flags) while 1: for event in pygame.event.get(): if event.type == QUIT: return elif event.type in (KEYUP, KEYDOWN): if event.type == KEYDOWN: if event.key == K_ESCAPE: return elif event.key == K_m: if SDL_IsMaximized(): SDL_Restore() else: SDL_Maximize() elif event.type == pygame.VIDEORESIZE: size = event.size screen = pygame.display.set_mode(size, video_flags) elif event.type == pygame.VIDEOEXPOSE: screen.fill((80, 0, 0)) screen.fill((255, 255, 0), pygame.Rect(0, 0, size[0]-1, 1)) screen.fill((255, 255, 0), pygame.Rect(0, size[1]-1, size[0], 1)) screen.fill((255, 255, 0), pygame.Rect(0, 0, 1, size[1]-1)) screen.fill((255, 255, 0), pygame.Rect(size[0]-1, 0, 1, size[1])) pygame.display.flip() pygame.time.wait(1) def main(): pygame.init() run() pygame.quit() if __name__ == "__main__": main() ## If you are still having problems, what version of Pygame and SDL are you using? Some window sizing anomalies were fixed (when they reworked the code) in the latest version of SDL (1.2.12). Hope that helps, cheers, John.
Re: [pygame] how do I maximize the window?
On Sun, Oct 14, 2007 at 10:01:32AM -0400, inhahe wrote: > hmm, I'm having a problem with this. when i maximize, the title bar > goes into the right place, etc., but the actual viewing space is a > little too far up. it stops, with no border, a few pixels above the > taskbar, and starts a few pixels above the title bar but behind it so > stuff is covered up by the title bar. is there any solution to this? > Does it work correctly when you click the maximize button manually? The call to SDL_Maximize() is equivalent. To make resizing work you, you have to handle the Pygame VIDEORESIZE event and ultimately call pygame.display.set_mode() with the value of event.size. I sometimes find it all a bit tricky to get right, what with potentially having to recreate all your surfaces again, cheers, John. > On 10/14/07, John Popplewell <[EMAIL PROTECTED]> wrote: > > On Sun, Oct 14, 2007 at 04:55:14AM +, Richard wrote: > > > How do I maximize the pygame window or start it maximized? not > > > fullscreen, just > > > maximized. by code, not by clicking on the maximize button. i can't > > > find a way > > > to do this. if there's really not a way to do it, that's kind of > > > disappointing. > > Hi, > > > > you can't using a built-in Pygame function. There is iconify() but no > > corresponding restore() or maximize(). It is a limitation of the > > underlying SDL library, which is being fixed in SDL-1.3 (or SDL-2). > > > > For now, I use the ctypes module to call the platform-specific > > functions: > > > > > > > > regards, > > John. > > > >
Re: [pygame] how do I maximize the window?
hmm, I'm having a problem with this. when i maximize, the title bar goes into the right place, etc., but the actual viewing space is a little too far up. it stops, with no border, a few pixels above the taskbar, and starts a few pixels above the title bar but behind it so stuff is covered up by the title bar. is there any solution to this? On 10/14/07, John Popplewell <[EMAIL PROTECTED]> wrote: > On Sun, Oct 14, 2007 at 04:55:14AM +, Richard wrote: > > How do I maximize the pygame window or start it maximized? not fullscreen, > > just > > maximized. by code, not by clicking on the maximize button. i can't find > > a way > > to do this. if there's really not a way to do it, that's kind of > > disappointing. > Hi, > > you can't using a built-in Pygame function. There is iconify() but no > corresponding restore() or maximize(). It is a limitation of the > underlying SDL library, which is being fixed in SDL-1.3 (or SDL-2). > > For now, I use the ctypes module to call the platform-specific > functions: > > import sys > import pygame > > if sys.platform == "win32": > from ctypes import windll, Structure, c_long, c_ulong, sizeof, byref > > SW_HIDE = 0 > SW_SHOWNORMAL = 1 > SW_NORMAL = 1 > SW_SHOWMINIMIZED= 2 > SW_SHOWMAXIMIZED= 3 > SW_MAXIMIZE = 3 > SW_SHOWNOACTIVATE = 4 > SW_SHOW = 5 > SW_MINIMIZE = 6 > SW_SHOWMINNOACTIVE = 7 > SW_SHOWNA = 8 > SW_RESTORE = 9 > SW_SHOWDEFAULT = 10 > SW_FORCEMINIMIZE= 11 > SW_MAX = 11 > > SWP_NOSIZE = 0x0001 > SWP_NOMOVE = 0x0002 > SWP_NOZORDER= 0x0004 > SWP_NOREDRAW= 0x0008 > SWP_NOACTIVATE = 0x0010 > SWP_FRAMECHANGED= 0x0020 > SWP_SHOWWINDOW = 0x0040 > SWP_HIDEWINDOW = 0x0080 > SWP_NOCOPYBITS = 0x0100 > SWP_NOOWNERZORDER = 0x0200 > SWP_NOSENDCHANGING = 0x0400 > SWP_DRAWFRAME = SWP_FRAMECHANGED > SWP_NOREPOSITION= SWP_NOOWNERZORDER > > HWND_TOP= 0 > HWND_BOTTOM = 1 > HWND_TOPMOST= -1 > HWND_NOTOPMOST = -2 > > user32 = windll.user32 > IsIconic= user32.IsIconic > IsZoomed= user32.IsZoomed > ShowWindow = user32.ShowWindow > GetWindowRect = user32.GetWindowRect > SetWindowPos= user32.SetWindowPos > GetForegroundWindow = user32.GetForegroundWindow > SetForegroundWindow = user32.SetForegroundWindow > > class RECT(Structure): > _fields_ = [ > ('left',c_long), > ('top', c_long), > ('right', c_long), > ('bottom', c_long), > ] > def width(self): return self.right - self.left > def height(self): return self.bottom - self.top > > > def getSDLWindow(): > return pygame.display.get_wm_info()['window'] > > def SDL_IsIconic(): > return IsIconic(getSDLWindow()) > > def SDL_IsMaximized(): > return IsZoomed(getSDLWindow()) > > def SDL_Minimize(): > return ShowWindow(getSDLWindow(), SW_MINIMIZE) > > def SDL_Maximize(): > return ShowWindow(getSDLWindow(), SW_MAXIMIZE) > > def SDL_Restore(): > return ShowWindow(getSDLWindow(), SW_RESTORE) > > def SDL_Show(state): > state = (SW_HIDE, SW_SHOW)[bool(state)] > return ShowWindow(getSDLWindow(), state) > > def SDL_Activate(): > hWnd = getSDLWindow() > if GetForegroundWindow() != hWnd: >SetForegroundWindow(hWnd) > > def SDL_GetWindowPos(): > rc = RECT() > GetWindowRect(getSDLWindow(), byref(rc)) > return rc.left, rc.top > > def SDL_SetWindowPos(x, y): > return SetWindowPos(getSDLWindow(), 0, x, y, 0, 0, > SWP_NOZORDER|SWP_NOSIZE) > > def SDL_AlwaysOnTop(state): > zorder = (HWND_NOTOPMOST, HWND_TOPMOST)[state] > return SetWindowPos(getSDLWindow(), zorder, 0, 0, 0, 0, > SWP_NOMOVE|SWP_NOSIZE) > > else: > def SDL_IsIconic(): > return 0 > > def SDL_IsMaximized(): > return 0 > > def SDL_Minimize(): > return 0 > > def SDL_Maximize(): > return 0 > > def SDL_Restore(): > return 0 > > def SDL_Show(state): > return 0 > > def SDL_Activate(): > pass > > def SDL_GetWindowPos(): > return (-1, -1) > > def SDL_SetWindowPos(x, y): > return 0 > > def SDL_AlwaysOnTop(state): > return 0 > > > I don't have any code for X, but I don't believe it's much more > complicated. > > Equivalent functions could be added to Pygame with support for other > Windowing systems, > > regards, > John. > >
Re: [pygame] how do I maximize the window?
On Sun, Oct 14, 2007 at 04:55:14AM +, Richard wrote: > How do I maximize the pygame window or start it maximized? not fullscreen, > just > maximized. by code, not by clicking on the maximize button. i can't find a > way > to do this. if there's really not a way to do it, that's kind of > disappointing. Hi, you can't using a built-in Pygame function. There is iconify() but no corresponding restore() or maximize(). It is a limitation of the underlying SDL library, which is being fixed in SDL-1.3 (or SDL-2). For now, I use the ctypes module to call the platform-specific functions: import sys import pygame if sys.platform == "win32": from ctypes import windll, Structure, c_long, c_ulong, sizeof, byref SW_HIDE = 0 SW_SHOWNORMAL = 1 SW_NORMAL = 1 SW_SHOWMINIMIZED= 2 SW_SHOWMAXIMIZED= 3 SW_MAXIMIZE = 3 SW_SHOWNOACTIVATE = 4 SW_SHOW = 5 SW_MINIMIZE = 6 SW_SHOWMINNOACTIVE = 7 SW_SHOWNA = 8 SW_RESTORE = 9 SW_SHOWDEFAULT = 10 SW_FORCEMINIMIZE= 11 SW_MAX = 11 SWP_NOSIZE = 0x0001 SWP_NOMOVE = 0x0002 SWP_NOZORDER= 0x0004 SWP_NOREDRAW= 0x0008 SWP_NOACTIVATE = 0x0010 SWP_FRAMECHANGED= 0x0020 SWP_SHOWWINDOW = 0x0040 SWP_HIDEWINDOW = 0x0080 SWP_NOCOPYBITS = 0x0100 SWP_NOOWNERZORDER = 0x0200 SWP_NOSENDCHANGING = 0x0400 SWP_DRAWFRAME = SWP_FRAMECHANGED SWP_NOREPOSITION= SWP_NOOWNERZORDER HWND_TOP= 0 HWND_BOTTOM = 1 HWND_TOPMOST= -1 HWND_NOTOPMOST = -2 user32 = windll.user32 IsIconic= user32.IsIconic IsZoomed= user32.IsZoomed ShowWindow = user32.ShowWindow GetWindowRect = user32.GetWindowRect SetWindowPos= user32.SetWindowPos GetForegroundWindow = user32.GetForegroundWindow SetForegroundWindow = user32.SetForegroundWindow class RECT(Structure): _fields_ = [ ('left',c_long), ('top', c_long), ('right', c_long), ('bottom', c_long), ] def width(self): return self.right - self.left def height(self): return self.bottom - self.top def getSDLWindow(): return pygame.display.get_wm_info()['window'] def SDL_IsIconic(): return IsIconic(getSDLWindow()) def SDL_IsMaximized(): return IsZoomed(getSDLWindow()) def SDL_Minimize(): return ShowWindow(getSDLWindow(), SW_MINIMIZE) def SDL_Maximize(): return ShowWindow(getSDLWindow(), SW_MAXIMIZE) def SDL_Restore(): return ShowWindow(getSDLWindow(), SW_RESTORE) def SDL_Show(state): state = (SW_HIDE, SW_SHOW)[bool(state)] return ShowWindow(getSDLWindow(), state) def SDL_Activate(): hWnd = getSDLWindow() if GetForegroundWindow() != hWnd: SetForegroundWindow(hWnd) def SDL_GetWindowPos(): rc = RECT() GetWindowRect(getSDLWindow(), byref(rc)) return rc.left, rc.top def SDL_SetWindowPos(x, y): return SetWindowPos(getSDLWindow(), 0, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE) def SDL_AlwaysOnTop(state): zorder = (HWND_NOTOPMOST, HWND_TOPMOST)[state] return SetWindowPos(getSDLWindow(), zorder, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE) else: def SDL_IsIconic(): return 0 def SDL_IsMaximized(): return 0 def SDL_Minimize(): return 0 def SDL_Maximize(): return 0 def SDL_Restore(): return 0 def SDL_Show(state): return 0 def SDL_Activate(): pass def SDL_GetWindowPos(): return (-1, -1) def SDL_SetWindowPos(x, y): return 0 def SDL_AlwaysOnTop(state): return 0 I don't have any code for X, but I don't believe it's much more complicated. Equivalent functions could be added to Pygame with support for other Windowing systems, regards, John.