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, size=(800, 600)) self.mainpanel.SetAutoLayout(True) self.leftwindow = wx.Panel(self.mainpanel, -1, (10, 10), (380, 450)) self.leftwindow.SetBackgroundColour(wx.WHITE) self.leftwindow.SetConstraints( anchors.LayoutAnchors(self.leftwindow, True, True, True, True)) self.rightwindow = wx.Panel(self.mainpanel, -1, (400, 10), (380, 450)) self.rightwindow.SetBackgroundColour(wx.WHITE) self.rightwindow.SetConstraints( anchors.LayoutAnchors(self.rightwindow, False, True, True, True)) playvideo = wx.Button(self.mainpanel, -1, "Play media on this window...", (500, 500)) playvideo.SetConstraints( anchors.LayoutAnchors(playvideo, False, False, True, True)) self.Bind(wx.EVT_BUTTON, self.playVideo, playvideo) #Create a DirectPython window from an existing wxPython window. tempWindow = d3d11.Window(handle=self.leftwindow.GetHandle()) #Create our resources. Note that if the size of the window #changes, you should call self.device.reset(). self.device = d3d11.Device(tempWindow, DRIVER_TYPE_WARP) self.effect = d3d11.Effect( d3d11x.getResourceDir("Effects", "Tutorial2.fx")) self.inputLayout = d3d11.InputLayout(vertexDesc, self.effect, 0, 0) self.vertexBuffer = d3d11.Buffer(vertexDesc, triangle, BIND_VERTEX_BUFFER) #We need to detach() the window. This means that it is up to #us (or wxPython) to mange the window from now on. tempWindow.detach() self.media = None self.Bind(wx.EVT_PAINT, self.onPaint) self.Bind(wx.EVT_TIMER, self.onTimer) self.Bind(wx.EVT_IDLE, self.onIdle) self.leftwindow.Bind(wx.EVT_SIZE, self.onSize) #Use a timer for rendering. It is not a very smooth #solution, you might want to tweak the time interval #or do something else, now it is jerky. self.timer = wx.Timer(self) self.timer.Start(10)
def playVideo(self, evt): dlg = wx.FileDialog(self, message="Choose a media file", defaultDir=os.getcwd(), defaultFile="", style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() tempWindow = d3d11.Window(handle=self.rightwindow.GetHandle()) try: #Load the media and play. onIdle() pumps messages. If the media #does not have any video a window is not actually needed. self.media = d3d11.Media(path, tempWindow) self.media.play() finally: #Make sure window always gets detached, otherwise it #closes 'rightwindow'. tempWindow.detach()
import math import time import cdata #Import DirectPython modules and constants. import d3d11 import d3d11x from d3d11c import * #First we need a window. If you don't want to do any visible #rendering this could be omitted. window = d3d11.Window() window.setTitle("Tutorial 2 - A colored triangle") window.show(SW_SHOW) #Then create a Device and tell it to use our window for drawing. #Use a software WARP-device, in real applications you might #try hardware first and fall back to software if that fails. device = d3d11.Device(window, DRIVER_TYPE_WARP) #Our vertex layout description: position (x, y, z) and color (r, g, b, a). #See the "Layouts and input layouts" article in the documentation. vertexDesc = [ ("POSITION", 0, FORMAT_R32G32B32_FLOAT, 0, 0, INPUT_PER_VERTEX_DATA, 0), ("COLOR", 0, FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0), #This is functionally same as above, only easier to read. I use the complex one now #so that you don't get confused when you encounter it in samples. #("POSITION", 0, FORMAT_R32G32B32_FLOAT),
def build(self, title=''): self._window = d3d11.Window() self._window.setRect((100, 100, 800, 600), client=True) self._window.setTitle(title) self._initDevice()