Example #1
0
    def resized(self, dw, dh):
        """
        Handle window resizing events.
        """
        GLViewport.resized(self, dw, dh)

        (w, h) = self.size
        if w == 0 and h == 0:
            # The window has been minimized, no need to draw anything.
            self.editor.renderer.render = False
            return

        if not self.editor.renderer.render:
            self.editor.renderer.render = True

        dis = None
        if sys.platform == 'linux2' and mcplatform.hasXlibDisplay:
            dis = mcplatform.Xlib.display.Display()
            win = dis.create_resource_object('window',
                                             display.get_wm_info()['window'])
            geom = win.query_tree().parent.get_geometry()

        if w >= 1000 and h >= 700:
            config.settings.windowWidth.set(w)
            config.settings.windowHeight.set(h)
            config.save()
            if dis:
                win.configure(height=geom.height, width=geom.width)
        elif w != 0 and h != 0:
            config.settings.windowWidth.set(1000)
            config.settings.windowHeight.set(700)
            config.save()
            if dis:
                win.configure(height=700, width=1000)
        if dw > 20 or dh > 20:
            if not hasattr(self, 'resizeAlert'):
                self.resizeAlert = self.shouldResizeAlert
            if self.resizeAlert:
                albow.alert(
                    "Window size increased. You may have problems using the cursor until MCEdit is restarted."
                )
                self.resizeAlert = False
        if dis:
            dis.sync()
Example #2
0
    def resized(self, dw, dh):
        """
        Handle window resizing events.
        """
        GLViewport.resized(self, dw, dh)

        (w, h) = self.size
        if w == 0 and h == 0:
            # The window has been minimized, no need to draw anything.
            self.editor.renderer.render = False
            return

        if not self.editor.renderer.render:
            self.editor.renderer.render = True

        dis = None
        if sys.platform == 'linux2' and mcplatform.hasXlibDisplay:
            dis = mcplatform.Xlib.display.Display()
            win = dis.create_resource_object('window', display.get_wm_info()['window'])
            geom = win.query_tree().parent.get_geometry()

        if w >= 1000 and h >= 700:
            config.settings.windowWidth.set(w)
            config.settings.windowHeight.set(h)
            config.save()
            if dis:
                win.configure(height=geom.height, width=geom.width)
        elif w !=0 and h !=0:
            config.settings.windowWidth.set(1000)
            config.settings.windowHeight.set(700)
            config.save()
            if dis:
                win.configure(height=700, width=1000)
        if dw > 20 or dh > 20:
            if not hasattr(self, 'resizeAlert'):
                self.resizeAlert = self.shouldResizeAlert
            if self.resizeAlert:
                albow.alert(
                    "Window size increased. You may have problems using the cursor until MCEdit is restarted.")
                self.resizeAlert = False
        if dis:
            dis.sync()
