pyqt4程序运行问题求助
写了一个小程序,用pyqt4,在eclipse测试没问题,直接双击.py文件运行后不显示主界面,也无报错提示,不知是否还需要加什么参数?
#-*-coding: utf-8-*-
import sys
import os
from PyQt4 import QtGui
from xml.dom import minidom
#fileroot = {'handbook':'/Users/congl/Documents/handbook'}
fileroot = {}
menudict={}
windowx = 0
#urltag = '/' #mac
urltag = '\\' #win
config = minidom.parse('config.xml')
file = config.getElementsByTagName('file')[0]
dirs = file.getElementsByTagName('dirs')
for i in dirs:
fileroot[i.getAttribute('name')] = i.childNodes[0].toxml()
def loadICON():
p = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ico.png")
return QtGui.QIcon(p)
class Task(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(100, 100, 640, 480)
self.setFixedSize(640, 480)
self.box = QtGui.QHBoxLayout()
#icon设置
self.icon = QtGui.QSystemTrayIcon(loadICON(), self)
self.menu = QtGui.QMenu(self)
#菜单设置
self.setFileMenu() #创建文件菜单
self.setSysMenu() #设定系统功能菜单
self.icon.show()
self.setTab()
def setTab(self):
self.tab = QtGui.QTabWidget()
#er = QtGui.QLabel('PyQt\nLabel')
#self.setting = self.tab.addTab(er,'setting')
self.setQuickFile()
okBotton = QtGui.QPushButton('OK', self)
okBotton.setGeometry(540,440, 80, 20)
self.box.addWidget(okBotton)
#快捷文件
splitter = QtGui.QSplitter(self)
splitter.setGeometry(20, 10, 600, 420)
splitter.addWidget(self.tab)
def setQuickFile(self):
setDirTable = QtGui.QTableWidget(10,2)
setDirTable.setHorizontalHeaderLabels([u'菜单标示', u'路径'])
setDirTable.setColumnWidth(0, 100)
setDirTable.setColumnWidth(1, 200)
setDirTable.verticalHeader().setVisible(False) #左侧表头不可见
settingbox = self.tab.addTab(setDirTable, u'设置目录')
def setFileMenu(self):
for dictname in fileroot:
handbook = self.menu.addMenu(dictname.decode('utf-8'))
filedir = os.walk(fileroot[dictname].decode('utf-8'))
for roots, dirs, files in filedir:
for dir in dirs:
if(menudict.has_key(roots)):
menudict[roots + urltag + dir] = menudict[roots].addMenu(dir.decode('utf-8'))
else:
menudict[roots + urltag + dir] = handbook.addMenu(dir.decode('utf-8'))
for file in files:
if(menudict.has_key(roots)):
if '.DS_Store' != file:
fileMeun = menudict[roots].addAction(file.decode('utf-8'))
fileMeun.triggered.connect(self.openFile)
fileMeun.setObjectName(roots.decode('utf-8')+urltag+file.decode('utf-8'))
else:
if '.DS_Store' != file:
fileMeun = handbook.addAction(file.decode('utf-8'))
fileMeun.triggered.connect(self.openFile)
fileMeun.setObjectName(roots.decode('utf-8')+urltag+file.decode('utf-8'))
self.icon.setContextMenu(self.menu)
def setSysMenu(self):
self.menu.addSeparator()
#设置
#settingMenu = self.menu.addAction(u'设置')
#settingMenu.triggered.connect(self.setting)
#退出
quitMenu = self.menu.addAction(u'退出')
quitMenu.triggered.connect(self.quit)
#打开文件
def openFile(self):
sender = self.sender()
str = 'start ' + unicode(sender.objectName()) + ''
type = sys.getfilesystemencoding()
# os.system('open "' + unicode(sender.objectName()) + '"') #MAc
os.system(str.decode('UTF-8').encode(type)) #win
def quit(self):
# sys.exit()
self.close()
def setting(self, event):
windowx = self.cursor().pos().x()
self.setGeometry(windowx-320, 0, 640, 480)
app = QtGui.QApplication(sys.argv)
task = Task()
task.show()
sys.exit(app.exec_())