基于argparse的命令行工具的自动生成ui

argparseui的Python项目详细描述


此文件是argparseui的一部分。

argparseui is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

argparseui is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with argparseui. If not, see <http://www.gnu.org/licenses/>.

argparseui

argparseui

的目的

argparseui可用于快速自动生成ui 从基于argparse的命令行工具

用户界面具有允许设置命令行选项的小部件

argparseui取决于pyqt

argparseui的状态

argparseui是我自己的工具

因此,它不支持argparse的所有可能性

使用时自行承担风险,但请随时记录错误/请求

基本解析器用法

import argparse
import sys
from PyQt4 import QtGui
import argparseui

# EXPERIMENT USING BASIC PARSER
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--make-argument-true", help="optional boolean argument", action="store_true")
parser.add_argument("-o","--make-other-argument-true", help="optional boolean argument 2", action="store_true",  default=True)
parser.add_argument("-n","--number", help="an optional number", type=int)
parser.add_argument("-r","--restricted-number", help="one of a few possible numbers", type=int, choices=[1,2,3],  default=2)
parser.add_argument("-c", "--counting-argument", help="counting #occurrences", action="count")
parser.add_argument("-d", "--default-value-argument", help="default value argument", type=float, default="3.14")
group = parser.add_mutually_exclusive_group()
group.add_argument("-v", "--verbose", action="store_true")
group.add_argument("-q", "--quiet", action="store_true")
parser.add_argument("posarg", help="positional argument", type=str)

app = QtGui.QApplication(sys.argv)
a = argparseui.ArgparseUi(parser)
a.show()
app.exec_()

if a.result() == 1: # Ok pressed
    parsed_args = a.parse_args() # ask argparse to parse the options
    print parsed_args            # print the parsed_options

# Do what you like with the arguments...

示例:使用“保存/加载”按钮并在按“确定”时保持对话框打开

import argparse
import sys
from PyQt4 import QtGui
import argparseui

def do_something(argparseuiinstance):
    options = argparseuiinstance.parse_args()
    print ("Options: ", options)

parser = argparse.ArgumentParser()
parser.add_argument("-m", "--make-argument-true", help="optional boolean argument", action="store_true")
parser.add_argument("-o","--make-other-argument-true", help="optional boolean argument 2", action="store_true",  default=True)

app = QtGui.QApplication(sys.argv)
a =     argparseui.ArgparseUi(parser,use_save_load_button=True,ok_button_handler=do_something)
a.show()
app.exec_()
if a.result() != 1:
    # Do what you like with the arguments...
    print ("Cancel pressed")

扩展功能

您可以将一些额外的命令行参数传递给argparseui:

*helptext_default* = string [default: ' [default=%(default)s]']
this argument can be used to customize the default value annotations in the ui

*remove\_defaults\_from_helptext* = True/False [default: False]
if enabled, this option will remove the default value annotations from
the labels in the ui

*use\_save\_load_button* = True/False [default: False]
if set to True, three extra buttons [Load options, Save Options, Save Options As] appear
the options are saved to (or loaded from) a command line option file in a file format compatible with
argparse's built-in support for loading options from file

*use_scrollbars* = True/False [default: False]
if set to True, the options are embedded in a scrollable panel

*window_title* = string [default: "Make your choice"]
if set to a string, this string will be used as dialog title

*left\_label\_alignment* = True/False [default: None]
if set to True, the checkboxes are left-aligned. This may be useful on platforms
like KDE or MacOsx which by default use right-alignment

*ok\_button\_handler* = function taking one argument [default:None]
if set to None, the dialog will close upon clicking the ok button and its result will be set to 1
if set to a function accepting an ArgparseUi instance as argument, clicking ok will call that function
with "self" as argument

*cancel\_button\_handler* = function taking one argument [default:None]
if set to None, the dialog will close upon clicking cancel and its result will be != 1
if set to a function accepting an ArgparseUi instance as argument, clicking cancel will call that
function with "self" as argument

贡献者

以下人员对argparseui做出了贡献

  • Stefaan Himpe
  • Thomas Hisch

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Dropbox java登录   java如何将“abcd1234”转换为INT1234   java如何实现compareTo()?   java如何查看SWT示例(Eclipse)源代码?   java内存直接映射到字符串   传递字符串时java Android应用程序崩溃   java是将Android游标(sqlite)提取到数组中以在AlertDialog中使用的最有效的方法。建设者   java如何检查udp/多播端口是否打开且可用?   如何在Java中创建弱引用?   java相同的异常针对不同的异常   swing Java JFrame问题与对话框   Eclipse Mars与Maven和SVN之间的java冲突?   如何在Java+swt中将对象停靠到父窗口?   如何区分Java输入类型?   java在Spring批处理中读取一个项目并将项目列表写入文件   java如何减少数据库表行整数值   java NullPointerException,即使对象不为null   如果站点地图的URL数超过maxnumber,则java会将其拆分为多个站点地图   java JFR显示LmaxDisruptor引擎内部的CPU利用率很高