Skip to content

Instantly share code, notes, and snippets.

Created December 31, 2017 13:49
Show Gist options
  • Save anonymous/49eb2d8981919deed61485bf88adcbc2 to your computer and use it in GitHub Desktop.
Save anonymous/49eb2d8981919deed61485bf88adcbc2 to your computer and use it in GitHub Desktop.
import os
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QToolBox
from PyQt5.QtWidgets import QPushButton, QVBoxLayout, QAction, QMenu
from PyQt5.QtWidgets import QLineEdit
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)
#Toolbox Methods
self.tbx_mthd_remove_count = QWidget()
self.tbx_mthd_remove_pattern = QWidget()
# 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(self.tbx_mthd_remove_count, signal)
elif signal == "Remove Pattern":
self.add_to_mthd_toolbox(self.tbx_mthd_remove_pattern, 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