Example #3
0
    def resized(self, dw, dh):
        """
        Handle window resizing events.
        """
        if DEBUG_WM:
            print "############################ RESIZED ############################"

        (w, h) = self.size
        config_w, config_h = config.settings.windowWidth.get(), config.settings.windowHeight.get()
        win = self.displayContext.win

        if DEBUG_WM and win:
            print "dw", dw, "dh", dh
            print "self.size (w, h) 1", self.size, "win.get_size", win.get_size()
            print "size 1", config_w, config_h
        elif DEBUG_WM and not win:
            print "win is None, unable to print debug messages"

        if win:
            x, y =  win.get_position()
            if DEBUG_WM:
                print "position", x, y
                print "config pos", (config.settings.windowX.get(), config.settings.windowY.get())

        if w == 0 and h == 0:
            # The window has been minimized, no need to draw anything.
            self.editor.renderer.render = False
            return

        # Mac window handling works better now, but `win`
        # doesn't exist. So to get this alert to show up
        # I'm checking if the platform is darwin. This only
        # works because the code block never actually references
        # `win`, otherwise it WOULD CRASH!!!
        # You cannot change further if statements like this
        # because they reference `win`
        if win or sys.platform == "darwin":
            # Handling too small resolutions.
            # Dialog texts.
            # "MCEdit does not support window resolutions below 1000x700.\nYou may not be able to access all functions at this resolution."
            # New buttons:
            # "Don't warn me again": disable the window popup across sessions.
            #     Tooltip: "Disable this message. Definitively. Even the next time you start MCEdit."
            # "OK": dismiss the window and let go, don't pop up again for the session
            #     Tooltip: "Continue and not see this message until you restart MCEdit"
            # "Cancel": resizes the window to the minimum size
            #     Tooltip: "Resize the window to the minimum recommended resolution."

            # If the config showWindowSizeWarning is true and self.resizeAlert is true, show the popup
            if (w < 1000 or h < 680) and config.settings.showWindowSizeWarning.get():
                _w = w
                _h = h
                if self.resizeAlert:
                    answer = "_OK"

                    # Force the size only for the dimension that needs it.
                    if w < 1000 and h < 680:
                        _w = 1000
                        _h = 680
                    elif w < 1000:
                        _w = 1000
                    elif h < 680:
                        _h = 680
                    if not albow.dialogs.ask_tied_to:
                        answer = albow.ask(
                                           "MCEdit does not support window resolutions below 1000x700.\nYou may not be able to access all functions at this resolution.",
                                           ["Don't remind me again.", "OK", "Cancel"], default=1, cancel=1,
                                           responses_tooltips = {"Don't remind me again.": "Disable this message. Definitively. Even the next time you start MCEdit.",
                                                                 "OK": "Continue and not see this message until you restart MCEdit",
                                                                 "Cancel": "Resize the window to the minimum recommended resolution."},
                                           tie_widget_to=True)
                    else:
                        if not albow.dialogs.ask_tied_to._visible:
                            albow.dialogs.ask_tied_to._visible = True
                            answer = albow.dialogs.ask_tied_to.present()
                    if answer == "Don't remind me again.":
                        config.settings.showWindowSizeWarning = False
                        self.resizeAlert = False
                    elif answer == "OK":
                        w, h = self.size
                        self.resizeAlert = False
                    elif answer == "Cancel":
                        w, h = _w, _h
                else:
                    if albow.dialogs.ask_tied_to:
                        albow.dialogs.ask_tied_to.dismiss("_OK")
                        del albow.dialogs.ask_tied_to
                        albow.dialogs.ask_tied_to = None
            elif (w >= 1000 or h >= 680):
                if albow.dialogs.ask_tied_tos:
                    for ask_tied_to in albow.dialogs.ask_tied_tos:
                        ask_tied_to._visible = False
                        ask_tied_to.dismiss("_OK")
                        ask_tied_to.set_parent(None)
                        del ask_tied_to

        if not win:
            if w < 1000:
                config.settings.windowWidth.set(1000)
                w = 1000
                x = config.settings.windowX.get()

            if h < 680:
                config.settings.windowHeight.set(680)
                h = 680
                y = config.settings.windowY.get()

        if not self.editor.renderer.render:
            self.editor.renderer.render = True

        save_geom = True

        if win:
            maximized = win.get_state() == mcplatform.MAXIMIZED
            sz = map(max, win.get_size(), (w, h))

            if DEBUG_WM:
                print "sz", sz
                print "maximized", maximized, "self.maximized", self.maximized

            if maximized:
                if DEBUG_WM:
                    print "maximize, saving maximized size"
                config.settings.windowMaximizedWidth.set(sz[0])
                config.settings.windowMaximizedHeight.set(sz[1])
                config.save()
                self.saved_pos = config.settings.windowX.get(), config.settings.windowY.get()
                save_geom = False
                self.resizing = 0
                win.set_mode(sz, self.displayContext.displayMode())
            else:
                if DEBUG_WM:
                    print "size 2", config.settings.windowWidth.get(), config.settings.windowHeight.get()
                    print "config_w", config_w, "config_h", config_h
                    print "pos", config.settings.windowX.get(), config.settings.windowY.get()
                if self.maximized != maximized:
                    if DEBUG_WM:
                        print "restoring window pos and size"
                        print "(config.settings.windowX.get(), config.settings.windowY.get())", (config.settings.windowX.get(), config.settings.windowY.get())
                    (w, h) = (config_w, config_h)
                    win.set_state(1, (w, h), self.saved_pos)
                else:
                    if DEBUG_WM:
                        print "window resized"
                        print "setting size to", (w, h), "and pos to", (x,y)
                    win.set_mode((w, h), self.displayContext.displayMode())
                    win.set_position((x, y))
                config.settings.windowMaximizedWidth.set(0)
                config.settings.windowMaximizedHeight.set(0)
                config.save()
            self.maximized = maximized

        if DEBUG_WM:
            print "self.size (w, h) 2", self.size, (w, h)
            surf = pygame.display.get_surface()
            print "display surf rect", surf.get_rect()
            if win:
                if hasattr(win.base_handler, 'get_geometry'):
                    print "win.base_handler geometry", win.base_handler.get_geometry()
                    print "win.base_handler.parent geometry", win.base_handler.query_tree().parent.get_geometry()
                    print "win.base_handler.parent.parent geometry", win.base_handler.query_tree().parent.query_tree().parent.get_geometry()

        if save_geom:
            config.settings.windowWidth.set(w)
            config.settings.windowHeight.set(h)
            config.save()

        # The alert window is disabled if win is not None
        if not win and (dw > 20 or dh > 20):
            if not hasattr(self, 'resizeAlert'):
                self.resizeAlert = self.shouldResizeAlert
            if self.resizeAlert:
                albow.alert(
                    "Window size increased. You may have problems using the cursor until MCEdit is restarted.")
                self.resizeAlert = False
        if win:
            win.sync()

        GLViewport.resized(self, dw, dh)
