pull from pyflakes branch: unravel/mangle imports

This commit is contained in:
David Sowder 2012-03-11 16:05:50 -05:00
parent a8ad2a5186
commit fead577efd
6 changed files with 830 additions and 857 deletions

View File

@ -9,9 +9,10 @@ OpenGLContext.scenegraph.boundingvolume module.
Based on code from:
http://www.markmorley.com/opengl/frustumculling.html
"""
from OpenGL.GL import *
from numpy import *
import logging
import logging
import numpy
import OpenGL.GL
context_log = logging.getLogger()
@ -30,9 +31,9 @@ def viewingMatrix(projection=None, model=None):
matrix, the function will raise a RuntimeError
"""
if projection is None:
projection = glGetDoublev(GL_PROJECTION_MATRIX)
projection = OpenGL.GL.glGetDoublev(OpenGL.GL.GL_PROJECTION_MATRIX)
if model is None:
model = glGetDoublev(GL_MODELVIEW_MATRIX)
model = OpenGL.GL.glGetDoublev(OpenGL.GL.GL_MODELVIEW_MATRIX)
# hmm, this will likely fail on 64-bit platforms :(
if projection is None or model is None:
context_log.warn(
@ -44,20 +45,20 @@ def viewingMatrix(projection=None, model=None):
if model:
return model
else:
return identity(4, 'd')
if allclose(projection, -1.79769313e+308):
return numpy.identity(4, 'd')
if numpy.allclose(projection, -1.79769313e+308):
context_log.warn(
"""Attempt to retrieve projection matrix when uninitialised %s, model=%s""",
projection, model,
)
return model
if allclose(model, -1.79769313e+308):
if numpy.allclose(model, -1.79769313e+308):
context_log.warn(
"""Attempt to retrieve model-view matrix when uninitialised %s, projection=%s""",
model, projection,
)
return projection
return dot(model, projection)
return numpy.dot(model, projection)
class Frustum (object):
@ -84,15 +85,15 @@ class Frustum (object):
frustcullaccel C extension module)
"""
distances = sum(self.planes[newaxis, :, :] * points[:, newaxis, :], -1)
distances = sum(self.planes[OpenGL.GL.newaxis, :, :] * points[:, OpenGL.GL.newaxis, :], -1)
return ~any(distances < -radius, -1)
def visible1(self, point, radius):
#return self.visible(array(point[newaxis, :]), radius)
#return self.visible(array(point[OpenGL.GL.newaxis, :]), radius)
distance = sum(self.planes * point, -1)
vis = ~any(distance < -radius)
#assert vis == self.visible(array(point)[newaxis, :], radius)
#assert vis == self.visible(array(point)[OpenGL.GL.newaxis, :], radius)
return vis
@ -113,8 +114,8 @@ class Frustum (object):
"""
if matrix is None:
matrix = viewingMatrix()
clip = ravel(matrix)
frustum = zeros((6, 4), 'd')
clip = numpy.ravel(matrix)
frustum = numpy.zeros((6, 4), 'd')
# right
frustum[0][0] = clip[3] - clip[0]
frustum[0][1] = clip[7] - clip[4]
@ -155,10 +156,10 @@ class Frustum (object):
@classmethod
def normalize(cls, frustum):
"""Normalize clipping plane equations"""
magnitude = sqrt(frustum[:, 0] * frustum[:, 0] + frustum[:, 1] * frustum[:, 1] + frustum[:, 2] * frustum[:, 2])
magnitude = numpy.sqrt(frustum[:, 0] * frustum[:, 0] + frustum[:, 1] * frustum[:, 1] + frustum[:, 2] * frustum[:, 2])
# eliminate any planes which have 0-length vectors,
# those planes can't be used for excluding anything anyway...
frustum = compress(magnitude, frustum, 0)
magnitude = compress(magnitude, magnitude, 0)
magnitude = reshape(magnitude.astype('d'), (len(frustum), 1))
frustum = numpy.compress(magnitude, frustum, 0)
magnitude = numpy.compress(magnitude, magnitude, 0)
magnitude = numpy.reshape(magnitude.astype('d'), (len(frustum), 1))
return frustum / magnitude

File diff suppressed because it is too large Load Diff

224
mcedit.py
View File

