示例#1
0
    def __init__(self, displayContext, *args):
        ws = displayContext.getWindowSize()
        r = rect.Rect(0, 0, ws[0], ws[1])
        GLViewport.__init__(self, r)
        self.displayContext = displayContext
        self.bg_color = (0, 0, 0, 1)
        self.anchor = "tlbr"

        if not config.config.has_section("Recent Worlds"):
            config.config.add_section("Recent Worlds")
            self.setRecentWorlds([""] * 5)

        self.optionsPanel = panels.OptionsPanel(self)
        if not albow.translate.buildTemplate:
            self.optionsPanel.getLanguageChoices()
            lng = config.settings.langCode.get()
            if lng not in self.optionsPanel.sgnal:
                lng = "en_US"
                config.settings.langCode.set(lng)
            albow.translate.setLang(lng)
        self.optionsPanel.initComponents()
        self.graphicsPanel = panels.GraphicsPanel(self)

        # &# Prototype for blocks/items names
        mclangres.buildResources(lang=albow.translate.getLang())
        # &#

        # .#
        self.keyConfigPanel = keys.KeyConfigPanel(self)
        # .#

        self.droppedLevel = None

        self.nbtCopyBuffer = None

        self.reloadEditor()

        """
        check command line for files dropped from explorer
        """
        if len(sys.argv) > 1:
            for arg in sys.argv[1:]:
                f = arg.decode(sys.getfilesystemencoding())
                if os.path.isdir(os.path.join(pymclevel.minecraftSaveFileDir, f)):
                    f = os.path.join(pymclevel.minecraftSaveFileDir, f)
                    self.droppedLevel = f
                    break
                if os.path.exists(f):
                    self.droppedLevel = f
                    break

        self.fileOpener = albow.FileOpener(self)
        self.add(self.fileOpener)

        self.fileOpener.focus()
示例#2
0
    def __init__(self, displayContext, *args):
        ws = displayContext.getWindowSize()
        r = rect.Rect(0, 0, ws[0], ws[1])
        GLViewport.__init__(self, r)
        self.displayContext = displayContext
        self.bg_color = (0, 0, 0, 1)
        self.anchor = 'tlbr'

        if not config.config.has_section("Recent Worlds"):
            config.config.add_section("Recent Worlds")
            self.setRecentWorlds([""] * 5)

        self.optionsPanel = panels.OptionsPanel(self)
        if not albow.translate.buildTemplate:
            self.optionsPanel.getLanguageChoices()
            lng = config.settings.langCode.get()
            if lng not in self.optionsPanel.sgnal:
                lng = "en_US"
                config.settings.langCode.set(lng)
            albow.translate.setLang(lng)
        self.optionsPanel.initComponents()
        self.graphicsPanel = panels.GraphicsPanel(self)

        #&# Prototype for blocks/items names
        mclangres.buildResources(lang=albow.translate.getLang())
        #&#

        #.#
        self.keyConfigPanel = keys.KeyConfigPanel(self)
        #.#

        self.droppedLevel = None

        self.nbtCopyBuffer = None

        self.reloadEditor()
        """
        check command line for files dropped from explorer
        """
        if len(sys.argv) > 1:
            for arg in sys.argv[1:]:
                f = arg.decode(sys.getfilesystemencoding())
                if os.path.isdir(
                        os.path.join(pymclevel.minecraftSaveFileDir, f)):
                    f = os.path.join(pymclevel.minecraftSaveFileDir, f)
                    self.droppedLevel = f
                    break
                if os.path.exists(f):
                    self.droppedLevel = f
                    break

        self.fileOpener = albow.FileOpener(self)
        self.add(self.fileOpener)

        self.fileOpener.focus()
示例#3
0
 def set_update_ui(self, v):
     GLViewport.set_update_ui(self, v)
     if v:
         #&# Prototype for blocks/items names
         mclangres.buildResources(lang=albow.translate.getLang())
         #&#
         self.keyConfigPanel = keys.KeyConfigPanel(self)
         self.graphicsPanel = panels.GraphicsPanel(self)
         if self.fileOpener in self.subwidgets:
             idx = self.subwidgets.index(self.fileOpener)
             self.remove(self.fileOpener)
             self.fileOpener = albow.FileOpener(self)
             if idx is not None:
                 self.add(self.fileOpener)
             self.fileOpener.focus()
