Source code for schrodinger.ui.qt.rename_favorite_dialog

from schrodinger import get_maestro
from schrodinger.Qt import QtWidgets
from schrodinger.Qt.QtCore import Qt

from . import rename_favorite_dialog_ui

maestro = get_maestro()


[docs]class RenameFavoriteDialog(QtWidgets.QDialog): """ A dialog that allows user to rename the display name of the favorite button inside favorite toolbar. """
[docs] def __init__(self, name, parent=None): """ :param parent: The Qt parent for the dialog. :type parent: `QtWidgets.QtWidget` """ super(RenameFavoriteDialog, self).__init__(parent) self.ui = rename_favorite_dialog_ui.Ui_Dialog() self.ui.setupUi(self) self.setWindowFlags(Qt.FramelessWindowHint) # Save the display name of the favorite button self.name = name # Set the current display name as default text self.ui.rename_line_edit.setText(name) self.ui.save_button.clicked.connect(self.accept) self.ui.cancel_button.clicked.connect(self.reject) self.ui.rename_line_edit.returnPressed.connect(self.accept) self.ui.rename_line_edit.textChanged.connect(self.enableSaveButton)
[docs] def enableSaveButton(self, text): """ A slot triggered when text changes in the line edit control. :param text: text string typed in the name line edit :type text: str """ enable = bool(str(text).strip()) self.ui.save_button.setEnabled(enable)
[docs] def show(self): """ Show the rename favorite dialog """ self.ui.rename_line_edit.setText(self.name) self.enableSaveButton(self.name) self.ui.rename_line_edit.selectAll() self.ui.rename_line_edit.setFocus(Qt.OtherFocusReason) super(RenameFavoriteDialog, self).exec()
[docs] def accept(self): """ When the user enters name and press enter See Qt documentation for additional method documentation. """ new_name = self.ui.rename_line_edit.text() if not new_name: return self.name = new_name super(RenameFavoriteDialog, self).accept()
[docs] def reject(self): """ Cancel the changes and close the dialog """ self.name = "" super(RenameFavoriteDialog, self).reject()
[docs]def rename_favorite(name): """ Show the rename favorite dialog and return the updated name """ if maestro: rename_dlg = RenameFavoriteDialog(name) rename_dlg.show() return rename_dlg.name