在我的脚本中,我有一个QPlainTextEdit窗口,当我运行按钮脚本时,在窗口中使用--- projectname-seg(Segment)-group_name ---打印一行,我的问题是:当我运行我的脚本行时被添加,当我再次运行它时被添加,但是我想在每次运行函数时在第二个-def Rev_Text中增加我的“ Seg”,就像每次运行函数时new_name change + 1一样。我在line_list中添加了新行,但是我无法提取最后一行并仅获得“ seg元素。我希望得到的结果精简于此:
---projectname-SEG01-group_name--->1st run function
---projectname-SEG02-group_name--->2nd run
---projectname-SEG03-group_name--->3rd run etc...
我的剧本:
`
from PySide2 import QtCore, QtWidgets
from PySide2.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit,QPlainTextEdit
from PySide2.QtCore import QSize
class Cam_Ext(QMainWindow):
def __init__(self, Custom):
QMainWindow.__init__(self, Custom)
self.setMinimumSize(QSize(700, 900))
self.setWindowTitle("Print groupes seletionner")
#self.reviewEdit = QtWidgets.QTextEdit()
###btn
self.btn = QtWidgets.QPushButton('Print groupes' , self)
self.btn.move(180, 100)
self.btn.resize(350, 40)
self.btn.setStyleSheet("background-color: rgb(255, 255, 255); font-family: arial; font-size: 17px; font-weight: bold;")
self.btn.clicked.connect(self.Renommer)
### text
self.line = QPlainTextEdit(self)
self.line.setStyleSheet("font-size: 14px; font-weight: bold; ")
self.line.move(100, 170)
self.line.resize(500, 400)
#btn 2
self.btn1 = QtWidgets.QPushButton('Plus', self)
self.btn1.move(180, 630)
self.btn1.resize(350, 40)
self.btn1.setStyleSheet("background-color: rgb(255, 255, 255); font-family: arial; font-size: 17px; font-weight: bold;")
self.btn1.clicked.connect(self.Rev_Text)
self.show()
def Renommer(self):
# -*- coding: utf-8 -*-
import PhotoScan
import os
doc = PhotoScan.app.document
pr_name = doc.path
project_name = os.path.split(pr_name)[-1]
os.path.splitext(project_name)
nn = os.path.splitext(project_name)[0]
print(nn,"nn")
group_list = list()
name_list = list()
groups = doc.chunk.camera_groups
# print(groups)
x = 0
seg = "Seg"
for group in groups:
if group.selected:
group_list.append(group.label)
else:
pass
new_name = str(nn[0:10]) + "-" + str(seg + str(x)) + "; " + str(' '.join(group_list))
#print(new_name)
self.line.appendPlainText("{}".format(new_name))
name_list.append(new_name)
# print(name_list, "name list")
def Rev_Text(self):
import os
import PhotoScan
from itertools import count
doc = PhotoScan.app.document
pr_name = doc.path
project_name = os.path.split(pr_name)[-1]
os.path.splitext(project_name)
nn = os.path.splitext(project_name)[0]
print(nn, "nn")
group_list = list()
name_list = list()
groups = doc.chunk.camera_groups
# print(groups)
x = 0
seg = "Seg"
for group in groups:
if group.selected:
group_list.append(group.label)
else:
pass
# print(new_name)
# self.line.appendPlainText("{}".format(new_name))
#
# name_list.append(new_name)
my_line = list()
text = self.line.toPlainText()
my_line.append(text)
print(my_line,"my line list liste avec tout les segments")
gg = ([item[-1] for item in my_line])
dd = [i.split(';', 1)[0] for i in my_line]
for xx in dd:
p = xx
print(p)
print(dd, "dd")
ddd = [i.split('-', 3)[3] for i in dd]
print(ddd, "dddddd")
# number = 0
# seg = "Seg"
i = 0
for x in ddd:
print(x,"x")
x = ('%s%02d' % i for i in count(1))
next(x)
# sss = ('%s%02d' %(x, i))
# i += 1
#new_s = str(new_seg)+1
new_name = str(nn[0:10]) + "-" + str(x) + "; " + str(' '.join(group_list))
# print(new_name, "new increment name")
self.line.appendPlainText("{}".format(new_name))
def main():
global doc
doc = PhotoScan.app.document
global app
app = QtWidgets.QApplication.instance()
Custom = app.activeWindow()
dlg = Cam_Ext(Custom)
PhotoScan.app.addMenuItem("Perazio/Print groupes seletionner", main)
任何帮助将不胜感激:-)
`