Forked from anonymous/gist:49eb2d8981919deed61485bf88adcbc2
Created
December 31, 2017 14:03
-
-
Save avaris/2c97f27e46c725e82b232d32e66e5841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from PyQt5.QtWidgets import QApplication, QWidget, QToolBox | |
from PyQt5.QtWidgets import QPushButton, QVBoxLayout, QAction, QMenu | |
from PyQt5.QtWidgets import QLineEdit, QLabel | |
class Remove(QWidget): | |
count = 0 | |
def __init__(self, parent=None): | |
super().__init__(parent) | |
layout = QVBoxLayout(self) | |
label = QLabel('Remove {}'.format(Remove.count)) | |
Remove.count += 1 | |
layout.addWidget(label) | |
class RemovePattern(QWidget): | |
count = 0 | |
def __init__(self, parent=None): | |
super().__init__(parent) | |
layout = QVBoxLayout(self) | |
label = QLabel('Remove Pattern {}'.format(RemovePattern.count)) | |
RemovePattern.count += 1 | |
layout.addWidget(label) | |
class RenamerUI(QWidget): | |
def __init__(self): | |
super().__init__() | |
self.layout_ui() | |
def layout_ui(self): | |
# Create Options Pane elements | |
self.add_mthd_btn = QPushButton("Add Method") | |
self.mthd_menu = QMenu() | |
self.add_mthd_btn.setMenu(self.mthd_menu) | |
self.method_toolbox = QToolBox() | |
self.line_tbx_indx = QLineEdit() | |
self.check_index = QPushButton("Check Index") | |
# Layouts | |
options_layout = QVBoxLayout() | |
options_layout.addWidget(self.add_mthd_btn) | |
options_layout.addWidget(self.line_tbx_indx) | |
options_layout.addWidget(self.check_index) | |
options_layout.addWidget(self.method_toolbox) | |
options_layout.addStretch() | |
self.setLayout(options_layout) | |
# Add items to menu | |
mthd_menu_remove_count = QAction("Remove", self) | |
self.mthd_menu.addAction(mthd_menu_remove_count) | |
mthd_menu_remove_pattern = QAction("Remove Pattern", self) | |
self.mthd_menu.addAction(mthd_menu_remove_pattern) | |
# Click Event | |
self.check_index.clicked.connect(self.chk_ind) | |
self.mthd_menu.triggered.connect(self.respond_to_mthd_menu) | |
def add_to_mthd_toolbox(self, method, signal): | |
self.method_toolbox.addItem(method, signal) | |
def respond_to_mthd_menu(self, sender): | |
signal = sender.text() | |
print(signal) | |
if signal == "Remove": | |
self.add_to_mthd_toolbox(Remove(self), signal) | |
elif signal == "Remove Pattern": | |
self.add_to_mthd_toolbox(RemovePattern(self), signal) | |
# Check the currentIndex of the QToolBox | |
def chk_ind(self): | |
self.line_tbx_indx.setText(str(self.method_toolbox.currentIndex())) | |
if __name__ == "__main__": | |
app = QApplication(sys.argv) | |
window = RenamerUI() | |
window.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment