473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Pmw problem in cygwin with Tkinter

I have a Tkinter app running on cygwin. It includes a Test menu item
that does nothing more than fetch a directory listing and display it
in a Toplevel window (I'd use a tkMessageBox showinfo widget, but for
some reason the text is invisible on cygwin).

After I close the Toplevel widget, all of the menus in my app behave
as though they have no contents to them, i..e I can press on the File
menu button, and see it depress, but the Exit submenu does not appear
(and neither do any of the other menus' submenus). However, a Quit
button in my status bar does respond, so the problem lies with the
menu.

Below are two apps that illustrate the problem. It's obvious that the
problem is with Pmw, and in particular with the menubar widget. The
first test app uses Pmw, and displays the problem behaviour. The
second test app uses basic Tk menus, and does not have a problem.

Any clues?

---
#test_subprocess3.py

from Tkinter import *

import os, sys
import subprocess

programHome = '/cygdrive/c/programs'
sys.path[:0] = [programHome]
try:
import Pmw
except ImportError:
print 'I need to have Pmw widget set installed in c:\\Programs\\Pmw'
sys.exit("missing Pmw")

class PumpAdmin(Pmw.MegaWidget):
def __init__(self, parent): #master=None):
Pmw.MegaWidget.__init__(self, parent)
#Frame.__init__(self, master, relief=SUNKEN, bd=2)
self.parent = parent

def drawGui(self):
'''draw the application'''

# Create the Balloon.
self.balloon = Pmw.Balloon(self.parent)

#---------- Menu bar ---------------

if 1:
menuBar=Pmw.MenuBar(self.parent, hull_relief='raised',
hull_borderwidth=1)
menuBar.pack(fill='x')
self.menuBar = menuBar

menuBar.addmenu('File', 'Close this window or exit')
menuBar.addmenuitem('File', 'command', 'Exit the
application', command=root.destroy, label='Exit')

menuBar.addmenu('Test', 'Test new features')
menuBar.addmenuitem('Test', 'command', 'Directory
listing', command=self.dir_list, label='Directory List')

# ------- Paned widget (central part of main window) -------

if 1:
panedWidget = Pmw.PanedWidget(self.parent,
orient = 'vertical', hull_height = 250, hull_width = 500)
self.panedWidget = panedWidget
self.panedWidget.add('results', min = 0.05)
self.panedWidget.pack(side='left', fill = 'both', expand = 1)

self.results =
Pmw.ScrolledText(self.panedWidget.pane('results'), text_wrap = 'none')
self.results.pack(fill = 'both', expand = 1)

# ----------------------- Status Bar --------------------------

if 1:
self.panedWidget.add('status', min = 0.05)
frmS = Frame(self.panedWidget.pane('status'))
self.frmS = frmS
frmS.pack(fill='x', expand=1)
labSpaceL = Label(frmS, text = ' ')
labSpaceR = Label(frmS, text = ' ')
labSystem = Button(frmS, text = 'Quit', command=root.destroy)
self.labSystem = labSystem
labSpaceL.pack(side='left')
self.labSystem.pack(side='left', fill='both',expand=0)
labSpaceR.pack(side='right')

def dir_list(self):
'''provide a listing of files in a directory'''
curdir = os.getcwd()
try:
p = subprocess.Popen(['ls',' -l'], bufsize=2048,
shell=True, close_fds=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(child_stdin, dirlist, retcode) = (p.stdin, p.stdout, p.stderr)
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", retcode
print 'error'
self.myshowerror("Error","Sorry, couldn't get a
directory listing")
else:
print 'no error'
#print dirlist
msgList = []
for dir in dirlist:
#print dir
msgList.append(dir)
msg = ''.join(msgList)
#print msg
print 'got to 1'
self.myshowinfo("Directory Listing for %s" % curdir, msg)
print 'got to 2'
#self.drawMenu()
except OSError,e:
print >>sys.stderr, "Execution failed:", e

def mymessage(self, title, msg, msgType='info'):
'''a workalike for the tkMessageBox showinfo since the former
results in invisible text in cygwin'''
top = Toplevel()
top.title(title)
t = Label(top, text='\n%s\n' % msgType.upper())
t.pack()
l = Label(top, text=msg)
l.pack()
b = Button(top,text="Ok", command=top.destroy)
b.pack()

def myshowinfo(self, title='', msg=''):
'''a workalike for the tkMessageBox showinfo since the former
results in invisible text in cygwin'''
self.mymessage(title, msg,'info')
root.focus_set()
root.update()

if __name__ == '__main__':
if 1:
root = Tk()
Pmw.initialise(root, size = 16, useTkOptionDb = 1)
root.geometry('500x400+100+100')
root.title("Test application")
app = PumpAdmin(root)
app.drawGui()
app.pack(fill = 'both', expand = 1)
root.deiconify()
root.update()
root.mainloop()

---
#test_subprocess2.py

from Tkinter import *

import os, sys
import subprocess

class AppUI(Frame):

def __init__(self, master=None):
Frame.__init__(self, master, relief=SUNKEN, bd=2)

def drawGui(self):
self.drawMenu()
self.drawCanvas()

def drawMenu(self):
self.menubar = Menu(self)
menu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="File", menu=menu)
menu.add_command(label="Exit", command=root.destroy)

menu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Test", menu=menu)
menu.add_command(label="Dir list", command=self.dir_list)
try:
self.master.config(menu=self.menubar)
except AttributeError:
# master is a toplevel window (Python 1.4/Tkinter 1.63)
self.master.tk.call(master, "config", "-menu", self.menubar)

def drawCanvas(self):
self.canvas = Canvas(self, bg="white", width=400, height=400,
bd=0, highlightthickness=0)
self.canvas.pack()

def dir_list(self):
'''provide a listing of files in a directory'''
#need to know which system to draw from
curdir = os.getcwd()
try:
#dirlist = subprocess.Popen('ls -l', shell=False,
bufsize=2048, stdout=subprocess.PIPE).stdout
#dirlist,retcode = subprocess.Popen('ls -l',
stdout=subprocess.PIPE).communicate()
#retcode = subprocess.call('ls -l', shell=False)
p = subprocess.Popen(['ls',' -l'], bufsize=2048,
shell=True, close_fds=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(child_stdin, dirlist, retcode) = (p.stdin, p.stdout, p.stderr)
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", retcode
print 'error'
self.myshowerror("Error","Sorry, couldn't get a
directory listing")
else:
print 'no error'
#print dirlist
msgList = []
for dir in dirlist:
#print dir
msgList.append(dir)
msg = ''.join(msgList)
#print msg
print 'got to 1'
self.myshowinfo("Directory Listing for %s" % curdir, msg)
print 'got to 2'
self.drawMenu()
except OSError,e:
print >>sys.stderr, "Execution failed:", e

def mymessage(self, title, msg, msgType='info'):
'''a workalike for the tkMessageBox showinfo since the former
results in invisible text in cygwin'''
top = Toplevel()
top.title(title)
t = Label(top, text='\n%s\n' % msgType.upper())
t.pack()
l = Label(top, text=msg)
l.pack()
b = Button(top,text="Ok", command=top.destroy)
b.pack()

def myshowinfo(self, title='', msg=''):
'''a workalike for the tkMessageBox showinfo since the former
results in invisible text in cygwin'''
self.mymessage(title, msg,'info')
root.focus_set()
root.update()
root = Tk()
app = AppUI(root)
app.drawGui()
app.pack()
root.mainloop()
thanks,
--
Stewart Midwinter
st*****@midwinter.ca
st***************@gmail.com
Skype, GoogleTalk, iChatAV, MSN, Yahoo: midtoad
AIM:midtoad1
Jan 5 '06 #1
0 2317

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

Similar topics

2
by: Jörg Maier | last post by:
Hey guys, i have a big problem using Tkinter and pexpect in cygwin. i try to program an winscp-like rsync Program for all posix Platforms (linux, macosx, cygwin). i got a class SslConnection...
0
by: dw | last post by:
Pehaba, does anyone knows how to install MySQLdb on cygwin? - test device: MySQLdb 0.9.2.0 targz + cygwin 1.5.7-cr-0x9e + python 2.3.3 on cygwin + mysql 4.0.17 win32 - modified setup.py's...
1
by: Laura Conrad | last post by:
I'm writing a GUI application in python, which will need to work on a Windows XP box. Mostly it does, but the feature where results are graphed in real time, which works fine on a debian LINUX...
1
by: Eric McRae | last post by:
I have created a somewhat complicated GUI which updates itself every 1/2 second by checking on several non-blocking sockets for data and modifying StringVars and/or canvas graphs when new...
0
by: denis | last post by:
Hello, Do you know if it is possible to use python + qt bindings in cygwin ? I've looked inside kde / cygwin. There is a package named qt-gcc-3 but I did'nt find the qt bindings for python :/ Is...
4
by: goberle | last post by:
I have installed the Cygwin package under WinXP. I am trying to insure that I have a reasonable development environment, and that things are working properly, by trying to compile and run the...
2
by: Steve Holden | last post by:
Is anyone aware of (a fix for) problems I'm having getting PIL 1.1.5 to create bitmaps using TrueType and openType fonts? When I create an image using the standard PIL fonts everything seems fine,...
0
by: gh14tq5 | last post by:
Hi, I've recently started learning python programming and have been experimenting with a few basic GUI programs. My work system is cygwin/Windows XP. I use X-windows in cygwin but when I run...
2
by: Stewart Midwinter | last post by:
this has me puzzled; I've created a small test app to show the problem I'm having. I want to use subprocess to execute system commands from inside a Tkinter app running under Cygwin. When I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.