@ -5,55 +5,51 @@ mcedit.py
Startup, main menu, keyboard configuration, automatic updating.
"""
import os
import os.path
import sys
import config
import shutil
import functools
import traceback
import logging
import pygame
from pygame.constants import *
from pygame import key, display, rect
import albow
from albow.dialogs import Dialog
from albow.openglwidgets import GLViewport
from albow.root import RootWidget
from albow.dialogs import Dialog
from albow import *
import config
import directories
import functools
from glbackground import Panel
from OpenGL import GL
from numpy import *
from pymclevel.mclevel import MCInfdevOldLevel, saveFileDir
from pymclevel.materials import *
MCInfdevOldLevel.loadedChunkLimit = 0
from release import release
import glutils
import leveleditor
from leveleditor import ControlSettings, Settings
import logging
import mceutils
import mcplatform
from mceutils import *
from mcplatform import platform_open
from leveleditor import Settings, ControlSettings
import numpy
from OpenGL import GL
import os
import os.path
import pygame
from pygame import display, key, rect
import pymclevel
import release
import shutil
import sys
import traceback
pymclevel.MCInfdevOldLevel.loadedChunkLimit = 0
ESCAPE = '\033'
class FileOpener(Widget):
class FileOpener(albow.Widget):
is_gl_container = True
def __init__(self, mcedit, *args, **kwargs):
kwargs['rect'] = mcedit.rect
Widget.__init__(self, *args, **kwargs)
albow.Widget.__init__(self, *args, **kwargs)
self.anchor = 'tlbr'
self.mcedit = mcedit
helpColumn = []
label = Label("{0} {1} {2} {3} {4} {5}".format(
label = albow.Label("{0} {1} {2} {3} {4} {5}".format(
config.config.get('Keys', 'Forward'),
config.config.get('Keys', 'Left'),
config.config.get('Keys', 'Back'),
@ -66,7 +62,7 @@ class FileOpener(Widget):
helpColumn.append(label)
def addHelp(text):
label = Label(text)
label = albow.Label(text)
label.anchor = 'whrt'
label.align = "r"
helpColumn.append(label)
@ -77,21 +73,21 @@ class FileOpener(Widget):
addHelp("Hold SHIFT to move along a major axis")
addHelp("Hold ALT for details")
helpColumn = Column(helpColumn, align="r")
helpColumn = albow.Column(helpColumn, align="r")
helpColumn.topright = self.topright
helpColumn.anchor = "whrt"
#helpColumn.is_gl_container = True
self.add(helpColumn)
keysColumn = [Label("")]
keysColumn = [albow.Label("")]
buttonsColumn = [leveleditor.ControlPanel.getHeader()]
shortnames = []
for world in self.mcedit.recentWorlds():
shortname = os.path.basename(world)
try:
if MCInfdevOldLevel.isLevel(world):
lev = MCInfdevOldLevel(world)
if pymclevel.MCInfdevOldLevel.isLevel(world):
lev = pymclevel.MCInfdevOldLevel(world)
shortname = lev.LevelName
if lev.LevelName != lev.displayName:
shortname = u"{0} ({1})".format(lev.LevelName, lev.displayName)
@ -112,13 +108,13 @@ class FileOpener(Widget):
('F{0}'.format(i + 1), shortnames[i], self.createLoadButtonHandler(world))
for i, world in enumerate(self.mcedit.recentWorlds())])
commandRow = HotkeyColumn(hotkeys, keysColumn, buttonsColumn)
commandRow = mceutils.HotkeyColumn(hotkeys, keysColumn, buttonsColumn)
commandRow.anchor = 'lrh'
sideColumn = mcedit.makeSideColumn()
sideColumn.anchor = 'wh'
contentRow = Row((commandRow, sideColumn))
contentRow = albow.Row((commandRow, sideColumn))
contentRow.center = self.center
contentRow.anchor = "rh"
self.add(contentRow)
@ -134,7 +130,7 @@ class FileOpener(Widget):
def key_down(self, evt):
keyname = key.name(evt.key)
if keyname == 'f4' and (key.get_mods() & (KMOD_ALT | KMOD_LALT | KMOD_RALT)):
if keyname == 'f4' and (key.get_mods() & (pygame.KMOD_ALT | pygame.KMOD_LALT | pygame.KMOD_RALT)):
raise SystemExit
if keyname in ('f1', 'f2', 'f3', 'f4', 'f5'):
self.mcedit.loadRecentWorldNumber(int(keyname[1]))
@ -247,32 +243,32 @@ class KeyConfigPanel(Dialog):
def __init__(self):
Dialog.__init__(self)
keyConfigTable = TableView(columns=[TableColumn("Command", 400, "l"), TableColumn("Assigned Key", 150, "r")])
keyConfigTable = albow.TableView(columns=[albow.TableColumn("Command", 400, "l"), albow.TableColumn("Assigned Key", 150, "r")])
keyConfigTable.num_rows = lambda: len(self.keyConfigKeys)
keyConfigTable.row_data = self.getRowData
keyConfigTable.row_is_selected = lambda x: x == self.selectedKeyIndex
keyConfigTable.click_row = self.selectTableRow
tableWidget = Widget()
tableWidget = albow.Widget()
tableWidget.add(keyConfigTable)
tableWidget.shrink_wrap()
self.keyConfigTable = keyConfigTable
buttonRow = (Button("Assign Key...", action=self.askAssignSelectedKey),
Button("Done", action=self.dismiss))
buttonRow = (albow.Button("Assign Key...", action=self.askAssignSelectedKey),
albow.Button("Done", action=self.dismiss))
buttonRow = Row(buttonRow)
buttonRow = albow.Row(buttonRow)
choiceButton = ChoiceButton(["WASD", "Arrows", "Numpad"], choose=self.choosePreset)
choiceButton = mceutils.ChoiceButton(["WASD", "Arrows", "Numpad"], choose=self.choosePreset)
if config.config.get("Keys", "Forward") == "up":
choiceButton.selectedChoice = "Arrows"
if config.config.get("Keys", "Forward") == "[8]":
choiceButton.selectedChoice = "Numpad"
choiceRow = Row((Label("Presets: "), choiceButton))
choiceRow = albow.Row((albow.Label("Presets: "), choiceButton))
self.choiceButton = choiceButton
col = Column((tableWidget, choiceRow, buttonRow))
col = albow.Column((tableWidget, choiceRow, buttonRow))
self.add(col)
self.shrink_wrap()
@ -310,7 +306,7 @@ class KeyConfigPanel(Dialog):
if labelString is None:
labelString = "Press a key to assign to the action \"{0}\"\n\nPress ESC to cancel.".format(configKey)
label = Label(labelString)
label = albow.Label(labelString)
panel.add(label)
panel.shrink_wrap()
@ -361,34 +357,34 @@ class GraphicsPanel(Panel):
self.texturePackChoice.selectedChoice = self.texturePack
self.texturePackChoice.choices = packs
self.texturePackChoice = texturePackChoice = ChoiceButton(getPacks(), choose=packChanged)
self.texturePackChoice = texturePackChoice = mceutils.ChoiceButton(getPacks(), choose=packChanged)
if self.texturePack in self.texturePackChoice.choices:
self.texturePackChoice.selectedChoice = self.texturePack
texturePackRow = Row((Label("Skin: "), texturePackChoice))
texturePackRow = albow.Row((albow.Label("Skin: "), texturePackChoice))
fieldOfViewRow = FloatInputRow("Field of View: ",
fieldOfViewRow = mceutils.FloatInputRow("Field of View: ",
ref=Settings.fov.propertyRef(), width=100, min=25, max=120)
targetFPSRow = IntInputRow("Target FPS: ",
targetFPSRow = mceutils.IntInputRow("Target FPS: ",
ref=Settings.targetFPS.propertyRef(), width=100, min=1, max=60)
bufferLimitRow = IntInputRow("Vertex Buffer Limit (MB): ",
bufferLimitRow = mceutils.IntInputRow("Vertex Buffer Limit (MB): ",
ref=Settings.vertexBufferLimit.propertyRef(), width=100, min=0)
fastLeavesRow = CheckBoxLabel("Fast Leaves",
fastLeavesRow = mceutils.CheckBoxLabel("Fast Leaves",
ref=Settings.fastLeaves.propertyRef(),
tooltipText="Leaves are solid, like Minecraft's 'Fast' graphics")
roughGraphicsRow = CheckBoxLabel("Rough Graphics",
roughGraphicsRow = mceutils.CheckBoxLabel("Rough Graphics",
ref=Settings.roughGraphics.propertyRef(),
tooltipText="All blocks are drawn the same way (overrides 'Fast Leaves')")
enableMouseLagRow = CheckBoxLabel("Enable Mouse Lag",
enableMouseLagRow = mceutils.CheckBoxLabel("Enable Mouse Lag",
ref=Settings.enableMouseLag.propertyRef(),
tooltipText="Enable choppy mouse movement for faster loading.")
settingsColumn = Column((fastLeavesRow,
settingsColumn = albow.Column((fastLeavesRow,
roughGraphicsRow,
enableMouseLagRow,
texturePackRow,
@ -397,17 +393,17 @@ class GraphicsPanel(Panel):
bufferLimitRow,
), align='r')
settingsColumn = Column((Label("Settings"),
settingsColumn = albow.Column((albow.Label("Settings"),
settingsColumn))
settingsRow = Row((settingsColumn,))
settingsRow = albow.Row((settingsColumn,))
optionsColumn = Column((settingsRow, Button("OK", action=mcedit.removeGraphicOptions)))
optionsColumn = albow.Column((settingsRow, albow.Button("OK", action=mcedit.removeGraphicOptions)))
self.add(optionsColumn)
self.shrink_wrap()
def _reloadTextures(self, pack):
if hasattr(alphaMaterials, "terrainTexture"):
if hasattr(pymclevel.alphaMaterials, "terrainTexture"):
self.mcedit.displayContext.loadTextures()
texturePack = Settings.skin.configProperty(_reloadTextures)
@ -421,67 +417,67 @@ class OptionsPanel(Dialog):
self.mcedit = mcedit
autoBrakeRow = CheckBoxLabel("Autobrake",
autoBrakeRow = mceutils.CheckBoxLabel("Autobrake",
ref=ControlSettings.autobrake.propertyRef(),
tooltipText="Apply brake when not pressing movement keys")
swapAxesRow = CheckBoxLabel("Swap Axes Looking Down",
swapAxesRow = mceutils.CheckBoxLabel("Swap Axes Looking Down",
ref=ControlSettings.swapAxes.propertyRef(),
tooltipText="Change the direction of the Forward and Backward keys when looking down")
cameraAccelRow = FloatInputRow("Camera Acceleration: ",
cameraAccelRow = mceutils.FloatInputRow("Camera Acceleration: ",
ref=ControlSettings.cameraAccel.propertyRef(), width=100, min=5.0)
cameraDragRow = FloatInputRow("Camera Drag: ",
cameraDragRow = mceutils.FloatInputRow("Camera Drag: ",
ref=ControlSettings.cameraDrag.propertyRef(), width=100, min=1.0)
cameraMaxSpeedRow = FloatInputRow("Camera Max Speed: ",
cameraMaxSpeedRow = mceutils.FloatInputRow("Camera Max Speed: ",
ref=ControlSettings.cameraMaxSpeed.propertyRef(), width=100, min=1.0)
cameraBrakeSpeedRow = FloatInputRow("Camera Braking Speed: ",
cameraBrakeSpeedRow = mceutils.FloatInputRow("Camera Braking Speed: ",
ref=ControlSettings.cameraBrakingSpeed.propertyRef(), width=100, min=1.0)
mouseSpeedRow = FloatInputRow("Mouse Speed: ",
mouseSpeedRow = mceutils.FloatInputRow("Mouse Speed: ",
ref=ControlSettings.mouseSpeed.propertyRef(), width=100, min=0.1, max=20.0)
invertRow = CheckBoxLabel("Invert Mouse",
invertRow = mceutils.CheckBoxLabel("Invert Mouse",
ref=ControlSettings.invertMousePitch.propertyRef(),
tooltipText="Reverse the up and down motion of the mouse.")
spaceHeightRow = IntInputRow("Low Detail Height",
spaceHeightRow = mceutils.IntInputRow("Low Detail Height",
ref=Settings.spaceHeight.propertyRef(),
tooltipText="When you are this far above the top of the world, move fast and use low-detail mode.")
blockBufferRow = IntInputRow("Block Buffer",
blockBufferRow = mceutils.IntInputRow("Block Buffer",
ref=Settings.blockBuffer.propertyRef(), min=1,
tooltipText="Amount of memory used for temporary storage. When more than this is needed, the disk is used instead.")
setWindowPlacementRow = CheckBoxLabel("Set Window Placement",
setWindowPlacementRow = mceutils.CheckBoxLabel("Set Window Placement",
ref=Settings.setWindowPlacement.propertyRef(),
tooltipText="Try to save and restore the window position.")
windowSizeRow = CheckBoxLabel("Window Resize Alert",
windowSizeRow = mceutils.CheckBoxLabel("Window Resize Alert",
ref=Settings.shouldResizeAlert.propertyRef(),
tooltipText="Reminds you that the cursor won't work correctly after resizing the window.")
visibilityCheckRow = CheckBoxLabel("Visibility Check",
visibilityCheckRow = mceutils.CheckBoxLabel("Visibility Check",
ref=Settings.visibilityCheck.propertyRef(),
tooltipText="Do a visibility check on chunks while loading. May cause a crash.")
longDistanceRow = CheckBoxLabel("Long-Distance Mode",
longDistanceRow = mceutils.CheckBoxLabel("Long-Distance Mode",
ref=Settings.longDistanceMode.propertyRef(),
tooltipText="Always target the farthest block under the cursor, even in mouselook mode. Shortcut: ALT-Z")
flyModeRow = CheckBoxLabel("Fly Mode",
flyModeRow = mceutils.CheckBoxLabel("Fly Mode",
ref=Settings.flyMode.propertyRef(),
tooltipText="Moving forward and backward will not change your altitude in Fly Mode.")
self.goPortableButton = goPortableButton = Button("Change", action=self.togglePortable)
self.goPortableButton = goPortableButton = albow.Button("Change", action=self.togglePortable)
goPortableButton.tooltipText = self.portableButtonTooltip()
goPortableRow = Row((ValueDisplay(ref=AttrRef(self, 'portableLabelText'), width=250, align='r'), goPortableButton))
goPortableRow = albow.Row((albow.ValueDisplay(ref=albow.AttrRef(self, 'portableLabelText'), width=250, align='r'), goPortableButton))
reportRow = CheckBoxLabel("Report Crashes",
reportRow = mceutils.CheckBoxLabel("Report Crashes",
ref=Settings.reportCrashes.propertyRef(),
tooltipText="Automatically report fatal errors to the author.")
@ -512,15 +508,15 @@ class OptionsPanel(Dialog):
goPortableRow,
)
rightcol = Column(options, align='r')
leftcol = Column(inputs, align='r')
rightcol = albow.Column(options, align='r')
leftcol = albow.Column(inputs, align='r')
optionsColumn = Column((Label("Options"),
Row((leftcol, rightcol), align="t")))
optionsColumn = albow.Column((albow.Label("Options"),
albow.Row((leftcol, rightcol), align="t")))
settingsRow = Row((optionsColumn,))
settingsRow = albow.Row((optionsColumn,))
optionsColumn = Column((settingsRow, Button("OK", action=self.dismiss)))
optionsColumn = albow.Column((settingsRow, albow.Button("OK", action=self.dismiss)))
self.add(optionsColumn)
self.shrink_wrap()
@ -550,12 +546,12 @@ class OptionsPanel(Dialog):
textChoices[1] = "This will move your schematics to your Documents folder and your settings to your Preferences folder. Continue?"
alertText = textChoices[mcplatform.portable]
if ask(alertText) == "OK":
if albow.ask(alertText) == "OK":
try:
[mcplatform.goPortable, mcplatform.goFixed][mcplatform.portable]()
except Exception, e:
traceback.print_exc()
alert(u"Error while moving files: {0}".format(repr(e)))
albow.alert(u"Error while moving files: {0}".format(repr(e)))
self.goPortableButton.tooltipText = self.portableButtonTooltip()
@ -592,11 +588,11 @@ class MCEdit(GLViewport):
if len(sys.argv) > 1:
for arg in sys.argv[1:]:
f = arg.decode(sys.getfilesystemencoding())
if isdir(join(saveFileDir, f)):
f = join(saveFileDir, f)
if os.path.isdir(os.path.join(pymclevel.saveFileDir, f)):
f = os.path.join(pymclevel.saveFileDir, f)
self.droppedLevel = f
break
if exists(f):
if os.path.exists(f):
self.droppedLevel = f
break
@ -704,7 +700,7 @@ class MCEdit(GLViewport):
def makeSideColumn(self):
def showhistory():
try:
with file(os.path.join(mcplatform.dataDir), 'history.txt') as f:
with file(os.path.join(directories.dataDir), 'history.txt') as f:
history = f.read()
history = "\n".join(history.split("\n")[:16])
@ -713,13 +709,13 @@ class MCEdit(GLViewport):
except Exception, e:
history = "Exception while reading history.txt: {0}".format(e)
if ask(history, ["Show history.txt", "OK"]) == "Show history.txt":
platform_open(os.path.join(mcplatform.dataDir), "history.txt")
if albow.ask(history, ["Show history.txt", "OK"]) == "Show history.txt":
platform_open(os.path.join(directories.dataDir), "history.txt")
def showLicense():
platform_open(os.path.join(mcplatform.dataDir, "LICENSE.txt"))
platform_open(os.path.join(directories.dataDir, "LICENSE.txt"))
readmePath = os.path.join(mcplatform.dataDir, "README.html")
readmePath = os.path.join(directories.dataDir, "README.html")
hotkeys = ([("",
"Keys",
@ -744,7 +740,7 @@ class MCEdit(GLViewport):
showLicense),
])
c = HotkeyColumn(hotkeys)
c = mceutils.HotkeyColumn(hotkeys)
return c
@ -778,7 +774,7 @@ class MCEdit(GLViewport):
if not hasattr(self, 'resizeAlert'):
self.resizeAlert = self.shouldResizeAlert
if self.resizeAlert:
alert("Window size increased. You may have problems using the cursor until MCEdit is restarted.")
albow.alert("Window size increased. You may have problems using the cursor until MCEdit is restarted.")
self.resizeAlert = False
shouldResizeAlert = Settings.shouldResizeAlert.configProperty()
@ -809,7 +805,7 @@ class MCEdit(GLViewport):
self.add(self.editor)
self.focus_switch = self.editor
alert("World created. To expand this infinite world, explore the world in Minecraft or use the Chunk Control tool to add or delete chunks.")
albow.alert("World created. To expand this infinite world, explore the world in Minecraft or use the Chunk Control tool to add or delete chunks.")
def removeEditor(self):
self.remove(self.editor)
@ -819,7 +815,7 @@ class MCEdit(GLViewport):
def confirm_quit(self):
if self.editor.unsavedEdits:
result = ask("There are {0} unsaved changes.".format(self.editor.unsavedEdits),
result = albow.ask("There are {0} unsaved changes.".format(self.editor.unsavedEdits),
responses=["Save and Quit", "Quit", "Cancel"])
if result == "Save and Quit":
self.saveAndQuit()
@ -851,14 +847,14 @@ class MCEdit(GLViewport):
rootwidget.add(mcedit)
rootwidget.focus_switch = mcedit
if 0 == len(alphaMaterials.yamlDatas):
alert("Failed to load minecraft.yaml. Check the console window for details.")
if 0 == len(pymclevel.alphaMaterials.yamlDatas):
albow.alert("Failed to load minecraft.yaml. Check the console window for details.")
if mcedit.droppedLevel:
mcedit.loadFile(mcedit.droppedLevel)
if mcedit.closeMinecraftWarning:
answer = ask("Warning: You must close Minecraft completely before editing. Save corruption may result. Get Satisfaction to learn more.", ["Get Satisfaction", "Don't remind me again.", "OK"], default=1, cancel=1)
answer = albow.ask("Warning: You must close Minecraft completely before editing. Save corruption may result. Get Satisfaction to learn more.", ["Get Satisfaction", "Don't remind me again.", "OK"], default=1, cancel=1)
if answer == "Get Satisfaction":
mcplatform.platform_open("http://getsatisfaction.com/mojang/topics/region_file_cache_interferes_with_map_editors_risking_save_corruption")
if answer == "Don't remind me again.":
@ -916,7 +912,7 @@ def main(argv):
try:
if not os.path.exists(mcplatform.schematicsDir):
shutil.copytree(
os.path.join(mcplatform.dataDir, u'stock-schematics'),
os.path.join(directories.dataDir, u'stock-schematics'),
mcplatform.schematicsDir
)
except Exception, e:
@ -946,16 +942,16 @@ class GLDisplayContext(object):
return max(20, w), max(20, h)
def displayMode(self):
displayMode = OPENGL | RESIZABLE
displayMode = pygame.OPENGL | pygame.RESIZABLE
if Settings.doubleBuffer.get():
displayMode |= DOUBLEBUF
displayMode |= pygame.DOUBLEBUF
return displayMode
def reset(self):
pygame.key.set_repeat(500, 100)
try:
display.gl_set_attribute(GL_SWAP_CONTROL, Settings.vsync.get())
display.gl_set_attribute(pygame.GL_SWAP_CONTROL, Settings.vsync.get())
except Exception, e:
logging.warning('Unable to set vertical sync: {0!r}'.format(e))
@ -988,9 +984,9 @@ class GLDisplayContext(object):
config.saveConfig()
try:
iconpath = os.path.join(mcplatform.dataDir, 'favicon.png')
iconpath = os.path.join(directories.dataDir, 'favicon.png')
iconfile = file(iconpath, 'rb')
icon = image.load(iconfile, 'favicon.png')
icon = pygame.image.load(iconfile, 'favicon.png')
display.set_icon(icon)
except Exception, e:
logging.warning('Unable to set icon: {0!r}'.format(e))
@ -1015,7 +1011,7 @@ class GLDisplayContext(object):
def makeTerrainTexture(mats):
w, h = 1, 1
teximage = zeros((w, h, 4), dtype='uint8')
teximage = numpy.zeros((w, h, 4), dtype='uint8')
teximage[:] = 127, 127, 127, 255
GL.glTexImage2D(
@ -1031,25 +1027,25 @@ class GLDisplayContext(object):
)
textures = (
(classicMaterials, 'terrain-classic.png'),
(indevMaterials, 'terrain-classic.png'),
(alphaMaterials, 'terrain.png'),
(pocketMaterials, 'terrain-pocket.png')
(pymclevel.classicMaterials, 'terrain-classic.png'),
(pymclevel.indevMaterials, 'terrain-classic.png'),
(pymclevel.alphaMaterials, 'terrain.png'),
(pymclevel.pocketMaterials, 'terrain-pocket.png')
)
for mats, matFile in textures:
try:
if mats.name == 'Alpha':
tex = loadAlphaTerrainTexture()
tex = mceutils.loadAlphaTerrainTexture()
else:
tex = loadPNGTexture(matFile)
tex = mceutils.loadPNGTexture(matFile)
self.terrainTextures[mats.name] = tex
except Exception, e:
logging.warning(
'Unable to load terrain from {0}, using flat colors.'
'Error was: {1!r}'.format(matFile, e)
)
self.terrainTextures[mats.name] = Texture(
self.terrainTextures[mats.name] = glutils.Texture(
functools.partial(makeTerrainTexture, mats)
)
mats.terrainTexture = self.terrainTextures[mats.name]

View File

@ -18,29 +18,26 @@ mceutils.py
Exception catching, some basic box drawing, texture pack loading, oddball UI elements
"""
from OpenGL import GL, GLU
import numpy
import httplib
import sys
import os
import platform
import traceback
import zipfile
from albow.controls import ValueDisplay
from albow import alert, ask, Button, Column, Label, root, Row, ValueButton, Widget
import config
from cStringIO import StringIO
from datetime import datetime
from pygame import image, display
import png
import config
import release
import directories
from errorreporting import reportCrash, reportException
import httplib
import mcplatform
from albow import ask, alert, Widget, Button, ValueButton, Column, Row, Label, root
import numpy
from OpenGL import GL, GLU
import os
import platform
import png
from pygame import display, image
import pymclevel
from albow.controls import ValueDisplay
from pymclevel import materials
from errorreporting import reportException, reportCrash
import release
import sys
import traceback
import zipfile
def alertException(func):
@ -55,14 +52,12 @@ def alertException(func):
return _alertException
from pymclevel.faces import *
def drawFace(box, face, type=GL.GL_QUADS):
x, y, z, = box.origin
x2, y2, z2 = box.maximum
if face == FaceXDecreasing:
if face == pymclevel.faces.FaceXDecreasing:
faceVertices = numpy.array(
(x, y2, z2,
@ -71,7 +66,7 @@ def drawFace(box, face, type=GL.GL_QUADS):
x, y, z2,
), dtype='f4')
elif face == FaceXIncreasing:
elif face == pymclevel.faces.FaceXIncreasing:
faceVertices = numpy.array(
(x2, y, z2,
@ -80,7 +75,7 @@ def drawFace(box, face, type=GL.GL_QUADS):
x2, y2, z2,
), dtype='f4')
elif face == FaceYDecreasing:
elif face == pymclevel.faces.FaceYDecreasing:
faceVertices = numpy.array(
(x2, y, z2,
x, y, z2,
@ -88,7 +83,7 @@ def drawFace(box, face, type=GL.GL_QUADS):
x2, y, z,
), dtype='f4')
elif face == FaceYIncreasing:
elif face == pymclevel.faces.FaceYIncreasing:
faceVertices = numpy.array(
(x2, y2, z,
x, y2, z,
@ -96,7 +91,7 @@ def drawFace(box, face, type=GL.GL_QUADS):
x2, y2, z2,
), dtype='f4')
elif face == FaceZDecreasing:
elif face == pymclevel.faces.FaceZDecreasing:
faceVertices = numpy.array(
(x, y, z,
x, y2, z,
@ -104,7 +99,7 @@ def drawFace(box, face, type=GL.GL_QUADS):
x2, y, z,
), dtype='f4')
elif face == FaceZIncreasing:
elif face == pymclevel.faces.FaceZIncreasing:
faceVertices = numpy.array(
(x2, y, z2,
x2, y2, z2,
@ -356,7 +351,7 @@ def loadAlphaTerrainTexture():
if foliageColorFile is not None:
w, h, data = loadPNGData(slurpZipExt(foliageColorFile))
color = data[77, 55, :3]
materials.alphaMaterials.flatColors[17, 0, :3] = color # xxxxxxx
pymclevel.materials.alphaMaterials.flatColors[17, 0, :3] = color # xxxxxxx
color = [c / 255.0 for c in color]
LeafBlockRenderer.leafColor = color
@ -366,7 +361,7 @@ def loadAlphaTerrainTexture():
if grassColorFile is not None:
w, h, data = loadPNGData(slurpZipExt(grassColorFile))
color = data[77, 55, :3]
materials.alphaMaterials.flatColors[2, 0, :3] = color # xxxxxxx
pymclevel.materials.alphaMaterials.flatColors[2, 0, :3] = color # xxxxxxx
color = [c / 255.0 for c in color]
GenericBlockRenderer.grassColor = color
@ -384,7 +379,7 @@ def loadAlphaTerrainTexture():
def loadPNGData(filename_or_data):
# if filename[1:4] != "PNG":
if isinstance(filename_or_data, basestring):
filename_or_data = os.path.join(mcplatform.dataDir, filename_or_data)
filename_or_data = os.path.join(directories.dataDir, filename_or_data)
filename_or_data = filename_or_data.encode(sys.getfilesystemencoding())
else:
# path = numpy.fromstring(filename, 'uint8')

View File

@ -18,11 +18,10 @@ mcplatform.py
Platform-specific functions, folder paths, and the whole fixed/portable nonsense.
"""
import sys
import directories
import os
from os.path import join, exists, dirname
from directories import *
from os.path import dirname, exists, join
import sys
enc = sys.getfilesystemencoding()
@ -32,9 +31,9 @@ if sys.platform == "win32":
plat = "win32"
if platform.architecture()[0] == "64bit":
plat = "win-amd64"
sys.path.append(join(dataDir, "pymclevel", "build", "lib." + plat + "-2.6").encode(enc))
sys.path.append(join(directories.dataDir, "pymclevel", "build", "lib." + plat + "-2.6").encode(enc))
os.environ["YAML_ROOT"] = join(dataDir, "pymclevel").encode(enc)
os.environ["YAML_ROOT"] = join(directories.dataDir, "pymclevel").encode(enc)
from pygame import display
@ -336,7 +335,7 @@ def platform_open(path):
win32_window_size = True
ini = u"mcedit.ini"
parentDir = dirname(dataDir)
parentDir = dirname(directories.dataDir)
docsFolder = documents_folder()
portableConfigFilePath = os.path.join(parentDir, ini)
portableSchematicsDir = os.path.join(parentDir, u"MCEdit-schematics")
@ -419,7 +418,7 @@ else:
schematicsDir = fixedSchematicsDir
portable = False
filtersDir = os.path.join(dataDir, "filters")
filtersDir = os.path.join(directories.dataDir, "filters")
if filtersDir not in [s.decode(sys.getfilesystemencoding())
if isinstance(s, str)
else s
@ -434,4 +433,4 @@ if portable:
else:
jarStorage = ServerJarStorage()
items.items = items.Items(join(dataDir, "pymclevel", "items.txt"))
items.items = items.Items(join(directories.dataDir, "pymclevel", "items.txt"))

File diff suppressed because it is too large Load Diff