class MainWindow(QMainWindow): # Variável armazena a última fonte selecionada. last_font = QFont() def __init__(self): super(MainWindow, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Widgets. self.label = self.ui.findChild(QObject, 'label') button = self.ui.findChild(QObject, 'button') button.clicked.connect(self.open_dialog) self.ui.show() def open_dialog(self): response, font = QFontDialog().getFont( self.last_font, parent=self.ui, title='Configuração da fonte.', ) if response: self.label.setText(f'Fonte selecionada: {font.family()}') self.label.setFont(font) self.last_font = font
class StoryScreen(QObject): story_finish = Signal() def __init__(self, ui_file, parent=None): super(StoryScreen, self).__init__(parent) self.window = QUiLoader().load(ui_file) self.extract_items() self.connect_signals() self.scene = 0 self.storyText = [] self.storyBegin = False image = QPixmap("images/cern_color.jpg") self.bottom_image.setPixmap(image) self.window.hide() def extract_items(self): self.next_button = self.window.findChild(QPushButton, "next_button") self.story_box = self.window.findChild(QTextBrowser, "story_box") self.story_image = self.window.findChild(QLabel, "story_image") self.bottom_image = self.window.findChild(QLabel, "bottom_image") def connect_signals(self): self.next_button.clicked.connect(self.go_next_screen) @Slot() def open_window(self): self.window.show() @Slot() def close_window(self): self.window.hide() def set_story_start(self): self.storyBegin = True self.scene += 1 self.update_screen() def go_next_screen(self): if not self.storyBegin: return if self.scene == 6: self.window.hide() self.scene = 0 self.update_screen() self.storyBegin = False self.story_box.clear() self.story_finish.emit() else: self.scene += 1 self.update_screen() def update_screen(self): self.story_box.setText(self.storyText[self.scene]) image = QPixmap("images/image_10{}.jpg".format(self.scene)) self.story_image.setPixmap(image)
class MainWidget(QWidget): last_color = Qt.white def __init__(self): super(MainWidget, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Widgets. self.label = self.ui.findChild(QObject, 'label') button = self.ui.findChild(QObject, 'button') button.clicked.connect(self.open_dialog) self.ui.show() def open_dialog(self): color = QColorDialog().getColor( parent=self.ui, title='Selecione uma cor', initial=self.last_color, ) if color.isValid(): self.last_color = color palette = self.label.palette() palette.setColor(QPalette.Background, color) self.label.setPalette(palette)
class AddVariableWindow(QObject): add_variable = Signal(Variable) def __init__(self, ui_file, compartment_list, parent=None): super(AddVariableWindow, self).__init__(parent) ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) self.window = QUiLoader().load(ui_file) add_button = self.window.findChild(QPushButton, 'AddButton') add_button.clicked.connect(self.on_add_clicked) self.compartment_list = compartment_list self.origin_combobox = self.window.findChild(QComboBox, 'OriginComboBox') self.destination_combobox = self.window.findChild( QComboBox, 'DestinationComboBox') for compartment in compartment_list: self.origin_combobox.addItem(compartment.name) self.destination_combobox.addItem(compartment.name) self.origin_combobox.addItem('Birth') self.destination_combobox.addItem('Death') self.window.setWindowIcon(QIcon(os.path.join( 'ui_files', 'icon.png'))) # Set the window icon self.window.show() def on_add_clicked(self): equationLE = self.window.findChild(QLineEdit, 'EquationLE') descriptionLE = self.window.findChild(QLineEdit, 'DescriptionLE') try: origin = self.compartment_list[self.origin_combobox.currentIndex()] except IndexError: origin = None try: end = self.compartment_list[ self.destination_combobox.currentIndex()] except IndexError: end = None if origin == end and origin is None: # Both are None QMessageBox.critical(self.window, "Error", "Origin and End cannot be Birth and Death") return elif origin == end: # Both are the same but not None QMessageBox.critical(self.window, "Error", "Origin and End cannot be the same") return new_variable = Variable(equation=parse_latex(str( equationLE.text())).simplify(), origin=origin, end=end, description=str(descriptionLE.text())) self.add_variable.emit(new_variable) self.window.destroy()
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Acessando a barra de ferramentas. # Toolbar pode ser movido para diversas áreas da janela. action_copiar = self.ui.findChild(QObject, 'action_copiar') action_copiar.triggered.connect(self.action_copy) action_colar = self.ui.findChild(QObject, 'action_colar') action_colar.triggered.connect(self.action_paste) self.ui.show() @staticmethod def action_copy(): print('Copiar') @staticmethod def action_paste(): print('Colar')
class MainWindow(QMainWindow): current_value = 0 def __init__(self): super(MainWindow, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Widgets. self.label = self.ui.findChild(QObject, 'label') button = self.ui.findChild(QObject, 'button') button.clicked.connect(self.start_progress_again) self.progress_dialog = QProgressDialog( parent=self.ui, labelText=( 'Ao clicar em cancelar o timer (QTimer) será parado e a barra ' 'de progresso é reiniciada.' ), cancelButtonText='Cancelar', minimum=0, maximum=100, ) self.progress_dialog.setWindowTitle('Titulo da janela de diálogo') self.progress_dialog.setModal(True) self.progress_dialog.canceled.connect(self.stop_progress) self.timer = QTimer() self.timer.timeout.connect(self.start_progress) self.timer.start(1000) self.ui.show() def start_progress(self): if self.current_value >= self.progress_dialog.maximum(): self.timer.stop() self.progress_dialog.reset() self.current_value = 0 else: self.current_value += 10 self.progress_dialog.setValue(self.current_value) def start_progress_again(self): self.timer.start(1000) def stop_progress(self): self.timer.stop() self.progress_dialog.reset() self.current_value = 0
class BankWindow(QObject): get_loan = Signal(int) def __init__(self, ui_file, parent=None): super(BankWindow, self).__init__(parent) self.window = QUiLoader().load(ui_file) self.extract_buttons() self.connect_signals() self.window.hide() def extract_buttons(self): self.interest_list = self.window.findChild(QListWidget, 'interest_list') self.back_button = self.window.findChild(QPushButton, 'back_button') self.loan_100_button = self.window.findChild(QPushButton, 'loan_100_button') self.loan_30_button = self.window.findChild(QPushButton, 'loan_30_button') self.loan_10_button = self.window.findChild(QPushButton, 'loan_10_button') def connect_signals(self): self.back_button.clicked.connect(self.close_window) self.loan_100_button.clicked.connect(self.loan_100) self.loan_30_button.clicked.connect(self.loan_30) self.loan_10_button.clicked.connect(self.loan_10) def open_window(self): self.window.show() def close_window(self): self.window.hide() def set_loan_amount(self, maxLoanAmount, loanInterest): self.interest_list.clear() self.interest_list.addItem( str("Max Loan Amount: ") + str(maxLoanAmount)) self.interest_list.addItem(str("Loan Interest: ") + str(loanInterest)) def loan_100(self): self.get_loan.emit(1.0) self.window.hide() def loan_30(self): self.get_loan.emit(0.3) self.window.hide() def loan_10(self): self.get_loan.emit(0.1) self.window.hide()
class MainScreen(QObject): submit_id = Signal(str) open_story = Signal() def __init__(self, ui_file, parent=None): super(MainScreen, self).__init__(parent) self.window = QUiLoader().load(ui_file) self.extract_items() self.connect_signals() self.inStory = False image = QPixmap("images/main.jpg") self.base_image.setPixmap(image) self.window.show() def extract_items(self): self.submit_button = self.window.findChild(QPushButton, "submit_button") self.input_line = self.window.findChild(QLineEdit, "input_line") self.base_image = self.window.findChild(QLabel, "base_image") def connect_signals(self): self.submit_button.clicked.connect(self.submit_id_number) self.submit_button.clicked.connect(self.input_line.clear) def open_window(self): self.window.show() def close_window(self): self.window.hide() @Slot() def set_story_false(self): self.inStory = False self.window.show() def submit_id_number(self): if self.inStory: return id = self.input_line.text() self.submit_id.emit(id) self.open_story.emit() self.inStory = True self.window.hide()
class MainWindow(QObject): def __init__(self): super().__init__() self.window = QUiLoader().load('./MainWindow.xml') self.label = self.window.findChild(QObject, 'label') self.line_edit = self.window.findChild(QObject, 'line_edit') self.window.show() @Slot() def on_button_clicked(self): text = self.line_edit.text() if text: self.label.setText(text) else: self.label.setText('Digite algo no campo de texto :)')
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Acessando o menu e conectando os métodos. action_sair_1 = self.ui.findChild(QObject, 'action_sair_1') action_sair_1.triggered.connect(self.close_app) action_sair_2 = self.ui.findChild(QObject, 'action_sair_2') action_sair_2.triggered.connect(self.close_app) action_sobre = self.ui.findChild(QObject, 'action_sobre') action_sobre.triggered.connect(self.about) self.ui.show() def close_app(self): self.ui.close() def about(self): icon = QIcon() icon.addPixmap(QPixmap('../../../images/icons/icon.png')) message_box = QMessageBox(parent=self) message_box.setWindowTitle('Título da caixa de texto') message_box.setWindowIcon(icon) message_box.setText( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ' 'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ' 'ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut ' 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' 'Excepteur sint occaecat cupidatat non proident, sunt in culpa ' 'qui officia deserunt mollit anim id est laborum.') response = message_box.exec() message_box.close()
class AddCompartment(QObject): add_compartment = Signal(Compartment) def __init__(self, ui_file, parent=None): super(AddCompartment, self).__init__(parent) ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) self.window = QUiLoader().load(ui_file) add_button = self.window.findChild(QPushButton, 'AddButton') add_button.clicked.connect(self.on_add_clicked) self.nameLE = self.window.findChild(QLineEdit, 'NameLE') self.symbolLE = self.window.findChild(QLineEdit, 'SymbolLE') self.initLE = self.window.findChild(QLineEdit, 'InitLE') self.infectionStateCheckBox = self.window.findChild( QCheckBox, 'InfectionStateCheckBox') # Add Constraints self.initLE.setValidator(QDoubleValidator()) self.nameLE.setMaxLength(32) self.symbolLE.setMaxLength(32) self.initLE.setMaxLength(16) self.window.setWindowIcon(QIcon(os.path.join( 'ui_files', 'icon.png'))) # Set the window icon self.window.show() def on_add_clicked(self): new_compartment = Compartment( name=str(self.nameLE.text()), symbol=sym.symbols(str(self.symbolLE.text())), value=float(self.initLE.text()), infection_state=True if self.infectionStateCheckBox.isChecked() else False) self.add_compartment.emit(new_compartment) self.window.destroy()
class MainWindow(QObject): def __init__(self): super().__init__() # Variável `window` **DEVE** utilizar `self`! # Variável window recebe a janela principal e os widgets. self.window = QUiLoader().load('./MainWindow.ui') # Acessando/atribuindo os widgets. self.label = self.window.findChild(QObject, 'label') self.line_edit = self.window.findChild(QObject, 'line_edit') push_button = self.window.findChild(QObject, 'push_button') # Conectando o signal a um slot. push_button.clicked.connect(self.on_button_clicked) self.window.show() def on_button_clicked(self): text = self.line_edit.text() if text: self.label.setText(text) else: self.label.setText('Digite algo no campo de texto :)')
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Widgets. self.label = self.ui.findChild(QObject, 'label') self.line_edit = self.ui.findChild(QObject, 'line_edit') push_button = self.ui.findChild(QObject, 'push_button') push_button.clicked.connect(self.on_button_clicked) self.ui.show() def on_button_clicked(self): text = self.line_edit.text() if text: self.label.setText(text) else: self.label.setText('Digite algo no campo de texto :)')
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Acessando a barra de estatus. statusbar = self.ui.findChild(QObject, 'statusbar') statusbar.setStyleSheet('color: red') statusbar.showMessage('Texto que será exibido na barra de estatus.', 5000) self.ui.show()
class HWindows(QWidget): def __init__(self, parent=None): super(HWindows, self).__init__() #? 创建文件夹 self.scripts_path = os.path.dirname( os.path.realpath(__file__)).replace('\\', '/') if not os.path.exists(self.scripts_path + "/HDRI_Path"): os.mkdir(self.scripts_path + "/HDRI_Path") #? load hdr_path try: hdrfile = open( self.scripts_path + "/HDRI_Path/hdri_browser_path.txt", 'r+') txt = hdrfile.readline() hdrfile.close() self.hdri = txt self.temp = "0" except (SyntaxError, IOError): hdrfile = open( self.scripts_path + "/HDRI_Path/hdri_browser_path.txt", 'w+') hdrfile.close() self.hdri = "" self.temp = "0" #? load render.txt try: render = open(self.scripts_path + "/HDRI_Path/render.txt", 'r+') rendertest = render.readline() render.close() self.renderfile = rendertest if len(rendertest) < 1: self.renderwirt() except (SyntaxError, IOError): self.renderwirt() #? load UI File self.ui = QUiLoader().load(self.scripts_path + "/ui/hdri_browser.ui") self.InitUI() def InitUI(self): mainlayout = QVBoxLayout() mainlayout.setSpacing(0) mainlayout.setContentsMargins(0, 0, 0, 0) mainlayout.addWidget(self.ui) self.GetWidgets() self.setLayout(mainlayout) self.setWindowTitle("HDRI Browser") self.setIcon() def setIcon(self): ''' 先创建base64 with open(r"C:\\Users\\hb\\Downloads\\icon\\1.svg", "rb") as f: # 用 rb 模式(二进制)打开文件 image = f.read() print(image) # 打印一下 ''' icon = b'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1609951839422" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1720" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><defs><style type="text/css">@font-face { font-weight: 400; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Book-cd7d2bcec649b1243839a15d5eb8f0a3.woff2") format("woff2"); }\n@font-face { font-weight: 500; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Medium-d74eac43c78bd5852478998ce63dceb3.woff2") format("woff2"); }\n@font-face { font-weight: 700; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Bold-83b8ceaf77f49c7cffa44107561909e4.woff2") format("woff2"); }\n@font-face { font-weight: 900; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Black-bf067ecb8aa777ceb6df7d72226febca.woff2") format("woff2"); }\n</style></defs><path d="M512 496c-77.6-60.8-77.6-179.2 0-240 77.6 60.8 77.6 178.4 0 240z" fill="#52DDB2" p-id="1721"></path><path d="M454.4 383.2h-2.4c-12.8-1.6-22.4-13.6-21.6-26.4 5.6-47.2 28.8-89.6 66.4-119.2 10.4-8 25.6-6.4 33.6 4s6.4 25.6-4 33.6c-27.2 21.6-44.8 52-48.8 87.2-0.8 11.2-11.2 20.8-23.2 20.8z" fill="#444B54" p-id="1722"></path><path d="M512 496c-12-98.4 71.2-181.6 169.6-169.6C693.6 424 610.4 508 512 496z" fill="#2B9E7D" p-id="1723"></path><path d="M509.6 496c12-98.4-71.2-181.6-169.6-169.6C328 424 411.2 508 509.6 496z" fill="#FFFFFF" p-id="1724"></path><path d="M531.2 520.8c-6.4 0-13.6 0-20-0.8h-4c-12.8-1.6-22.4-13.6-20.8-26.4v-1.6c0.8-8.8 6.4-16 14.4-20 6.4-2.4 13.6-2.4 20 0.8 37.6 3.2 73.6-10.4 100.8-37.6 23.2-23.2 36.8-53.6 37.6-86.4-27.2 0.8-53.6 10.4-75.2 27.2-7.2 5.6-16 6.4-24 3.2s-13.6-10.4-14.4-19.2c-4-34.4-21.6-64-48-85.6-10.4-8-12-23.2-4-33.6 8-10.4 23.2-12 33.6-4 27.2 21.6 47.2 49.6 58.4 82.4 30.4-15.2 64.8-20.8 99.2-16.8 11.2 1.6 19.2 9.6 20.8 20.8 6.4 54.4-12 107.2-50.4 146.4-33.6 32.8-77.6 51.2-124 51.2zM340.8 393.6c-11.2 0-21.6-8-24-20-2.4-16.8-3.2-33.6-0.8-50.4 1.6-11.2 9.6-19.2 20.8-20.8 48-5.6 95.2 8 132.8 38.4 10.4 8 12 23.2 3.2 33.6-8 10.4-23.2 12-33.6 3.2-22.4-17.6-48.8-28-76-28.8 0 5.6 0.8 11.2 1.6 16.8 2.4 12.8-6.4 25.6-20 27.2-1.6 0.8-2.4 0.8-4 0.8z" fill="#444B54" p-id="1725"></path><path d="M380.8 432c34.4-1.6 67.2 3.2 97.6 13.6 21.6 7.2 45.6 7.2 67.2 0 30.4-9.6 63.2-14.4 97.6-13.6 141.6 5.6 258.4 118.4 268 260C922.4 856 792.8 992 632 992c-43.2 0-84-9.6-120-27.2-36 17.6-76.8 27.2-120 27.2-160.8 0-290.4-136-279.2-299.2C122.4 551.2 239.2 437.6 380.8 432z" fill="#FF5576" p-id="1726"></path><path d="M204 600c-4.8 0-9.6-1.6-14.4-4.8-10.4-8-12.8-23.2-5.6-33.6 38.4-53.6 96-89.6 160-101.6 12.8-2.4 25.6 6.4 28 19.2 2.4 12.8-6.4 25.6-19.2 28-52 9.6-98.4 39.2-129.6 82.4-4 6.4-11.2 10.4-19.2 10.4zM164.8 689.6c-6.4 0-12.8-2.4-16.8-7.2-4.8-4-7.2-10.4-7.2-16.8 0-1.6 0-3.2 0.8-4.8 0-1.6 0.8-3.2 1.6-4.8 0.8-1.6 1.6-3.2 2.4-4 0.8-1.6 1.6-2.4 3.2-4 0.8-0.8 2.4-2.4 4-3.2 1.6-0.8 2.4-1.6 4-2.4 1.6-0.8 3.2-0.8 4.8-1.6 8-1.6 16 0.8 21.6 6.4 0.8 0.8 2.4 2.4 3.2 4 0.8 1.6 1.6 2.4 2.4 4 0.8 1.6 0.8 3.2 1.6 4.8 0 1.6 0.8 3.2 0.8 4.8 0 6.4-2.4 12.8-7.2 16.8-7.2 4.8-12.8 8-19.2 8z" fill="#FFFFFF" p-id="1727"></path><path d="M530.4 972.8c3.2 1.6 6.4 2.4 9.6 4 1.6 0.8 4 0.8 5.6 1.6 3.2 0.8 5.6 1.6 8.8 3.2 2.4 0.8 4 0.8 6.4 1.6 3.2 0.8 5.6 1.6 8.8 2.4 2.4 0.8 4.8 0.8 6.4 1.6 3.2 0.8 5.6 1.6 8.8 1.6 2.4 0 4.8 0.8 7.2 0.8 3.2 0.8 5.6 0.8 8.8 0.8 2.4 0 4.8 0.8 7.2 0.8 3.2 0 5.6 0.8 8.8 0.8h29.6c3.2 0 5.6 0 8.8-0.8h4.8c4-0.8 8-0.8 12.8-1.6h0.8c122.4-18.4 220.8-116.8 236.8-240.8 0.8-3.2 0.8-6.4 0.8-9.6v-4c0-4 0.8-7.2 0.8-11.2 0-9.6 0-20-0.8-30.4-9.6-141.6-124.8-254.4-264.8-260.8C726.4 473.6 792 556.8 792 656c0 141.6-56 264-200 264-40 0-63.2-38.4-88-22.4-44.8 28-95.2 48-152 38.4h-1.6c-50.4 0-58.4 41.6-10.4 51.2 1.6 0 3.2 0.8 4.8 0.8 1.6 0 4 0.8 5.6 0.8 2.4 0.8 5.6 0.8 8.8 0.8 1.6 0 3.2 0.8 5.6 0.8 3.2 0 6.4 0.8 9.6 0.8h18.4c43.2 0 84-9.6 120-27.2 4.8 2.4 8.8 4 13.6 6.4 0.8 1.6 2.4 1.6 4 2.4z" fill="#C95065" p-id="1728"></path><path d="M632 1016c-19.2 0-39.2-1.6-58.4-5.6-40.8-8-83.2-8-124 0-19.2 4-38.4 5.6-58.4 5.6-84 0-164.8-35.2-222.4-96.8-56.8-61.6-85.6-143.2-80-228C99.2 538.4 227.2 414.4 380 408c33.6-1.6 66.4 2.4 97.6 12 6.4 1.6 12 3.2 17.6 4.8 19.2 4.8 41.6 9.6 85.6 32 12 5.6 16.8 20 11.2 32s-20 16.8-32 11.2c-39.2-19.2-57.6-24-76-28-6.4-1.6-12.8-3.2-20-4.8-26.4-8-54.4-11.2-82.4-10.4-128.8 4.8-236.8 109.6-245.6 237.6-4.8 72 19.2 140 68 192.8C253.6 939.2 320 968 392 968c16.8 0 32.8-1.6 48.8-4.8 47.2-8.8 95.2-8.8 142.4 0 16 3.2 32.8 4.8 48.8 4.8 72 0 138.4-28.8 187.2-81.6 48.8-52 72.8-120.8 68-192.8-8.8-128-116-232.8-244.8-237.6-13.6-0.8-23.2-12-23.2-24.8 0.8-13.6 11.2-24 24.8-23.2 152.8 5.6 280.8 130.4 291.2 282.4 5.6 85.6-23.2 166.4-80.8 228.8C796.8 980.8 716 1016 632 1016z" fill="#444B54" p-id="1729"></path><path d="M872 1016H152c-13.6 0-24-10.4-24-24s10.4-24 24-24h720c13.6 0 24 10.4 24 24s-10.4 24-24 24zM992 1016c-1.6 0-3.2 0-4.8-0.8-1.6 0-3.2-0.8-4.8-1.6-1.6-0.8-2.4-1.6-4-2.4-1.6-0.8-2.4-1.6-4-3.2l-3.2-3.2c-0.8-1.6-1.6-2.4-2.4-4-0.8-1.6-0.8-3.2-1.6-4.8 0-1.6-0.8-3.2-0.8-4.8 0-1.6 0-3.2 0.8-4.8 0-1.6 0.8-3.2 1.6-4.8 0.8-1.6 1.6-2.4 2.4-4 0.8-1.6 1.6-2.4 3.2-4s2.4-2.4 4-3.2c1.6-0.8 2.4-1.6 4-2.4 1.6-0.8 3.2-0.8 4.8-1.6 3.2-0.8 6.4-0.8 9.6 0 1.6 0 3.2 0.8 4.8 1.6 1.6 0.8 3.2 1.6 4 2.4 1.6 0.8 2.4 1.6 4 3.2 0.8 0.8 2.4 2.4 3.2 4 0.8 1.6 1.6 2.4 2.4 4 0.8 1.6 0.8 3.2 1.6 4.8 0 1.6 0.8 3.2 0.8 4.8 0 1.6 0 3.2-0.8 4.8 0 1.6-0.8 3.2-1.6 4.8s-1.6 3.2-2.4 4c-0.8 1.6-1.6 2.4-3.2 3.2-4.8 5.6-11.2 8-17.6 8z" fill="#444B54" p-id="1730"></path></svg>' icon_get = QPixmap() icon_get.loadFromData(icon) appIcon = QIcon(icon_get) self.setWindowIcon(appIcon) def GetWidgets(self): """ 设置控件 """ #& btn_proj_path加载图标 image = b'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1609656219985" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8030" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><defs><style type="text/css">@font-face { font-weight: 400; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Book-cd7d2bcec649b1243839a15d5eb8f0a3.woff2") format("woff2"); }\n@font-face { font-weight: 500; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Medium-d74eac43c78bd5852478998ce63dceb3.woff2") format("woff2"); }\n@font-face { font-weight: 700; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Bold-83b8ceaf77f49c7cffa44107561909e4.woff2") format("woff2"); }\n@font-face { font-weight: 900; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Black-bf067ecb8aa777ceb6df7d72226febca.woff2") format("woff2"); }\n</style></defs><path d="M928 444H820V330.4c0-17.7-14.3-32-32-32H473L355.7 186.2c-1.5-1.4-3.5-2.2-5.5-2.2H96c-17.7 0-32 14.3-32 32v592c0 17.7 14.3 32 32 32h698c13 0 24.8-7.9 29.7-20l134-332c1.5-3.8 2.3-7.9 2.3-12 0-17.7-14.3-32-32-32zM136 256h188.5l119.6 114.4H748V444H238c-13 0-24.8 7.9-29.7 20L136 643.2V256z m635.3 512H159l103.3-256h612.4L771.3 768z" p-id="8031" fill="#dbdbdb"></path></svg>' btn_proj_path_icon = QPixmap() btn_proj_path_icon.loadFromData(image) btn_image = b'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1610118992486" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2753" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><defs><style type="text/css">@font-face { font-weight: 400; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Book-cd7d2bcec649b1243839a15d5eb8f0a3.woff2") format("woff2"); }@font-face { font-weight: 500; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Medium-d74eac43c78bd5852478998ce63dceb3.woff2") format("woff2"); }@font-face { font-weight: 700; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Bold-83b8ceaf77f49c7cffa44107561909e4.woff2") format("woff2"); }@font-face { font-weight: 900; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Black-bf067ecb8aa777ceb6df7d72226febca.woff2") format("woff2"); }</style></defs><path d="M832 626.592l-128-128-128 128-256.48-256.448L192 497.632V191.872h640V626.56z m0 205.28H192V588.16l127.52-127.52L576 717.12l128-128 128 128v114.72z m0-704H128v768h768v-768h-64z" fill="#dbdbdb" p-id="2754"></path><path d="M672 319.872c-17.632 0-32 14.368-32 32 0 17.6 14.368 32 32 32 17.632 0 32-14.4 32-32 0-17.632-14.368-32-32-32m0 128c-52.928 0-96-43.072-96-96s43.072-96 96-96 96 43.072 96 96-43.072 96-96 96" fill="#dbdbdb" p-id="2755"></path></svg>' btn_image_icon = QPixmap() btn_image_icon.loadFromData(btn_image) btn_proj_path = self.ui.findChild(QPushButton, "proj_path") self.btn_creatimg = self.ui.findChild(QPushButton, "creatimg") self.cleanimage = self.ui.findChild(QPushButton, "cleanimage") self.folderlist = self.ui.findChild(QComboBox, "path_list") self.path_info = self.ui.findChild(QLabel, "path_info") self.rendererlist = self.ui.findChild(QComboBox, "renderlist") self.hdrilist = self.ui.findChild(QListWidget, "hdrilist") btn_proj_path.setIcon(btn_proj_path_icon) self.btn_creatimg.setIcon(btn_image_icon) self.hdrilist.setViewMode(QListView.IconMode) self.hdrilist.setIconSize(QSize(150, 100)) self.hdrilist.setResizeMode(QListWidget.Adjust) self.path_info.setText(self.hdri) self.hdrilist.customContextMenuRequested[QtCore.QPoint].connect( self.ListWidgetContext) btn_proj_path.clicked.connect(self.set_hdri_folder) if hou.applicationVersionString() > '18.0': self.btn_creatimg.clicked.connect(self.create_image_to_jpg) else: self.btn_creatimg.clicked.connect(self.version) self.cleanimage.clicked.connect(self.delerrorimage) self.folderlist.activated.connect(self.Refresh) self.folderlist.activated.connect(self.CreateInterface) self.renderset() self.Refresh() self.CreateInterface() def renderwirt(self): """写入文件 """ render = open(self.scripts_path + "/HDRI_Path/render.txt", 'w+') renderer = "Redshift,Mantra,Arnold,Vray,Octane" render.write(renderer) render.close() self.renderfile = renderer def renderset(self): """添加render渲染器列表 """ rendertext = self.renderfile rendersort = rendertext.split(",") for render in rendersort: self.rendererlist.addItem(render) def set_hdri_folder(self): """设置hdri文件夹 """ setpath = hou.ui.selectFile(title="Set Hdri Path", file_type=hou.fileType.Directory) newpath = os.path.dirname(setpath) + "/" if (newpath != "/"): self.hdri = newpath f = open(self.scripts_path + "/HDRI_Path/hdri_browser_path.txt", "w+") f.write(newpath) f.close() self.Refresh() self.CreateInterface() self.path_info.setText(self.hdri) def Refresh(self): """设置路径 """ if self.hdri != self.temp and self.hdri != "": self.folderlist.clear() for folder in os.listdir(self.hdri): full_path = os.path.join(self.hdri, folder) if os.path.isdir(full_path): self.folderlist.addItem(folder) self.temp = self.hdri self.instexpath = self.hdri + str( self.folderlist.currentText()) + "/Thumbnails/" self.texpath = self.hdri + str( self.folderlist.currentText()) + "/HDRIs/" def CreateInterface(self): """创建缩略图 """ self.hdrilist.clear() try: for file in os.listdir(self.instexpath): if file.endswith('.jpg'): file_temp = file.split(".") del file_temp[-1] name = ".".join(file_temp) indextex0 = self.instexpath + file icon = QtGui.QIcon(indextex0) item = QListWidgetItem(icon, "") item.setSizeHint(QSize(155, 100)) item.setText(name) item.setToolTip('<b>%s</b><br><img src="%s">' % (name, indextex0)) self.hdrilist.addItem(item) except WindowsError: pass #! 这里不知道是不是bug问题,还是自己思路错了,会加item传递进去,导致执行多次事件,加了disconnect强制中断事件. try: self.hdrilist.clicked.disconnect(self.setTex) except Exception: pass self.hdrilist.clicked.connect(self.setTex) try: self.hdrilist.doubleClicked.disconnect(self.create_node) except Exception: pass self.hdrilist.doubleClicked.connect(self.create_node) def setTex(self, item): """节点设置贴图路径 Args: item (index): 传入父类item的数据 """ texname = item.data() for texture in os.listdir(self.texpath): tex = texture.split(texname) if len(tex) >= 2: texname = texture node_path = self.texpath + texname try: node = hou.selectedNodes()[0] light_node = node.parm('env_map') if (light_node == None): light_node = node.parm('ar_light_color_texture') if (light_node == None): light_node = node.parm('A_FILENAME') light_node.set(node_path) light_node.set(node_path) light_node.set(node_path) except AttributeError: hou.ui.setStatusMessage( '======================================================================没找到可以放环境贴图参数的位置,============确认下是不是选择错节点了,或者灯光节点没有切换成环境灯光模式.=================如果要创建节点,请保证不要选择节点======================================================================', severity=hou.severityType.Warning) t = Timer(5, self.clean_message) t.start() except IndexError: pass def create_node(self, item): """创建节点并设置贴图 Args: item (index): 传入父类item的数据 """ texname = item.data() for texture in os.listdir(self.texpath): j = texture.split(texname) if len(j) >= 2: texname = texture node_path = self.texpath + texname render_name = self.rendererlist.currentText() if render_name == "Redshift": try: rslight = hou.node('/obj/').createNode('rslightdome') rslight.setCurrent(True, True) rslight.moveToGoodPosition() rs_env = rslight.parm('env_map') rs_env.set(node_path) except hou.OperationFailed: hou.ui.setStatusMessage( '==========================好像没安装Redshift渲染器==================没安装是创建不了Redshift环境灯光节点的======================================================================', severity=hou.severityType.Warning) t = Timer(5, self.clean_message) t.start() elif render_name == "Mantra": try: with hou.undos.group("创建Mantra环境灯光节点"): mtlight = hou.node('/obj/').createNode('envlight') mt_env = mtlight.parm('env_map') mt_env.set(node_path) mtlight.setCurrent(True, True) mtlight.moveToGoodPosition() hou.ui.setStatusMessage('已成功创建Mantra环境灯光节点', severity=hou.severityType.Message) except: hou.ui.displayMessage("这你都能报错???\n别弄了赶紧找小的救命", severity=hou.severityType.Error) elif render_name == "Arnold": try: with hou.undos.group("创建Arnold环境灯光节点"): arlight = hou.node('/obj/').createNode('arnold_light') arlight.parm("ar_light_type").set('skydome') arlight.parm("ar_light_color_type").set('texture') arlight.setCurrent(True, True) arlight.moveToGoodPosition() ar_env = arlight.parm('ar_light_color_texture') ar_env.set(node_path) hou.ui.setStatusMessage('已成功创建Arnold环境灯光节点', severity=hou.severityType.Message) except hou.OperationFailed: hou.ui.setStatusMessage( '==========================好像没安装Arnold渲染器==================没安装是创建不了Arnold环境灯光节点的======================================================================', severity=hou.severityType.Warning) t = Timer(5, self.clean_message) t.start() elif render_name == "Vray": try: with hou.undos.group("创建Vray环境灯光节点"): vrlight = hou.node('/obj/').createNode('VRayNodeLightDome') vrlight.setCurrent(True, True) vrlight.moveToGoodPosition() vr_env = vrlight.parm('dome_tex') vr_env.set(node_path) hou.ui.setStatusMessage('已成功创建Vray环境灯光节点', severity=hou.severityType.Message) pass except hou.OperationFailed: hou.ui.setStatusMessage( '==========================好像没安装Vray渲染器==================没安装是创建不了Vray环境灯光节点的======================================================================', severity=hou.severityType.Warning) t = Timer(5, self.clean_message) t.start() elif render_name == "Octane": try: with hou.undos.group("创建Octane环境灯光节点"): oclight = hou.node('/shop/').createNode( 'octane_rendertarget_dl') oclight.parm("parmKernel").set('1') oclight.parm("parmEnvironment").set('1') oclight.setCurrent(True, True) oclight.moveToGoodPosition() oc_env = oclight.parm('A_FILENAME') oc_env.set(node_path) hou.ui.setStatusMessage('已成功创建Octane环境灯光节点', severity=hou.severityType.Message) except hou.OperationFailed: hou.ui.setStatusMessage( '==========================好像没安装Octane渲染器==================没安装是创建不了Octane环境灯光节点的======================================================================', severity=hou.severityType.Warning) t = Timer(5, self.clean_message) t.start() else: hou.ui.displayMessage( "目前只支持\n-------Redshift,Vray,Mantra,Arnold-------\n提示报错,请注意在该工具脚本存在位置的HDRI_Path/render.txt里的内容,格式如下\nRedshift,Vray,Mantra,Arnold\n解决不了,就删除render.txt文件,重新打开工具", severity=hou.severityType.Error) def create_image_to_jpg(self): Directory = self.hdri + self.folderlist.currentText() + '/' self.file_Directory = Directory hdri_exr = self.check(Directory) if hdri_exr == []: hou.ui.displayMessage("在%s路径下没找到.hdr或.exr后缀需要生成缩略图的环境贴图" % Directory, severity=hou.severityType.Error) else: for filename in hdri_exr: if filename.split('.')[1] == 'hdr': type = 'hdr' dir = Directory + '*.hdr' else: type = 'exr' dir = Directory + '*.exr' self.create_top(type, dir) def create_top(self, type, dir): thdir = self.file_Directory + '/Thumbnails/' if not os.path.exists(thdir): os.mkdir(thdir) hipsave = hou.ui.displayMessage( '==========由于此功能是利用PDG进行,需要保存文件备份==============\n==============会调用CPU核心数-1的资源进行缩略图生成==============\n=========在生成完成前,请不要进行其他操作,防止意外发生XD=========\n该功能还有BUG存在(只遇到过一次,找不到原因,不知道怎么再次触发)', buttons=('保存文件后启动', '保存到Backup后启动', '关闭'), severity=hou.severityType.Warning, default_choice=0, close_choice=2, title='创建PDG进行缩略图生成') if hipsave == 0: hou.hipFile.save() if hipsave == 1: hou.hipFile.saveAsBackup() if hipsave == 0 or hipsave == 1: with hou.undos.group("创建top节点进行缩略图生成"): hou.ui.setStatusMessage( '==========================正在进行缩略图生成,请不要进行其他操作,防止意外发生==========================', severity=hou.severityType.Fatal) top = hou.node('/obj').createNode('topnet', '%s_to_jpg' % type) top.setComment(' 缩略图生成中') top.setCurrent(True, True) top.moveToGoodPosition() group = top.parmTemplateGroup() destroy = hou.ButtonParmTemplate( 'del', '自毁', script_callback= 'hou.pwd().destroy(disable_safety_checks=False)', script_callback_language=hou.scriptLanguage.Python) pausee = hou.ButtonParmTemplate( 'pause', '暂停', script_callback='hou.pwd().pauseCook()', script_callback_language=hou.scriptLanguage.Python) cancelCook = hou.ButtonParmTemplate( 'cancelCook', '取消', script_callback='hou.pwd().pauseCook()', script_callback_language=hou.scriptLanguage.Python) folder = group.findFolder('Scheduler') group.appendToFolder(folder, destroy) top.setParmTemplateGroup(group) top.setGenericFlag(hou.nodeFlag.DisplayComment, True) localscheduler = top.children()[0] localscheduler.parm('maxprocsmenu').set('-1') top_path = top.path() filepattern = hou.node(top_path).createNode('filepattern') filepattern.parm('pattern').set('%s' % dir) attributefromstring = filepattern.createOutputNode( 'attributefromstring') attributefromstring.parm('sourcestring').set('`@filename`') attributefromstring.parm('useregex').set('on') attributefromstring.parm('matchstring').set('(.+?)\.') ropcomposite = attributefromstring.createOutputNode( 'ropcomposite') ropcomposite.parm('tres').set('specify') ropcomposite.parm('res1').set('400') ropcomposite.parm('res2').set('200') ropcomposite.parm('copoutput').set( '`@directory`/Thumbnails/`@group0`.jpg') ropcomposite.setGenericFlag(hou.nodeFlag.OutputForDisplay, 1) ropcomposite.executeGraph(False, False, False, True) pdg_node = ropcomposite.getPDGNode() pdg_context = ropcomposite.getPDGGraphContext() pdg_context.addEventHandler(self.print_done_and_remove, pdg.EventType.CookComplete, True) top.layoutChildren() top.parm('cookbutton').pressButton() return top def print_done_and_remove(self, handler, event): self.CreateInterface() hou.ui.setStatusMessage( '==========================已成功生成缩略图===================在创建的节点上有***自毁***按钮,点击删除节点======================', severity=hou.severityType.Warning) hou.ui.displayMessage( '=======================已成功生成缩略图=====================\n===在创建的节点上有***自毁***按钮,点击按钮删除节点===', severity=hou.severityType.Message) Directory = self.file_Directory cheaktype = ['hdr', 'exr'] t = Timer(5, self.clean_message) t.start() dir = Directory + '/HDRIs/' if not os.path.exists(dir): os.mkdir(dir) for file in os.listdir(Directory): if not (file == 'HDRIs' or file == 'Thumbnails'): file_path = os.path.join(Directory, file) if file.split('.')[-1] in cheaktype: shutil.move(file_path, dir) def version(self): hou.ui.displayMessage( '=======由于此功能是PDG生成,18.0以上变动太多,只适用于18.0以上的版本(包括18.0)=======\n=====================自行将缩略图400*200放在Thumbnails文件夹内====================\n=================================HDR放在HDRIs内=================================\n=================================右键刷新贴图====================================' ) def check(self, dir): filename_list = [] Thumbnails_list = [] HDRIs_list = [] check_file = [".hdr", ".exr"] for root, dir_name, files_name in os.walk(dir): if not (os.path.basename(root) == 'HDRIs' and os.path.basename(root) == 'Thumbnails'): for filename in os.listdir(root): if os.path.splitext(filename)[1] in check_file: file_path = os.path.join(root, filename) try: shutil.move(file_path, dir) except shutil.Error: pass filename_list.append(filename) try: os.rmdir(root) except OSError: pass if os.path.exists(self.instexpath) and os.path.exists( self.texpath): if os.path.basename(root) == 'Thumbnails': for filenamee in os.listdir(root): Thumbnails_list.append(filenamee) if os.path.basename(root) == 'HDRIs': for roott, dir_namee, files_namee in os.walk(root): for i in files_namee: HDRIs_list.append(i) result_list = self.list_dif(Thumbnails_list, HDRIs_list) if len(result_list) > 0: for i in result_list: filename_list.append(i) for root, dir_name, files_name in os.walk( os.path.join(dir, 'HDRIs')): if (files_name in result_list): if os.path.splitext(files_name)[1] in check_file: file_pathh = os.path.join(root, files_name) try: shutil.move(file_pathh, dir) except shutil.Error: pass try: os.rmdir(root) except OSError: pass while '' in filename_list: filename_list.remove('') return filename_list def list_dif(self, list1, list2): t1 = set(list1) h1 = set(list2) result = h1.difference(t1) result_list = list(result) return result_list def ListWidgetContext(self, point): """设置右键菜单 """ try: index = self.hdrilist.currentIndex() file_name = index.data() self.fullname = file_name self.filename_path = self.texpath + file_name if os.path.exists(self.filename_path + '.exr'): self.file_path = self.filename_path + '.exr' else: self.file_path = self.filename_path + '.hdr' self.file_jpg = self.instexpath + file_name + ".jpg" self.file_path_fix = self.file_path.replace('/', '\\') except TypeError: pass popMenu = QMenu(self) pop_Menu_open_file = popMenu.addAction('打开文件') pop_Menu_open_file.triggered.connect(self.open_file) pop_Menu_open_file_path = popMenu.addAction('打开文件路径') pop_Menu_open_file_path.triggered.connect(self.open_file_path) pop_Menu_rename_file_path = popMenu.addAction('重命名') pop_Menu_rename_file_path.triggered.connect(self.rename) pop_Menu_ref_file_path = popMenu.addAction('刷新') pop_Menu_ref_file_path.triggered.connect(self.CreateInterface) pop_Menu_del_file_path = popMenu.addAction('删除文件和缩略图') pop_Menu_del_file_path.triggered.connect(self.delfile) popMenu.exec_(QCursor.pos()) def open_file(self): try: os.startfile(self.file_path, 'open') except WindowsError: try: self.file_path = self.file_path.replace('.exr', '.hdr') os.startfile(self.file_path, 'open') except WindowsError: hou.ui.displayMessage("缩略图存在,但找不到源文件", severity=hou.severityType.Error) except: pass def open_file_path(self): """ 用subprocess可以避免cmd黑色窗口弹出 """ try: temp = open(self.file_path) temp.close() subprocess.Popen(r'explorer /select,%s' % self.file_path_fix) except IOError: self.file_path_fix = self.file_path_fix.replace('.exr', '.hdr') subprocess.Popen(r'explorer /select,%s' % self.file_path_fix) except: pass def rename(self): file_suffix = self.file_path.split('.')[-1] i = True while i == True: i = False hou.ui.setStatusMessage('输入新的文件名称', severity=hou.severityType.Message) inputs = hou.ui.readInput('重命名文件名字', buttons=('确定', '关闭'), severity=hou.severityType.Message) newname = inputs[1] try: if inputs[0] == 0: os.rename( self.file_path, self.texpath + '%s' % newname + '.' + file_suffix) os.rename(self.file_jpg, self.instexpath + '%s' % newname + '.jpg') hou.ui.setStatusMessage('已重命名', severity=hou.severityType.Message) self.CreateInterface() t = Timer(3, self.clean_message) t.start() except WindowsError: if hou.ui.displayMessage("当前文件名字已存在,无法命名", severity=hou.severityType.Error) == 0: i = True else: pass def delerrorimage(self): Thumbnails_list = [] HDRIs_list = [] cheak = ['hdr', 'exr'] if os.path.exists(self.instexpath): for image in os.listdir(self.instexpath): if image.split('.')[1] == 'jpg': newimage = image.split('.')[0] Thumbnails_list.append(newimage) if os.path.exists(self.texpath): for hdr in os.listdir(self.texpath): try: if hdr.split('.')[1] in cheak: newhdr = hdr.split('.')[0] HDRIs_list.append(newhdr) except: pass result_list = self.list_dif(HDRIs_list, Thumbnails_list) while '' in result_list: result_list.remove('') if len(result_list) > 0: for rename in result_list: image_full_path = os.path.join(self.instexpath, rename + '.jpg') os.remove(image_full_path) self.CreateInterface() hou.ui.setStatusMessage( '============================已清理无效缩略图=====================================', severity=hou.severityType.Message) t = Timer(3, self.clean_message) t.start() def delfile(self): try: file_suffix = self.file_path.split('.')[-1] os.remove(self.texpath + self.fullname + '.' + file_suffix) os.remove(self.file_jpg) self.CreateInterface() hou.ui.setStatusMessage( '==========================已删除文件和缩略图============================', severity=hou.severityType.Message) t = Timer(3, self.clean_message) t.start() except TypeError: hou.ui.displayMessage("请选中缩略图再进行操作", severity=hou.severityType.Error) except AttributeError: hou.ui.displayMessage("请选中缩略图再进行操作", severity=hou.severityType.Error) def clean_message(self): message = hou.ui.setStatusMessage("")
class MainWidget(QWidget): # Home do usuário. home = QDir().home().path() def __init__(self): super(MainWidget, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Widgets. self.label = self.ui.findChild(QObject, 'label') btn_open_file = self.ui.findChild(QObject, 'btn_open_file') btn_open_file.clicked.connect(self.open_file_dialog) btn_open_files = self.ui.findChild(QObject, 'btn_open_files') btn_open_files.clicked.connect(self.open_files_dialog) btn_open_dir = self.ui.findChild(QObject, 'btn_open_dir') btn_open_dir.clicked.connect(self.open_dir_dialog) btn_save_file = self.ui.findChild(QObject, 'btn_save_file') btn_save_file.clicked.connect(self.open_save_dialog) self.ui.show() def open_file_dialog(self): file = QFileDialog().getOpenFileName( parent=self, caption='Selecione um arquivo', dir=str(self.home), filter=('PNG (*.png);;JPG (*.jpg, *.jpeg);;' 'TXT (*.txt);;Todos (*.*)'), ) if file[0]: self.label.setText( f'<b>Arquivo selecionado</b>: {file[0]}<br>' f'<b>Filtro utilizado</b>: {file[1]}', ) def open_files_dialog(self): files = QFileDialog().getOpenFileNames( parent=self, caption='Selecione os arquivos', dir=str(self.home), filter=('PNG (*.png);;JPG (*.jpg, *.jpeg);;' 'TXT (*.txt);;Todos (*.*)'), ) if files[0]: text = '<b>Arquivos selecionados</b>:<br>' for file in files[0]: text += f'- {file}<br>' text += f'<b>Filtro utilizado</b>: {files[1]}' self.label.setText(text) def open_dir_dialog(self): path = QFileDialog().getExistingDirectory( parent=self, caption='Selecione um diretório', dir=str(self.home), ) if path: self.label.setText(f'<b>Diretório selecionado</b>: {path}') def open_save_dialog(self): file = QFileDialog().getSaveFileName( parent=self, caption='Salvar arquivo', dir=str(self.home), filter='.png;;.txt;;.jpg;;', ) if file[0]: if file[0].endswith(file[1]): text = f'<b>Arquivo salvo em</b>: {file[0]}<br>' else: text = f'<b>Arquivo salvo em</b>: {file[0]}{file[1]}<br>' text += f'<b>Filtro utilizado</b>: {file[1]}' self.label.setText(text)
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Widgets. self.label = self.ui.findChild(QObject, 'label') btn_input_text = self.ui.findChild(QObject, 'btn_input_text') btn_input_text.clicked.connect(self.open_input_text_dialog) btn_input_mult_line = self.ui.findChild(QObject, 'btn_input_mult_line') btn_input_mult_line.clicked.connect( self.open_input_mult_line_text_dialog) btn_input_int = self.ui.findChild(QObject, 'btn_input_int') btn_input_int.clicked.connect(self.open_input_int_dialog) btn_input_float = self.ui.findChild(QObject, 'btn_input_float') btn_input_float.clicked.connect(self.open_input_float_dialog) btn_input_choice = self.ui.findChild(QObject, 'btn_input_choice') btn_input_choice.clicked.connect(self.open_input_choice_dialog) self.ui.show() def open_input_text_dialog(self): value, response = QInputDialog().getText( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo.', # label (str): Texto que será exibido junto com o input. 'Digite algo no input e clique em OK:', # echo (QLineEdit). QLineEdit.Normal, # text (str): Valor inicial do input. 'Digite algo', ) if response and value: self.label.setText(f'<b>Valor digitado</b>: {value}') def open_input_mult_line_text_dialog(self): value, response = QInputDialog().getMultiLineText( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo.', # label (str): Texto que será exibido junto com o input. 'Digite algo na caixa de texto e clique em OK:', # text (str): Valor inicial do input. 'Digite algo', ) if response and value: self.label.setText(f'<b>Valor digitado</b>: {value}') def open_input_int_dialog(self): value, response = QInputDialog().getInt( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo.', # label (str): Texto que será exibido junto com o input. 'Digite um numero inteiro e clique em OK:', # value (int). Valor inicial do input. 0, # minValue (int). Valor mínimo do input. -10, # maxValue (int). Valor maximo do input. 10, # step (int). Valor do incremento/decremento. 2, ) if response and value: self.label.setText(f'<b>Valor digitado</b>: {value}') def open_input_float_dialog(self): value, response = QInputDialog().getDouble( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo.', # label (str): Texto que será exibido junto com o input. 'Digite algo e clique em OK:', # value (float): Valor inicial do input. 0, # minValue (float): Valor mínimo do input. -10, # maxValue (float): Valor maximo do input. 10, # decimals(int): Numero de casas decimais. 2, ) if response and value: self.label.setText(f'<b>Valor digitado</b>: {value:.2f}') def open_input_choice_dialog(self): value, response = QInputDialog().getItem( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo.', # label (str): Texto que será exibido junto com o input. 'Selecione um dos itens e clique em OK:', # items ([str]): Lista com o texto que será exibido. ['item 1', 'item 2', 'item 3'], # current (int): Valor inicial (index). 1, # editable (bool): Valor determina se o campo pode ser editado. False, ) if response and value: self.label.setText(f'<b>Valor selecionado</b>: {value}')
class PropertyWindow(QObject): buy_property = Signal(int) def __init__(self, ui_file, parent=None): super(PropertyWindow, self).__init__(parent) self.window = QUiLoader().load(ui_file) self.extract_buttons() self.connect_signals() self.window.hide() def extract_buttons(self): self.back_button = self.window.findChild(QPushButton, 'back_button') self.estate_apartment_button = self.window.findChild( QPushButton, 'estate_apartment_button') self.estate_house_button = self.window.findChild( QPushButton, 'estate_house_button') self.estate_penthouse_button = self.window.findChild( QPushButton, 'estate_penthouse_button') self.vehicle_economy_button = self.window.findChild( QPushButton, 'vehicle_economy_button') self.vehicle_middle_button = self.window.findChild( QPushButton, 'vehicle_middle_button') self.vehicle_luxury_button = self.window.findChild( QPushButton, 'vehicle_luxury_button') def connect_signals(self): self.back_button.clicked.connect(self.close_window) self.estate_apartment_button.clicked.connect(self.buy_estate_apartment) self.estate_house_button.clicked.connect(self.buy_estate_house) self.estate_penthouse_button.clicked.connect(self.buy_estate_penthouse) self.vehicle_economy_button.clicked.connect(self.buy_vehicle_economy) self.vehicle_middle_button.clicked.connect(self.buy_vehicle_middle) self.vehicle_luxury_button.clicked.connect(self.buy_vehicle_luxury) def open_window(self): self.window.show() def close_window(self): self.window.hide() def buy_estate_apartment(self): self.buy_property.emit(1) self.window.hide() def buy_estate_house(self): self.buy_property.emit(2) self.window.hide() def buy_estate_penthouse(self): self.buy_property.emit(3) self.window.hide() def buy_vehicle_economy(self): self.buy_property.emit(4) self.window.hide() def buy_vehicle_middle(self): self.buy_property.emit(5) self.window.hide() def buy_vehicle_luxury(self): self.buy_property.emit(6) self.window.hide()
class MainWidget(QWidget): def __init__(self): super(MainWidget, self).__init__() # Caminho até o arquivo de interface. # path = QDir(__file__).currentPath() # ui_file = QDir(path).filePath('MainWindow.ui') ui_file = QDir(QDir(__file__).currentPath()).filePath('MainWindow.ui') self.ui = QUiLoader().load(ui_file, None) # Widgets. self.label = self.ui.findChild(QObject, 'label') btn_dialog = self.ui.findChild(QObject, 'btn_dialog') btn_dialog.clicked.connect(self.open_dialog) btn_dialog_about = self.ui.findChild(QObject, 'btn_dialog_about') btn_dialog_about.clicked.connect(self.open_dialog_about) btn_dialog_aboutqt = self.ui.findChild(QObject, 'btn_dialog_aboutqt') btn_dialog_aboutqt.clicked.connect(self.open_dialog_aboutqt) btn_dialog_critical = self.ui.findChild(QObject, 'btn_dialog_critical') btn_dialog_critical.clicked.connect(self.open_dialog_critical) btn_dialog_information = self.ui.findChild(QObject, 'btn_dialog_information') btn_dialog_information.clicked.connect(self.open_dialog_information) btn_dialog_question = self.ui.findChild(QObject, 'btn_dialog_question') btn_dialog_question.clicked.connect(self.open_dialog_question) btn_dialog_warning = self.ui.findChild(QObject, 'btn_dialog_warning') btn_dialog_warning.clicked.connect(self.open_dialog_warning) self.ui.show() def open_dialog(self): dialog = QMessageBox(parent=self.ui) dialog.setWindowTitle('Título do diálogo') dialog.setText('Texto do diálogo') dialog.setInformativeText('Texto informativo do diálogo') dialog.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) dialog.setDefaultButton(QMessageBox.Cancel) response = dialog.exec() if response == QMessageBox.Save: print('Botão de SALVAR pressionado') elif response == QMessageBox.Discard: print('Botão de DESCARTAR pressionado') elif response == QMessageBox.Cancel: print('Botão de CANCELAR/FECHAR pressionado') def open_dialog_about(self): QMessageBox().about( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo', # text (str): Texto que será exibido na janela de diálogo. 'Texto da janela de diálogo', ) def open_dialog_aboutqt(self): QMessageBox().aboutQt( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo', ) def open_dialog_critical(self): QMessageBox().critical( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo', # text (str): Texto que será exibido na janela de diálogo. 'Texto da janela de diálogo', ) def open_dialog_information(self): QMessageBox().information( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo', # text (str): Texto que será exibido na janela de diálogo. 'Texto da janela de diálogo', ) def open_dialog_question(self): response = QMessageBox().question( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo', # text (str): Texto que será exibido na janela de diálogo. 'Texto da janela de diálogo', ) if response == QMessageBox.StandardButton.Yes: print('Botão SIM pressionado') if response == QMessageBox.StandardButton.No: print('Botão NÃO/FECHAR pressionado') def open_dialog_warning(self): QMessageBox().warning( # parent (QWidget): Pai da janela de diálogo. self.ui, # title (str): Título da janela de diálogo. 'Título da janela de diálogo', # text (str): Texto que será exibido na janela de diálogo. 'Texto da janela de diálogo', )
class HWindows(QWidget): def __init__(self,parent=None): super(HWindows, self).__init__() #? 创建文件夹 self.scripts_path = os.path.dirname(os.path.realpath(__file__)).replace('\\','/') if not os.path.exists(self.scripts_path +"/HDRI_Path"): os.mkdir(self.scripts_path +"/HDRI_Path") #? load hdr_path try: hdrfile = open(self.scripts_path + "/HDRI_Path/hdri_browser_path.txt",'r+') txt = hdrfile.readline() hdrfile.close() self.hdri = txt self.temp = "0"; except (SyntaxError,IOError): hdrfile = open(self.scripts_path + "/HDRI_Path/hdri_browser_path.txt",'w+') hdrfile.close() self.hdri = "" self.temp = "0"; #? load render.txt try: render = open(self.scripts_path + "/HDRI_Path/render.txt",'r+') rendertest = render.readline() render.close() self.renderfile = rendertest if len(rendertest) < 1 : self.renderwirt() except (SyntaxError,IOError): self.renderwirt() #? load UI File self.ui = QUiLoader().load(self.scripts_path + "/ui/hdri_browser.ui") self.InitUI() def InitUI(self): mainlayout = QVBoxLayout() mainlayout.setSpacing(0); mainlayout.setContentsMargins(0,0,0,0) mainlayout.addWidget(self.ui) self.GetWidgets() self.setLayout(mainlayout) self.setWindowTitle("HDRI Browser") self.setIcon() def setIcon(self): ''' 先创建base64 with open(r"C:\\Users\\hb\\Downloads\\icon\\1.svg", "rb") as f: # 用 rb 模式(二进制)打开文件 image = f.read() print(image) # 打印一下 ''' icon= b'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1609951839422" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1720" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><defs><style type="text/css">@font-face { font-weight: 400; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Book-cd7d2bcec649b1243839a15d5eb8f0a3.woff2") format("woff2"); }\n@font-face { font-weight: 500; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Medium-d74eac43c78bd5852478998ce63dceb3.woff2") format("woff2"); }\n@font-face { font-weight: 700; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Bold-83b8ceaf77f49c7cffa44107561909e4.woff2") format("woff2"); }\n@font-face { font-weight: 900; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Black-bf067ecb8aa777ceb6df7d72226febca.woff2") format("woff2"); }\n</style></defs><path d="M512 496c-77.6-60.8-77.6-179.2 0-240 77.6 60.8 77.6 178.4 0 240z" fill="#52DDB2" p-id="1721"></path><path d="M454.4 383.2h-2.4c-12.8-1.6-22.4-13.6-21.6-26.4 5.6-47.2 28.8-89.6 66.4-119.2 10.4-8 25.6-6.4 33.6 4s6.4 25.6-4 33.6c-27.2 21.6-44.8 52-48.8 87.2-0.8 11.2-11.2 20.8-23.2 20.8z" fill="#444B54" p-id="1722"></path><path d="M512 496c-12-98.4 71.2-181.6 169.6-169.6C693.6 424 610.4 508 512 496z" fill="#2B9E7D" p-id="1723"></path><path d="M509.6 496c12-98.4-71.2-181.6-169.6-169.6C328 424 411.2 508 509.6 496z" fill="#FFFFFF" p-id="1724"></path><path d="M531.2 520.8c-6.4 0-13.6 0-20-0.8h-4c-12.8-1.6-22.4-13.6-20.8-26.4v-1.6c0.8-8.8 6.4-16 14.4-20 6.4-2.4 13.6-2.4 20 0.8 37.6 3.2 73.6-10.4 100.8-37.6 23.2-23.2 36.8-53.6 37.6-86.4-27.2 0.8-53.6 10.4-75.2 27.2-7.2 5.6-16 6.4-24 3.2s-13.6-10.4-14.4-19.2c-4-34.4-21.6-64-48-85.6-10.4-8-12-23.2-4-33.6 8-10.4 23.2-12 33.6-4 27.2 21.6 47.2 49.6 58.4 82.4 30.4-15.2 64.8-20.8 99.2-16.8 11.2 1.6 19.2 9.6 20.8 20.8 6.4 54.4-12 107.2-50.4 146.4-33.6 32.8-77.6 51.2-124 51.2zM340.8 393.6c-11.2 0-21.6-8-24-20-2.4-16.8-3.2-33.6-0.8-50.4 1.6-11.2 9.6-19.2 20.8-20.8 48-5.6 95.2 8 132.8 38.4 10.4 8 12 23.2 3.2 33.6-8 10.4-23.2 12-33.6 3.2-22.4-17.6-48.8-28-76-28.8 0 5.6 0.8 11.2 1.6 16.8 2.4 12.8-6.4 25.6-20 27.2-1.6 0.8-2.4 0.8-4 0.8z" fill="#444B54" p-id="1725"></path><path d="M380.8 432c34.4-1.6 67.2 3.2 97.6 13.6 21.6 7.2 45.6 7.2 67.2 0 30.4-9.6 63.2-14.4 97.6-13.6 141.6 5.6 258.4 118.4 268 260C922.4 856 792.8 992 632 992c-43.2 0-84-9.6-120-27.2-36 17.6-76.8 27.2-120 27.2-160.8 0-290.4-136-279.2-299.2C122.4 551.2 239.2 437.6 380.8 432z" fill="#FF5576" p-id="1726"></path><path d="M204 600c-4.8 0-9.6-1.6-14.4-4.8-10.4-8-12.8-23.2-5.6-33.6 38.4-53.6 96-89.6 160-101.6 12.8-2.4 25.6 6.4 28 19.2 2.4 12.8-6.4 25.6-19.2 28-52 9.6-98.4 39.2-129.6 82.4-4 6.4-11.2 10.4-19.2 10.4zM164.8 689.6c-6.4 0-12.8-2.4-16.8-7.2-4.8-4-7.2-10.4-7.2-16.8 0-1.6 0-3.2 0.8-4.8 0-1.6 0.8-3.2 1.6-4.8 0.8-1.6 1.6-3.2 2.4-4 0.8-1.6 1.6-2.4 3.2-4 0.8-0.8 2.4-2.4 4-3.2 1.6-0.8 2.4-1.6 4-2.4 1.6-0.8 3.2-0.8 4.8-1.6 8-1.6 16 0.8 21.6 6.4 0.8 0.8 2.4 2.4 3.2 4 0.8 1.6 1.6 2.4 2.4 4 0.8 1.6 0.8 3.2 1.6 4.8 0 1.6 0.8 3.2 0.8 4.8 0 6.4-2.4 12.8-7.2 16.8-7.2 4.8-12.8 8-19.2 8z" fill="#FFFFFF" p-id="1727"></path><path d="M530.4 972.8c3.2 1.6 6.4 2.4 9.6 4 1.6 0.8 4 0.8 5.6 1.6 3.2 0.8 5.6 1.6 8.8 3.2 2.4 0.8 4 0.8 6.4 1.6 3.2 0.8 5.6 1.6 8.8 2.4 2.4 0.8 4.8 0.8 6.4 1.6 3.2 0.8 5.6 1.6 8.8 1.6 2.4 0 4.8 0.8 7.2 0.8 3.2 0.8 5.6 0.8 8.8 0.8 2.4 0 4.8 0.8 7.2 0.8 3.2 0 5.6 0.8 8.8 0.8h29.6c3.2 0 5.6 0 8.8-0.8h4.8c4-0.8 8-0.8 12.8-1.6h0.8c122.4-18.4 220.8-116.8 236.8-240.8 0.8-3.2 0.8-6.4 0.8-9.6v-4c0-4 0.8-7.2 0.8-11.2 0-9.6 0-20-0.8-30.4-9.6-141.6-124.8-254.4-264.8-260.8C726.4 473.6 792 556.8 792 656c0 141.6-56 264-200 264-40 0-63.2-38.4-88-22.4-44.8 28-95.2 48-152 38.4h-1.6c-50.4 0-58.4 41.6-10.4 51.2 1.6 0 3.2 0.8 4.8 0.8 1.6 0 4 0.8 5.6 0.8 2.4 0.8 5.6 0.8 8.8 0.8 1.6 0 3.2 0.8 5.6 0.8 3.2 0 6.4 0.8 9.6 0.8h18.4c43.2 0 84-9.6 120-27.2 4.8 2.4 8.8 4 13.6 6.4 0.8 1.6 2.4 1.6 4 2.4z" fill="#C95065" p-id="1728"></path><path d="M632 1016c-19.2 0-39.2-1.6-58.4-5.6-40.8-8-83.2-8-124 0-19.2 4-38.4 5.6-58.4 5.6-84 0-164.8-35.2-222.4-96.8-56.8-61.6-85.6-143.2-80-228C99.2 538.4 227.2 414.4 380 408c33.6-1.6 66.4 2.4 97.6 12 6.4 1.6 12 3.2 17.6 4.8 19.2 4.8 41.6 9.6 85.6 32 12 5.6 16.8 20 11.2 32s-20 16.8-32 11.2c-39.2-19.2-57.6-24-76-28-6.4-1.6-12.8-3.2-20-4.8-26.4-8-54.4-11.2-82.4-10.4-128.8 4.8-236.8 109.6-245.6 237.6-4.8 72 19.2 140 68 192.8C253.6 939.2 320 968 392 968c16.8 0 32.8-1.6 48.8-4.8 47.2-8.8 95.2-8.8 142.4 0 16 3.2 32.8 4.8 48.8 4.8 72 0 138.4-28.8 187.2-81.6 48.8-52 72.8-120.8 68-192.8-8.8-128-116-232.8-244.8-237.6-13.6-0.8-23.2-12-23.2-24.8 0.8-13.6 11.2-24 24.8-23.2 152.8 5.6 280.8 130.4 291.2 282.4 5.6 85.6-23.2 166.4-80.8 228.8C796.8 980.8 716 1016 632 1016z" fill="#444B54" p-id="1729"></path><path d="M872 1016H152c-13.6 0-24-10.4-24-24s10.4-24 24-24h720c13.6 0 24 10.4 24 24s-10.4 24-24 24zM992 1016c-1.6 0-3.2 0-4.8-0.8-1.6 0-3.2-0.8-4.8-1.6-1.6-0.8-2.4-1.6-4-2.4-1.6-0.8-2.4-1.6-4-3.2l-3.2-3.2c-0.8-1.6-1.6-2.4-2.4-4-0.8-1.6-0.8-3.2-1.6-4.8 0-1.6-0.8-3.2-0.8-4.8 0-1.6 0-3.2 0.8-4.8 0-1.6 0.8-3.2 1.6-4.8 0.8-1.6 1.6-2.4 2.4-4 0.8-1.6 1.6-2.4 3.2-4s2.4-2.4 4-3.2c1.6-0.8 2.4-1.6 4-2.4 1.6-0.8 3.2-0.8 4.8-1.6 3.2-0.8 6.4-0.8 9.6 0 1.6 0 3.2 0.8 4.8 1.6 1.6 0.8 3.2 1.6 4 2.4 1.6 0.8 2.4 1.6 4 3.2 0.8 0.8 2.4 2.4 3.2 4 0.8 1.6 1.6 2.4 2.4 4 0.8 1.6 0.8 3.2 1.6 4.8 0 1.6 0.8 3.2 0.8 4.8 0 1.6 0 3.2-0.8 4.8 0 1.6-0.8 3.2-1.6 4.8s-1.6 3.2-2.4 4c-0.8 1.6-1.6 2.4-3.2 3.2-4.8 5.6-11.2 8-17.6 8z" fill="#444B54" p-id="1730"></path></svg>' icon_get = QPixmap() icon_get.loadFromData(icon) appIcon = QIcon(icon_get) self.setWindowIcon(appIcon) def GetWidgets(self): """ 设置控件 """ #& btn_proj_path加载图标 image = b'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1609656219985" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8030" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><defs><style type="text/css">@font-face { font-weight: 400; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Book-cd7d2bcec649b1243839a15d5eb8f0a3.woff2") format("woff2"); }\n@font-face { font-weight: 500; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Medium-d74eac43c78bd5852478998ce63dceb3.woff2") format("woff2"); }\n@font-face { font-weight: 700; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Bold-83b8ceaf77f49c7cffa44107561909e4.woff2") format("woff2"); }\n@font-face { font-weight: 900; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Black-bf067ecb8aa777ceb6df7d72226febca.woff2") format("woff2"); }\n</style></defs><path d="M928 444H820V330.4c0-17.7-14.3-32-32-32H473L355.7 186.2c-1.5-1.4-3.5-2.2-5.5-2.2H96c-17.7 0-32 14.3-32 32v592c0 17.7 14.3 32 32 32h698c13 0 24.8-7.9 29.7-20l134-332c1.5-3.8 2.3-7.9 2.3-12 0-17.7-14.3-32-32-32zM136 256h188.5l119.6 114.4H748V444H238c-13 0-24.8 7.9-29.7 20L136 643.2V256z m635.3 512H159l103.3-256h612.4L771.3 768z" p-id="8031" fill="#dbdbdb"></path></svg>' btn_proj_path_icon = QPixmap() btn_proj_path_icon.loadFromData(image) btn_image = b'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1610118992486" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2753" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><defs><style type="text/css">@font-face { font-weight: 400; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Book-cd7d2bcec649b1243839a15d5eb8f0a3.woff2") format("woff2"); }@font-face { font-weight: 500; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Medium-d74eac43c78bd5852478998ce63dceb3.woff2") format("woff2"); }@font-face { font-weight: 700; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Bold-83b8ceaf77f49c7cffa44107561909e4.woff2") format("woff2"); }@font-face { font-weight: 900; font-style: normal; font-family: Circular-Loom; src: url("https://cdn.loom.com/assets/fonts/circular/CircularXXWeb-Black-bf067ecb8aa777ceb6df7d72226febca.woff2") format("woff2"); }</style></defs><path d="M832 626.592l-128-128-128 128-256.48-256.448L192 497.632V191.872h640V626.56z m0 205.28H192V588.16l127.52-127.52L576 717.12l128-128 128 128v114.72z m0-704H128v768h768v-768h-64z" fill="#dbdbdb" p-id="2754"></path><path d="M672 319.872c-17.632 0-32 14.368-32 32 0 17.6 14.368 32 32 32 17.632 0 32-14.4 32-32 0-17.632-14.368-32-32-32m0 128c-52.928 0-96-43.072-96-96s43.072-96 96-96 96 43.072 96 96-43.072 96-96 96" fill="#dbdbdb" p-id="2755"></path></svg>' btn_image_icon = QPixmap() btn_image_icon.loadFromData(btn_image ) btn_proj_path = self.ui.findChild(QPushButton,"proj_path") self.btn_creatimg = self.ui.findChild(QPushButton,"creatimg") self.folderlist = self.ui.findChild(QComboBox, "path_list") self.path_info = self.ui.findChild(QLabel, "path_info") self.rendererlist = self.ui.findChild(QComboBox,"renderlist") self.hdrilist = self.ui.findChild(QListWidget, "hdrilist") btn_proj_path.setIcon(btn_proj_path_icon) self.btn_creatimg.setIcon(btn_image_icon) self.hdrilist.setViewMode(QListView.IconMode) self.hdrilist.setIconSize(QSize(150,100)) self.hdrilist.setResizeMode(QListWidget.Adjust) self.path_info.setText(self.hdri) self.hdrilist.customContextMenuRequested[QtCore.QPoint].connect(self.ListWidgetContext) btn_proj_path.clicked.connect(self.set_hdri_folder) self.btn_creatimg.clicked.connect(self.create_image_to_jpg) self.folderlist.activated.connect(self.Refresh) self.folderlist.activated.connect(self.CreateInterface) self.renderset() self.Refresh() self.CreateInterface() def renderwirt(self): """写入文件 """ render = open(self.scripts_path + "/HDRI_Path/render.txt",'w+') renderer = "Redshift,Mantra,Arnold,Vray,Octane" render.write(renderer) render.close() self.renderfile = renderer def renderset(self): """添加render渲染器列表 """ rendertext = self.renderfile rendersort = rendertext.split(",") for render in rendersort: self.rendererlist.addItem(render) def set_hdri_folder(self): """设置hdri文件夹 """ setpath = hou.ui.selectFile(title="Set Hdri Path",file_type=hou.fileType.Directory) newpath = os.path.dirname(setpath) +"/" if (newpath != "/"): self.hdri = newpath f = open(self.scripts_path + "/HDRI_Path/hdri_browser_path.txt","w+") f.write(newpath) f.close() self.Refresh() self.CreateInterface() self.path_info.setText(self.hdri) def Refresh(self): """设置路径 """ if self.hdri != self.temp and self.hdri !="": self.folderlist.clear() for folder in os.listdir(self.hdri): self.folderlist.addItem(folder) self.temp = self.hdri self.instexpath = self.hdri + str(self.folderlist.currentText()) + "/Thumbnails/" self.texpath = self.hdri + str(self.folderlist.currentText()) + "/HDRIs/" def CreateInterface(self): """创建缩略图 """ self.hdrilist.clear() try: for file in os.listdir(self.instexpath): if file.endswith('.jpg'): file_temp = file.split(".") del file_temp[-1] name = ".".join(file_temp) indextex0 = self.instexpath + file icon = QtGui.QIcon(indextex0) item = QListWidgetItem(icon, "") item.setSizeHint(QSize(155,100)) item.setText(name) item.setToolTip('<b>%s</b><br><img src="%s">' % (name, indextex0)) self.hdrilist.addItem(item) except WindowsError: pass #! 这里不知道是不是bug问题,还是自己思路错了,会加item传递进去,导致执行多次事件,加了disconnect强制中断事件. try: self.hdrilist.clicked.disconnect(self.setTex) except Exception: pass self.hdrilist.clicked.connect(self.setTex) try:self.hdrilist.doubleClicked.disconnect(self.create_node) except Exception: pass self.hdrilist.doubleClicked.connect(self.create_node) def setTex(self,item): """节点设置贴图路径 Args: item (index): 传入父类item的数据 """ texname = item.data() for texture in os.listdir(self.texpath): j = texture.split(texname) if len(j)>=2: texname = texture node_path = self.texpath + texname try: node = hou.selectedNodes()[0] light_node = node.parm('env_map') if(light_node == None): light_node = node.parm('ar_light_color_texture') if (light_node == None): light_node = node.parm('A_FILENAME') light_node.set(node_path) light_node.set(node_path) light_node.set(node_path) except AttributeError: hou.ui.displayMessage("没找到可以放环境贴图参数的位置,\n确认下是不是选择错节点了,\n或者灯光节点没有切换成环境灯光模式.\n---------如果要创建节点,请保证不要选择节点---------",severity=hou.severityType.Error) except IndexError: pass def create_node(self,item): """创建节点并设置贴图 Args: item (index): 传入父类item的数据 """ texname = item.data() for texture in os.listdir(self.texpath): j = texture.split(texname) if len(j)>=2: texname = texture node_path = self.texpath + texname render_name = self.rendererlist.currentText() if render_name == "Redshift": try: rslight = hou.node('/obj/').createNode('rslightdome') rslight.setCurrent(True, True) rslight.moveToGoodPosition() rs_env = rslight.parm('env_map') rs_env.set(node_path) except hou.OperationFailed: hou.ui.displayMessage("好像没安装Redshift渲染器,\n没安装是创建不了Redshift环境灯光节点的",severity=hou.severityType.Error) elif render_name == "Mantra": try: mtlight = hou.node('/obj/').createNode('envlight') mtlight.setCurrent(True, True) mtlight.moveToGoodPosition() mt_env = mtlight.parm('env_map') mt_env.set(node_path) except: hou.ui.displayMessage("这你都能报错???\n别弄了赶紧找小的救命",severity=hou.severityType.Error) elif render_name == "Arnold": try: arlight = hou.node('/obj/').createNode('arnold_light') arlight.parm("ar_light_type").set('skydome') arlight.parm("ar_light_color_type").set('texture') arlight.setCurrent(True, True) arlight.moveToGoodPosition() ar_env = arlight.parm('ar_light_color_texture') ar_env.set(node_path) except hou.OperationFailed: hou.ui.displayMessage("好像没安装Arnold渲染器,\n没安装是创建不了Arnold环境灯光节点的",severity=hou.severityType.Error) elif render_name == "Vray": try: vrlight = hou.node('/obj/').createNode('VRayNodeLightDome') vrlight.setCurrent(True, True) vrlight.moveToGoodPosition() vr_env = vrlight.parm('dome_tex') vr_env.set(node_path) pass except hou.OperationFailed: hou.ui.displayMessage("好像没安装Vray渲染器,\n没安装是创建不了Vray环境灯光节点的",severity=hou.severityType.Error) elif render_name == "Octane": try: oclight = hou.node('/shop/').createNode('octane_rendertarget_dl') oclight.parm("parmKernel").set('1') oclight.parm("parmEnvironment").set('1') oclight.setCurrent(True, True) oclight.moveToGoodPosition() oc_env = oclight.parm('A_FILENAME') oc_env.set(node_path) except hou.OperationFailed: hou.ui.displayMessage("好像没安装Octane渲染器,\n没安装是创建不了Octane环境灯光节点的",severity=hou.severityType.Error) else: hou.ui.displayMessage("目前只支持\n-------Redshift,Vray,Mantra,Arnold-------\n提示报错,请注意在该工具脚本存在位置的HDRI_Path/render.txt里的内容,格式如下\nRedshift,Vray,Mantra,Arnold\n解决不了,就删除render.txt文件,重新打开工具",severity=hou.severityType.Error) def create_image_to_jpg(self): Directory = self.hdri + self.folderlist.currentText()+'/' hdri_exr = self.check(Directory) if hdri_exr == []: hou.ui.displayMessage("没找到.hdr、.exr后缀的环境贴图",severity=hou.severityType.Error) else: for filename in hdri_exr: if filename.split('.')[1] == 'hdr': type = 'hdr' dir = Directory+'*.hdr' else : type = 'exr' dir = Directory+'*.exr' self.create_top(type,dir) def create_top(self,type,dir): top = hou.node('/obj').createNode('topnet','%s_to_jpg'%type) top.setComment(' 缩略图生成中') top.setCurrent(True, True) top.moveToGoodPosition() group = top.parmTemplateGroup() destroy = hou.ButtonParmTemplate('del','自毁',script_callback='hou.pwd().destroy(disable_safety_checks=False)',script_callback_language=hou.scriptLanguage.Python) folder = group.findFolder('Scheduler') group.appendToFolder(folder,destroy) top.setParmTemplateGroup(group) print('会调用CPU核心数-1的资源进行缩略图转换.\n在转换完成前,请不要进行其他操作,防止意外发生XD') top.setGenericFlag(hou.nodeFlag.DisplayComment,True) localscheduler = top.children()[0] localscheduler.parm('maxprocsmenu').set('-1') top_path = top.path() filepattern = hou.node(top_path).createNode('filepattern') filepattern.parm('pattern').set('%s'%dir) attributefromstring = filepattern.createOutputNode('attributefromstring') attributefromstring.parm('sourcestring').set('`@filename`') attributefromstring.parm('useregex').set('on') attributefromstring.parm('matchstring').set('(.+?)\.') ropcomposite = attributefromstring.createOutputNode('ropcomposite') ropcomposite.parm('tres').set('specify') ropcomposite.parm('res1').set('400') ropcomposite.parm('res2').set('200') ropcomposite.parm('copoutput').set('`@directory`/Thumbnails/`@group0`.jpg') filerename = ropcomposite.createOutputNode('filerename') filerename.parm('pdg_workitemgeneration').set('3') filerename.parm('originalpath').set('`@directory`/`@group0`.%s'%type) filerename.parm('newpath').set('`@directory`/HDRIs/`@group0`.%s'%type) mapall = filerename.createOutputNode('mapall') pythonscript = mapall.createOutputNode('pythonscript') pythonscript.parm('pdg_workitemgeneration').set('3') pythonscript.parm('script').set('import hou\nprint ("\\n好耶,没报错\\n缩略图已成功创建完成,可以点击自毁按钮删除节点:)\\n\\nHDRI Browser内右键刷新缩略图")\nhou.pwd().parent().setComment(" 自毁程序:已在该节点参数面板就绪\\nHDRI内右键刷新缩略图")') top.layoutChildren() pythonscript.setGenericFlag(hou.nodeFlag.OutputForDisplay, 1) top.parm('cookbutton').pressButton() return top def check(self,dir): filename_list = [] check_file = [".hdr",".exr"] for filename in os.listdir(dir): if os.path.splitext(filename)[1] in check_file : filename_list.append(filename) return filename_list def ListWidgetContext(self,point): """设置右键菜单 """ try: index = self.hdrilist.currentIndex() file_name = index.data() self.file_path = self.texpath +file_name+".exr" self.file_path_fix = self.file_path.replace('/','\\') except TypeError: pass popMenu = QMenu(self) pop_Menu_open_file = popMenu.addAction('打开文件') pop_Menu_open_file.triggered.connect(self.open_file) pop_Menu_open_file_path = popMenu.addAction('打开文件路径') pop_Menu_open_file_path.triggered.connect(self.open_file_path) pop_Menu_ref_file_path = popMenu.addAction('刷新') pop_Menu_ref_file_path.triggered.connect(self.CreateInterface) popMenu.exec_(QCursor.pos()) def open_file(self): try: os.startfile(self.file_path, 'open') except WindowsError: self.file_path = self.file_path.replace('.exr','.hdr') os.startfile(self.file_path, 'open') except: pass def open_file_path(self): """ 用subprocess可以避免cmd黑色窗口弹出 """ try: temp = open(self.file_path) temp.close() subprocess.Popen(r'explorer /select,%s'%self.file_path_fix) # os.system('explorer /n,/select,%s'%self.file_path_fix) except IOError: self.file_path_fix = self.file_path_fix.replace('.exr','.hdr') subprocess.Popen(r'explorer /select,%s'%self.file_path_fix) # os.system('explorer /n,/select,%s'%self.file_path_fix) except: pass
class CryptoWindow(QObject): buy_crypto = Signal(int) sell_crypto = Signal(int) def __init__(self, ui_file, parent=None): super(CryptoWindow, self).__init__(parent) self.window = QUiLoader().load(ui_file) self.extract_buttons() self.connect_signals() self.window.hide() def extract_buttons(self): self.back_button = self.window.findChild(QPushButton, 'back_button') self.buy_button_1 = self.window.findChild(QPushButton, 'buy_button_1') self.buy_button_2 = self.window.findChild(QPushButton, 'buy_button_2') self.buy_button_3 = self.window.findChild(QPushButton, 'buy_button_3') self.buy_button_4 = self.window.findChild(QPushButton, 'buy_button_4') self.buy_button_5 = self.window.findChild(QPushButton, 'buy_button_5') self.buy_button_6 = self.window.findChild(QPushButton, 'buy_button_6') self.sell_button_1 = self.window.findChild(QPushButton, 'sell_button_1') self.sell_button_2 = self.window.findChild(QPushButton, 'sell_button_2') self.sell_button_3 = self.window.findChild(QPushButton, 'sell_button_3') self.sell_button_4 = self.window.findChild(QPushButton, 'sell_button_4') self.sell_button_5 = self.window.findChild(QPushButton, 'sell_button_5') self.sell_button_6 = self.window.findChild(QPushButton, 'sell_button_6') def connect_signals(self): self.back_button.clicked.connect(self.close_window) self.buy_button_1.clicked.connect(self.buy_crypto_1) self.buy_button_2.clicked.connect(self.buy_crypto_2) self.buy_button_3.clicked.connect(self.buy_crypto_3) self.buy_button_4.clicked.connect(self.buy_crypto_4) self.buy_button_5.clicked.connect(self.buy_crypto_5) self.buy_button_6.clicked.connect(self.buy_crypto_6) self.sell_button_1.clicked.connect(self.sell_crypto_1) self.sell_button_2.clicked.connect(self.sell_crypto_2) self.sell_button_3.clicked.connect(self.sell_crypto_3) self.sell_button_4.clicked.connect(self.sell_crypto_4) self.sell_button_5.clicked.connect(self.sell_crypto_5) self.sell_button_6.clicked.connect(self.sell_crypto_6) def open_window(self): self.window.show() def close_window(self): self.window.hide() def buy_crypto_1(self): self.buy_crypto.emit(1) self.window.hide() def buy_crypto_2(self): self.buy_crypto.emit(2) self.window.hide() def buy_crypto_3(self): self.buy_crypto.emit(3) self.window.hide() def buy_crypto_4(self): self.buy_crypto.emit(4) self.window.hide() def buy_crypto_5(self): self.buy_crypto.emit(5) self.window.hide() def buy_crypto_6(self): self.buy_crypto.emit(6) self.window.hide() def sell_crypto_1(self): self.sell_crypto.emit(1) self.window.hide() def sell_crypto_2(self): self.sell_crypto.emit(2) self.window.hide() def sell_crypto_3(self): self.sell_crypto.emit(3) self.window.hide() def sell_crypto_4(self): self.sell_crypto.emit(4) self.window.hide() def sell_crypto_5(self): self.sell_crypto.emit(5) self.window.hide() def sell_crypto_6(self): self.sell_crypto.emit(6) self.window.hide()
class MainWindow(QObject): open_crypto = Signal() open_property = Signal() open_investment = Signal() open_bank = Signal() living_expenses = Signal(int) card_repay = Signal(int) end_turn_signal = Signal() def __init__(self, ui_file, parent=None): super(MainWindow, self).__init__(parent) self.window = QUiLoader().load(ui_file) self.extract_buttons() self.connect_signals() self.window.show() self.fee_payment_list = self.window.findChild(QListWidget, 'fee_payment') def extract_buttons(self): self.bank_button = self.window.findChild(QPushButton, 'BankButton') self.crypto_button = self.window.findChild(QPushButton, 'CryptoButton') self.property_button = self.window.findChild(QPushButton, 'PropertyButton') self.investment_button = self.window.findChild(QPushButton, 'InvestmentButton') self.end_turn_button = self.window.findChild(QPushButton, 'end_turn') self.living_card_button = self.window.findChild( QPushButton, 'living_card') self.living_savings_button = self.window.findChild( QPushButton, 'living_savings') self.card_repay_button = self.window.findChild(QPushButton, 'card_repay') self.card_notrepay_button = self.window.findChild( QPushButton, 'card_notrepay') def connect_signals(self): self.bank_button.clicked.connect(self.open_bank_window) self.crypto_button.clicked.connect(self.open_crypto_window) self.property_button.clicked.connect(self.open_property_window) self.investment_button.clicked.connect(self.open_investment_window) self.living_card_button.clicked.connect(self.living_expenses_card) self.living_savings_button.clicked.connect( self.living_expenses_savings) self.card_repay_button.clicked.connect(self.credit_card_repay) self.card_notrepay_button.clicked.connect(self.credit_card_notrepay) self.end_turn_button.clicked.connect(self.end_turn) def open_window(self): self.window.show() def close_window(self): self.window.hide() def open_bank_window(self): self.open_bank.emit() def open_crypto_window(self): self.open_crypto.emit() def open_property_window(self): self.open_property.emit() def open_investment_window(self): self.open_investment.emit() def living_expenses_card(self): self.living_expenses.emit(1) def living_expenses_savings(self): self.living_expenses.emit(2) def credit_card_repay(self): self.card_repay.emit(1) def credit_card_notrepay(self): self.card_repay.emit(2) def display_fee_payment(self, payment): self.fee_payment_list.addItem(payment) def end_turn(self): self.end_turn_signal.emit()
class InvestmentWindow(QObject): make_investment = Signal(int) def __init__(self, ui_file, parent=None): super(InvestmentWindow, self).__init__(parent) self.window = QUiLoader().load(ui_file) self.extract_buttons() self.connect_signals() self.window.hide() def extract_buttons(self): self.back_button = self.window.findChild(QPushButton, 'back_button') self.stock_low_button = self.window.findChild(QPushButton, 'stock_low_button') self.stock_avg_button = self.window.findChild(QPushButton, 'stock_avg_button') self.stock_high_button = self.window.findChild(QPushButton, 'stock_high_button') self.fixed_3_button = self.window.findChild(QPushButton, 'fixed_3_button') self.fixed_6_button = self.window.findChild(QPushButton, 'fixed_6_button') self.fixed_12_button = self.window.findChild(QPushButton, 'fixed_12_button') def connect_signals(self): self.back_button.clicked.connect(self.close_window) self.stock_low_button.clicked.connect(self.buy_stock_low) self.stock_avg_button.clicked.connect(self.buy_stock_avg) self.stock_high_button.clicked.connect(self.buy_stock_high) self.fixed_3_button.clicked.connect(self.buy_fixed_3) self.fixed_6_button.clicked.connect(self.buy_fixed_6) self.fixed_12_button.clicked.connect(self.buy_fixed_12) def open_window(self): self.window.show() def close_window(self): self.window.hide() def buy_stock_low(self): self.make_investment.emit(1) self.window.hide() def buy_stock_avg(self): self.make_investment.emit(2) self.window.hide() def buy_stock_high(self): self.make_investment.emit(3) self.window.hide() def buy_fixed_3(self): self.make_investment.emit(4) self.window.hide() def buy_fixed_6(self): self.make_investment.emit(5) self.window.hide() def buy_fixed_12(self): self.make_investment.emit(6) self.window.hide()