我正在编写脚本程序,并且在UI方面有些挣扎。我已经制作了几个UI,所有这些UI似乎都可以单独正常工作,但是我不知道如何将在UI中输入的数据用于其他功能。我正在尝试获取Gun类型(由用户在中选择Bullet_Spray_Generator
),然后影响随后调用哪个UI。每种枪支类型均需要不同的滑块值集,因此我为每种滑块创建了不同的UI。我认为我需要将从BSG中选择的数据传递到if
函数中,以调用正确的(第二个)UI,但是运行它总是会跳转到该else
函数并关闭窗口。到目前为止,这是我的代码:
import maya.cmds as cmds
from functools import partial
if (cmds.window("Bullet_Spray_Generator", exists = True)):
cmds.deleteUI("Bullet_Spray_Generator")
if (cmds.window("BSG2", exists = True)):
cmds.deleteUI("BSG2")
cmds.select(all=True)
cmds.delete()
def goShoot(numOfShots, distToTarget, *pArgs):
print "Begin"
cmds.deleteUI("BSG2")
createWall()
def cancelShoot(*pArgs):
print "cancel"
cmds.deleteUI("Bullet_Spray_Generator")
def createWall():
cmds.select(all=True)
cmds.delete()
wall = cmds.polyCube(h=10, w=15, d=1, name='wall')
cmds.move(0,5,0, 'wall')
def createGunUI(gunType, *pArgs):
if (GunSelectCtrl == 'Pistol'):
createPistolUI()
elif (GunSelectCtrl == 'Shotgun'):
createShotgunUI()
elif (GunSelectCtrl == 'SMG'):
createSMGUI()
elif (GunSelectCtrl == 'Sniper Rifle'):
createSniperUI()
elif (GunSelectCtrl == 'RPG'):
createRPGUI()
else:
print "Something went wrong"
cancelShoot()
def createPistolUI():
cmds.window("Pistol")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=9, value=4, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("Pistol")
def createShotgunUI():
cmds.window("Shotgun")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=4, value=2, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("Shotgun")
def createSMGUI():
cmds.window("SMG")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=20, value=4, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("SMG")
def createSniperUI():
cmds.window("Sniper")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=2, value=2, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("Sniper")
def createRPGUI():
cmds.window("RPG")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=1, value=1, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("RPG")
def printNewMenuItem(item):
print item
return item
def createUI():
cmds.window("Bullet_Spray_Generator")
cmds.columnLayout(adjustableColumn=True)
GunSelectCtrl = cmds.optionMenu(label='Gun', changeCommand=printNewMenuItem)
cmds.menuItem(label='Pistol')
cmds.menuItem(label='Shotgun')
cmds.menuItem(label='SMG')
cmds.menuItem(label='Sniper Rifle')
cmds.menuItem(label='RPG')
cmds.button(label = "Continue", command = partial(createGunUI, GunSelectCtrl))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("Bullet_Spray_Generator")
createUI()
非常感谢您的任何帮助。
您应该使用字典:
myDic = {}
myDic["anyString"] = "Value, String, Tuples,...etc"
print myDic
使用dic的好处是您不必担心嵌套变量。
为了展示字典的功能,我还添加了一个函数createWeaponUI()
。
如果在选择Shotgun的情况下单击“
Continue”,它将使用createWeaponUI()创建一个手枪//弹枪UI。您只需要storedDataDic["weqponYouWant_preset"]
在顶部为每种武器添加即可生成所需的任何ui。相比于复制/粘贴50个UI并使用50
if / elif来告诉您应该使用哪种武器ui,它更容易阅读。
这是您使用dic修改的脚本:
import maya.cmds as cmds
from functools import partial
storedDataDic = {}
storedDataDic["weapon"] = ["Pistol", "Shotgun", "SMG", "Sniper Rifle", "RPG"]
storedDataDic["weaponSelected"] = storedDataDic["weapon"][0]
storedDataDic["Shotgun_preset"] = [(1,4,2), (1,50,25)]
storedDataDic["Pistol_preset"] = [(1,18,2), (1,25,10)]
if (cmds.window("Bullet_Spray_Generator", exists = True)):
cmds.deleteUI("Bullet_Spray_Generator")
if (cmds.window("BSG2", exists = True)):
cmds.deleteUI("BSG2")
cmds.select(all=True)
cmds.delete()
def goShoot(numOfShots, distToTarget, *pArgs):
print "Begin"
cmds.deleteUI("BSG2")
createWall()
def cancelShoot(*pArgs):
print "cancel"
cmds.deleteUI("Bullet_Spray_Generator")
def createWall():
cmds.select(all=True)
cmds.delete()
wall = cmds.polyCube(h=10, w=15, d=1, name='wall')
cmds.move(0,5,0, 'wall')
def createGunUI(gunType, *pArgs):
if (gunType == 'Pistol'):
createWeaponUI()
elif (gunType == 'Shotgun'):
createWeaponUI()
elif (gunType == 'SMG'):
createSMGUI()
elif (gunType == 'Sniper Rifle'):
createSniperUI()
elif (gunType == 'RPG'):
createRPGUI()
else:
print "Something went wrong"
cancelShoot()
def createPistolUI():
cmds.window("Pistol")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=9, value=4, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("Pistol")
def createShotgunUI():
cmds.window("Shotgun")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=4, value=2, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("Shotgun")
def createSMGUI():
cmds.window("SMG")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=20, value=4, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("SMG")
def createSniperUI():
cmds.window("Sniper")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=2, value=2, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("Sniper")
def createRPGUI():
cmds.window("RPG")
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
NumBulletsCtrl = cmds.intSliderGrp(label='Number of Shots',
minValue=1, maxValue=1, value=1, field=True)
DistCtrl = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=1, maxValue=50, value=25, field=True)
cmds.button(label = "Fire", command = lambda *args: goShoot(cmds.intSliderGrp(NumBulletsCtrl,
query=True, value=True), cmds.intSliderGrp(DistCtrl, query=True, value=True), ))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("RPG")
def printNewMenuItem(item):
print item
storedDataDic["weaponSelected"] = item
return storedDataDic["weaponSelected"]
def ui_refreshSelWeapon(fun, *args):
createGunUI(storedDataDic["weaponSelected"])
def createUI():
cmds.window("Bullet_Spray_Generator")
cmds.columnLayout(adjustableColumn=True)
GunSelectCtrl = cmds.optionMenu(label='Gun', changeCommand=printNewMenuItem)
for i in storedDataDic["weapon"]:
cmds.menuItem(label=i)
cmds.button(label = "Continue", command = ui_refreshSelWeapon)
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow("Bullet_Spray_Generator")
createUI()
weapon_uiDic = {}
def createWeaponUI():
weaponName = storedDataDic["weaponSelected"]
if cmds.window(weaponName, exists=True):
cmds.deleteUI(weaponName)
cmds.window(weaponName)
cmds.columnLayout(adjustableColumn=True)
cmds.deleteUI("Bullet_Spray_Generator")
nbP= storedDataDic[weaponName + "_preset"][0]
dcP = storedDataDic[weaponName + "_preset"][1]
weapon_uiDic["NumBulletsCtrl"] = cmds.intSliderGrp(label='Number of Shots',
minValue=nbP[0], maxValue=nbP[1], value=nbP[2], field=True)
weapon_uiDic["DistCtrl"] = cmds.intSliderGrp(label='Distance to Target (metres)',
minValue=dcP[0], maxValue=dcP[1], value=dcP[2], field=True)
weapon_uiDic["fireButton"] = cmds.button(label = "Fire",
command = lambda *args: goShoot(cmds.intSliderGrp(weapon_uiDic["NumBulletsCtrl"],
query=True, value=True), cmds.intSliderGrp(weapon_uiDic["DistCtrl"], query=True, value=True)))
cmds.button(label = "Cancel", command = cancelShoot)
cmds.showWindow(weaponName)
- -编辑 - -
我预设了手枪以使其更清晰
我们有一个SpringBoot(版本1.5.12)REST Api,带有springfox-swagger2和springfox-swagger-ui(版本2.9.2) 我可以在http://localhost:8080/swagger-ui.html看到Swagger UI 我如何配置swagger-ui来读取我的swagger.yaml/json配置文件,而不是自动生成它?我尝试了几个配置都没
嗨,伙计们,我正在尝试使用自己的“导出”按钮创建多个表,我使用ui:重复标签生成所有数据表,问题是我需要将表的ID放在dataextor的目标属性中,因为在JSF中您不能动态生成ID,我无法区分数据表,它们都具有相同的ID:(:
问题内容: 我需要将两个参数传递并接收到要转换为使用ui-router的状态。 例如使用下面的链接将状态转换为with 和参数: 控制器中的接收和值: 我得到了在控制器中。 有人可以帮助我了解如何完成它吗? 编辑: 问题答案: 我创建了一个示例来说明如何操作。更新的定义将是: 这将是控制器: 我们可以看到,状态状态现在的url定义为: 这意味着url中的参数应为 这两个链接将正确地将参数传递给控制
本文向大家介绍Angularjs中的ui-bootstrap的使用教程,包括了Angularjs中的ui-bootstrap的使用教程的使用技巧和注意事项,需要的朋友参考一下 1.新建uiBootstrap.html页面,引入依赖的js和css类库 2.新建uiBootstrap.js文件,定义一个uiModule 模块,引入依赖的模块 3.定义dialog弹出窗口的模板 4.定义一个 UiCon
我正在玩spring WebFlux。我已经创建了一个项目,该项目将监听mongo封顶的集合,并在数据到达时返回数据流量。 我正在我的repository方法中使用。 我的控制器看起来像这样 一切正常。我通过添加一个对此进行了测试,每当有一个新项目添加到我的capped集合中时,doOnNext中的consumer就会被执行。 现在我想让这个显示在浏览器上。我想用ReactJs(我对前端是全新的)
一旦您下载了 jQuery UI,您将得到一个 zip 压缩包,包含下列文件: /css/ /development-bundle/ /js/ index.html 在网页上使用 jQuery UI 在文本编辑器中打开 index.html,您将看到引用了一些外部文件:主题、jQuery 和 jQuery UI。通常情况下,您需要在页面中引用这三个文件,以便使用 jQuery UI 的窗体小部件和