QPlainTextEdit text and increase filename in new line in the window

走远了吗. 提交于 2019-12-24 19:13:40

问题


In my script I have a QPlainTextEdit window , when I run my pushbutton script printing a line in my window with ---projectname-seg(Segment)-group_name---, My problem is: when I run my script line is added, when I run it again is added to but I would like to increase my "Seg" in my second -def Rev_Text, each time when I run my function, like new_name change+1 each time when I run my function. I add a new line to my line_list but I can't extract last line and get only "seg element. I would like to get results lite that:

---projectname-SEG01-group_name--->1st run function
---projectname-SEG02-group_name--->2nd run
---projectname-SEG03-group_name--->3rd run etc...

That my script:

    `

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)

Any help will be appreciated :-)

`

来源:https://stackoverflow.com/questions/51781776/qplaintextedit-text-and-increase-filename-in-new-line-in-the-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!