【发布时间】:2015-07-31 18:26:10
【问题描述】:
所以,我正在尝试整理一个基本的“版本控制”脚本供个人使用。它适用于命令行,但后来我决定加入一个 GUI。一切都开始变得奇怪了。
我正在使用 python 2.7.9 和可在https://github.com/chriskiehl/Gooey 获得的粘性版本
问题是解析器自己工作正常,它获取正确的数据,返回它,当我只启动我的 parse.py 文件时它就可用了。 Gui 窗口打开,我输入信息,它启动,我的调试打印显示正确的信息。
但是,当我尝试启动整个程序时,我在窗口中输入信息,点击开始,它只会弹出另一个粘糊糊的窗口,再次询问信息,依此类推,直到我决定关闭现在打开的 400 个窗口。似乎每次,它都会重新启动整个 Gooey 进程。
用于解析的函数:
import argparse
from gooey import Gooey
from gooey import GooeyParser
@Gooey
def initOptParser():
defaultFolderPath = "./TEST"
archivePath = "./Archives"
parser = argparse.ArgumentParser(description="Copy files to specified location")
parser.add_argument('files', metavar='file', type=str, nargs='+',
help='file(s) or directory that you wish to copy' )
parser.add_argument('-p', '--path', metavar='path',dest='path', type=str,
help='Path which will be considered as root of all projects. Default is currently : ' + defaultFolderPath,
default=defaultFolderPath)
parser.add_argument('projectName', metavar='projectName', type=str,
help='The project you wish to retrieve/add files to/from.')
parser.add_argument('-v', '--version', metavar='versionName', type=str,
help='The name of the directory which will be created during an update. By default, this will be : DATE_TIME.')
parser.add_argument('-o', '--overwrite',
help='Overwrites the files in the current version of specified project. (no new directory creation)', action="store_true")
parser.add_argument('-m', '--message', metavar='logMessage', type=str, help='Use to specify a log message which will be put in a .txt file. (default : commit.txt)')
parser.add_argument('-g', '--get', dest='method', action='store_const', help='Retrieve files from project (last version by default)', const=get, default=push)
parser.add_argument('-l', '--lock', action="store_true",
help='Locks the current project. Can be overriden/ignored on demand. (Will ask other users if they want to pull files)'+
'Unlocked when next push from the locking user is made')
parser.add_argument('user', metavar='userName', type=str, help='Specify your name.')
parser.add_argument('-a', '--archive', metavar='archivePath', type=str, help='Use to specify a directory which will be used as an archive. Current default is : ' + archivePath)
parser.add_argument('-s', '--store', metavar="destPath", help='Use to specify where you want the files retrieved from the project to be copied.')
args = parser.parse_args()
printOptions(args) # Just a basic function with a few prints to make sure data is there
args.method() # Either get() or push(). For now i'm using two factice functions who just print their name.
return (args)
initOptParser()
如果我们坚持这一点,所有数据都会保持正常,我可以访问它,一切都很好。
但是,当我尝试简单地这样做时:
import sys
sys.path.insert(0, 'C:/Users/USER/Projects/pythonFileScript/srcs')
import parse
def start():
parse.initOptParser()
由于 parse.py 在 srcs 目录中,而 launch.py 在 pythonFileScript 中,每次我输入参数并点击开始时,它就会崩溃并开始吐出一个窗口。
我觉得这真的很令人沮丧和好奇。而且我一生都无法弄清楚它为什么会这样做。
所以,我来找你了:到底为什么会发生这种情况?
如果我的问题似乎缺少任何细节,或者不够明确/研究/详细,请告诉我,我会适当修改。
【问题讨论】: