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
こんなんなる。
よくこんなスクラップブックで計算したりする。
コメント