So I’m on a mac for now, and that mean one menu bar at the top of the screen.
This gives me a tk window, and adds a Tools menu like I want:
from Tkinter import *
root=Tk()
menubar = Menu(root)
toolsMenu=Menu(menubar)
toolsMenu.add_command(label="Some Tool")
menubar.add_cascade(label="Tools", menu=toolsMenu)
root.config(menu=menubar)
mainloop()
Now for panda:
from panda3d.core import loadPrcFileData
loadPrcFileData('', 'want-tk 1') # appears to not do anything
import direct.directbase.DirectStart
from direct.tkwidgets import AppShell
base.startTk() # appears to not do anything
shell= AppShell.AppShell()
run()
This gives 3 windows,
1: “Generic Application Frame” with “edit” and “help” popup menus at the top pretending to be like a menu bar or something
2: an empty tk window
3: a panda window (the only one I want)
It does not give me a reference to anything I can add menus to though. (I tried it on shell and got errors). Also, the run() call seems to block Tk from getting any time. If I use Tkinter directly, I can do menus, but I still get its blank window, and if I hide that window, the menus go away, and Tkinter does not get time to run at all. (My attempts at update tasks as below failed as well)
I tried adding this:
from direct.task import Task
def refreshApp(task):
shell.update()
return Task.cont
taskMgr.add(refreshApp, "refreshApp")
but it seems to have no effect.
And now for my slightly better luck with wx:
from direct.showbase.ShowBase import ShowBase
import direct.directbase.DirectStart
from direct.wxwidgets import WxAppShell
base.startWx()
base.setFrameRateMeter(True)
w=WxAppShell.WxAppShell
w.appname='X'
w.appversion='0.0'
w.copyright='Copyright 2010 Craig Macomber.\nAll Rights Reserved.'
w.contactname='Craig Macomber'
w.contactemail='X'
s=WxAppShell.WxAppShell()
#some yhings that exist: s.about, s.menuBar, s.menuFile, s.menuHelp
from wx import wx
menu = wx.Menu()
s.menuBar.Append(menu, "&Tools");
#base.taskMgr.remove("igLoop") # Makes everything freeze if uncommented
run()
This gives 2 windows, one empty one called “X” (or what ever I set my app name to I imagine), and a panda window. It also gives 2 help menus (one it makes, and the default system one that shows up after you click the menu bar. I think I can just delete the one panda makes on mac). I can add my own menus though, and wx seems to get the time it needs to work.
Currently, at least on mac, I can get menus that work with wx, if I ignore the extra help menu showing up, and the blank window that quits the app if you close it. I can’t make Tkinter and panda play together at all.
I haven’t gotten a good test in on windows yet (panda crashes on launch on my virtual windows box due to crappy graphics support, maybe I can make it work) and I did do a small wx test on linux, but the panda frame inside the wx window did not move when the window was moved, though I could probably fix that if I tried enough.
I’d rather avoid having larger and/or separate third party libraries, so if possible, I would either like to avoid wx, or discover a easy way to include it with my app. I think Tkinter comes with python, so it should be less of an issue.
So, how can I make Tkinter add menus to a panda application without spaying little empty windows around, and do so in a way where there is not a mainloop conflict? panda seems to have some built in stuff for doing this, but I can’t find any documentation about it at all (there is base.starttk/wx and want-tk/wx, there might be more, and I don’t even know what those things do.)
Also, in the long run, I’ll want to have multiple panda windows with menus. It would be good if what ever approach I end up won’t prohibit this, though it is not critical.