示例#4
0
 def set_update_ui(self, v):
     GLViewport.set_update_ui(self, v)
     if v:
         #&# Prototype for blocks/items names
         mclangres.buildResources(lang=albow.translate.getLang())
         #&#
         self.keyConfigPanel = keys.KeyConfigPanel(self)
         self.graphicsPanel = panels.GraphicsPanel(self)
         if self.fileOpener in self.subwidgets:
             idx = self.subwidgets.index(self.fileOpener)
             self.remove(self.fileOpener)
             self.fileOpener = albow.FileOpener(self)
             if idx is not None:
                 self.add(self.fileOpener)
             self.fileOpener.focus()
示例#5
0
    def __init__(self, editor):
        self.editor = editor
        rect = editor.mcedit.rect
        GLViewport.__init__(self, rect)

        near = 0.5
        far = 4000.0

        self.near = near
        self.far = far

        self.brake = False
        self.lastTick = datetime.now()
        # self.nearheight = near * tang

        self.cameraPosition = (16., 45., 16.)
        self.velocity = [0., 0., 0.]

        self.yaw = -45.  # degrees
        self._pitch = 0.1

        self.cameraVector = self._cameraVector()

        # A state machine to dodge an apparent bug in pygame that generates erroneous mouse move events
        # 0 = bad event already happened
        #   1 = app just started or regained focus since last bad event
        #   2 = mouse cursor was hidden after state 1, next event will be bad
        self.avoidMouseJumpBug = 1

        config.settings.drawSky.addObserver(self)
        config.settings.drawFog.addObserver(self)
        config.settings.superSecretSettings.addObserver(self)
        config.settings.showCeiling.addObserver(self)
        config.controls.cameraAccel.addObserver(self, "accelFactor")
        config.controls.cameraMaxSpeed.addObserver(self, "maxSpeed")
        config.controls.cameraBrakingSpeed.addObserver(self, "brakeMaxSpeed")
        config.controls.invertMousePitch.addObserver(self)
        config.controls.autobrake.addObserver(self)
        config.controls.swapAxes.addObserver(self)

        config.settings.fov.addObserver(self, "fovSetting", callback=self.updateFov)

        self.mouseVector = (0, 0, 0)

        self.root = self.get_root()
示例#6
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()
示例#7
0
 def set_update_ui(self, v):
     GLViewport.set_update_ui(self, v)
     if v:
         #&# Prototype for blocks/items names
         if self.editor.level:
             if self.editor.level.gamePlatform == "Java": # added this so the original functionality of this function does not change
                 mclangres.buildResources(self.editor.level.gameVersionNumber, albow.translate.getLang())
             else:
                 mclangres.buildResources(self.editor.level.gamePlatform, albow.translate.getLang())
         #&#
         self.keyConfigPanel = keys.KeyConfigPanel(self)
         self.graphicsPanel = panels.GraphicsPanel(self)
         if self.fileOpener in self.subwidgets:
             idx = self.subwidgets.index(self.fileOpener)
             self.remove(self.fileOpener)
             self.fileOpener = albow.FileOpener(self)
             if idx is not None:
                 self.add(self.fileOpener)
             self.fileOpener.focus()
