|
From: Symion <kn...@ip...> - 2011-05-31 07:45:22
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#ffffff">
Hi there,<br>
<br>
I have recently been testing the Tkinter module with the idea of
building GUI's for controlling things like Visual.<br>
<br>
Tkinter makes it very easy to create Lists, Sliders, Buttons, Menus
as well as viewing and editing Text files.<br>
<br>
I would like to be able to strip the OS decorator from Visual and
insert the visual.scene into either a Tkinter Canvas or a Tkinter
Frame object.<br>
Alternately, it might be easier to assume Visual is already wrapped
in a Tkinter TopLevel Object and try to insert Tkinter widgets into
the current window surround.<br>
<br>
When I chased down this idea and looked at the "ui" module it shed
no light as the instantiation vanished into C!<br>
<br>
Is there a way to have them Running and Interacting at the same
time?<br>
Has anyone written code for this?<br>
If this could be achieved it would be very useful!<br>
I note that master.update() might be relevant for Tkinter to
continue operation but how to control Visual?<br>
Any help would be greatly appreciated.<br>
<br>
Since I have had problems running Tkinter and Visual together, I
have developed a simple to use method that enables one or the other
to be "in the drivers seat".<br>
It is based on the fact that Visual uses the escape key to end
program execution, so I set Tkinter to act the same.<br>
Now pressing the 'Esc' key will switch between Visual and Tkinter,
no problems!<br>
<br>
This means that Tkinter can be used to modify or define Visual
environment or Objects, then press 'Esc' and you are in Visual.<br>
Once in Visual it is possible to modify or define Tkinter
environment or Objects, then press 'Esc' and you are in Tkinter!<br>
<br>
Source Code: TkInVisual.py<br>
<br>
<small><small>from Tkinter import *<br>
import vis<br>
from math import (sqrt, pi)<br>
from os import (access as Access, path as Path, F_OK)<br>
<br>
class TkInVisual:<br>
"""Tkinter : Visual Interaction.<br>
'esc' key will flip between Visual and Tkinter<br>
Visual Control:<br>
Tkinter Panel:<br>
'f1' = menu on|off<br>
'f2' = canvas on|off<br>
'f3' = button on|off<br>
'enter' = close Tkinter - leave Visual
open <br>
'end' = quit and close Both<br>
"""<br>
def __init__(self):<br>
"""Access multiple lists via Visual/Tkinter"""<br>
self.version="1.0.0"<br>
self.copyright = "Tkinter Method - GNU (c) Symion MMXI"<br>
self.xpos, self.ypos, self.wide, self.high = 8, 8, 400,
300<br>
self.visual = vis.scene<br>
self.visual.visible = False<br>
self.visual.title = "{0} : {1}".format(self.copyright,
self.version)<br>
self.visual.autoscale = False<br>
self.visual.range = 256<br>
self.visual.access = 6 # new vis.scene.variable<br>
#<br>
# For old graphics card users * Time to upgrade? *<br>
#<br>
self.visual.enable_shaders = False<br>
# Pre-set opening list<br>
self.inform = dict()<br>
self.memory = ["Master_methods", "Frame_methods",<br>
"LabelFrame_methods", "Canvas_methods",<br>
"Text_methods", "Entry_methods",<br>
"Listbox_methods", "Scrollbar_methods",<br>
"Label_methods", "Button_methods",<br>
"Menu_methods", "Graphic_methods"]<br>
self.action = ["self.Do_a", "self.Do_b", "self.Do_c",<br>
"self.Do_d", "self.Do_e", "self.Do_f",<br>
"self.Do_g", "self.Do_h", "self.Do_i",<br>
"self.Do_j", "self.Do_k", "self.Do_l"]<br>
<br>
def Create_widget(self, title, config):<br>
"""config = [Menu 0|1, Graphic 0|1, Button 0|1|]"""<br>
self.parent = Tk()<br>
self.parent.title(title)<br>
self.parent["borderwidth"] = 4<br>
# Customise Tkinter Panel<br>
self.parent.tk_setPalette(background="#B0B0B0",<br>
activeForeground="#FFFFFF",<br>
selectForeground="#FFFF00",<br>
activeBackground="#FF0000")<br>
# self.parent.geometry("=%dx%d+%d+%d" %(self.wide,<br>
# self.high,<br>
# self.xpos,<br>
# self.ypos))<br>
self.parent.geometry("+%d+%d" % (self.xpos, self.ypos))<br>
self.parent.resizable(width=False, height=False)<br>
self.parent.bind("<Escape>", self.Ok_go)<br>
self.parent.bind("<End>", self.Ok_quit)<br>
base = LabelFrame(self.parent,<br>
fg="#0000FF",<br>
font=("times", 14, "normal"),<br>
bd=5,<br>
text="Tkinter Object Methods")<br>
base.grid()<br>
rows = 0<br>
# config = [Menu 0|1, Graphic 0|1, Button 0|1]<br>
if config[1] > 0:<br>
paper = Canvas(base,<br>
width=self.wide,<br>
height=self.high//3,<br>
bg="#FFFFFF",<br>
relief=RIDGE,<br>
borderwidth=2)<br>
paper.grid(row=rows, column=0, columnspan=2)<br>
rows += 1<br>
if config[0] > 0:<br>
self.menubar = Menu(self.parent)<br>
# create 1st pulldown menu<br>
filemenu = Menu(self.menubar, tearoff=0,<br>
activebackground="#FF0000")<br>
self.menubar.add_cascade(label = " Methods ",
menu=filemenu)<br>
# <br>
for a,b in zip(self.memory[:5], self.action[:5]):<br>
filemenu.add_command(label = a, command=eval(b))<br>
filemenu.add_separator()<br>
filemenu.add_command(label=" Exit : End",
command=self.Ok_quit)<br>
if False:<br>
# create 2nd pulldown<br>
visualmenu = Menu(self.menubar,<br>
tearoff=0,<br>
activebackground="#00FF00")<br>
self.menubar.add_cascade(label=" Visual ",
menu=visualmenu)<br>
visualmenu.add_command(label=" Objects ",
command=self.Test)<br>
visualmenu.add_separator()<br>
visualmenu.add_command(label=" Open ",
command=self.Test)<br>
visualmenu.add_command(label=" Close ",
command=self.Test)<br>
visualmenu.add_separator()<br>
visualmenu.add_command(label=" Edit ",
command=self.Test)<br>
# create 3rd<br>
extramenu = Menu(self.menubar,<br>
tearoff=0,<br>
activebackground="#0000FF")<br>
self.menubar.add_cascade(label=" Extras ",
menu=extramenu)<br>
# <br>
for a,b in zip(self.memory[5:], self.action[5:]):<br>
extramenu.add_command(label = a,
command=eval(b))<br>
#<br>
# display the menu<br>
self.parent["menu"] = self.menubar<br>
self.parent.config(padx=12, pady=12)<br>
self.label = Label(base, font=("times", 14, "normal"))<br>
self.label.grid(row=rows,<br>
column=0,<br>
columnspan=2,<br>
sticky=E+W,<br>
padx=5,<br>
ipadx=5)<br>
rows += 1<br>
# Build a List Table of info.<br>
self.list_table = Listbox(base,<br>
bg="white",<br>
width=50,<br>
borderwidth=2,<br>
font=("times", 12, "normal"),<br>
relief=SUNKEN)<br>
# "A list of Tkinter Object Methods"<br>
self.visual.access = self.visual.access%len(self.memory)<br>
self.Make_list(self.visual.access)<br>
# <br>
self.list_table.grid(row=rows, column=0, columnspan=2,<br>
ipadx=5, ipady=5, sticky=E+W)<br>
self.list_table.bind("<Return>", self.Ach_tung)<br>
self.list_table.bind("<Double-Button-1>",
self.By_pass)<br>
self.scroll_bar = Scrollbar(base,<br>
orient=VERTICAL,<br>
takefocus=FALSE,<br>
highlightthickness=4)<br>
self.scroll_bar["command"] = self.list_table.yview<br>
self.scroll_bar.grid(row=rows, column=1, columnspan=2,
sticky=N+S+E)<br>
self.list_table["yscrollcommand"]= self.scroll_bar.set<br>
self.list_table["activestyle"] = "dotbox"<br>
self.list_table.focus_set()<br>
rows += 1<br>
#<br>
# Button pad<br>
#<br>
if config[2] > 0:<br>
i = 0<br>
for y in range(6):<br>
for x in range(2):<br>
a, b = self.memory[i], eval(self.action[i])<br>
test = Button(base, text=a, command=b)<br>
test.grid(row=rows + y, column=x,
columnspan=1, sticky=E+W)<br>
test.bind("<Return>", b)<br>
i += 1<br>
rows += y + 1<br>
qquit = Button(base, text="Back to Visual",
command=self.Ok_go)<br>
qquit.grid(row=rows, column=0, columnspan=2, sticky=E+W)<br>
qquit.bind("<Return>", self.Ok_go)<br>
<br>
def Make_list(self, ndata):<br>
self.visual.access = ndata<br>
self.label["text"] = self.memory[ndata]<br>
self.data = "self.{0}()".format(self.memory[ndata])<br>
self.Build_list(eval(self.data).config().keys())<br>
<br>
def Do_remove(self):<br>
n = range(self.list_table.size())<br>
for a in n:<br>
self.list_table.delete(0)<br>
<br>
def Build_list(self, table):<br>
self.Do_remove()<br>
for a in table:<br>
self.list_table.insert(END, a)<br>
<br>
def Do_a(self, event=None):<br>
self.Make_list(0)<br>
<br>
def Do_b(self, event=None):<br>
self.Make_list(1)<br>
<br>
def Do_c(self, event=None):<br>
self.Make_list(2)<br>
<br>
def Do_d(self, event=None):<br>
self.Make_list(3)<br>
<br>
def Do_e(self, event=None):<br>
self.Make_list(4)<br>
<br>
def Do_f(self, event=None):<br>
self.Make_list(5)<br>
<br>
def Do_g(self, event=None):<br>
self.Make_list(6)<br>
<br>
def Do_h(self, event=None):<br>
self.Make_list(7)<br>
<br>
def Do_i(self, event=None):<br>
self.Make_list(8)<br>
<br>
def Do_j(self, event=None):<br>
self.Make_list(9)<br>
<br>
def Do_k(self, event=None):<br>
self.Make_list(10)<br>
<br>
def Do_l(self, event=None):<br>
self.Make_list(11)<br>
<br>
def Test(self, event=None):<br>
print self.menubar.cget('type')<br>
<br>
def Ach_tung(self, event=None):<br>
self.answer = self.list_table.get(ACTIVE)<br>
# Do other things than simply printing it into V-IDLE<br>
# Append to a list or build a dictionary perhaps?<br>
try:<br>
self.inform[self.answer] = (self.visual.access,
self.answer)<br>
a = self.inform.get(self.answer)<br>
# self.inform.append((self.visual.access,
self.answer))<br>
# a = self.inform[-1]<br>
except:<br>
a = None<br>
finally:<br>
if a:<br>
self.De_code(a)<br>
else:<br>
b =
self.memory[self.visual.access].replace("_methods", "")<br>
print "{0}['{1}'] = ".format(b.lower(),
self.answer)<br>
<br>
def By_pass(self, event=None):<br>
self.answer = self.list_table.get(ACTIVE)<br>
self.De_code((self.visual.access, self.answer))<br>
<br>
def De_code(self, a):<br>
b = self.memory[a[0]]<br>
M = eval("self.{0}()".format(b))<br>
mc = M.cget(a[1])<br>
if mc.__class__.__name__ == "Tcl_Obj":<br>
mc = mc.string <br>
b = b.replace("_methods", "")<br>
print "{0}['{1}'] = {2}".format(b, a[1], repr(mc))<br>
del M<br>
<br>
def Ok_go(self, event=None):<br>
self.xpos = self.parent.winfo_x()<br>
self.ypos = self.parent.winfo_y()<br>
self.parent.destroy()<br>
<br>
def Ok_quit(self, event=None):<br>
self.Ok_go()<br>
self.acts = False<br>
<br>
#<br>
# Make list<br>
#<br>
<br>
def Master_methods(self):<br>
return self.parent<br>
<br>
def Frame_methods(self):<br>
return Frame(self.parent)<br>
<br>
def LabelFrame_methods(self):<br>
return LabelFrame(self.parent)<br>
<br>
def Canvas_methods(self):<br>
return Canvas(self.parent)<br>
<br>
def Text_methods(self):<br>
return Text(self.parent)<br>
<br>
...
[truncated message content] |
|
From: Symion <kn...@ip...> - 2011-05-31 08:47:54
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 31/05/2011 5:15 PM, Symion wrote:
<blockquote cite="mid:4DE...@ip..." type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
Sorry, I should have included a little more explanation of how to
control the Tkinter side.<br>
</blockquote>
You can extract the values of items in the Listbox, here are the
methods.<br>
Tkinter : Visual Interaction.<br>
'Esc' key will flip between Visual and Tkinter<br>
Visual Control of Tkinter:<br>
'f1' = Menu on|off<br>
'f2' = Canvas on|off<br>
'f3' = Button Bank on|off<br>
Tkinter Control:<br>
To select item from a Listbox and Reveal its value:<br>
Double Click Left Mouse Key inside Listbox<br>
OR<br>
Use Keyboard cursors and the Enter Key.<br>
'tab' will navigate around Gadget.<br>
'space bar' will activate widget current.<br>
'enter' = close Tkinter - leave Visual open
<br>
'end' = quit and close in either!<br>
<br>
<blockquote cite="mid:4DE...@ip..." type="cite">
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
<a class="moz-txt-link-freetext" href="http://p.sf.net/sfu/quest-sfdev2dev">http://p.sf.net/sfu/quest-sfdev2dev</a></pre>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Visualpython-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Vis...@li...">Vis...@li...</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/visualpython-users">https://lists.sourceforge.net/lists/listinfo/visualpython-users</a>
</pre>
</blockquote>
<br>
</body>
</html>
|