def __init__(self, parent, add_callable, allow_empty_input=False): self._add_callable = add_callable self._allow_empty_input = allow_empty_input QW.QWidget.__init__(self, parent) self._text_input = QW.QLineEdit(self) self._text_input.installEventFilter( ClientGUICommon.TextCatchEnterEventFilter(self._text_input, self.EnterText)) self._paste_button = ClientGUICommon.BetterBitmapButton( self, CC.global_pixmaps().paste, self._Paste) self._paste_button.setToolTip( 'Paste multiple inputs from the clipboard. Assumes the texts are newline-separated.' ) self.setFocusProxy(self._text_input) # hbox = QP.HBoxLayout() QP.AddToLayout(hbox, self._text_input, CC.FLAGS_EXPAND_BOTH_WAYS) QP.AddToLayout(hbox, self._paste_button, CC.FLAGS_CENTER_PERPENDICULAR) self.setLayout(hbox)
def __init__(self, parent, message, default='', placeholder=None, allow_blank=False, suggestions=None, max_chars=None, password_entry=False, min_char_width=72): if suggestions is None: suggestions = [] Dialog.__init__(self, parent, 'enter text', position='center') self._chosen_suggestion = None self._allow_blank = allow_blank self._max_chars = max_chars button_choices = [] for text in suggestions: button_choices.append( ClientGUICommon.BetterButton(self, text, self.ButtonChoice, text)) self._text = QW.QLineEdit(self) self._text.textChanged.connect(self.EventText) self._text.installEventFilter( ClientGUICommon.TextCatchEnterEventFilter(self._text, self.EnterText)) width = ClientGUIFunctions.ConvertTextToPixelWidth( self._text, min_char_width) self._text.setMinimumWidth(width) if password_entry: self._text.setEchoMode(QW.QLineEdit.Password) if self._max_chars is not None: self._text.setMaxLength(self._max_chars) self._ok = ClientGUICommon.BetterButton(self, 'ok', self.done, QW.QDialog.Accepted) self._ok.setObjectName('HydrusAccept') self._cancel = QW.QPushButton('cancel', self) self._cancel.clicked.connect(self.reject) self._cancel.setObjectName('HydrusCancel') # self._text.setText(default) if placeholder is not None: self._text.setPlaceholderText(placeholder) if len(default) > 0: self._text.setSelection(0, len(default)) self._CheckText() # hbox = QP.HBoxLayout() QP.AddToLayout(hbox, self._ok, CC.FLAGS_CENTER_PERPENDICULAR) QP.AddToLayout(hbox, self._cancel, CC.FLAGS_CENTER_PERPENDICULAR) st_message = ClientGUICommon.BetterStaticText(self, message) st_message.setWordWrap(True) vbox = QP.VBoxLayout() QP.AddToLayout(vbox, st_message, CC.FLAGS_EXPAND_PERPENDICULAR) for button in button_choices: QP.AddToLayout(vbox, button, CC.FLAGS_EXPAND_PERPENDICULAR) QP.AddToLayout(vbox, self._text, CC.FLAGS_EXPAND_BOTH_WAYS) QP.AddToLayout(vbox, hbox, CC.FLAGS_ON_RIGHT) self.setLayout(vbox) size_hint = self.sizeHint() size_hint.setWidth(max(size_hint.width(), 250)) QP.SetInitialSize(self, size_hint)