示例#8
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()
示例#9
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)
示例#10
0
    def __init__(self, displayContext, *args):
        if DEBUG_WM:
            print "############################ __INIT__ ###########################"
        self.resizeAlert = config.settings.showWindowSizeWarning.get()
        self.maximized = config.settings.windowMaximized.get()
        self.saved_pos = config.settings.windowX.get(), config.settings.windowY.get()
        if displayContext.win and DEBUG_WM:
            print "* self.displayContext.win.state", displayContext.win.get_state()
            print "* self.displayContext.win.position", displayContext.win.get_position()
            self.dis = None
            self.win = None
            self.wParent = None
            self.wGrandParent = None
            self.linux = False
            if sys.platform == 'linux2' and mcplatform.hasXlibDisplay:
                self.linux = True
                self.dis = dis = mcplatform.Xlib.display.Display()
                self.win = win = dis.create_resource_object('window', display.get_wm_info()['window'])
                curDesk = os.environ.get('XDG_CURRENT_DESKTOP')
                if curDesk in ('GNOME', 'X-Cinnamon', 'Unity'):
                    self.geomReciever = self.maximizeHandler = wParent = win.query_tree().parent
                    self.geomSender = wGrandParent = wParent.query_tree().parent
                elif curDesk == 'KDE':
                    self.maximizeHandler = win.query_tree().parent
                    wParent = win.query_tree().parent.query_tree().parent
                    wGrandParent = wParent.query_tree().parent.query_tree().parent
                    self.geomReciever = self.geomSender = win.query_tree().parent.query_tree().parent.query_tree().parent
                else:
                    self.maximizeHandler = self.geomReciever = self.geomSender = wGrandParent = wParent = None
                self.wParent = wParent
                self.wGrandParent = wGrandParent
                root = dis.screen().root
                windowID = root.get_full_property(dis.intern_atom('_NET_ACTIVE_WINDOW'), mcplatform.Xlib.X.AnyPropertyType).value[0]
                print "###\nwindowID", windowID
                window = dis.create_resource_object('window', windowID)
                print "###\nwindow.get_geometry()", window.get_geometry()
                print "###\nself.win", self.win.get_geometry()
                print "###\nself.wParent.get_geometry()", self.wParent.get_geometry()
                print "###\nself.wGrandParent.get_geometry()", self.wGrandParent.get_geometry()
                try:
                    print "###\nself.wGrandParent.query_tree().parent.get_geometry()", self.wGrandParent.query_tree().parent.get_geometry()
                except:
                    pass
                print "###\nself.maximizeHandler.get_geometry()", self.maximizeHandler.get_geometry()
                print "###\nself.geomReciever.get_geometry()", self.geomReciever.get_geometry()
                print "###\nself.geomSender.get_geometry()", self.geomSender.get_geometry()
                print "###\nself.win", self.win
                print "###\nself.wParent", self.wParent
                print "###\nself.wGrandParent", self.wGrandParent
                print "###\nself.maximizeHandler", self.maximizeHandler
                print "###\nself.geomReciever", self.geomReciever
                print "###\nself.geomSender", self.geomSender

        ws = displayContext.getWindowSize()
        r = rect.Rect(0, 0, ws[0], ws[1])
        GLViewport.__init__(self, r)
        if DEBUG_WM:
            print "self.size", self.size, "ws", ws
        if displayContext.win and self.maximized:
            # Send a maximize event now
            displayContext.win.set_state(mcplatform.MAXIMIZED)
            # Flip pygame.display to avoid to see the splash un-centered.
            pygame.display.flip()
        self.displayContext = displayContext
        self.bg_color = (0, 0, 0, 1)
        self.anchor = 'tlbr'

        if not config.config.has_section("Recent Worlds"):
            config.config.add_section("Recent Worlds")
            self.setRecentWorlds([""] * 5)

        self.optionsPanel = panels.OptionsPanel(self)
        if not albow.translate.buildTemplate:
            self.optionsPanel.getLanguageChoices()
            lng = config.settings.langCode.get()
            if lng not in self.optionsPanel.sgnal:
                lng = "en_US"
                config.settings.langCode.set(lng)
            albow.translate.setLang(lng)
        # Set the window caption here again, since the initialization is done through several steps...
        display.set_caption(('MCEdit ~ ' + release.get_version()%_("for")).encode('utf-8'), 'MCEdit')
        self.optionsPanel.initComponents()
        self.graphicsPanel = panels.GraphicsPanel(self)

        #&# Prototype for blocks/items names
        mclangres.buildResources(lang=albow.translate.getLang())
        #&#

        #.#
        self.keyConfigPanel = keys.KeyConfigPanel(self)
        #.#

        self.droppedLevel = None

        self.nbtCopyBuffer = None

        self.reloadEditor()

        """
        check command line for files dropped from explorer
        """
        if len(sys.argv) > 1:
            for arg in sys.argv[1:]:
                f = arg.decode(sys.getfilesystemencoding())
                if os.path.isdir(os.path.join(pymclevel.minecraftSaveFileDir, f)):
                    f = os.path.join(pymclevel.minecraftSaveFileDir, f)
                    self.droppedLevel = f
                    break
                if os.path.exists(f):
                    self.droppedLevel = f
                    break

        self.fileOpener = albow.FileOpener(self)
        self.add(self.fileOpener)

        self.fileOpener.focus()
