473,714 Members | 2,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

threads, sockets, pyopengl, pickle (and tkinter...)

I am developing an engineering application for modelling multiphase
flows in large pipe networks, and have just discovered the joy of
pyopengl for 3D visualization. However the incantation I'm using -
with glut on Windows - doesnt coexist well with other python gui's -
glutMainLoop() appears not to work alongside tkinter.mainloo p(). (I
tried putting them in separate threads but no success there either)
The issue has been raised in various discussions here in the past with
no satisfacory resolution as far as I can see, though Togl has been
suggested - but all I can find on the project page is c-source code,
havent managed to get the demo Togl stuff in the pyopengl installation
to work.

Anyway, I've tried another avenue of attack - running the
visualization portion in a separate application to the
design/computation part, and communicating by sockets, this has a
useful advantage that the two parts of the application can run on
different machines if needed.

So when I want to update the display, the design app packages up the
drawing data into a display list (just a python list in fact
with each entry an instruction to draw a particular element, colors
etc), then pickles the thing up and send it through the socket.

At the other end the display app reads from the socket - this runs in
a separate thread, unpickles the data and puts it in a global variable
which the gl drawing function can access. The two relevant routines
and the stuff to fire everything off are appended. (doGlutMain() sets
up all the gle stuff and sets glutDrawFunctio n() with DrawStuff)

This *almost* works, except that things block until I generate some
event in the OpenGL display window - even just giving it the focus
after sending off some data. I'm not quite sure how to rectify this -
any suggestions would be appreciated. Perhaps doing something with the
glutIdleFunctio n()? And am I doing the right thing with the lock stuff?

Finally could someone confirm that pickled data never contains a "."
character apart at the end of the string (I use this as a delimiter in
the socket communiction.) There was an old posting (from Guido
himself) that seemed to imply this.


# draw routine
def DrawStuff():
global lock
if dList:
for z in dList:
glPopMatrix ()
glutSwapBuffers ()
# Server program
def getData():
global lock, dList
HOST = ''
PORT = 50007
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
s.bind((HOST, PORT))
conn, addr = s.accept()
while 1:
while data[-1:] != ".":
data += conn.recv(4096)
z = cPickle.loads(d ata)
dList = z
glutPostRedispl ay()
print len(z)
conn.send("rsnd ")
thread.start_ne w_thread(getDat a, ())
doGlutMain(Draw Stuff)

Bruce Rule 1.
Jul 18 '05 #1
0 1917

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Julia Goolia | last post by:
hello, i read that it is bad to use threads with tkinter. so my question is how does one create a gui program with sockets? at one point you have to call mainloop() which does not return. then you are not free to do stuff with the sockets. what's up with that? thanks so much for your time!
by: george.trojan | last post by:
My application consists of Tkinter GUI that has to communicate with a remote server. The communication is bi-directional: the GUI responds to remote requests and user actions uch as pressing a button) should send messages to the server. I want to have the network interface implemented as a separate thread, as it may take a while to proccess incoming messages. My initial approach is the following
by: Jim Lewis | last post by:
Pickling an instance of a class, gives "can't pickle instancemethod objects". What does this mean? How do I find the class method creating the problem?
by: Kevin Walzer | last post by:
I'm trying to decide whether I need threads in my Tkinter application or not. My app is a front end to a command-line tool; it feeds commands to the command-line program, then reads its output and displays it in a Tkinter text widget. Some of the commands are long-running and/or return thousands of lines of output. I initially thought I needed to use threading, because the GUI would block when reading the output, even when I configured...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.