Example #4
0
    def resized(self, dw, dh):
        """
        Handle window resizing events.
        """
        if DEBUG_WM:
            print "############################ RESIZED ############################"

        (w, h) = self.size
        config_w, config_h = config.settings.windowWidth.get(), config.settings.windowHeight.get()
        win = self.displayContext.win

        if DEBUG_WM and win:
            print "dw", dw, "dh", dh
            print "self.size (w, h) 1", self.size, "win.get_size", win.get_size()
            print "size 1", config_w, config_h
        elif DEBUG_WM and not win:
            print "win is None, unable to print debug messages"

        if win:
            x, y = win.get_position()
            if DEBUG_WM:
                print "position", x, y
                print "config pos", (config.settings.windowX.get(), config.settings.windowY.get())

        if w == 0 and h == 0:
            # The window has been minimized, no need to draw anything.
            self.editor.renderer.render = False
            return

        # Mac window handling works better now, but `win`
        # doesn't exist. So to get this alert to show up
        # I'm checking if the platform is darwin. This only
        # works because the code block never actually references
        # `win`, otherwise it WOULD CRASH!!!
        # You cannot change further if statements like this
        # because they reference `win`
        if win or sys.platform == "darwin":
            # Handling too small resolutions.
            # Dialog texts.
            # "MCEdit does not support window resolutions below 1000x700.\nYou may not be able to access all functions at this resolution."
            # New buttons:
            # "Don't warn me again": disable the window popup across sessions.
            #     Tooltip: "Disable this message. Definitively. Even the next time you start MCEdit."
            # "OK": dismiss the window and let go, don't pop up again for the session
            #     Tooltip: "Continue and not see this message until you restart MCEdit"
            # "Cancel": resizes the window to the minimum size
            #     Tooltip: "Resize the window to the minimum recommended resolution."

            # If the config showWindowSizeWarning is true and self.resizeAlert is true, show the popup
            if (w < 1000 or h < 680) and config.settings.showWindowSizeWarning.get():
                _w = w
                _h = h
                if self.resizeAlert:
                    answer = "_OK"

                    # Force the size only for the dimension that needs it.
                    if w < 1000 and h < 680:
                        _w = 1000
                        _h = 680
                    elif w < 1000:
                        _w = 1000
                    elif h < 680:
                        _h = 680
                    if not albow.dialogs.ask_tied_to:
                        answer = albow.ask(
                            "MCEdit does not support window resolutions below 1000x700.\nYou may not be able to access all functions at this resolution.",
                            ["Don't remind me again.", "OK", "Cancel"], default=1, cancel=1,
                            responses_tooltips={
                                "Don't remind me again.": "Disable this message. Definitively. Even the next time you start MCEdit.",
                                "OK": "Continue and not see this message until you restart MCEdit",
                                "Cancel": "Resize the window to the minimum recommended resolution."},
                            tie_widget_to=True)
                    else:
                        if not albow.dialogs.ask_tied_to._visible:
                            albow.dialogs.ask_tied_to._visible = True
                            answer = albow.dialogs.ask_tied_to.present()
                    if answer == "Don't remind me again.":
                        config.settings.showWindowSizeWarning.set(False)
                        self.resizeAlert = False
                    elif answer == "OK":
                        w, h = self.size
                        self.resizeAlert = False
                    elif answer == "Cancel":
                        w, h = _w, _h
                else:
                    if albow.dialogs.ask_tied_to:
                        albow.dialogs.ask_tied_to.dismiss("_OK")
                        del albow.dialogs.ask_tied_to
                        albow.dialogs.ask_tied_to = None
            elif w >= 1000 or h >= 680:
                if albow.dialogs.ask_tied_tos:
                    for ask_tied_to in albow.dialogs.ask_tied_tos:
                        ask_tied_to._visible = False
                        ask_tied_to.dismiss("_OK")
                        ask_tied_to.set_parent(None)
                        del ask_tied_to

        if not win:
            if w < 1000:
                config.settings.windowWidth.set(1000)
                w = 1000
                x = config.settings.windowX.get()

            if h < 680:
                config.settings.windowHeight.set(680)
                h = 680
                y = config.settings.windowY.get()

        if not self.editor.renderer.render:
            self.editor.renderer.render = True

        save_geom = True

        if win:
            maximized = win.get_state() == mcplatform.MAXIMIZED
            sz = map(max, win.get_size(), (w, h))

            if DEBUG_WM:
                print "sz", sz
                print "maximized", maximized, "self.maximized", self.maximized

            if maximized:
                if DEBUG_WM:
                    print "maximize, saving maximized size"
                config.settings.windowMaximizedWidth.set(sz[0])
                config.settings.windowMaximizedHeight.set(sz[1])
                config.save()
                self.saved_pos = config.settings.windowX.get(), config.settings.windowY.get()
                save_geom = False
                self.resizing = 0
                win.set_mode(sz, self.displayContext.displayMode())
            else:
                if DEBUG_WM:
                    print "size 2", config.settings.windowWidth.get(), config.settings.windowHeight.get()
                    print "config_w", config_w, "config_h", config_h
                    print "pos", config.settings.windowX.get(), config.settings.windowY.get()
                if self.maximized != maximized:
                    if DEBUG_WM:
                        print "restoring window pos and size"
                        print "(config.settings.windowX.get(), config.settings.windowY.get())", (
                        config.settings.windowX.get(), config.settings.windowY.get())
                    (w, h) = (config_w, config_h)
                    win.set_state(1, (w, h), self.saved_pos)
                else:
                    if DEBUG_WM:
                        print "window resized"
                        print "setting size to", (w, h), "and pos to", (x, y)
                    win.set_mode((w, h), self.displayContext.displayMode())
                    win.set_position((x, y))
                config.settings.windowMaximizedWidth.set(0)
                config.settings.windowMaximizedHeight.set(0)
                config.save()
            self.maximized = maximized

        if DEBUG_WM:
            print "self.size (w, h) 2", self.size, (w, h)
            surf = pygame.display.get_surface()
            print "display surf rect", surf.get_rect()
            if win:
                if hasattr(win.base_handler, 'get_geometry'):
                    print "win.base_handler geometry", win.base_handler.get_geometry()
                    print "win.base_handler.parent geometry", win.base_handler.query_tree().parent.get_geometry()
                    print "win.base_handler.parent.parent geometry", win.base_handler.query_tree().parent.query_tree().parent.get_geometry()

        if save_geom:
            config.settings.windowWidth.set(w)
            config.settings.windowHeight.set(h)
            config.save()

        # The alert window is disabled if win is not None
        if not win and (dw > 20 or dh > 20):
            if not hasattr(self, 'resizeAlert'):
                self.resizeAlert = self.shouldResizeAlert
            if self.resizeAlert:
                albow.alert(
                    "Window size increased. You may have problems using the cursor until MCEdit is restarted.")
                self.resizeAlert = False
        if win:
            win.sync()

        GLViewport.resized(self, dw, dh)