示例#11
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)
示例#12
0
    def __init__(self, displayContext, *args):
        if DEBUG_WM:
            print "############################ __INIT__ ###########################"
        self.resizeAlert = config.settings.showWindowSizeWarning.get()
        self.maximized = config.settings.windowMaximized.get()
        self.saved_pos = config.settings.windowX.get(), config.settings.windowY.get()
        if displayContext.win and DEBUG_WM:
            print "* self.displayContext.win.state", displayContext.win.get_state()
            print "* self.displayContext.win.position", displayContext.win.get_position()
            self.dis = None
            self.win = None
            self.wParent = None
            self.wGrandParent = None
            self.linux = False
            if sys.platform == 'linux2' and mcplatform.hasXlibDisplay:
                self.linux = True
                self.dis = dis = mcplatform.Xlib.display.Display()
                self.win = win = dis.create_resource_object('window', display.get_wm_info()['window'])
                curDesk = os.environ.get('XDG_CURRENT_DESKTOP')
                if curDesk in ('GNOME', 'X-Cinnamon', 'Unity'):
                    self.geomReciever = self.maximizeHandler = wParent = win.query_tree().parent
                    self.geomSender = wGrandParent = wParent.query_tree().parent
                elif curDesk == 'KDE':
                    self.maximizeHandler = win.query_tree().parent
                    wParent = win.query_tree().parent.query_tree().parent
                    wGrandParent = wParent.query_tree().parent.query_tree().parent
                    self.geomReciever = self.geomSender = win.query_tree().parent.query_tree().parent.query_tree().parent
                else:
                    self.maximizeHandler = self.geomReciever = self.geomSender = wGrandParent = wParent = None
                self.wParent = wParent
                self.wGrandParent = wGrandParent
                root = dis.screen().root
                windowID = root.get_full_property(dis.intern_atom('_NET_ACTIVE_WINDOW'), mcplatform.Xlib.X.AnyPropertyType).value[0]
                print "###\nwindowID", windowID
                window = dis.create_resource_object('window', windowID)
                print "###\nwindow.get_geometry()", window.get_geometry()
                print "###\nself.win", self.win.get_geometry()
                print "###\nself.wParent.get_geometry()", self.wParent.get_geometry()
                print "###\nself.wGrandParent.get_geometry()", self.wGrandParent.get_geometry()
                try:
                    print "###\nself.wGrandParent.query_tree().parent.get_geometry()", self.wGrandParent.query_tree().parent.get_geometry()
                except:
                    pass
                print "###\nself.maximizeHandler.get_geometry()", self.maximizeHandler.get_geometry()
                print "###\nself.geomReciever.get_geometry()", self.geomReciever.get_geometry()
                print "###\nself.geomSender.get_geometry()", self.geomSender.get_geometry()
                print "###\nself.win", self.win
                print "###\nself.wParent", self.wParent
                print "###\nself.wGrandParent", self.wGrandParent
                print "###\nself.maximizeHandler", self.maximizeHandler
                print "###\nself.geomReciever", self.geomReciever
                print "###\nself.geomSender", self.geomSender

        ws = displayContext.getWindowSize()
        r = rect.Rect(0, 0, ws[0], ws[1])
        GLViewport.__init__(self, r)
        if DEBUG_WM:
            print "self.size", self.size, "ws", ws
        if displayContext.win and self.maximized:
            # Send a maximize event now
            displayContext.win.set_state(mcplatform.MAXIMIZED)
            # Flip pygame.display to avoid to see the splash un-centered.
            pygame.display.flip()
        self.displayContext = displayContext
        self.bg_color = (0, 0, 0, 1)
        self.anchor = 'tlbr'

        if not config.config.has_section("Recent Worlds"):
            config.config.add_section("Recent Worlds")
            self.setRecentWorlds([""] * 5)

        self.optionsPanel = panels.OptionsPanel(self)
        if not albow.translate.buildTemplate:
            self.optionsPanel.getLanguageChoices()
            lng = config.settings.langCode.get()
            if lng not in self.optionsPanel.sgnal:
                lng = "en_US"
                config.settings.langCode.set(lng)
            albow.translate.setLang(lng)
        # Set the window caption here again, since the initialization is done through several steps...
        display.set_caption(('MCEdit ~ ' + release.get_version() % _("for")).encode('utf-8'), 'MCEdit')
        self.optionsPanel.initComponents()
        self.graphicsPanel = panels.GraphicsPanel(self)

        #.#
        self.keyConfigPanel = keys.KeyConfigPanel(self)
        #.#

        self.droppedLevel = None

        self.nbtCopyBuffer = None

        self.reloadEditor()

        """
        check command line for files dropped from explorer
        """
        if len(sys.argv) > 1:
            for arg in sys.argv[1:]:
                f = arg.decode(sys.getfilesystemencoding())
                if os.path.isdir(os.path.join(pymclevel.minecraftSaveFileDir, f)):
                    f = os.path.join(pymclevel.minecraftSaveFileDir, f)
                    self.droppedLevel = f
                    break
                if os.path.exists(f):
                    self.droppedLevel = f
                    break

        self.fileOpener = albow.FileOpener(self)
        self.add(self.fileOpener)

        self.fileOpener.focus()
示例#13
0
 def set_update_translation(self, v):
     GLViewport.set_update_translation(self, v)
     if v:
         self.keyConfigPanel = keys.KeyConfigPanel(self)
         self.graphicsPanel = panels.GraphicsPanel(self)
示例#14
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()