Progress with VPython-wx
Bruce Sherwood <[email protected]> Fri, 25 Jan 2013 15:55:22 -0700
| Newsgroups | gmane.comp.python.visualpython.user |
|---|---|
| Message-ID | <CAFDG03iOOK2UVpjcAKnC-u+zrVxvdUHYKqcwOMszfj0DiqG1=A@mail.gmail.com> |
--===============3100764272832428261==
Content-Type: multipart/alternative; boundary=047d7b33d5fc8498e404d424d2dd
--047d7b33d5fc8498e404d424d2dd
Content-Type: text/plain; charset=UTF-8
It occurs to me that a note I posted to the wxPython forum might be of some
interest to the VPython community:
You might like to see how far we've gotten, with lots of help from this
wxPython community. Below is a screen shot of the wxPython-based VPython
(the image of this demo came from Windows and also displays correctly on
Linux; everything but the menus works on a Mac). In the past, the 3D canvas
had to fill the window; there couldn't be other widgets in the window. In
the program, the 3D cube rotates, and the controls let you change the
color, the rotation speed, and the rotation direction, and you can also
type into the text control.
The 3D portion of the code is pretty trivial. The first statement creates a
window and the second places an OpenGL canvas in the left half of the
window. You'll note that some adjustment is made so that the canvas is L*L
but the window is larger.
w = window(width=2*(L+window.get_dw()), height=L+window.get_dh(),
title='Widgets')
display(window=w, y = 0, width=L, height=L, forward=-vector(0,1,2))
cube = box(color=color.red)
... wxPython code to make widgets for setting color, and rotation speed and
direction
while True:
rate(100)
cube.rotate(axis=(0,1,0), angle=cube.dir*cube.dtheta)
Of equal importance to widgets is the fact that it was possible to
eliminate very nearly all platform-dependent C++ code (there are small
instances of platform-dependent Python code, but that's trivial). The only
remaining platform-dependent C++ code is GetProcAddress. Of critical
importance is that the new VPython works on 64-bit Cocoa-based Macs,
something that was impossible with the old VPython, which was Carbon-based.
I've also run up against a significant platform-dependent display issue
which I've "solved" temporarily on one particular Linux with hard-coded
integers. The VPython API has always had the user specify the width and
height of a window as the outer bounds, so that one can easily place (say)
two windows adjacent to each other or one below the other, with the canvas
being smaller than that. I need to know the dimensions of the writable
area, but unfortunately only for Windows will wxWidgets give me the
dimensions of borders, title bar, and menu bar. For Mac and Linux, the
values are all -1. For both Windows and Mac, these values are probably
extremely stable (I use hard-coded integers for the Mac), but on different
distributions of Linux, or for different window managers on the same Linux,
I don't know how to get the dimension information I need.
Note that my problems are somewhat different from those using wxPython to
create apps. VPython is middleware; people use VPython to create apps. This
puts an additional burden on VPython to be universally cross-platform, not
just cross-platform for a particular app.
Availability note: At vpython.org one can get an experimental version of
the wxPython-based VPython, but the support for widgets isn't yet included
even in that experimental package. However, the up-to-date source code is
available at
https://github.com/BruceSherwood/vpython-wx.
The program widgets.py that generated the image is at the repository in
site-packages/visual/examples.
[image: Inline image 1]
--047d7b33d5fc8498e404d424d2dd
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div style=3D"font-family:arial,sans-serif;font-size:13px"=
>It occurs to me that a note I posted to the wxPython forum might be of som=
e interest to the VPython community:</div><div style=3D"font-family:arial,s=
ans-serif;font-size:13px">
<br></div><div style=3D"font-family:arial,sans-serif;font-size:13px">You mi=
ght like to see how far we've gotten, with lots of help from this wxPyt=
hon community. Below is a screen shot of the wxPython-based VPython (the im=
age of this demo came from Windows and also displays correctly on Linux; ev=
erything but the menus works on a Mac). In the past, the 3D canvas had to f=
ill the window; there couldn't be other widgets in the window. In the p=
rogram, the 3D cube rotates, and the controls let you change the color, the=
rotation speed, and the rotation direction, and you can also type into the=
text control.=C2=A0</div>
<div style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px">The 3D portion of the =
code is pretty trivial. The first statement creates a window and the second=
places an OpenGL canvas in the left half of the window. You'll note th=
at some adjustment is made so that the canvas is L*L but the window is larg=
er.</div>
<div style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px"><div>w =3D window(widt=
h=3D2*(L+window.get_dw()), height=3DL+window.get_dh(), title=3D'Widgets=
')</div>
<div>display(window=3Dw, y =3D 0, width=3DL, height=3DL, forward=3D-vector(=
0,1,2))<br></div><div><div>cube =3D box(color=3Dcolor.red)</div><div></div>=
</div><div><br></div><div>... wxPython code to make widgets for setting col=
or, and rotation speed and direction</div>
<div><br></div><div>while True:<br></div></div><div style=3D"font-family:ar=
ial,sans-serif;font-size:13px"><div>=C2=A0 =C2=A0 rate(100)</div><div>=C2=
=A0 =C2=A0 cube.rotate(axis=3D(0,1,0), angle=3Dcube.dir*cube.dtheta)</div><=
/div><div style=3D"font-family:arial,sans-serif;font-size:13px">
<br></div><div style=3D"font-family:arial,sans-serif;font-size:13px">Of equ=
al importance to widgets is the fact that it was possible to eliminate very=
nearly all platform-dependent C++ code (there are small instances of platf=
orm-dependent Python code, but that's trivial). The only remaining plat=
form-dependent C++ code is=C2=A0GetProcAddress. Of critical importance is t=
hat the new VPython works on 64-bit Cocoa-based Macs, something that was im=
possible with the old VPython, which was Carbon-based.</div>
<div style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px">I've also run up a=
gainst a significant platform-dependent display issue which I've "=
solved" temporarily on one particular Linux with hard-coded integers. =
The VPython API has always had the user specify the width and height of a w=
indow as the outer bounds, so that one can easily place (say) two windows a=
djacent to each other or one below the other, with the canvas being smaller=
than that. I need to know the dimensions of the writable area, but unfortu=
nately only for Windows will wxWidgets give me the dimensions of borders, t=
itle bar, and menu bar. For Mac and Linux, the values are all -1. For both =
Windows and Mac, these values are probably extremely stable (I use hard-cod=
ed integers for the Mac), but on different distributions of Linux, or for d=
ifferent window managers on the same Linux, I don't know how to get the=
dimension information I need.</div>
<div style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px">Note that my problems =
are somewhat different from those using wxPython to create apps. VPython is=
middleware; people use VPython to create apps. This puts an additional bur=
den on VPython to be universally cross-platform, not just cross-platform fo=
r a particular app.</div>
<div style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px">Availability note: At=
=C2=A0<a href=3D"http://vpython.org/" target=3D"_blank">vpython.org</a>=C2=
=A0one can get an experimental version of the wxPython-based VPython, but t=
he support for widgets isn't yet included even in that experimental pac=
kage. However, the up-to-date source code is available at=C2=A0</div>
<div style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px"><a href=3D"https://git=
hub.com/BruceSherwood/vpython-wx" target=3D"_blank">https://github.com/Bruc=
eSherwood/vpython-wx</a>.</div>
<div style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px">The program widgets.py=
that generated the image is at the repository in site-packages/visual/exam=
ples.</div>
<div style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px"><img src=3D"https://ma=
il.google.com/mail/u/0/?ui=3D2&ik=3D0cd495e3e0&view=3Datt&th=3D=
13c737fe928345a5&attid=3D0.1&disp=3Demb&realattid=3Dii_13c7367c=
e1e00963&zw&atsh=3D1" alt=3D"Inline image 1" width=3D"540" height=
=3D"280" class=3D"" style=3D""></div>
</div>
--047d7b33d5fc8498e404d424d2dd--
--===============3100764272832428261==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
--===============3100764272832428261==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Visualpython-users mailing list
Visualpython-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/visualpython-users
--===============3100764272832428261==--