Last active
March 14, 2022 03:05
-
-
Save nyaocat/ac0165ff2e25576ea89337158ea1d80e to your computer and use it in GitHub Desktop.
pysdl2 in wxpython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sdl2 | |
import sdl2.ext | |
import math | |
import wx | |
class SDL2Timer(wx.Timer): | |
def Yaruzo(self, a): | |
sdl2.ext.init() | |
# window = sdl2.SDL_CreateWindow("Hi".encode("utf-8"), | |
# sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED, | |
# 300, 200, 0) | |
self.window = sdl2.SDL_CreateWindowFrom(a) | |
self.renderer = sdl2.SDL_CreateRenderer(self.window, -1, sdl2.SDL_RENDERER_SOFTWARE) | |
self.rotate = 0.0 | |
self.Start(16) | |
def Notify(self): | |
sdl2.SDL_SetRenderDrawColor(self.renderer, 0, 0, 0, 255) | |
sdl2.SDL_RenderClear(self.renderer) | |
sdl2.SDL_SetRenderDrawColor(self.renderer, 255, 0, 0, 255) | |
self.rotate += 0.01 | |
sdl2.SDL_RenderDrawLine(self.renderer, | |
math.floor(60 + 40 * math.cos(self.rotate)), | |
math.floor(60 + 40 * math.sin(self.rotate)), | |
math.floor(60 - 40 * math.cos(self.rotate)), | |
math.floor(60 - 40 * math.sin(self.rotate)) | |
) | |
sdl2.SDL_RenderPresent(self.renderer) | |
application = wx.App() | |
frame = wx.Frame(None, wx.ID_ANY, 'pysdl2 and wxpython', size=(300, 200)) | |
class SDL2Panel(wx.Panel): | |
def __init__(self, parent, ID, tplSize): | |
wx.Panel.__init__(self, parent, ID, pos=(0, 30), size=tplSize) | |
self.SetBackgroundColour('#bbccaa') | |
self.tm = SDL2Timer() | |
self.tm.Yaruzo(self.GetHandle()) | |
def btn1(event): | |
m = wx.MessageDialog(None, 'aieeeee', 'Aooooo') | |
m.ShowModal() | |
button_1 = wx.Button(frame, wx.ID_ANY, 'ボタン1') | |
button_1.Bind(wx.EVT_BUTTON, btn1) | |
inner_panel_1 = SDL2Panel(frame, wx.ID_ANY, (300, 200)) | |
layout = wx.BoxSizer(wx.VERTICAL) | |
# layout.Add(inner_panel_1, proportion=1, flag=wx.EXPAND) | |
layout.Add(button_1, flag=wx.EXPAND | wx.ALIGN_BOTTOM) | |
frame.SetSizer(layout) | |
frame.Show() | |
application.MainLoop() |
I have already forgotten in which environment this worked.
Even if it works, it is extremely unstable and should not be put to practical use.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm unsure if this works. I receive a SIGSEGV error on run attempt.
My Info:
Ubuntu 20.04.3 LTS
Python 3.8.10
wxPython 4.1.1
pySDL 0.9.9
Update: Upon further testing, it for me in Win 10, but not Linux. Also, the wx.ALIGN_BOTTOM flag is now invalid (?).