100が消したいので両方に100かけて
2分の1は0.5なので1割る2
100 *0.5 =50
100 * 現在の値 (1) / 配列の長さ(2) = X
100 *0.5 =50
percent= 100*i/arr_len
こうなるので
重たい処理を入れないとうまく見えないが。実際に動くサンプル(動かない)
# -*- coding: utf-8 -*-
import os
from functools import partial
import time
import imp
import maya.cmds as cmds
from maya import OpenMaya
import maya.api.OpenMaya as om
from collections import OrderedDict
import math
from pymel.core import *
import pymel.core as pm
import maya.mel as mel
try:
imp.find_module('PySide2')
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
except ImportError:
from PySide.QtGui import *
from PySide.QtCore import *
def get_maya_pointer():
try:
import maya.cmds as cmds
from maya import OpenMayaUI
except ImportError:
return None
try:
imp.find_module("shiboken2")
import shiboken2
return shiboken2.wrapInstance(long(OpenMayaUI.MQtUtil.mainWindow()), QWidget)
except ImportError:
import shiboken
return shiboken.wrapInstance(long(OpenMayaUI.MQtUtil.mainWindow()), QWidget)
class Sample_UI(QMainWindow):
def __init__(self, parent = None):
super(Sample_UI, self).__init__(parent)
self.setObjectName("Sample_Window")
self.setWindowTitle("Sample Window")
#self._initUI()
self.errorDialog = QErrorMessage(self)
def _initUI(self):
wrapper = QWidget()
self.setCentralWidget(wrapper)
mainLayout = QVBoxLayout()
self.havyFunc()
def _showProgressDialog(self):
print("---------------------ProgressBar Starting--------------------------")
self.max = 100
self.progressDialog = QProgressDialog("Progress...", "Cancel", 0, self.max, self)
self.progressDialog.setWindowTitle("Progress Dialog")
def setProgress(self,count):
print("---------------------setProgress ( "+str(count)+"/100 )--------------------------")
qApp.processEvents()
if self.progressDialog.wasCanceled():
self.progressDialog.setValue(100)
self.progressDialog.setValue(count)
self.progressDialog.setLabelText("Progress... %d %%" % count)
def havyfunc(self):
#--------------------------------------------------
self._showProgressDialog()
self.setProgress(1)
#--------------------------------------------------
duplicatedMesh_vtx_arr=[1,2,3,4,5]
arr_len=len(duplicatedMesh_vtx_arr)
for i in range(0,duplicatedMesh_vtx_arr_len):
#---------------------------------------------------
parcent=(100*i/duplicatedMesh_vtx_arr_len) /2
self.setProgress(parcent)
print("setProgress("+str(parcent)+")")
#---------------------------------------------------
#重たい処理1
for i in range(0,duplicatedMesh_vtx_arr_len):
#---------------------------------------------------
parcent=(100*i/duplicatedMesh_vtx_arr_len) /2 +50
self.setProgress(parcent)
print("setProgress("+str(parcent)+")")
#---------------------------------------------------
#重たい処理2
#--------------------------------------
self.setProgress(100)
print("setProgress("+str(100)+")")
#--------------------------------------
def start():
maya_win = get_maya_pointer()
ui = Sample_UI(parent = maya_win)
#ui= MyDialog()
ui.show()
return ui
def starter():
app = QApplication.instance()
if app is None:
app = QApplication([])
ui = start()
app.exec_()
print("__name__= "+__name__)
#if __name__ == '__main__':
if __name__ == 'NppMaya' or __name__ == '__main__':
starter()
いっこめの重い処理
parcent=(100*i/duplicatedMesh_vtx_arr_len) /2
にこめの重い処理
parcent=(100*i/duplicatedMesh_vtx_arr_len) /2 +50
こんなんなる。
よくこんなスクラップブックで計算したりする。
うごかないので更新しておいた。
# -*- coding: utf-8 -*-
import os
from functools import partial
import time
import imp
"""
PySide2モジュールを探し、ある場合はそちらをインポートします。
"""
try:
imp.find_module('PySide2')
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
except ImportError:
from PySide.QtGui import *
from PySide.QtCore import *
LOGO_IMAGE = r"画像のパスをここに入れてください。"
def get_maya_pointer():
"""
Mayaのメインウィンドウを取得する関数
"""
try:
import maya.cmds as cmds
from maya import OpenMayaUI
except ImportError:
return None
"""
実は2017ではshibokenも2になっているので、あればshiboken2をインポートします。
"""
try:
imp.find_module("shiboken2")
import shiboken2
return shiboken2.wrapInstance(int(OpenMayaUI.MQtUtil.mainWindow()), QWidget)
except ImportError:
import shiboken
return shiboken.wrapInstance(int(OpenMayaUI.MQtUtil.mainWindow()), QWidget)
class DF_TalkUI(QMainWindow):
def __init__(self, parent = None):
super(DF_TalkUI, self).__init__(parent)
self.setObjectName("DF_Talk_Window")
self.setWindowTitle("DF Talk Window")
#self._initUI()
self.errorDialog = QErrorMessage(self) # QErrorMessageインスタンスの保持
def myInit(self,qApp):
self.qApp=qApp
wrapper = QWidget()
self.setCentralWidget(wrapper)
mainLayout = QVBoxLayout()
wrapper.setLayout(mainLayout)
#-----------------------------------------------------------------------
# sixth row
#-----------------------------------------------------------------------
sixthHorizontalArea = QHBoxLayout()
sixthHorizontalArea.setSpacing(20)
mainLayout.addLayout(sixthHorizontalArea)
progressDialogBtn = QPushButton("Progress Dialog")
sixthHorizontalArea.addWidget(progressDialogBtn)
progressDialogBtn.clicked.connect(self._showProgressDialog)
#-----------------------------------------------------------------------
# seventh row
#-----------------------------------------------------------------------
def _makeHorizontalLine(self):
hline = QFrame()
hline.setFrameShape(QFrame.HLine)
hline.setFrameShadow(QFrame.Sunken)
return hline
def _showProgressDialog(self):
"""
QProgressDialog表示スロット
"""
max = 100
progressDialog = QProgressDialog("Progress...", "Cancel", 0, max, self)
progressDialog.setWindowTitle("Progress Dialog")
for count in range(max+1):
self.qApp.processEvents()
if progressDialog.wasCanceled():
break
progressDialog.setValue(count)
progressDialog.setLabelText("Progress... %d %%" % count)
time.sleep(0.1)
def start(app):
maya_win = get_maya_pointer()
ui = DF_TalkUI(parent = maya_win)
ui.myInit(app)
ui.show()
return ui
if __name__ == '__main__':
app = QApplication.instance()
if app is None:
app = QApplication([])
ui = start(app)
app.exec_()
動くように直したもの
# -*- coding: utf-8 -*-
import os
from functools import partial
import time
import imp
"""
PySide2モジュールを探し、ある場合はそちらをインポートします。
"""
try:
imp.find_module('PySide2')
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
except ImportError:
from PySide.QtGui import *
from PySide.QtCore import *
LOGO_IMAGE = r"画像のパスをここに入れてください。"
def get_maya_pointer():
"""
Mayaのメインウィンドウを取得する関数
"""
try:
import maya.cmds as cmds
from maya import OpenMayaUI
except ImportError:
return None
"""
実は2017ではshibokenも2になっているので、あればshiboken2をインポートします。
"""
try:
imp.find_module("shiboken2")
import shiboken2
return shiboken2.wrapInstance(int(OpenMayaUI.MQtUtil.mainWindow()), QWidget)
except ImportError:
import shiboken
return shiboken.wrapInstance(int(OpenMayaUI.MQtUtil.mainWindow()), QWidget)
class DF_TalkUI(QMainWindow):
def __init__(self, parent = None):
super(DF_TalkUI, self).__init__(parent)
self.setObjectName("DF_Talk_Window")
self.setWindowTitle("DF Talk Window")
#self._initUI()
self.errorDialog = QErrorMessage(self) # QErrorMessageインスタンスの保持
def myInit(self,qApp):
self.qApp=qApp
wrapper = QWidget()
self.setCentralWidget(wrapper)
mainLayout = QVBoxLayout()
wrapper.setLayout(mainLayout)
#-----------------------------------------------------------------------
# sixth row
#-----------------------------------------------------------------------
sixthHorizontalArea = QHBoxLayout()
sixthHorizontalArea.setSpacing(20)
mainLayout.addLayout(sixthHorizontalArea)
progressDialogBtn = QPushButton("Progress Dialog")
sixthHorizontalArea.addWidget(progressDialogBtn)
progressDialogBtn.clicked.connect(self.havyfunc)
#-----------------------------------------------------------------------
# seventh row
#-----------------------------------------------------------------------
#self.havyfunc()
def _showProgressDialog(self):
print("---------------------ProgressBar Starting--------------------------")
self.max = 100
self.progressDialog = QProgressDialog("Progress...", "Cancel", 0, self.max, self)
self.progressDialog.setWindowTitle("Progress Dialog")
self.progressDialog.show()
def setProgress(self,count):
print("---------------------setProgress ( "+str(count)+"/100 )--------------------------")
self.qApp.processEvents()
if self.progressDialog.wasCanceled():
self.progressDialog.setValue(100)
self.progressDialog.setValue(count)
self.progressDialog.setLabelText("Progress... %d %%" % count)
def havyfunc(self):
#--------------------------------------------------
self._showProgressDialog()
self.setProgress(1)
#--------------------------------------------------
duplicatedMesh_vtx_arr=[1,2,3,4,5]
duplicatedMesh_vtx_arr_len=len(duplicatedMesh_vtx_arr)
for i in range(0,duplicatedMesh_vtx_arr_len):
#---------------------------------------------------
parcent=(100*i/duplicatedMesh_vtx_arr_len) /2
self.setProgress(parcent)
print("setProgress("+str(parcent)+")")
time.sleep(0.1)
#---------------------------------------------------
#重たい処理1
for i in range(0,duplicatedMesh_vtx_arr_len):
#---------------------------------------------------
parcent=(100*i/duplicatedMesh_vtx_arr_len) /2 +50
self.setProgress(parcent)
print("setProgress("+str(parcent)+")")
time.sleep(0.1)
#---------------------------------------------------
#重たい処理2
#--------------------------------------
self.setProgress(100)
print("setProgress("+str(100)+")")
#--------------------------------------
def _makeHorizontalLine(self):
hline = QFrame()
hline.setFrameShape(QFrame.HLine)
hline.setFrameShadow(QFrame.Sunken)
return hline
"""
def _showProgressDialog(self):
#QProgressDialog表示スロット
max = 100
progressDialog = QProgressDialog("Progress...", "Cancel", 0, max, self)
progressDialog.setWindowTitle("Progress Dialog")
for count in range(max+1):
self.qApp.processEvents()
if progressDialog.wasCanceled():
break
progressDialog.setValue(count)
progressDialog.setLabelText("Progress... %d %%" % count)
time.sleep(0.1)
"""
def start(app):
maya_win = get_maya_pointer()
ui = DF_TalkUI(parent = maya_win)
ui.myInit(app)
ui.show()
return ui
if __name__ == '__main__':
app = QApplication.instance()
if app is None:
app = QApplication([])
ui = start(app)
app.exec_()