Форум сайта python.su
Приветик всем )
Я работаю сейчас с directpython и столкнулась с проблемой которая поставила меня в тупик Может кто-то сталкивался с чем-то подобным…
Вот текст:
import os import d3d from d3dc import * try: import wx except: d3d.messageBox(u"wxPython sample", u"wxPython is not available.\n\nThis sample will not work without it.") raise #Simple pre-transformed triangle. triangle = ( (10.0, 400.0, 0.5, 1.0, 0x80ffff00), (190.0, 10.0, 0.5, 1.0, 0x80ff00ff), (370.0, 400.0, 0.5, 1.0, 0x8000ff00), ) class MainFrame(wx.Frame): def __init__(self, parent, id, title, pos, size=(800, 600)): wx.Frame.__init__(self, parent, id, title, pos, size) self.mainpanel = wx.Panel(self, -1) self.leftwindow = wx.Panel(self.mainpanel, -1, (10, 10), (380, 450)) self.leftwindow.SetBackgroundColour(wx.WHITE) self.rightwindow = wx.Panel(self.mainpanel, -1, (400, 10), (380, 450)) self.rightwindow.SetBackgroundColour(wx.WHITE) useleft = wx.Button(self.mainpanel, -1, "Use left window", (100, 500)) self.Bind(wx.EVT_BUTTON, self.useLeft, useleft) playvideo = wx.Button(self.mainpanel, -1, "Play media...", (200, 500)) self.Bind(wx.EVT_BUTTON, self.playVideo, playvideo) useright = wx.Button(self.mainpanel, -1, "Use right window", (520, 500)) self.Bind(wx.EVT_BUTTON, self.useRight, useright) self.Bind(wx.EVT_PAINT, self.onPaint) self.Bind(wx.EVT_IDLE, self.onIdle) #Create a device that preserves its backbuffer after #present() by using SWAPCOPY a = 0.0245389764825 print round(a,4) d3d.createDevice(u"", u"", 0, 0, False, CREATE.HARDWARE | CREATE.SWAPCOPY, self.leftwindow.GetHandle()) print round(a,4) self.override = 0 self.media = None self.mesh = d3d.StaticMesh(u"xfiles/static.bigship.x") self.render() #We only have to render once, use present() to show it. def render(self): d3d.clear() d3d.beginScene() d3d.setState(RS.LIGHTING, True) d3d.setState(RS.AMBIENT, 0x00202020) d3d.setState(RS.SPECULARENABLE, True) d3d.setLight(0, LIGHT.POINT, 0xffff0000, 50.0, (0.0, 30.0, 0.0)) d3d.setState(RS.ZWRITEENABLE, False) d3d.setState(RS.ALPHABLENDENABLE, True) d3d.setState(RS.FVF, FVF.XYZRHW | FVF.DIFFUSE) d3d.drawVertices(TYPE.TRIANGLELIST, triangle) d3d.setState(RS.ALPHABLENDENABLE, False) d3d.setState(RS.ZWRITEENABLE, True) d3d.setView((0.0, 28.0, -28.0,), (0.0, 0.0, 0.0)) d3d.setTransform((0.0, 0.0, 0.0), (0.0, 0.5, 0.0)) self.mesh.render() d3d.endScene() def playVideo(self, evt): wildcard = "Media files (.avi)|*.avi|MP3 (.mp3)|*.mp3|All (*.*)|*.*" dlg = wx.FileDialog(self, message="Choose a file", defaultDir=os.getcwd(), defaultFile="", style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() self.media = d3d.Media(unicode(path)) self.media.play() self.useRight(None) #Use the left window for video. def useRight(self, evt): self.override = self.rightwindow.GetHandle() self.present() self.leftwindow.Refresh() def useLeft(self, evt): self.override = 0 self.present() self.rightwindow.Refresh() def present(self): try: d3d.present(self.override) except: #Device is not functional. For example #Fast user switching or power saving modes can cause this. try: #Try to reset. d3d.reset() except: #Failed, try again later. return #All ok, continue as usual. The backbuffer has #been lost however, so we need to render it again. self.render() def onIdle(self, evt): if self.media != None: cur, end = self.media.positions() if cur == end: #Loop the media. self.media.positions(0, end) self.present() def onPaint(self, evt): dc = wx.PaintDC(self) self.present() class MainApp(wx.App): def OnInit(self): frame = MainFrame(None, -1, "DirectPython with wxPython", (10, 10), (800, 600)) frame.CenterOnScreen() frame.Show() return True if __name__ == "__main__": app = MainApp(False) app.MainLoop()
Офлайн
страшная штука вайлд-импорты….
import os
import d3d
import wx
class MainFrame(wx.Frame):
def __init__(self, parent, _id, title, pos, size=(800, 600)):
a = 0.0245389764825
print id(round)
u = round(a,4)
print u
d3d.createDevice()
print u == round(a, 4)
print u*1.0 == round(a, 4)*1.0
print u
print u*1
print round(a,4)*1
class MainApp(wx.App):
def OnInit(self):
frame = MainFrame(None, -1, “DirectPython with wxPython”, (10, 10), (800, 600))
return True
if __name__ == “__main__”:
app = MainApp(False)
app.MainLoop()
…………………..
10992576
0.0245
False
True
0.0245
0.0244999993593
0.0244999993593
вобщем красота. в целом на точность оно не повлияет, но round после инициализации будет выдавать не совсем красивые значения.
Офлайн