WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   tkinter window focus (https://forum.worldviz.com/showthread.php?t=1602)

John P 08-13-2008 11:50 PM

tkinter window focus
 
I've read some posts about getting the tkinter library working within the vizard gui and have some further questions.

1 - Can a tkinter dialog be displayed in front of a vizard window? I haven't had any luck with this in either window or fullscreen mode.

2 - Until a tkinter window is closed the vizard thread events are blocked. I don't really see any way around that. Key press events (and i assume any other vizard events) actually build up and all trigger at the time the tkinter dialog is closed.

I know there are some vizard dialog alternatives but at this point I would really like to get tkinter running. Any suggestions would be welcomed.

farshizzo 08-14-2008 04:14 PM

I'm pretty sure Tkinter has a call to bring a window to the foreground. However, to solve the issues you are experiencing the dialog window needs to be a child of the vizard window. The problem is that there is no way to specify an existing non-tk window as the parent of a tk dialog. I'm not very familiar with Tkinter, so I don't know of any workaround.

Using raw win32 calls I have been able to display a modal dialog over a vizard window, so I know this is technically possible.

sircedric4 08-28-2009 06:52 AM

Quote:

Originally Posted by farshizzo (Post 6119)
I'm pretty sure Tkinter has a call to bring a window to the foreground. However, to solve the issues you are experiencing the dialog window needs to be a child of the vizard window. The problem is that there is no way to specify an existing non-tk window as the parent of a tk dialog. I'm not very familiar with Tkinter, so I don't know of any workaround.

Using raw win32 calls I have been able to display a modal dialog over a vizard window, so I know this is technically possible.

I am using the win32ui to create a standard "browse" for a file dialog box for my gui but the dialog box comes in under the Vizard window and everything is frozen waiting on the dialog box to finish. You mentioned you were able to display the modal over the vizard window, could you please tell me how you were able to do this?

Thank you.

farshizzo 08-28-2009 03:27 PM

Here is a sample script that shows how to display modal file/color dialogs over the Vizard window:
Code:

import viz
import win32ui
import win32con

viz.go()

color_button = viz.addButtonLabel('color change')
color_button.translate(0.285,0.59)

file_button = viz.addButtonLabel('choose file')
file_button.translate(0.5,0.59)

def ChooseColor():
        """You can find documentation for CreateColorDialog at the following site:
                http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/pywin32/win32ui__CreateColorDialog_meth.html"""
        parent = win32ui.CreateWindowFromHandle(viz.window.getHandle())
        dlg = win32ui.CreateColorDialog(0,win32con.CC_FULLOPEN,parent)
        if dlg.DoModal() == win32con.IDOK:
                clr = dlg.GetColor()
                r = win32con.GetRValue(clr) / 255.0
                g = win32con.GetGValue(clr) / 255.0
                b = win32con.GetBValue(clr) / 255.0
                print r,g,b

vizact.onbuttonup(color_button,ChooseColor)


def ChooseFile():
        """You can find documentation for CreateFileDialog at the following site:
                http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/pywin32/win32ui__CreateFileDialog_meth.html"""
        parent = win32ui.CreateWindowFromHandle(viz.window.getHandle())
        dlg = win32ui.CreateFileDialog(1,'','',0,'',parent)
        if dlg.DoModal() == win32con.IDOK:
                print dlg.GetFileName()
       
vizact.onbuttonup(file_button,ChooseFile)


sircedric4 08-31-2009 05:51 AM

Thanks, that worked like a charm. :D


All times are GMT -7. The time now is 10:22 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC