class BaseSaveFileDialog(BaseFileFolderDialog, object): def __init__(self, name='SaveFile', title='Save File', size=(200, 125), fixed_size=False, frame_less=True, hide_title=False, parent=None, use_app_browser=False): parent = parent or dcc.get_main_window() super(BaseSaveFileDialog, self).__init__(name=name, title=title, size=size, fixed_size=fixed_size, frame_less=frame_less, hide_title=hide_title, use_app_browser=use_app_browser, parent=parent) self._open_button.setText('Save') size = QSize(42, 24) self.new_directory_button = QPushButton('New') self.new_directory_button.setToolTip('Create new directory') self.new_directory_button.setMinimumSize(size) self.new_directory_button.setMaximumWidth(size) self.new_directory_button.clicked.connect(self.create_new_directory) self.grid.itemAtPosition(0, 1).addWidget(self.new_directory_button, 0, 5) def accept(self, *args, **kwargs): selected_file, selected_dir, selected_filename = self.get_result() if not os.path.isdir(selected_file): if os.path.exists(selected_file): message_box = QMessageBox() message_box.setWindowTitle('Confirm File Selection') message_box.setText( 'File "%s" exists.\nDo you want to overwrite it?' % selected_file) message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) message_box.setDefaultButton(QMessageBox.No) rv = message_box.exec_() if rv == QMessageBox.Yes and not os.path.isdir(selected_file): super(BaseSaveFileDialog, self).accept() else: super(BaseSaveFileDialog, self).accept() def create_new_directory(self): name, ok = QInputDialog.getText(self, 'New directory name', 'Name:', QLineEdit.Normal, 'New Directory') if ok and name: path = os.path.join(self.directory, name) if os.path.exists(path): msg_box = QMessageBox(self) msg_box.setWindowTitle('Error') msg_box.setText('Directory already exists') msg_box.exec_() else: try: os.makedirs(path) self.update_view() except os.error as e: msg_box = QMessageBox(self) msg_box.setWindowTitle('Error') msg_box.setText('Cannot create directory') msg_box.exec_()
class ExpandablePanel(base.BaseWidget, object): def __init__(self, header_text, min_height=30, max_height=1000, show_header_text=True, is_opened=False, parent=None): self._header_text = header_text self._show_header_text = show_header_text self._min_height = min_height self._max_height = max_height if is_opened: self._panel_state = PanelState.OPEN else: self._panel_state = PanelState.CLOSED self._collapse_icon = QIcon() self._icon = QPushButton() self._icon.setMaximumSize(20, 20) self._icon.setIcon(self._collapse_icon) super(ExpandablePanel, self).__init__(parent=parent) self.setObjectName('ExpandablePanel') self.update_size() self.update_icon() def ui(self): super(ExpandablePanel, self).ui() widget_palette = QPalette() widget_palette.setColor(QPalette.Background, QColor.fromRgb(60, 60, 60)) self.setAutoFillBackground(True) self.setPalette(widget_palette) frame = QFrame() frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Sunken) self.main_layout.addWidget(frame) main_layout = layouts.VerticalLayout(spacing=0, margins=(2, 2, 2, 2), parent=frame) main_layout.setAlignment(Qt.AlignTop) self._header_area = QWidget() self._header_area.setMinimumHeight(20) self._widget_area = QWidget() self._widget_area.setAutoFillBackground(True) self._widget_area.setPalette(widget_palette) self._header_text_label = dividers.Divider(self._header_text) self._widget_layout = layouts.VerticalLayout(spacing=5) self._widget_layout.setMargin(5) self._widget_area.setLayout(self._widget_layout) header_layout = layouts.HorizontalLayout(margins=(0, 0, 0, 0)) header_layout.addWidget(self._icon) header_layout.addWidget(self._header_text_label) self._header_area.setLayout(header_layout) main_layout.addWidget(self._header_area) main_layout.addWidget(self._widget_area) self._icon.clicked.connect(self.change_state) def update_icon(self): if self._panel_state == PanelState.OPEN: self._icon.setStyleSheet( 'QLabel {image: url(:/icons/open_hover_collapsible_panel) no-repeat;} ' 'QLabel:hover {image:url(:/icons/open_hover_collapsible_panel) no-repeat;}') self._icon.setToolTip('Close') self._widget_area.show() else: self._icon.setStyleSheet( 'QLabel {image: url(:/icons/closed_collapsible_panel) no-repeat;} ' 'QLabel:hover {image:url(:/icons/closed_hover_collapsible_panel) no-repeat;}') self._icon.setToolTip('Open') self._widget_area.hide() def update_size(self): if self._panel_state == PanelState.OPEN: self.setMaximumHeight(self._max_height) self.setMinimumHeight(self._min_height) else: self.setMaximumHeight(self._min_height) self.setMinimumHeight(self._min_height) def change_state(self): if not self._show_header_text: self._header_text_label.setVisible(False) if self._panel_state == PanelState.OPEN: self._panel_state = PanelState.CLOSED # self._header_text_label.setText('Closed') self._widget_area.hide() else: self._panel_state = PanelState.OPEN # self._header_text_label.setText('Open') self._widget_area.show() self.update_icon() self.update_size() def add_widget(self, widget): self._widget_layout.addWidget(widget) def add_layout(self, layout): self._widget_layout.addLayout(layout)
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.data = ParticleData() toolbar = self.addToolBar("Test") openButton = QPushButton("") openButton.setFlat(True) openButton.setIconSize(QSize(32, 32)) openButton.setIcon(QIcon("/jobs2/soft/icons/dlight/open.png")) openButton.setToolTip("Open File") toolbar.addWidget(openButton) openButton.clicked.connect(self.openSlot) QShortcut(QKeySequence(Qt.CTRL + Qt.Key_O), self, self.openSlot) saveButton = QPushButton("") saveButton.setFlat(True) saveButton.setIconSize(QSize(32, 32)) saveButton.setIcon(QIcon("/jobs2/soft/icons/dlight/file_save.png")) saveButton.setToolTip("Save File") toolbar.addWidget(saveButton) saveButton.clicked.connect(self.saveSlot) QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), self, self.saveSlot) saveDeltaButton = QPushButton("") saveDeltaButton.setFlat(True) saveDeltaButton.setIconSize(QSize(32, 32)) saveDeltaButton.setIcon( QIcon("/jobs2/soft/icons/dlight/file_save_as.png")) saveDeltaButton.setToolTip("Save File As Delta") toolbar.addWidget(saveDeltaButton) saveDeltaButton.clicked.connect(self.saveDeltaSlot) QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S), self, self.saveDeltaSlot) addParticleButton = QPushButton("Particle") addParticleButton.setFlat(True) addParticleButton.setIconSize(QSize(32, 32)) addParticleButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addParticleButton.setToolTip("Add Particle") toolbar.addWidget(addParticleButton) addParticleButton.clicked.connect(self.addParticleSlot) addAttributeButton = QPushButton("Attribute") addAttributeButton.setFlat(True) addAttributeButton.setIconSize(QSize(32, 32)) addAttributeButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addAttributeButton.setToolTip("Add Attribute") toolbar.addWidget(addAttributeButton) addAttributeButton.clicked.connect(self.addAttributeSlot) splitter = QSplitter(self) self.setCentralWidget(splitter) particleTable = ParticleTableWidget(self.data, self) splitter.addWidget(particleTable) right = QWidget(self) splitter.addWidget(right) vbox = QVBoxLayout(right) right.setLayout(vbox) fixedAttrWidget = FixedAttributesWidget(self.data, self) vbox.addWidget(fixedAttrWidget) indexedStrings = IndexedStringsWidget(self.data, self) vbox.addWidget(indexedStrings) vbox.addStretch() # TODD: SCROLLABLE AREAS FOR EVERYTHING self.data.dirtied.connect(self.dataDirtiedSlot) # Configure ctrl-w to close the window QShortcut(QKeySequence(Qt.CTRL + Qt.Key_W), self, self.close)
class BaseFileFolderDialog(BaseDialog, abstract_dialog.AbstractFileFolderDialog): """ Base dialog classes for folders and files """ def_title = 'Select File' def_size = (200, 125) def_use_app_browser = False def __init__(self, name='BaseFileFolder', parent=None, **kwargs): super(BaseFileFolderDialog, self).__init__(name=name, parent=parent) self.directory = None self.filters = None self._use_app_browser = kwargs.pop('use_app_browser', self.def_use_app_browser) self.set_filters('All Files (*.*)') # By default, we set the directory to the user folder self.set_directory(os.path.expanduser('~')) self.center() def open_app_browser(self): return def ui(self): super(BaseFileFolderDialog, self).ui() from tpDcc.libs.qt.widgets import directory self.places = dict() self.grid = layouts.GridLayout() sub_grid = layouts.GridLayout() self.grid.addWidget(QLabel('Path:'), 0, 0, Qt.AlignRight) self.path_edit = QLineEdit(self) self.path_edit.setReadOnly(True) self.filter_box = QComboBox(self) self.file_edit = QLineEdit(self) self.view = directory.FileListWidget(self) self.view.setWrapping(True) self.view.setFocusPolicy(Qt.StrongFocus) self.open_button = QPushButton('Select', self) self.cancel_button = QPushButton('Cancel', self) size = QSize(32, 24) self.up_button = QPushButton('Up') self.up_button.setToolTip('Go up') self.up_button.setMinimumSize(size) self.up_button.setMaximumSize(size) size = QSize(56, 24) self.refresh_button = QPushButton('Reload') self.refresh_button.setToolTip('Reload file list') self.refresh_button.setMinimumSize(size) self.refresh_button.setMaximumSize(size) self.show_hidden = QCheckBox('Hidden') self.show_hidden.setChecked(False) self.show_hidden.setToolTip('Toggle show hidden files') sub_grid.addWidget(self.up_button, 0, 1) sub_grid.addWidget(self.path_edit, 0, 2) sub_grid.addWidget(self.refresh_button, 0, 3) sub_grid.addWidget(self.show_hidden, 0, 4) self.grid.addLayout(sub_grid, 0, 1) self.grid.addWidget(self.get_drives_widget(), 1, 0) self.grid.addWidget(self.view, 1, 1) self.grid.addWidget(QLabel('File name:'), 7, 0, Qt.AlignRight) self.grid.addWidget(self.file_edit, 7, 1) self.filter_label = QLabel('Filter:') self.grid.addWidget(self.filter_label, 8, 0, Qt.AlignRight) self.grid.addWidget(self.filter_box, 8, 1) hbox = layouts.GridLayout() hbox.addWidget(self.open_button, 0, 0, Qt.AlignRight) hbox.addWidget(self.cancel_button, 0, 1, Qt.AlignRight) self.grid.addLayout(hbox, 9, 1, Qt.AlignRight) self.main_layout.addLayout(self.grid) self.setGeometry(200, 100, 600, 400) self.open_button.clicked.connect(self.accept) self.cancel_button.clicked.connect(self.reject) self.up_button.clicked.connect(self.go_up) self.refresh_button.clicked.connect(self.update_view) self.show_hidden.stateChanged.connect(self.update_view) self.view.directory_activated.connect( self.activate_directory_from_view) self.view.file_activated.connect(self.activate_file_from_view) self.view.file_selected.connect(self.select_file_item) self.view.folder_selected.connect(self.select_folder_item) self.view.up_requested.connect(self.go_up) self.view.update_requested.connect(self.update_view) def exec_(self, *args, **kwargs): if self._use_app_browser: return self.open_app_browser() else: self.update_view() self.filter_box.currentIndexChanged.connect(self.update_view) accepted = super(BaseFileFolderDialog, self).exec_() self.filter_box.currentIndexChanged.disconnect(self.update_view) return self.get_result() if accepted == 1 else None def set_filters(self, filters, selected=0): self.filter_box.clear() filter_types = filters.split(';;') for ft in filter_types: extensions = string.extract(ft, '(', ')') filter_name = string.rstrips(ft, '({})'.format(extensions)) extensions = extensions.split(' ') self.filter_box.addItem( '{} ({})'.format(filter_name, ','.join(extensions)), extensions) if 0 <= selected < self.filter_box.count(): self.filter_box.setCurrentIndex(selected) self.filters = filters def get_drives_widget(self): """ Returns a QGroupBox widget that contains all disk drivers of the PC in a vertical layout :return: QGroupBox """ w = QGroupBox('') w.setParent(self) box = layouts.VerticalLayout() box.setAlignment(Qt.AlignTop) places = [(getpass.getuser(), os.path.realpath(os.path.expanduser('~')))] places += [ (q, q) for q in [os.path.realpath(x.absolutePath()) for x in QDir().drives()] ] for label, loc in places: icon = QFileIconProvider().icon(QFileInfo(loc)) drive_btn = QRadioButton(label) drive_btn.setIcon(icon) drive_btn.setToolTip(loc) drive_btn.setProperty('path', loc) drive_btn.clicked.connect(self.go_to_drive) self.places[loc] = drive_btn box.addWidget(drive_btn) w.setLayout(box) return w def go_to_drive(self): """ Updates widget to show the content of the selected disk drive """ sender = self.sender() self.set_directory(sender.property('path'), False) def get_result(self): tf = self.file_edit.text() sf = self.get_file_path(tf) return sf, os.path.dirname(sf), tf.split(os.pathsep) def get_filter_patterns(self): """ Get list of filter patterns that are being used by the widget :return: list<str> """ idx = self.filter_box.currentIndex() if idx >= 0: return self.filter_box.itemData(idx) else: return [] def get_file_path(self, file_name): """ Returns file path of the given file name taking account the selected directory :param file_name: str, name of the file without path :return: str """ sname = file_name.split(os.pathsep)[0] return os.path.realpath( os.path.join(os.path.abspath(self.directory), sname)) # def accept(self): # self._overlay.close() # super(BaseFileFolderDialog, self).accept() # # # def reject(self): # self._overlay.close() # super(BaseFileFolderDialog, self).reject() def update_view(self): """ Updates file/folder view :return: """ self.view.clear() qdir = QDir(self.directory) qdir.setNameFilters(self.get_filter_patterns()) filters = QDir.Dirs | QDir.AllDirs | QDir.Files | QDir.NoDot | QDir.NoDotDot if self.show_hidden.isChecked(): filters = filters | QDir.Hidden entries = qdir.entryInfoList(filters=filters, sort=QDir.DirsFirst | QDir.Name) file_path = self.get_file_path('..') if os.path.exists(file_path) and file_path != self.directory: icon = QFileIconProvider().icon(QFileInfo(self.directory)) QListWidgetItem(icon, '..', self.view, 0) for info in entries: icon = QFileIconProvider().icon(info) suf = info.completeSuffix() name, tp = (info.fileName(), 0) if info.isDir() else ( '%s%s' % (info.baseName(), '.%s' % suf if suf else ''), 1) QListWidgetItem(icon, name, self.view, tp) self.view.setFocus() def set_directory(self, path, check_drive=True): """ Sets the directory that you want to explore :param path: str, valid path :param check_drive: bool, :return: """ self.directory = os.path.realpath(path) self.path_edit.setText(self.directory) self.file_edit.setText('') # If necessary, update selected disk driver if check_drive: for loc in self.places: rb = self.places[loc] rb.setAutoExclusive(False) rb.setChecked(loc.lower() == self.directory.lower()) rb.setAutoExclusive(True) self.update_view() self.up_button.setEnabled(not self.cant_go_up()) def go_up(self): """ Updates the current directory to go to its parent directory """ self.set_directory(os.path.dirname(self.directory)) def cant_go_up(self): """ Checks whether we can naviage to current selected parent directory or not :return: bool """ return os.path.dirname(self.directory) == self.directory def activate_directory_from_view(self, name): """ Updates selected directory :param name: str, name of the directory """ self.set_directory(os.path.join(self.directory, name)) def activate_file_from_view(self, name): """ Updates selected file text and returns its info by accepting it :param name: str, name of the file """ self.select_file_item(name=name) self.accept() def select_file_item(self, name): """ Updates selected file text and returns its info by accepting it :param name: str, name of the file """ self.file_edit.setText(name) def select_folder_item(self, name): """ Updates selected folder text and returns its info by accepting it :param name: str, name of the folder """ self.file_edit.setText(name)
class TestRunner(ToolInstance): def __init__(self, session, name): super().__init__(session, name) self.tool_window = MainToolWindow(self) self._build_ui() def _build_ui(self): """ ui should have: * table with a list of available tests and show results after they are done * way to filter tests * button to run tests """ layout = QFormLayout() # table to list test classes and the results self.table = QTableWidget() self.table.setColumnCount(2) self.table.setHorizontalHeaderLabels(["test", "result"]) self.table.horizontalHeader().setSectionResizeMode( 0, self.table.horizontalHeader().Interactive) self.table.setEditTriggers(QTableWidget.NoEditTriggers) self.table.horizontalHeader().setSectionResizeMode( 1, self.table.horizontalHeader().Stretch) self.table.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.table.setSelectionBehavior(self.table.SelectRows) layout.addRow(self.table) self.filter = QLineEdit() self.filter.setPlaceholderText("filter test names") self.filter.setClearButtonEnabled(True) self.filter.textChanged.connect(self.apply_filter) layout.addRow(self.filter) self.profile = QCheckBox() self.profile.setToolTip("profile functions called during testing " "using cProfile") layout.addRow("profile calls:", self.profile) self.run_button = QPushButton("run tests") self.run_button.clicked.connect(self.run_tests) self.run_button.setToolTip( "if no tests are selected on the table, run all tests\n" + "otherwise, run selected tests") layout.addRow(self.run_button) self.fill_table() self.table.resizeColumnToContents(0) self.tool_window.ui_area.setLayout(layout) self.tool_window.manage(None) def apply_filter(self, text=None): """filter table to only show tests matching text""" if text is None: text = self.filter.text() if text: text = text.replace("(", "\(") text = text.replace(")", "\)") m = QRegularExpression(text) m.setPatternOptions(QRegularExpression.CaseInsensitiveOption) if m.isValid(): m.optimize() filter = lambda row_num: m.match( self.table.item(row_num, 0).text()).hasMatch() else: return else: filter = lambda row: True for i in range(0, self.table.rowCount()): self.table.setRowHidden(i, not filter(i)) def fill_table(self): """adds test names to the table""" mgr = self.session.test_manager for name in mgr.tests.keys(): row = self.table.rowCount() self.table.insertRow(row) test_name = QTableWidgetItem() test_name.setData(Qt.DisplayRole, name) self.table.setItem(row, 0, test_name) def run_tests(self): """run the tests selected on the table and show the results""" from TestManager.commands.test import test test_list = [] use_selected = True for row in self.table.selectionModel().selectedRows(): if self.table.isRowHidden(row.row()): continue test_name = self.table.item(row.row(), 0).text() test_list.append(test_name) if not test_list: use_selected = False for i in range(0, self.table.rowCount()): if self.table.isRowHidden(i): continue test_name = self.table.item(i, 0).text() test_list.append(test_name) if not test_list: test_list = ["all"] results, stats = test(self.session, test_list, profile=self.profile.checkState() == Qt.Checked) cell_widgets = [] for name in results: widget = QWidget() widget_layout = QHBoxLayout(widget) widget_layout.setContentsMargins(0, 0, 0, 0) success_button = get_button("success") fail_button = get_button("fail") skip_button = get_button("skip") error_button = get_button("error") expected_fail_button = get_button("expected fail") unexpected_success_button = get_button("unexpected success") success_count = 0 fail_count = 0 error_count = 0 unexpected_success_count = 0 expected_fail_count = 0 skip_count = 0 success_tooltip = "Successes:\n" fail_tooltip = "Failed tests:\n" error_tooltip = "Errors during test:\n" unexpected_success_tooltip = "Unexpected successes:\n" expected_fail_tooltip = "Expected fails:\n" skip_tooltip = "Skipped tests:\n" for case in results[name]: result, msg = results[name][case] if result == "success": success_count += 1 success_tooltip += "%s.%s: %s\n" % ( case.__class__.__qualname__, case._testMethodName, msg) elif result == "fail": fail_count += 1 fail_tooltip += "%s.%s failed: %s\n" % ( case.__class__.__qualname__, case._testMethodName, msg) elif result == "error": error_count += 1 error_tooltip += "error during %s.%s: %s\n" % ( case.__class__.__qualname__, case._testMethodName, msg) elif result == "expected_failure": expected_fail_count += 1 expected_fail_tooltip += "intended failure during %s.%s: %s\n" % ( case.__class__.__qualname__, case._testMethodName, msg) elif result == "skip": skip_count += 1 skip_tooltip += "%s.%s\n" % (case.__class__.__qualname__, case._testMethodName) elif result == "unexpected_success": unexpected_success_count += 1 unexpected_success_tooltip += "%s.%s should not have worked, but did\n" % ( case.__class__.__qualname__, case._testMethodName) success_tooltip = success_tooltip.strip() fail_tooltip = fail_tooltip.strip() error_tooltip = error_tooltip.strip() expected_fail_tooltip = expected_fail_tooltip.strip() skip_tooltip = skip_tooltip.strip() unexpected_success_tooltip = unexpected_success_tooltip.strip() icon_count = 0 if success_count: success_button.setText("%i" % success_count) success_button.setToolTip(success_tooltip) success_button.clicked.connect( lambda *args, t_name=name, res=success_tooltip: self. tool_window.create_child_window( "successes for %s" % t_name, text=res, window_class=ResultsWindow, )) widget_layout.insertWidget(icon_count, success_button, 1) icon_count += 1 if fail_count: fail_button.setText("%i" % fail_count) fail_button.setToolTip(fail_tooltip) fail_button.clicked.connect( lambda *args, res=fail_tooltip: self.tool_window. create_child_window( "failures for %s" % name, text=res, window_class=ResultsWindow, )) widget_layout.insertWidget(icon_count, fail_button, 1) icon_count += 1 if error_count: error_button.setText("%i" % error_count) error_button.setToolTip(error_tooltip) error_button.clicked.connect( lambda *args, res=error_tooltip: self.tool_window. create_child_window( "errors for %s" % name, text=res, window_class=ResultsWindow, )) widget_layout.insertWidget(icon_count, error_button, 1) icon_count += 1 if unexpected_success_count: unexpected_success_button.setText("%i" % unexpected_success_count) unexpected_success_button.setToolTip( unexpected_success_tooltip) unexpected_success_button.clicked.connect( lambda *args, res=unexpected_success_tooltip: self. tool_window.create_child_window( "unexpected successes for %s" % name, text=res, window_class=ResultsWindow, )) widget_layout.insertWidget(icon_count, unexpected_success_button, 1) icon_count += 1 if expected_fail_count: expected_fail_button.setText("%i" % expected_fail_count) expected_fail_button.setToolTip(expected_fail_tooltip) expected_fail_button.clicked.connect( lambda *args, res=expected_fail_tooltip: self.tool_window. create_child_window( "expected failures for %s" % name, text=res, window_class=ResultsWindow, )) widget_layout.insertWidget(icon_count, expected_fail_button, 1) icon_count += 1 if skip_count: skip_button.setText("%i" % skip_count) skip_button.setToolTip(skip_tooltip) skip_button.clicked.connect( lambda *args, res=skip_tooltip: self.tool_window. create_child_window( "skipped tests for %s" % name, text=res, window_class=ResultsWindow, )) widget_layout.insertWidget(icon_count, skip_button, 1) cell_widgets.append(widget) widget_count = 0 if use_selected: for row in self.table.selectionModel().selectedRows(): if self.table.isRowHidden(row.row()): continue self.table.setCellWidget(row.row(), 1, cell_widgets[widget_count]) self.table.resizeRowToContents(row.row()) widget_count += 1 else: for i in range(0, self.table.rowCount()): if self.table.isRowHidden(i): continue self.table.setCellWidget(i, 1, cell_widgets[widget_count]) # self.table.resizeRowToContents(i) widget_count += 1 if self.profile.checkState() == Qt.Checked: self.tool_window.create_child_window("stats", text=stats, window_class=ResultsWindow)
def create_flat_button( icon=None, icon_size=None, name='', text=200, background_color=[54, 51, 51], ui_color=68, border_color=180, push_col=120, checkable=True, w_max=None, w_min=None, h_max=None, h_min=None, policy=None, tip=None, flat=True, hover=True, destroy_flag=False, context=None, ): btn = QPushButton() btn.setText(name) btn.setCheckable(checkable) if icon: if isinstance(icon, QIcon): btn.setIcon(icon) else: btn.setIcon(QIcon(icon)) btn.setFlat(flat) if flat: change_button_color(button=btn, text_color=text, bg_color=ui_color, hi_color=background_color, mode='button', hover=hover, destroy=destroy_flag, ds_color=border_color) btn.toggled.connect( lambda: change_button_color(button=btn, text_color=text, bg_color=ui_color, hi_color=background_color, mode='button', toggle=True, hover=hover, destroy=destroy_flag, ds_color=border_color)) else: change_button_color(button=btn, text_color=text, bg_color=background_color, hi_color=push_col, mode='button', hover=hover, destroy=destroy_flag, ds_color=border_color) if w_max: btn.setMaximumWidth(w_max) if w_min: btn.setMinimumWidth(w_min) if h_max: btn.setMaximumHeight(h_max) if h_min: btn.setMinimumHeight(h_min) if icon_size: btn.setIconSize(QSize(*icon_size)) if policy: btn.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding) if tip: btn.setToolTip(tip) if context: btn.setContextMenuPolicy(Qt.CustomContextMenu) btn.customContextMenuRequested.connect(context) return btn
def fill_tree(self, trigger_name=None, trigger_job=None): item_stack = [self.tree.invisibleRootItem()] self.tree.clear() jobs = self.session.seqcrow_job_manager.jobs for job in jobs: name = job.name parent = item_stack[0] item = QTreeWidgetItem(parent) item_stack.append(item) item.setData(self.NAME_COL, Qt.DisplayRole, job) item.setText(self.NAME_COL, name) if isinstance(job, LocalJob): if job.killed: item.setText(self.STATUS_COL, "killed") del_job_widget = QWidget() del_job_layout = QGridLayout(del_job_widget) del_job = QPushButton() del_job.clicked.connect( lambda *args, job=job: self.remove_job(job)) del_job.setIcon( QIcon(del_job_widget.style().standardIcon( QStyle.SP_DialogDiscardButton))) del_job.setFlat(True) del_job_layout.addWidget(del_job, 0, 0, 1, 1, Qt.AlignHCenter) del_job_layout.setColumnStretch(0, 1) del_job_layout.setContentsMargins(0, 0, 0, 0) self.tree.setItemWidget(item, self.DEL_COL, del_job_widget) elif job.isRunning(): if job in self.session.seqcrow_job_manager.unknown_status_jobs: unk_widget = QWidget() unk_layout = QGridLayout(unk_widget) unk = QPushButton() unk.setIcon( QIcon(unk_widget.style().standardIcon( QStyle.SP_MessageBoxQuestion))) unk.setFlat(True) unk.clicked.connect(lambda *args, job=job: self. show_ask_if_running(job)) unk_layout.addWidget(unk, 0, 0, 1, 1, Qt.AlignHCenter) unk_layout.setColumnStretch(0, 1) unk_layout.setContentsMargins(0, 0, 0, 0) self.tree.setItemWidget(item, self.STATUS_COL, unk_widget) else: item.setText(self.STATUS_COL, "running") kill_widget = QWidget() kill_layout = QGridLayout(kill_widget) kill = QPushButton() kill.setIcon( QIcon(kill_widget.style().standardIcon( QStyle.SP_DialogCancelButton))) kill.setFlat(True) kill.clicked.connect(lambda *args, job=job: job.kill()) kill.clicked.connect( lambda *args, session=self.session: session. seqcrow_job_manager.triggers.activate_trigger( JOB_QUEUED, "resume")) kill_layout.addWidget(kill, 0, 0, 1, 1, Qt.AlignLeft) kill_layout.setColumnStretch(0, 0) kill_layout.setContentsMargins(0, 0, 0, 0) self.tree.setItemWidget(item, self.KILL_COL, kill_widget) elif job.isFinished(): if not job.error: item.setText(self.STATUS_COL, "finished") else: error_widget = QWidget() error_layout = QGridLayout(error_widget) error = QPushButton() error.setIcon( QIcon(error_widget.style().standardIcon( QStyle.SP_MessageBoxWarning))) error.setFlat(True) error.setToolTip( "job did not finish without errors or output file cannot be found" ) error_layout.addWidget(error, 0, 0, 1, 1, Qt.AlignHCenter) error_layout.setColumnStretch(0, 1) error_layout.setContentsMargins(0, 0, 0, 0) self.tree.setItemWidget(item, self.STATUS_COL, error_widget) del_job_widget = QWidget() del_job_layout = QGridLayout(del_job_widget) del_job = QPushButton() del_job.clicked.connect( lambda *args, job=job: self.remove_job(job)) del_job.setIcon( QIcon(del_job_widget.style().standardIcon( QStyle.SP_DialogDiscardButton))) del_job.setFlat(True) del_job_layout.addWidget(del_job, 0, 0, 1, 1, Qt.AlignHCenter) del_job_layout.setColumnStretch(0, 1) del_job_layout.setContentsMargins(0, 0, 0, 0) self.tree.setItemWidget(item, self.DEL_COL, del_job_widget) else: item.setText(self.STATUS_COL, "queued") priority_widget = QWidget() priority_layout = QGridLayout(priority_widget) inc_priority = QPushButton() inc_priority.setIcon( QIcon(priority_widget.style().standardIcon( QStyle.SP_ArrowUp))) inc_priority.setFlat(True) inc_priority.clicked.connect( lambda *args, job=job: self.session.seqcrow_job_manager .increase_priotity(job)) priority_layout.addWidget(inc_priority, 0, 0, 1, 1, Qt.AlignRight) dec_priority = QPushButton() dec_priority.setIcon( QIcon(priority_widget.style().standardIcon( QStyle.SP_ArrowDown))) dec_priority.setFlat(True) dec_priority.clicked.connect( lambda *args, job=job: self.session.seqcrow_job_manager .decrease_priotity(job)) priority_layout.addWidget(dec_priority, 0, 1, 1, 1, Qt.AlignLeft) priority_layout.setColumnStretch(0, 1) priority_layout.setColumnStretch(1, 1) priority_layout.setContentsMargins(0, 0, 0, 0) self.tree.setItemWidget(item, self.CHANGE_PRIORITY, priority_widget) kill_widget = QWidget() kill_layout = QGridLayout(kill_widget) kill = QPushButton() kill.setIcon( QIcon(kill_widget.style().standardIcon( QStyle.SP_DialogCancelButton))) kill.setFlat(True) kill.clicked.connect(lambda *args, job=job: job.kill()) kill.clicked.connect( lambda *args, session=self.session: session. seqcrow_job_manager.triggers.activate_trigger( JOB_QUEUED, "resume")) kill_layout.addWidget(kill, 0, 0, 1, 1, Qt.AlignLeft) kill_layout.setColumnStretch(0, 0) kill_layout.setContentsMargins(0, 0, 0, 0) self.tree.setItemWidget(item, self.KILL_COL, kill_widget) item.setText(self.SERVER_COL, "local") if job.scratch_dir and os.path.exists(job.scratch_dir): browse_widget = QWidget() browse_layout = QGridLayout(browse_widget) browse = QPushButton() browse.clicked.connect( lambda *args, job=job: self.browse_local(job)) browse.setIcon( QIcon(browse_widget.style().standardIcon( QStyle.SP_DirOpenIcon))) browse.setFlat(True) browse_layout.addWidget(browse, 0, 0, 1, 1, Qt.AlignLeft) browse_layout.setColumnStretch(0, 1) browse_layout.setContentsMargins(0, 0, 0, 0) self.tree.setItemWidget(item, self.BROWSE_COL, browse_widget) self.tree.expandItem(item) self.tree.resizeColumnToContents(self.STATUS_COL) self.tree.resizeColumnToContents(self.SERVER_COL) self.tree.resizeColumnToContents(self.CHANGE_PRIORITY) self.tree.resizeColumnToContents(self.KILL_COL) self.tree.resizeColumnToContents(self.DEL_COL) self.tree.resizeColumnToContents(self.BROWSE_COL)
def _build_ui(self): layout = QGridLayout() tabs = QTabWidget() calc_widget = QWidget() calc_layout = QFormLayout(calc_widget) settings_widget = QWidget() settings_layout = QFormLayout(settings_widget) steric_map_widget = QWidget() steric_layout = QFormLayout(steric_map_widget) cutout_widget = QWidget() vol_cutout_layout = QFormLayout(cutout_widget) layout.addWidget(tabs) tabs.addTab(calc_widget, "calculation") tabs.addTab(settings_widget, "settings") tabs.addTab(steric_map_widget, "steric map") tabs.addTab(cutout_widget, "volume cutout") self.radii_option = QComboBox() self.radii_option.addItems(["Bondi", "UMN"]) ndx = self.radii_option.findText(self.settings.radii, Qt.MatchExactly) self.radii_option.setCurrentIndex(ndx) settings_layout.addRow("radii:", self.radii_option) self.scale = QDoubleSpinBox() self.scale.setValue(self.settings.vdw_scale) self.scale.setSingleStep(0.01) self.scale.setRange(1., 1.5) settings_layout.addRow("VDW scale:", self.scale) set_ligand_atoms = QPushButton("set ligands to current selection") set_ligand_atoms.clicked.connect(self.set_ligand_atoms) set_ligand_atoms.setToolTip( "specify atoms to use in calculation\n" + "by default, all atoms will be used unless a single center is specified\n" + "in the case of a single center, all atoms except the center is used" ) calc_layout.addRow(set_ligand_atoms) self.set_ligand_atoms = set_ligand_atoms self.radius = QDoubleSpinBox() self.radius.setValue(self.settings.center_radius) self.radius.setSuffix(" \u212B") self.radius.setDecimals(1) self.radius.setSingleStep(0.1) self.radius.setRange(1., 15.) settings_layout.addRow("radius around center:", self.radius) self.method = QComboBox() self.method.addItems(["Lebedev", "Monte-Carlo"]) self.method.setToolTip("Lebedev: deterministic method\n" + "Monte-Carlo: non-deterministic method") ndx = self.method.findText(self.settings.method, Qt.MatchExactly) self.method.setCurrentIndex(ndx) settings_layout.addRow("integration method:", self.method) leb_widget = QWidget() leb_layout = QFormLayout(leb_widget) leb_layout.setContentsMargins(0, 0, 0, 0) self.radial_points = QComboBox() self.radial_points.addItems(["20", "32", "64", "75", "99", "127"]) self.radial_points.setToolTip( "more radial points will give more accurate results, but integration will take longer" ) ndx = self.radial_points.findText(self.settings.radial_points, Qt.MatchExactly) self.radial_points.setCurrentIndex(ndx) leb_layout.addRow("radial points:", self.radial_points) self.angular_points = QComboBox() self.angular_points.addItems([ "110", "194", "302", "590", "974", "1454", "2030", "2702", "5810" ]) self.angular_points.setToolTip( "more angular points will give more accurate results, but integration will take longer" ) ndx = self.angular_points.findText(self.settings.angular_points, Qt.MatchExactly) self.angular_points.setCurrentIndex(ndx) leb_layout.addRow("angular points:", self.angular_points) settings_layout.addRow(leb_widget) mc_widget = QWidget() mc_layout = QFormLayout(mc_widget) mc_layout.setContentsMargins(0, 0, 0, 0) self.min_iter = QSpinBox() self.min_iter.setValue(self.settings.minimum_iterations) self.min_iter.setRange(0, 10000) self.min_iter.setToolTip( "each iteration is 3000 points\n" + "iterations continue until convergence criteria are met") mc_layout.addRow("minimum interations:", self.min_iter) settings_layout.addRow(mc_widget) if self.settings.method == "Lebedev": mc_widget.setVisible(False) elif self.settings.method == "Monte-Carlo": leb_widget.setVisible(False) self.report_component = QComboBox() self.report_component.addItems(["total", "quadrants", "octants"]) ndx = self.report_component.findText(self.settings.report_component, Qt.MatchExactly) self.report_component.setCurrentIndex(ndx) settings_layout.addRow("report volume:", self.report_component) self.use_scene = QCheckBox() self.use_scene.setChecked(self.settings.use_scene) self.use_scene.setToolTip( "quadrants/octants will use the orientation the molecule is displayed in" ) settings_layout.addRow("use display orientation:", self.use_scene) self.method.currentTextChanged.connect( lambda text, widget=leb_widget: widget.setVisible(text == "Lebedev" )) self.method.currentTextChanged.connect( lambda text, widget=mc_widget: widget.setVisible(text == "Monte-Carlo")) self.use_centroid = QCheckBox() self.use_centroid.setChecked(self.settings.use_centroid) self.use_centroid.setToolTip( "place the center between selected atoms\n" + "might be useful for polydentate ligands") calc_layout.addRow("use centroid of centers:", self.use_centroid) self.steric_map = QCheckBox() self.steric_map.setChecked(self.settings.steric_map) self.steric_map.setToolTip( "produce a 2D projection of steric bulk\ncauses buried volume to be reported for individual quadrants" ) steric_layout.addRow("create steric map:", self.steric_map) self.num_pts = QSpinBox() self.num_pts.setRange(25, 250) self.num_pts.setValue(self.settings.num_pts) self.num_pts.setToolTip("number of points along x and y axes") steric_layout.addRow("number of points:", self.num_pts) self.include_vbur = QCheckBox() self.include_vbur.setChecked(self.settings.include_vbur) steric_layout.addRow("label quadrants with %V<sub>bur</sub>", self.include_vbur) self.map_shape = QComboBox() self.map_shape.addItems(["circle", "square"]) ndx = self.map_shape.findText(self.settings.map_shape, Qt.MatchExactly) self.map_shape.setCurrentIndex(ndx) steric_layout.addRow("map shape:", self.map_shape) self.auto_minmax = QCheckBox() self.auto_minmax.setChecked(self.settings.auto_minmax) steric_layout.addRow("automatic min. and max.:", self.auto_minmax) self.map_min = QDoubleSpinBox() self.map_min.setRange(-15., 0.) self.map_min.setSuffix(" \u212B") self.map_min.setSingleStep(0.1) self.map_min.setValue(self.settings.map_min) steric_layout.addRow("minimum value:", self.map_min) self.map_max = QDoubleSpinBox() self.map_max.setRange(0., 15.) self.map_max.setSuffix(" \u212B") self.map_max.setSingleStep(0.1) self.map_max.setValue(self.settings.map_max) steric_layout.addRow("maximum value:", self.map_max) self.num_pts.setEnabled(self.settings.steric_map) self.steric_map.stateChanged.connect( lambda state, widget=self.num_pts: widget.setEnabled(state == Qt. Checked)) self.include_vbur.setEnabled(self.settings.steric_map) self.steric_map.stateChanged.connect( lambda state, widget=self.include_vbur: widget.setEnabled( state == Qt.Checked)) self.map_shape.setEnabled(self.settings.steric_map) self.steric_map.stateChanged.connect( lambda state, widget=self.map_shape: widget.setEnabled(state == Qt. Checked)) self.auto_minmax.setEnabled(self.settings.steric_map) self.steric_map.stateChanged.connect( lambda state, widget=self.auto_minmax: widget.setEnabled( state == Qt.Checked)) self.map_min.setEnabled(not self.settings.auto_minmax and self.settings.steric_map) self.steric_map.stateChanged.connect( lambda state, widget=self.map_min, widget2=self.auto_minmax: widget .setEnabled(state == Qt.Checked and not widget2.isChecked())) self.auto_minmax.stateChanged.connect( lambda state, widget=self.map_min, widget2=self.steric_map: widget. setEnabled(not state == Qt.Checked and widget2.isChecked())) self.map_max.setEnabled(not self.settings.auto_minmax and self.settings.steric_map) self.steric_map.stateChanged.connect( lambda state, widget=self.map_max, widget2=self.auto_minmax: widget .setEnabled(state == Qt.Checked and not widget2.isChecked())) self.auto_minmax.stateChanged.connect( lambda state, widget=self.map_max, widget2=self.steric_map: widget. setEnabled(not state == Qt.Checked and widget2.isChecked())) self.display_cutout = QComboBox() self.display_cutout.addItems(["no", "free", "buried"]) ndx = self.display_cutout.findText(self.settings.display_cutout, Qt.MatchExactly) self.display_cutout.setCurrentIndex(ndx) self.display_cutout.setToolTip("show free or buried volume") vol_cutout_layout.addRow("display volume:", self.display_cutout) self.point_spacing = QDoubleSpinBox() self.point_spacing.setDecimals(3) self.point_spacing.setRange(0.01, 0.5) self.point_spacing.setSingleStep(0.005) self.point_spacing.setSuffix(" \u212B") self.point_spacing.setValue(self.settings.point_spacing) self.point_spacing.setToolTip( "distance between points on cutout\n" + "smaller spacing will narrow gaps, but increase time to create the cutout" ) vol_cutout_layout.addRow("point spacing:", self.point_spacing) self.intersection_scale = QDoubleSpinBox() self.intersection_scale.setDecimals(2) self.intersection_scale.setRange(1., 10.) self.intersection_scale.setSingleStep(0.5) self.intersection_scale.setSuffix("x") self.intersection_scale.setToolTip( "relative density of points where VDW radii intersect\n" + "higher density will narrow gaps, but increase time to create cutout" ) self.intersection_scale.setValue(self.settings.intersection_scale) vol_cutout_layout.addRow("intersection density:", self.intersection_scale) self.cutout_labels = QComboBox() self.cutout_labels.addItems(["none", "quadrants", "octants"]) ndx = self.cutout_labels.findText(self.settings.cutout_labels, Qt.MatchExactly) self.cutout_labels.setCurrentIndex(ndx) vol_cutout_layout.addRow("label sections:", self.cutout_labels) self.point_spacing.setEnabled(self.settings.display_cutout != "no") self.intersection_scale.setEnabled( self.settings.display_cutout != "no") self.cutout_labels.setEnabled(self.settings.display_cutout != "no") self.display_cutout.currentTextChanged.connect( lambda text, widget=self.point_spacing: widget.setEnabled(text != "no")) self.display_cutout.currentTextChanged.connect( lambda text, widget=self.intersection_scale: widget.setEnabled( text != "no")) self.display_cutout.currentTextChanged.connect( lambda text, widget=self.cutout_labels: widget.setEnabled(text != "no")) calc_vbur_button = QPushButton( "calculate % buried volume for selected centers") calc_vbur_button.clicked.connect(self.calc_vbur) calc_layout.addRow(calc_vbur_button) self.calc_vbur_button = calc_vbur_button remove_vbur_button = QPushButton( "remove % buried volume visualizations") remove_vbur_button.clicked.connect(self.del_vbur) vol_cutout_layout.addRow(remove_vbur_button) self.table = QTableWidget() self.table.setColumnCount(3) self.table.setHorizontalHeaderLabels(['model', 'center', '%Vbur']) self.table.setSelectionBehavior(QTableWidget.SelectRows) self.table.setEditTriggers(QTableWidget.NoEditTriggers) self.table.resizeColumnToContents(0) self.table.resizeColumnToContents(1) self.table.resizeColumnToContents(2) self.table.horizontalHeader().setSectionResizeMode( 0, QHeaderView.Interactive) self.table.horizontalHeader().setSectionResizeMode( 1, QHeaderView.Interactive) self.table.horizontalHeader().setSectionResizeMode( 2, QHeaderView.Stretch) calc_layout.addRow(self.table) menu = QMenuBar() export = menu.addMenu("&Export") clear = QAction("Clear data table", self.tool_window.ui_area) clear.triggered.connect(self.clear_table) export.addAction(clear) copy = QAction("&Copy CSV to clipboard", self.tool_window.ui_area) copy.triggered.connect(self.copy_csv) shortcut = QKeySequence(Qt.CTRL + Qt.Key_C) copy.setShortcut(shortcut) export.addAction(copy) self.copy = copy save = QAction("&Save CSV...", self.tool_window.ui_area) save.triggered.connect(self.save_csv) #this shortcut interferes with main window's save shortcut #I've tried different shortcut contexts to no avail #thanks Qt... #shortcut = QKeySequence(Qt.CTRL + Qt.Key_S) #save.setShortcut(shortcut) #save.setShortcutContext(Qt.WidgetShortcut) export.addAction(save) delimiter = export.addMenu("Delimiter") comma = QAction("comma", self.tool_window.ui_area, checkable=True) comma.setChecked(self.settings.delimiter == "comma") comma.triggered.connect(lambda *args, delim="comma": self.settings. __setattr__("delimiter", delim)) delimiter.addAction(comma) tab = QAction("tab", self.tool_window.ui_area, checkable=True) tab.setChecked(self.settings.delimiter == "tab") tab.triggered.connect(lambda *args, delim="tab": self.settings. __setattr__("delimiter", delim)) delimiter.addAction(tab) space = QAction("space", self.tool_window.ui_area, checkable=True) space.setChecked(self.settings.delimiter == "space") space.triggered.connect(lambda *args, delim="space": self.settings. __setattr__("delimiter", delim)) delimiter.addAction(space) semicolon = QAction("semicolon", self.tool_window.ui_area, checkable=True) semicolon.setChecked(self.settings.delimiter == "semicolon") semicolon.triggered.connect(lambda *args, delim="semicolon": self. settings.__setattr__("delimiter", delim)) delimiter.addAction(semicolon) add_header = QAction("&Include CSV header", self.tool_window.ui_area, checkable=True) add_header.setChecked(self.settings.include_header) add_header.triggered.connect(self.header_check) export.addAction(add_header) comma.triggered.connect( lambda *args, action=tab: action.setChecked(False)) comma.triggered.connect( lambda *args, action=space: action.setChecked(False)) comma.triggered.connect( lambda *args, action=semicolon: action.setChecked(False)) tab.triggered.connect( lambda *args, action=comma: action.setChecked(False)) tab.triggered.connect( lambda *args, action=space: action.setChecked(False)) tab.triggered.connect( lambda *args, action=semicolon: action.setChecked(False)) space.triggered.connect( lambda *args, action=comma: action.setChecked(False)) space.triggered.connect( lambda *args, action=tab: action.setChecked(False)) space.triggered.connect( lambda *args, action=semicolon: action.setChecked(False)) semicolon.triggered.connect( lambda *args, action=comma: action.setChecked(False)) semicolon.triggered.connect( lambda *args, action=tab: action.setChecked(False)) semicolon.triggered.connect( lambda *args, action=space: action.setChecked(False)) menu.setNativeMenuBar(False) self._menu = menu layout.setMenuBar(menu) menu.setVisible(True) self.tool_window.ui_area.setLayout(layout) self.tool_window.manage(None)
class RowTableWidget(QFrame): double_clicked = Signal(object) def __init__(self, auto_resize=False, single_row_select=True, context_menu_callback=None, last_column_stretch=True, has_counters=False, parent=None ): QFrame.__init__(self, parent) self._has_counters = has_counters self.model = None self.table_view = RowTableView(auto_resize, single_row_select, context_menu_callback, last_column_stretch) self.table_view.doubleClicked.connect(self._double_clicked) if has_counters: self.counters = Counters() self.counters.button_clicked.connect(self._counter_clicked) self.search_bar = QLineEdit() self.search_bar.setFixedHeight(SEARCHBAR_HEIGHT) self.search_bar.textChanged.connect(self.set_search_text) self.search_bar.setToolTip("Search bar") self.auto_size_button = QPushButton('<>') self.auto_size_button.setFixedSize(SEARCHBAR_HEIGHT, SEARCHBAR_HEIGHT) self.auto_size_button.clicked.connect(self._auto_size_clicked) self.auto_size_button.setToolTip("Auto size") self.status_label = QLabel(STATUS_LABEL_MESSAGE.format(0, 0)) self.status_label.setFixedWidth(STATUS_LABEL_WIDTH) self.progress_bar = QProgressBar() self.progress_bar.setFormat('') layout = QGridLayout() layout.addWidget(self.search_bar, 0, 0, 1, 3) layout.addWidget(self.auto_size_button, 0, 3) if has_counters: layout.addWidget(self.counters, 1, 0, 1, 2) layout.addWidget(self.table_view, 1, 2, 1, 2) else: layout.addWidget(self.table_view, 1, 0, 1, 4) layout.addWidget(self.status_label, 2, 0) layout.addWidget(self.progress_bar, 2, 1, 1, 3) layout.setColumnStretch(2, 100) self.setLayout(layout) def set_model(self, model): self.model = model self.table_view.setModel(model) model.modelReset.connect(self._set_progress_maximum) model.modelReset.connect(self._update_status) if self._has_counters: model.modelReset.connect(self._update_counters) self._update_counters() model.progress_updated.connect(self._update_progress) self._set_progress_maximum() self._update_status() self.progress_bar.setVisible(model.has_background_callback) @property def selected_rows(self): return [self.model.data(index, Qt.UserRole) for index in self.table_view.selectionModel().selectedIndexes() if index.column() == 0] @property def search_text(self): return self.search_bar.text() def set_search_text(self, text): self.search_bar.blockSignals(True) self.search_bar.setText(text) self.search_bar.blockSignals(False) self.model.set_search_text(text) def _set_progress_maximum(self): self.progress_bar.setMaximum(self.model.progress_max) # do better ? def _update_progress(self, value): self.progress_bar.setValue(value) def _update_status(self): self.status_label.setText(STATUS_LABEL_MESSAGE.format( self.model.rowCount(), self.model.total_row_count )) def _counter_clicked(self, entry, checked_buttons): entries = [entry for entry, active in checked_buttons.items() if active] self.model.set_search_counters(entries) def _update_counters(self): self.counters.set(self.model.counters) def _auto_size_clicked(self): with Hourglass(): self.table_view.resizeColumnsToContents() def _double_clicked(self, index): row = self.model.data(index, Qt.UserRole) self.double_clicked.emit(row) def state(self): header_sizes = list() header = self.table_view.horizontalHeader() for section_index in range(header.count()): header_sizes.append(header.sectionSize(section_index)) return { 'header_sizes': header_sizes, 'search_text': self.search_bar.text() } def load_state(self, state): header = self.table_view.horizontalHeader() for section_index, size in enumerate(state['header_sizes']): header.resizeSection(section_index, size) self.search_bar.setText(state['search_text'])
def _build_ui(self): layout = QGridLayout() library_tabs = QTabWidget() #ligand tab ligand_tab = QWidget() ligand_layout = QFormLayout(ligand_tab) self.ligand_name = QLineEdit() self.ligand_name.setText("") self.ligand_name.setPlaceholderText("leave blank to preview") self.ligand_name.setToolTip( "name of ligand you are adding to your ligand library\nleave blank to open a new model with just the ligand" ) ligand_layout.addRow("ligand name:", self.ligand_name) ligand_key_atoms = QPushButton("set key atoms to current selection") ligand_key_atoms.clicked.connect(self.update_key_atoms) ligand_key_atoms.setToolTip( "the current selection will be the key atoms for the ligand\nleave blank to automatically determine key atoms" ) ligand_layout.addRow(ligand_key_atoms) libadd_ligand = QPushButton("add current selection to library") libadd_ligand.clicked.connect(self.libadd_ligand) ligand_layout.addRow(libadd_ligand) #substituent tab sub_tab = QWidget() sub_layout = QFormLayout(sub_tab) self.sub_name = QLineEdit() self.sub_name.setText("") self.sub_name.setPlaceholderText("leave blank to preview") self.sub_name.setToolTip( "name of substituent you are adding to your substituent library\nleave blank to open a new model with just the substituent" ) sub_layout.addRow("substituent name:", self.sub_name) self.sub_confs = QSpinBox() self.sub_confs.setMinimum(1) sub_layout.addRow("number of conformers:", self.sub_confs) self.sub_angle = QSpinBox() self.sub_angle.setRange(0, 180) self.sub_angle.setSingleStep(30) sub_layout.addRow("angle between conformers:", self.sub_angle) libadd_sub = QPushButton("add current selection to library") libadd_sub.clicked.connect(self.libadd_substituent) sub_layout.addRow(libadd_sub) #ring tab ring_tab = QWidget() ring_layout = QFormLayout(ring_tab) self.ring_name = QLineEdit() self.ring_name.setText("") self.ring_name.setPlaceholderText("leave blank to preview") self.ring_name.setToolTip( "name of ring you are adding to your ring library\nleave blank to open a new model with just the ring" ) ring_layout.addRow("ring name:", self.ring_name) libadd_ring = QPushButton("add ring with selected walk to library") libadd_ring.clicked.connect(self.libadd_ring) ring_layout.addRow(libadd_ring) library_tabs.addTab(sub_tab, "substituent") library_tabs.addTab(ring_tab, "ring") library_tabs.addTab(ligand_tab, "ligand") self.library_tabs = library_tabs layout.addWidget(library_tabs) whats_this = QLabel() whats_this.setText( "<a href=\"req\" style=\"text-decoration: none;\">what's this?</a>" ) whats_this.setTextFormat(Qt.RichText) whats_this.setTextInteractionFlags(Qt.TextBrowserInteraction) whats_this.linkActivated.connect(self.open_link) whats_this.setToolTip( "click for more information about AaronTools libraries") layout.addWidget(whats_this) self.tool_window.ui_area.setLayout(layout) self.tool_window.manage(None)
def _build_ui(self): layout = QGridLayout() self.library_tabs = QTabWidget() #add a tab for ligands self.ligand_tab = QWidget() self.ligand_layout = QVBoxLayout(self.ligand_tab) self.lig_table = LigandTable() self.ligand_layout.addWidget(self.lig_table) showKeyAtomsCheck = QCheckBox('show key atoms') showKeyAtomsCheck.setToolTip( "ligand's coordinating atoms will be highlighted") showKeyAtomsCheck.toggle() showKeyAtomsCheck.stateChanged.connect(self.showKeyAtoms) self.ligand_layout.addWidget(showKeyAtomsCheck) self.lig_color = ColorButton('key atom color', has_alpha_channel=True) self.lig_color.setToolTip("highlight color for ligand's key atoms") self.lig_color.set_color(self.settings.key_atom_color) self.ligand_layout.addWidget(self.lig_color) openLigButton = QPushButton("open selected ligands") openLigButton.setToolTip( "ligands selected in the table will be loaded into ChimeraX") openLigButton.clicked.connect(self.open_ligands) self.ligand_layout.addWidget(openLigButton) self.openLigButton = openLigButton #add a tab for substituents self.substituent_tab = QWidget() self.substituent_layout = QVBoxLayout(self.substituent_tab) self.sub_table = SubstituentTable() self.substituent_layout.addWidget(self.sub_table) showGhostConnectionCheck = QCheckBox('show ghost connection') showGhostConnectionCheck.setToolTip( "ligand's coordinating atoms will be highlighted") showGhostConnectionCheck.toggle() showGhostConnectionCheck.stateChanged.connect(self.showGhostConnection) self.substituent_layout.addWidget(showGhostConnectionCheck) self.sub_color = ColorButton('ghost connection color', has_alpha_channel=True) self.sub_color.setToolTip("color of ghost connection") self.sub_color.set_color(self.settings.ghost_connection_color) self.substituent_layout.addWidget(self.sub_color) openSubButton = QPushButton("open selected substituents") openSubButton.setToolTip( "substituents selected in the table will be loaded into ChimeraX") openSubButton.clicked.connect(self.open_substituents) self.substituent_layout.addWidget(openSubButton) self.openSubButton = openSubButton #add a tab for rings self.ring_tab = QWidget() self.ring_layout = QVBoxLayout(self.ring_tab) self.ring_table = RingTable() self.ring_layout.addWidget(self.ring_table) showRingWalkCheck = QCheckBox('show ring walk') showRingWalkCheck.setToolTip( "arrows will show the way AaronTools traverses the ring") showRingWalkCheck.toggle() showRingWalkCheck.stateChanged.connect(self.showRingWalk) self.ring_layout.addWidget(showRingWalkCheck) self.ring_color = ColorButton('walk arrow color', has_alpha_channel=True) self.ring_color.setToolTip("color of walk arrows") self.ring_color.set_color(self.settings.ring_walk_color) self.ring_layout.addWidget(self.ring_color) openRingButton = QPushButton("open selected rings") openRingButton.setToolTip( "rings selected in the table will be loaded into ChimeraX") openRingButton.clicked.connect(self.open_rings) self.ring_layout.addWidget(openRingButton) self.openRingButton = openRingButton self.library_tabs.resize(300, 200) self.library_tabs.addTab(self.ligand_tab, "ligands") self.library_tabs.addTab(self.substituent_tab, "substituents") self.library_tabs.addTab(self.ring_tab, "rings") layout.addWidget(self.library_tabs) self.tool_window.ui_area.setLayout(layout) self.tool_window.manage(None)
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.data = ParticleData() toolbar = self.addToolBar("Test") openButton = QPushButton("") openButton.setFlat(True) openButton.setIconSize( QSize(32, 32) ) openButton.setIcon(QIcon("/jobs2/soft/icons/dlight/open.png")) openButton.setToolTip( "Open File" ) toolbar.addWidget(openButton) openButton.clicked.connect(self.openSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.Key_O), self, self.openSlot ) saveButton = QPushButton("") saveButton.setFlat(True) saveButton.setIconSize( QSize(32, 32) ) saveButton.setIcon(QIcon("/jobs2/soft/icons/dlight/file_save.png")) saveButton.setToolTip( "Save File" ) toolbar.addWidget(saveButton) saveButton.clicked.connect(self.saveSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.Key_S), self, self.saveSlot ) saveDeltaButton = QPushButton("") saveDeltaButton.setFlat(True) saveDeltaButton.setIconSize( QSize(32, 32) ) saveDeltaButton.setIcon(QIcon("/jobs2/soft/icons/dlight/file_save_as.png")) saveDeltaButton.setToolTip( "Save File As Delta" ) toolbar.addWidget(saveDeltaButton) saveDeltaButton.clicked.connect(self.saveDeltaSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S), self, self.saveDeltaSlot ) addParticleButton = QPushButton("Particle") addParticleButton.setFlat(True) addParticleButton.setIconSize( QSize(32, 32) ) addParticleButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addParticleButton.setToolTip( "Add Particle" ) toolbar.addWidget(addParticleButton) addParticleButton.clicked.connect(self.addParticleSlot) addAttributeButton = QPushButton("Attribute") addAttributeButton.setFlat(True) addAttributeButton.setIconSize( QSize(32, 32) ) addAttributeButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addAttributeButton.setToolTip( "Add Attribute" ) toolbar.addWidget(addAttributeButton) addAttributeButton.clicked.connect(self.addAttributeSlot) splitter = QSplitter(self) self.setCentralWidget(splitter) particleTable = ParticleTableWidget(self.data, self) splitter.addWidget(particleTable) right = QWidget(self) splitter.addWidget(right) vbox = QVBoxLayout(right) right.setLayout(vbox) fixedAttrWidget = FixedAttributesWidget(self.data, self) vbox.addWidget(fixedAttrWidget) indexedStrings = IndexedStringsWidget(self.data, self) vbox.addWidget(indexedStrings) vbox.addStretch() # TODD: SCROLLABLE AREAS FOR EVERYTHING self.data.dirtied.connect(self.dataDirtiedSlot) # Configure ctrl-w to close the window QShortcut( QKeySequence(Qt.CTRL + Qt.Key_W), self, self.close )
class SaveWidget(BaseSaveWidget, object): def __init__(self, item, settings, temp_path=None, parent=None): self._script_job = None self._sequence_path = None self._icon_path = '' super(SaveWidget, self).__init__(item=item, settings=settings, temp_path=temp_path, parent=parent) self.create_sequence_widget() self.update_thumbnail_size() try: self._on_selection_changed() # self.set_script_job_enabled(True) except NameError as e: LOGGER.error('{} | {}'.format(e, traceback.format_exc())) def ui(self): super(SaveWidget, self).ui() model_panel_layout = layouts.HorizontalLayout() model_panel_layout.setContentsMargins(0, 0, 0, 0) model_panel_layout.setSpacing(0) thumbnail_layout = layouts.VerticalLayout() thumbnail_layout.setContentsMargins(0, 0, 0, 0) thumbnail_layout.setSpacing(0) self._thumbnail_frame = QFrame() self._thumbnail_frame.setMinimumSize(QSize(50, 50)) self._thumbnail_frame.setMaximumSize(QSize(150, 150)) self._thumbnail_frame.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._thumbnail_frame.setFrameShape(QFrame.NoFrame) self._thumbnail_frame.setFrameShadow(QFrame.Plain) self._thumbnail_frame.setLineWidth(0) self._thumbnail_frame.setLayout(thumbnail_layout) model_panel_layout.addWidget(self._thumbnail_frame) self._thumbnail_btn = QPushButton() self._thumbnail_btn.setMinimumSize(QSize(0, 0)) self._thumbnail_btn.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._thumbnail_btn.setMaximumSize(QSize(150, 150)) self._thumbnail_btn.setToolTip('Take snapshot') self._thumbnail_btn.setStyleSheet( 'color: rgb(40, 40, 40);border: 0px solid rgb(0, 0, 0, 150);background-color: rgb(254, 255, 230, 200);' ) self._thumbnail_btn.setIcon(resources.icon('thumbnail')) self._thumbnail_btn.setToolTip(""" Click to capture a thumbnail from the current viewport.\n CTRL + Click to show the capture window for better framing """) thumbnail_layout.addWidget(self._thumbnail_btn) self._extra_layout.addLayout(model_panel_layout) def setup_signals(self): super(SaveWidget, self).setup_signals() self._thumbnail_btn.clicked.connect(self._on_thumbnail_capture) def resizeEvent(self, event): """ Overrides base QWidget resizeEvent function :param event: QResizeEvent """ self.update_thumbnail_size() def icon_path(self): """ Returns the icon path to be used for the thumbnail :return: str """ return self._icon_path def set_icon(self, icon): """ Sets the icon for the create widget thumbnail :param icon: QIcon """ self._thumbnail_btn.setIcon(icon) self._thumbnail_btn.setIconSize(QSize(200, 200)) self._thumbnail_btn.setText('') def sequence_path(self): """ Returns the playblast path :return: str """ return self._sequence_path def set_sequence_path(self, path): """ Sets the disk location for the image sequence to be saved :param path: str """ self._sequence_path = path self._thumbnail_btn.set_dirname(os.path.dirname(path)) def create_sequence_widget(self): """ Creates a sequence widget to replace the static thumbnail widget """ sequence_widget = widgets.LibraryImageSequenceWidget(self) sequence_widget.setObjectName('thumbnailButton') sequence_widget.setStyleSheet(self._thumbnail_btn.styleSheet()) sequence_widget.setToolTip(self._thumbnail_btn.toolTip()) camera_icon = resources.get('icons', 'camera.svg') expand_icon = resources.get('icons', 'expand.svg') folder_icon = resources.get('icons', 'folder.svg') sequence_widget.addAction(camera_icon, 'Capture new image', 'Capture new image', self._on_thumbnail_capture) sequence_widget.addAction(expand_icon, 'Show Capture window', 'Show Capture window', self._on_show_capture_window) sequence_widget.addAction(folder_icon, 'Load image from disk', 'Load image from disk', self._on_show_browse_image_dialog) sequence_widget.setIcon(resources.icon('thumbnail2')) self._thumbnail_frame.layout().insertWidget(0, sequence_widget) self._thumbnail_btn.hide() self._thumbnail_btn = sequence_widget self._thumbnail_btn.clicked.connect(self._on_thumbnail_capture) def set_sequence(self, source): """ Sets the sequenced path for the thumbnail widget :param source: str """ self.set_thumbnail(source, sequence=True) def set_thumbnail(self, source, sequence=False): """ Sets the thumbnail :param source: str :param sequence: bool """ source = os.path.normpath(source) # TODO: Find a way to remove temp folder afteer saving the file # filename, extension = os.path.splitext(source) # with path_utils.temp_dir() as dir_path: # dir_path = path_utils.temp_dir() # target = os.path.join(dir_path, 'thumbnail{}'.format(extension)) # shutil.copyfile(source, target) # tpQtLib.logger.debug('Source Thumbnail: {}'.format(source)) # tpQtLib.logger.debug('Target Thumbnail: {}'.format(target)) # self._icon_path = target # self._thumbnail_btn.set_path(target) self._icon_path = source self._thumbnail_btn.set_path(source) if sequence: self.set_sequence_path(source) def update_thumbnail_size(self): """ Updates the thumbnail button to teh size of the widget """ width = self.width() - 10 if width > 250: width = 250 size = QSize(width, width) self._thumbnail_btn.setIconSize(size) self._thumbnail_btn.setMaximumSize(size) self._thumbnail_frame.setMaximumSize(size) def show_by_frame_dialog(self): """ Show the by frame dialog """ help_text = """ To help speed up the playblast you can set the "by frame" to another greather than 1. For example if the "by frame" is set to 2 it will playblast every second frame """ options = self._options_widget.values() by_frame = options.get('byFrame', 1) start_frame, end_frame = options.get('frameRange', [None, None]) duration = 1 if start_frame is not None and end_frame is not None: duration = end_frame - start_frame if duration > 100 and by_frame == 1: buttons = QDialogButtonBox.Ok | QDialogButtonBox.Cancel result = messagebox.MessageBox.question( self.library_window(), title='Tip', text=help_text, buttons=buttons, enable_dont_show_checkbox=True) if result != QDialogButtonBox.Ok: raise Exception('Cancelled by user') def show_thumbnail_capture_dialog(self): """ Asks the user if they would like to capture a thumbnail :return: int """ buttons = QDialogButtonBox.Yes | QDialogButtonBox.Ignore | QDialogButtonBox.Cancel parent = self.item().library_window() btn = messagebox.MessageBox.question( None, 'Create a thumbnail', 'Would you like to capture a thumbnail?', buttons=buttons) if btn == QDialogButtonBox.Yes: self.thumbnail_capture() return btn def thumbnail_capture(self, show=False): """ Captures a playblast and saves it to the temporal thumbnail path :param show: bool """ options = self._options_widget.values() start_frame, end_frame = options.get('frameRange', [None, None]) step = options.get('byFrame', 1) if not qtutils.is_control_modifier(): self.show_by_frame_dialog() if not self._temp_path or not os.path.isdir(self._temp_path): self._temp_path = tempfile.mkdtemp() self._temp_path = os.path.join(self._temp_path, 'thumbnail.jpg') try: snapshot.SnapshotWindow(path=self._temp_path, on_save=self._on_thumbnail_captured) # thumbnail.ThumbnailCaptureDialog.thumbnail_capture( # path=self._temp_path, # show=show, # start_frame=start_frame, # end_frame=end_frame, # step=step, # clear_cache=False, # captured=self._on_thumbnail_captured # ) except Exception as e: messagebox.MessageBox.critical(self.library_window(), 'Error while capturing thumbnail', str(e)) LOGGER.error(traceback.format_exc()) def save(self, path, icon_path, objects=None): """ Saves the item with the given objects to the given disk location path :param path: list(str) :param icon_path: str :param objects: str """ item = self.item() options = self._options_widget.values() sequence_path = self.sequence_path() if sequence_path: sequence_path = os.path.dirname(sequence_path) item.save(path=path, objects=objects, icon_path=icon_path, sequence_path=sequence_path, **options) self.close() def _on_selection_changed(self): """ Internal callback functino that is called when DCC selection changes """ if self._options_widget: self._options_widget.validate() def _on_thumbnail_capture(self): self.thumbnail_capture(show=False) def _on_thumbnail_captured(self, captured_path): """ Internal callback function that is called when thumbnail is captured :param captured_path: str """ self.set_sequence(captured_path) def _on_show_capture_window(self): """ Internal callback function that shows the capture window for framing """ self.thumbnail_capture(show=True) def _on_show_browse_image_dialog(self): """ Internal callback function that shows a file dialog for choosing an image from disk """ file_dialog = QFileDialog(self, caption='Open Image', filter='Image Files (*.png *.jpg)') file_dialog.fileSelected.connect(self.set_thumbnail) file_dialog.exec_()