Example #5
0
    def resized(self, dw, dh):
        """
        Handle window resizing events.
        """
        if DEBUG_WM:
            print "############################ RESIZED ############################"
        GLViewport.resized(self, dw, dh)

        (w, h) = self.size
        config_w, config_h = config.settings.windowWidth.get(), config.settings.windowHeight.get()
        if DEBUG_WM:
            print "dw", dw, "dh", dh
            print "self.size (w, h) 1", self.size
            print "size 1", config_w, config_h
        if w == 0 and h == 0:
            # The window has been minimized, no need to draw anything.
            self.editor.renderer.render = False
            return

        if not self.editor.renderer.render:
            self.editor.renderer.render = True

        save_geom = True
        restore_pos = False
        flush = True
        win = self.displayContext.win
        if win:
            maximized = win.get_state() == mcplatform.MAXIMIZED
            sz = map(max, win.get_size(), (w, h))
            if DEBUG_WM:
                print "sz", sz
                print "maximized", maximized, "self.maximized", self.maximized
            if maximized:
                if DEBUG_WM:
                    print "maximize, saving maximized size"
                config.settings.windowMaximizedWidth.set(sz[0])
                config.settings.windowMaximizedHeight.set(sz[1])
                config.save()
                save_geom = False
                pygame.display.set_mode(sz, self.displayContext.displayMode())
                pygame.display.flip()
            else:
                if DEBUG_WM:
                    print "size 2", config.settings.windowWidth.get(), config.settings.windowHeight.get()
                    print "config_w", config_w, "config_h", config_h
                    print "pos", config.settings.windowX.get(), config.settings.windowY.get()
                if self.maximized != maximized:
                    flush = False
                    if DEBUG_WM:
                        print "restoring window pos and size"
                    pygame.display.set_mode((config_w, config_h), self.displayContext.displayMode())
                    pygame.display.flip()
                    if DEBUG_WM:
                        print "(config.settings.windowX.get(), config.settings.windowY.get())", (config.settings.windowX.get(), config.settings.windowY.get())
                    win.set_size((config_w, config_h), update=False)
                    win.set_position((config.settings.windowX.get(), config.settings.windowY.get()), update=True)
                    self.size = (w, h) = (config_w, config_h)
                else:
                    pygame.display.set_mode((w, h), self.displayContext.displayMode())
                config.settings.windowMaximizedWidth.set(0)
                config.settings.windowMaximizedHeight.set(0)
                config.save()
            self.maximized = maximized


        if DEBUG_WM:
            print "self.size (w, h) 2", self.size, (w, h)
            surf = pygame.display.get_surface()
            print "display surf rect", surf.get_rect()
            if win:
                try:
                    print "win.base_handler geometry", win.base_handler.get_geometry()
                    print "win.base_handler.parent geometry", win.base_handler.query_tree().parent.get_geometry()
                    print "win.base_handler.parent.parent geometry", win.base_handler.query_tree().parent.query_tree().parent.get_geometry()
                except:
                    pass

        if w >= 1000 and h >= 680:
            if save_geom:
                config.settings.windowWidth.set(w)
                config.settings.windowHeight.set(h)
                config.save()
            if win and flush:
                win.set_size(sz, update=False)
        elif w !=0 and h !=0:
            if save_geom:
                config.settings.windowWidth.set(1000)
                config.settings.windowHeight.set(680)
                config.save()
            if win and flush:
                win.set_size((1000, 680), update=False)
        # The alert window is disabled if win is not None
        if not win and (dw > 20 or dh > 20):
            if not hasattr(self, 'resizeAlert'):
                self.resizeAlert = self.shouldResizeAlert
            if self.resizeAlert:
                albow.alert(
                    "Window size increased. You may have problems using the cursor until MCEdit is restarted.")
                self.resizeAlert = False
        if win:
            win.flush()