Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed openGLDemo, simplified guidemo and restored fondemo in it #2345

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
cache: pip
cache-dependency-path: .github/workflows/main.yml
check-latest: true
- run: pip install types-regex types-setuptools mypy==1.11
- run: pip install types-regex types-setuptools PyOpenGL mypy==1.11
- run: mypy . --python-version=${{ matrix.python-version }}

pyright:
Expand All @@ -164,7 +164,7 @@ jobs:
cache-dependency-path: .github/workflows/main.yml
check-latest: true
# pyright vendors typeshed, but let's make sure we have the most up to date stubs
- run: pip install types-regex types-setuptools
- run: pip install types-regex types-setuptools PyOpenGL
- uses: jakebailey/pyright-action@v2
with:
python-version: ${{ matrix.python-version }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ https://mhammond.github.io/pywin32_installers.html.
Coming in build 309, as yet unreleased
--------------------------------------

* Fixed "Open GL Demo" (`Pythonwin/pywin/Demos/openGLDemo.py`) and restore "Font" demo in `Pythonwin/pywin/Demos/guidemo.py` (#2345, @Avasam)

Build 308, released 2024-10-12
------------------------------
* Fix Pythonwin displaying syntax errors in Python 3.13 (#2393)
Expand Down
53 changes: 13 additions & 40 deletions Pythonwin/pywin/Demos/guidemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import sys

import __main__
import regutil
import win32api
import win32ui
import pywin.dialogs.list

demos = [ # ('Font', 'import fontdemo;fontdemo.FontDemo()'),
demos = [
("Font", "import fontdemo;fontdemo.FontDemo()"),
("Open GL Demo", "import openGLDemo;openGLDemo.test()"),
("Threaded GUI", "import threadedgui;threadedgui.ThreadedDemo()"),
("Tree View Demo", "import hiertest;hiertest.demoboth()"),
Expand All @@ -19,58 +18,32 @@
("OCX Control Demo", "from ocx import ocxtest;ocxtest.demo()"),
("OCX Serial Port Demo", "from ocx import ocxserialtest; ocxserialtest.test()"),
(
"IE4 Control Demo",
"Internet Explorer Control Demo",
'from ocx import webbrowser; webbrowser.Demo("http://www.python.org")',
),
]


def demo():
def _exec_demo(cmd):
try:
# seeif I can locate the demo files.
import fontdemo
except ImportError:
# else put the demos direectory on the path (if not already)
try:
instPath = regutil.GetRegistryDefaultValue(
regutil.BuildDefaultPythonKey() + "\\InstallPath"
)
except win32api.error:
print(
"The InstallPath can not be located, and the Demos directory is not on the path"
)
instPath = "."

demosDir = win32ui.FullPath(instPath + "\\Demos")
for path in sys.path:
if win32ui.FullPath(path) == demosDir:
break
else:
sys.path.append(demosDir)
import fontdemo
exec(cmd)
except Exception as error:
print(f"Demo of {cmd} failed - {type(error)}:{error}")

import sys

def demo():
if "/go" in sys.argv:
for name, cmd in demos:
try:
exec(cmd)
except:
print(f"Demo of {cmd} failed - {sys.exc_info()[0]}:{sys.exc_info()[1]}")
_exec_demo(cmd)
return
# Otherwise allow the user to select the demo to run

import pywin.dialogs.list

while 1:
# Otherwise allow the user to select the demo to run
while True:
rc = pywin.dialogs.list.SelectFromLists("Select a Demo", demos, ["Demo Title"])
if rc is None:
break
title, cmd = demos[rc]
try:
exec(cmd)
except:
print(f"Demo of {title} failed - {sys.exc_info()[0]}:{sys.exc_info()[1]}")
_exec_demo(cmd)


if __name__ == __main__.__name__:
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/Demos/ocx/webbrowser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This demo uses the IE4 Web Browser control.
# This demo uses the Internet Explorer Web Browser control.

# It catches an "OnNavigate" event, and updates the frame title.
# (event stuff by Neil Hodgson)
Expand All @@ -16,7 +16,7 @@
"{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1
)
if WebBrowserModule is None:
raise ImportError("IE4 does not appear to be installed.")
raise ImportError("Internet Explorer does not appear to be installed.")


class MyWebBrowser(activex.Control, WebBrowserModule.WebBrowser):
Expand Down
69 changes: 57 additions & 12 deletions Pythonwin/pywin/Demos/openGLDemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,55 @@

import sys

from pywin.mfc import docview

try:
from OpenGL.GL import * # nopycln: import
from OpenGL.GLU import * # nopycln: import
from OpenGL.GL import (
GL_COLOR_BUFFER_BIT,
GL_DEPTH_BUFFER_BIT,
GL_DEPTH_TEST,
GL_MODELVIEW,
GL_PROJECTION,
GL_QUAD_STRIP,
GL_QUADS,
GL_TRIANGLE_FAN,
glBegin,
glClear,
glClearColor,
glClearDepth,
glColor3f,
glEnable,
glEnd,
glFinish,
glLoadIdentity,
glMatrixMode,
glPopMatrix,
glPushMatrix,
glRotatef,
glTranslatef,
glVertex3f,
glViewport,
)
from OpenGL.GLU import (
GLU_FILL,
GLU_SMOOTH,
gluCylinder,
gluNewQuadric,
gluPerspective,
gluQuadricDrawStyle,
gluQuadricNormals,
)
from OpenGL.WGL import (
PIXELFORMATDESCRIPTOR,
ChoosePixelFormat,
DescribePixelFormat,
GetPixelFormat,
SetPixelFormat,
SwapBuffers,
wglCreateContext,
wglDeleteContext,
wglGetCurrentContext,
wglGetCurrentDC,
wglMakeCurrent,
)
except ImportError:
print("The OpenGL extensions do not appear to be installed.")
print("This Pythonwin demo can not run")
Expand All @@ -16,6 +60,7 @@
import win32api
import win32con
import win32ui
from pywin.mfc import docview

PFD_TYPE_RGBA = 0
PFD_TYPE_COLORINDEX = 1
Expand Down Expand Up @@ -117,24 +162,24 @@ def OnEraseBkgnd(self, dc):
# The OpenGL helpers
def _SetupPixelFormat(self):
dc = self.dc.GetSafeHdc()
pfd = CreatePIXELFORMATDESCRIPTOR()
pfd = PIXELFORMATDESCRIPTOR()
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER
pfd.iPixelType = PFD_TYPE_RGBA
pfd.cColorBits = 24
pfd.cDepthBits = 32
pfd.iLayerType = PFD_MAIN_PLANE
pixelformat = ChoosePixelFormat(dc, pfd)
SetPixelFormat(dc, pixelformat, pfd)
self._CreateRGBPalette()
self._CreateRGBPalette(pfd)

def _CreateRGBPalette(self):
dc = self.dc.GetSafeHdc()
n = GetPixelFormat(dc)
pfd = DescribePixelFormat(dc, n)
def _CreateRGBPalette(self, pfd):
hdc = self.dc.GetSafeHdc()
iPixelFormat = GetPixelFormat(hdc)
DescribePixelFormat(hdc, iPixelFormat, pfd.nSize, pfd)
if pfd.dwFlags & PFD_NEED_PALETTE:
n = 1 << pfd.cColorBits
iPixelFormat = 1 << pfd.cColorBits
pal = []
for i in range(n):
for i in range(iPixelFormat):
this = (
ComponentFromIndex(i, pfd.cRedBits, pfd.cRedShift),
ComponentFromIndex(i, pfd.cGreenBits, pfd.cGreenShift),
Expand Down
Loading