2013-02-19 00:11:43 +00:00
import os
import re
2020-04-22 21:00:35 +00:00
2019-11-14 03:56:30 +00:00
from qtpy import QtCore as QC
from qtpy import QtWidgets as QW
from qtpy import QtGui as QG
2020-04-22 21:00:35 +00:00
from hydrus . core import HydrusConstants as HC
from hydrus . core import HydrusData
from hydrus . core import HydrusGlobals as HG
2020-07-29 20:52:44 +00:00
2020-04-22 21:00:35 +00:00
from hydrus . client import ClientConstants as CC
from hydrus . client . gui import ClientGUIFrames
from hydrus . client . gui import ClientGUIFunctions
from hydrus . client . gui import ClientGUIShortcuts
from hydrus . client . gui import QtPorting as QP
2020-07-15 20:52:09 +00:00
from hydrus . client . gui . lists import ClientGUIListBoxes
2020-11-25 22:22:47 +00:00
from hydrus . client . gui . search import ClientGUIACDropdown
2021-03-17 21:59:28 +00:00
from hydrus . client . gui . widgets import ClientGUICommon
2013-02-19 00:11:43 +00:00
2019-11-14 03:56:30 +00:00
class Dialog ( QP . Dialog ) :
2013-02-19 00:11:43 +00:00
2019-11-14 03:56:30 +00:00
def __init__ ( self , parent , title , style = QC . Qt . Dialog , position = ' topleft ' ) :
QP . Dialog . __init__ ( self , parent )
2013-02-19 00:11:43 +00:00
2019-12-05 05:29:32 +00:00
self . setWindowFlags ( style )
self . setWindowTitle ( title )
2013-07-31 21:26:38 +00:00
if parent is not None and position == ' topleft ' :
2013-02-19 00:11:43 +00:00
2019-12-11 23:18:37 +00:00
parent_tlw = self . parentWidget ( ) . window ( )
2015-02-25 19:34:30 +00:00
2020-02-26 22:28:52 +00:00
pos = parent_tlw . pos ( ) + QC . QPoint ( 50 , 50 )
2013-02-19 00:11:43 +00:00
2020-02-26 22:28:52 +00:00
self . move ( pos )
2016-01-13 22:08:19 +00:00
2015-08-26 21:18:39 +00:00
2019-11-14 03:56:30 +00:00
self . setWindowFlag ( QC . Qt . WindowContextHelpButtonHint , on = False )
2013-02-19 00:11:43 +00:00
2017-12-06 22:06:56 +00:00
self . _new_options = HG . client_controller . new_options
2016-06-29 19:55:46 +00:00
2019-11-14 03:56:30 +00:00
self . setWindowIcon ( QG . QIcon ( HG . client_controller . frame_icon_pixmap ) )
2013-02-19 00:11:43 +00:00
2019-11-14 03:56:30 +00:00
self . _widget_event_filter = QP . WidgetEventFilter ( self )
2013-07-24 20:26:00 +00:00
2015-08-26 21:18:39 +00:00
if parent is not None and position == ' center ' :
2019-11-20 23:10:46 +00:00
QP . CallAfter ( QP . CenterOnWindow , parent , self )
2015-08-26 21:18:39 +00:00
2014-02-05 20:54:28 +00:00
2017-05-10 21:33:58 +00:00
HG . client_controller . ResetIdleTimer ( )
2014-12-03 22:56:40 +00:00
2013-07-24 20:26:00 +00:00
2019-11-14 03:56:30 +00:00
def keyPressEvent ( self , event ) :
2019-02-27 23:03:30 +00:00
( modifier , key ) = ClientGUIShortcuts . ConvertKeyEventToSimpleTuple ( event )
2019-11-14 03:56:30 +00:00
if key == QC . Qt . Key_Escape :
2019-02-27 23:03:30 +00:00
2019-11-14 03:56:30 +00:00
self . done ( QW . QDialog . Rejected )
2019-02-27 23:03:30 +00:00
else :
2019-11-14 03:56:30 +00:00
QP . Dialog . keyPressEvent ( self , event )
2019-02-27 23:03:30 +00:00
2020-02-26 22:28:52 +00:00
def SetInitialSize ( self , size : QC . QSize ) :
2015-01-07 23:09:00 +00:00
2020-04-29 21:44:12 +00:00
display_size = ClientGUIFunctions . GetDisplaySize ( self )
2015-11-11 21:20:41 +00:00
2020-02-26 22:28:52 +00:00
width = min ( display_size . width ( ) , size . width ( ) )
height = min ( display_size . height ( ) , size . height ( ) )
2015-11-11 21:20:41 +00:00
2019-11-14 03:56:30 +00:00
self . resize ( QC . QSize ( width , height ) )
2015-01-07 23:09:00 +00:00
min_width = min ( 240 , width )
2015-11-18 22:44:07 +00:00
min_height = min ( 240 , height )
2015-01-07 23:09:00 +00:00
2019-11-14 03:56:30 +00:00
self . setMinimumSize ( QC . QSize ( min_width , min_height ) )
2015-01-07 23:09:00 +00:00
2013-03-15 02:38:12 +00:00
class DialogChooseNewServiceMethod ( Dialog ) :
def __init__ ( self , parent ) :
2015-05-20 21:31:40 +00:00
Dialog . __init__ ( self , parent , ' how to set up the account? ' , position = ' center ' )
2013-07-31 21:26:38 +00:00
2021-04-28 21:43:16 +00:00
register_message = ' I want to initialise a new account with the server. I have a registration token (a hexadecimal key starting with \' r \' ). '
2013-03-15 02:38:12 +00:00
2019-11-14 03:56:30 +00:00
self . _register = QW . QPushButton ( register_message , self )
self . _register . clicked . connect ( self . EventRegister )
2013-03-15 02:38:12 +00:00
2015-05-20 21:31:40 +00:00
setup_message = ' The account is already initialised; I just want to add it to this client. I have a normal access key. '
2013-03-15 02:38:12 +00:00
2019-11-14 03:56:30 +00:00
self . _setup = QW . QPushButton ( setup_message , self )
self . _setup . clicked . connect ( self . accept )
2013-07-31 21:26:38 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2015-05-20 21:31:40 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , self . _register , CC . FLAGS_EXPAND_PERPENDICULAR )
2022-03-30 20:28:13 +00:00
st = ClientGUICommon . BetterStaticText ( self , ' -or- ' )
st . setAlignment ( QC . Qt . AlignCenter )
QP . AddToLayout ( vbox , st , CC . FLAGS_EXPAND_PERPENDICULAR )
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , self . _setup , CC . FLAGS_EXPAND_PERPENDICULAR )
2015-05-20 21:31:40 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2015-05-20 21:31:40 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2015-05-20 21:31:40 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2013-03-15 02:38:12 +00:00
2013-07-24 20:26:00 +00:00
self . _should_register = False
2013-03-15 02:38:12 +00:00
2021-06-23 21:11:38 +00:00
ClientGUIFunctions . SetFocusLater ( self . _register )
2013-07-31 21:26:38 +00:00
2013-03-15 02:38:12 +00:00
2019-11-14 03:56:30 +00:00
def EventRegister ( self ) :
2013-03-15 02:38:12 +00:00
2013-07-24 20:26:00 +00:00
self . _should_register = True
2013-03-15 02:38:12 +00:00
2019-11-14 03:56:30 +00:00
self . done ( QW . QDialog . Accepted )
2013-03-15 02:38:12 +00:00
2019-05-22 22:35:06 +00:00
def GetRegister ( self ) :
return self . _should_register
2013-03-15 02:38:12 +00:00
2013-11-27 18:27:11 +00:00
class DialogGenerateNewAccounts ( Dialog ) :
2014-08-27 22:15:22 +00:00
def __init__ ( self , parent , service_key ) :
2013-11-27 18:27:11 +00:00
2015-12-09 23:16:41 +00:00
Dialog . __init__ ( self , parent , ' configure new accounts ' )
2013-11-27 18:27:11 +00:00
2015-12-09 23:16:41 +00:00
self . _service_key = service_key
2013-11-27 18:27:11 +00:00
2022-03-30 20:28:13 +00:00
self . _num = ClientGUICommon . BetterSpinBox ( self , min = 1 , max = 10000 , width = 80 )
2013-11-27 18:27:11 +00:00
2017-03-02 02:14:56 +00:00
self . _account_types = ClientGUICommon . BetterChoice ( self )
2013-11-27 18:27:11 +00:00
2017-03-02 02:14:56 +00:00
self . _lifetime = ClientGUICommon . BetterChoice ( self )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . _ok = QW . QPushButton ( ' OK ' , self )
self . _ok . clicked . connect ( self . EventOK )
2020-02-26 22:28:52 +00:00
self . _ok . setObjectName ( ' HydrusAccept ' )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . _cancel = QW . QPushButton ( ' Cancel ' , self )
self . _cancel . clicked . connect ( self . reject )
2020-02-26 22:28:52 +00:00
self . _cancel . setObjectName ( ' HydrusCancel ' )
2015-12-09 23:16:41 +00:00
#
2019-11-14 03:56:30 +00:00
self . _num . setValue ( 1 )
2015-12-09 23:16:41 +00:00
2017-06-28 20:23:21 +00:00
service = HG . client_controller . services_manager . GetService ( service_key )
2015-12-09 23:16:41 +00:00
response = service . Request ( HC . GET , ' account_types ' )
account_types = response [ ' account_types ' ]
2017-03-02 02:14:56 +00:00
for account_type in account_types :
2019-11-14 03:56:30 +00:00
self . _account_types . addItem ( account_type . GetTitle ( ) , account_type )
2017-03-02 02:14:56 +00:00
2019-11-14 03:56:30 +00:00
self . _account_types . setCurrentIndex ( 0 )
2017-03-02 02:14:56 +00:00
2017-03-15 20:13:04 +00:00
for ( s , value ) in HC . lifetimes :
2017-03-02 02:14:56 +00:00
2019-11-14 03:56:30 +00:00
self . _lifetime . addItem ( s , value )
2017-03-02 02:14:56 +00:00
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . _lifetime . setCurrentIndex ( 3 ) # one year
2013-11-27 18:27:11 +00:00
2015-12-09 23:16:41 +00:00
#
2019-11-14 03:56:30 +00:00
ctrl_box = QP . HBoxLayout ( )
2015-12-09 23:16:41 +00:00
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( ctrl_box , ClientGUICommon . BetterStaticText ( self , ' generate ' ) , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( ctrl_box , self . _num , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( ctrl_box , self . _account_types , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( ctrl_box , ClientGUICommon . BetterStaticText ( self , ' accounts, to expire in ' ) , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( ctrl_box , self . _lifetime , CC . FLAGS_CENTER_PERPENDICULAR )
2013-11-27 18:27:11 +00:00
2019-11-14 03:56:30 +00:00
b_box = QP . HBoxLayout ( )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( b_box , self . _ok , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( b_box , self . _cancel , CC . FLAGS_CENTER_PERPENDICULAR )
2013-11-27 18:27:11 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , ctrl_box , CC . FLAGS_EXPAND_SIZER_PERPENDICULAR )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( vbox , b_box , CC . FLAGS_ON_RIGHT )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2015-12-09 23:16:41 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2015-12-09 23:16:41 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2013-11-27 18:27:11 +00:00
2021-06-23 21:11:38 +00:00
ClientGUIFunctions . SetFocusLater ( self . _ok )
2013-11-27 18:27:11 +00:00
2019-11-14 03:56:30 +00:00
def EventOK ( self ) :
2013-11-27 18:27:11 +00:00
2019-11-14 03:56:30 +00:00
num = self . _num . value ( )
2013-11-27 18:27:11 +00:00
2019-07-24 21:39:02 +00:00
account_type = self . _account_types . GetValue ( )
2017-03-02 02:14:56 +00:00
account_type_key = account_type . GetAccountTypeKey ( )
2013-11-27 18:27:11 +00:00
2019-07-24 21:39:02 +00:00
lifetime = self . _lifetime . GetValue ( )
2013-11-27 18:27:11 +00:00
2017-03-02 02:14:56 +00:00
if lifetime is None :
expires = None
else :
expires = HydrusData . GetNow ( ) + lifetime
2013-11-27 18:27:11 +00:00
2017-06-28 20:23:21 +00:00
service = HG . client_controller . services_manager . GetService ( self . _service_key )
2013-11-27 18:27:11 +00:00
try :
2017-03-15 20:13:04 +00:00
request_args = { ' num ' : num , ' account_type_key ' : account_type_key }
if expires is not None :
request_args [ ' expires ' ] = expires
2013-11-27 18:27:11 +00:00
2014-01-29 21:59:42 +00:00
response = service . Request ( HC . GET , ' registration_keys ' , request_args )
2013-11-27 18:27:11 +00:00
registration_keys = response [ ' registration_keys ' ]
2016-11-02 21:09:14 +00:00
ClientGUIFrames . ShowKeys ( ' registration ' , registration_keys )
2013-11-27 18:27:11 +00:00
2017-03-02 02:14:56 +00:00
finally :
2019-11-14 03:56:30 +00:00
self . done ( QW . QDialog . Accepted )
2017-03-02 02:14:56 +00:00
2013-11-27 18:27:11 +00:00
2014-07-09 22:15:14 +00:00
class DialogInputLocalBooruShare ( Dialog ) :
def __init__ ( self , parent , share_key , name , text , timeout , hashes , new_share = False ) :
2015-12-09 23:16:41 +00:00
Dialog . __init__ ( self , parent , ' configure local booru share ' )
2014-07-09 22:15:14 +00:00
2019-11-14 03:56:30 +00:00
self . _name = QW . QLineEdit ( self )
2014-07-09 22:15:14 +00:00
2019-11-14 03:56:30 +00:00
self . _text = QW . QPlainTextEdit ( self )
self . _text . setMinimumHeight ( 100 )
2015-12-09 23:16:41 +00:00
message = ' expires in '
self . _timeout_number = ClientGUICommon . NoneableSpinCtrl ( self , message , none_phrase = ' no expiration ' , max = 1000000 , multiplier = 1 )
self . _timeout_multiplier = ClientGUICommon . BetterChoice ( self )
2019-11-14 03:56:30 +00:00
self . _timeout_multiplier . addItem ( ' minutes ' , 60 )
self . _timeout_multiplier . addItem ( ' hours ' , 60 * 60 )
self . _timeout_multiplier . addItem ( ' days ' , 60 * 60 * 24 )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . _copy_internal_share_link = QW . QPushButton ( ' copy internal share link ' , self )
self . _copy_internal_share_link . clicked . connect ( self . EventCopyInternalShareURL )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . _copy_external_share_link = QW . QPushButton ( ' copy external share link ' , self )
self . _copy_external_share_link . clicked . connect ( self . EventCopyExternalShareURL )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . _ok = QW . QPushButton ( ' ok ' , self )
self . _ok . clicked . connect ( self . accept )
2020-02-26 22:28:52 +00:00
self . _ok . setObjectName ( ' HydrusAccept ' )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . _cancel = QW . QPushButton ( ' cancel ' , self )
self . _cancel . clicked . connect ( self . reject )
2020-02-26 22:28:52 +00:00
self . _cancel . setObjectName ( ' HydrusCancel ' )
2015-12-09 23:16:41 +00:00
#
self . _share_key = share_key
2019-11-14 03:56:30 +00:00
self . _name . setText ( name )
self . _text . setPlainText ( text )
2015-12-09 23:16:41 +00:00
if timeout is None :
2014-07-09 22:15:14 +00:00
2015-12-09 23:16:41 +00:00
self . _timeout_number . SetValue ( None )
2014-07-09 22:15:14 +00:00
2019-07-24 21:39:02 +00:00
self . _timeout_multiplier . SetValue ( 60 )
2014-07-09 22:15:14 +00:00
2015-12-09 23:16:41 +00:00
else :
2014-07-09 22:15:14 +00:00
2018-02-14 21:47:18 +00:00
time_left = HydrusData . GetTimeDeltaUntilTime ( timeout )
2014-07-09 22:15:14 +00:00
2015-12-09 23:16:41 +00:00
if time_left < 60 * 60 * 12 : time_value = 60
elif time_left < 60 * 60 * 24 * 7 : time_value = 60 * 60
else : time_value = 60 * 60 * 24
2014-07-09 22:15:14 +00:00
2019-01-09 22:59:03 +00:00
self . _timeout_number . SetValue ( time_left / / time_value )
2014-07-09 22:15:14 +00:00
2019-07-24 21:39:02 +00:00
self . _timeout_multiplier . SetValue ( time_value )
2014-07-09 22:15:14 +00:00
2015-12-09 23:16:41 +00:00
self . _hashes = hashes
2017-12-06 22:06:56 +00:00
self . _service = HG . client_controller . services_manager . GetService ( CC . LOCAL_BOORU_SERVICE_KEY )
internal_port = self . _service . GetPort ( )
if internal_port is None :
2019-11-14 03:56:30 +00:00
self . _copy_internal_share_link . setEnabled ( False )
self . _copy_external_share_link . setEnabled ( False )
2017-12-06 22:06:56 +00:00
2015-12-09 23:16:41 +00:00
#
2016-08-31 19:55:14 +00:00
rows = [ ]
2015-12-09 23:16:41 +00:00
2016-08-31 19:55:14 +00:00
rows . append ( ( ' share name: ' , self . _name ) )
rows . append ( ( ' share text: ' , self . _text ) )
2015-12-09 23:16:41 +00:00
2016-08-31 19:55:14 +00:00
gridbox = ClientGUICommon . WrapInGrid ( self , rows )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
timeout_box = QP . HBoxLayout ( )
QP . AddToLayout ( timeout_box , self . _timeout_number , CC . FLAGS_EXPAND_BOTH_WAYS )
QP . AddToLayout ( timeout_box , self . _timeout_multiplier , CC . FLAGS_EXPAND_BOTH_WAYS )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
link_box = QP . HBoxLayout ( )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( link_box , self . _copy_internal_share_link , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( link_box , self . _copy_external_share_link , CC . FLAGS_CENTER_PERPENDICULAR )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
b_box = QP . HBoxLayout ( )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( b_box , self . _ok , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( b_box , self . _cancel , CC . FLAGS_CENTER_PERPENDICULAR )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2015-12-09 23:16:41 +00:00
2018-07-04 20:48:28 +00:00
intro = ' Sharing ' + HydrusData . ToHumanInt ( len ( self . _hashes ) ) + ' files. '
2015-12-09 23:16:41 +00:00
intro + = os . linesep + ' Title and text are optional. '
if new_share : intro + = os . linesep + ' The link will not work until you ok this dialog. '
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , ClientGUICommon . BetterStaticText ( self , intro ) , CC . FLAGS_EXPAND_PERPENDICULAR )
QP . AddToLayout ( vbox , gridbox , CC . FLAGS_EXPAND_SIZER_PERPENDICULAR )
QP . AddToLayout ( vbox , timeout_box , CC . FLAGS_EXPAND_SIZER_PERPENDICULAR )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( vbox , link_box , CC . FLAGS_ON_RIGHT )
QP . AddToLayout ( vbox , b_box , CC . FLAGS_ON_RIGHT )
2015-12-09 23:16:41 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2014-07-09 22:15:14 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2014-07-09 22:15:14 +00:00
2019-12-05 05:29:32 +00:00
size_hint . setWidth ( max ( size_hint . width ( ) , 350 ) )
2014-07-09 22:15:14 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2014-07-09 22:15:14 +00:00
2021-06-23 21:11:38 +00:00
ClientGUIFunctions . SetFocusLater ( self . _ok )
2014-07-09 22:15:14 +00:00
2019-11-14 03:56:30 +00:00
def EventCopyExternalShareURL ( self ) :
2014-07-09 22:15:14 +00:00
2019-05-22 22:35:06 +00:00
internal_port = self . _service . GetPort ( )
2014-07-09 22:15:14 +00:00
2019-05-22 22:35:06 +00:00
if internal_port is None :
2017-03-02 02:14:56 +00:00
2019-11-14 03:56:30 +00:00
QW . QMessageBox . warning ( self , ' Warning ' , ' The local booru is not currently running! ' )
2017-03-02 02:14:56 +00:00
2014-07-09 22:15:14 +00:00
2019-05-22 22:35:06 +00:00
try :
url = self . _service . GetExternalShareURL ( self . _share_key )
except Exception as e :
HydrusData . ShowException ( e )
2019-11-14 03:56:30 +00:00
QW . QMessageBox . critical ( self , ' Error ' , ' Unfortunately, could not generate an external URL: {} ' . format ( e ) )
2019-05-22 22:35:06 +00:00
return
2014-07-09 22:15:14 +00:00
2017-05-10 21:33:58 +00:00
HG . client_controller . pub ( ' clipboard ' , ' text ' , url )
2014-07-09 22:15:14 +00:00
2019-11-14 03:56:30 +00:00
def EventCopyInternalShareURL ( self ) :
2014-07-09 22:15:14 +00:00
2017-06-28 20:23:21 +00:00
self . _service = HG . client_controller . services_manager . GetService ( CC . LOCAL_BOORU_SERVICE_KEY )
2014-07-09 22:15:14 +00:00
2020-07-08 22:00:33 +00:00
url = self . _service . GetInternalShareURL ( self . _share_key )
2014-07-09 22:15:14 +00:00
2017-05-10 21:33:58 +00:00
HG . client_controller . pub ( ' clipboard ' , ' text ' , url )
2014-07-09 22:15:14 +00:00
def GetInfo ( self ) :
2019-11-14 03:56:30 +00:00
name = self . _name . text ( )
2014-07-09 22:15:14 +00:00
2019-11-14 03:56:30 +00:00
text = self . _text . toPlainText ( )
2014-07-09 22:15:14 +00:00
timeout = self . _timeout_number . GetValue ( )
2019-07-24 21:39:02 +00:00
if timeout is not None : timeout = timeout * self . _timeout_multiplier . GetValue ( ) + HydrusData . GetNow ( )
2014-07-09 22:15:14 +00:00
return ( self . _share_key , name , text , timeout , self . _hashes )
2013-07-31 21:26:38 +00:00
class DialogInputNamespaceRegex ( Dialog ) :
def __init__ ( self , parent , namespace = ' ' , regex = ' ' ) :
2015-10-14 21:02:25 +00:00
Dialog . __init__ ( self , parent , ' configure quick namespace ' )
2013-07-31 21:26:38 +00:00
2019-11-14 03:56:30 +00:00
self . _namespace = QW . QLineEdit ( self )
2013-07-31 21:26:38 +00:00
2019-11-14 03:56:30 +00:00
self . _regex = QW . QLineEdit ( self )
2015-10-14 21:02:25 +00:00
self . _shortcuts = ClientGUICommon . RegexButton ( self )
2020-07-08 22:00:33 +00:00
self . _regex_intro_link = ClientGUICommon . BetterHyperLink ( self , ' a good regex introduction ' , ' https://www.aivosto.com/vbtips/regex.html ' )
self . _regex_practise_link = ClientGUICommon . BetterHyperLink ( self , ' regex practice ' , ' https://regexr.com/3cvmf ' )
2015-10-14 21:02:25 +00:00
2019-11-14 03:56:30 +00:00
self . _ok = QW . QPushButton ( ' OK ' , self )
self . _ok . clicked . connect ( self . EventOK )
2020-02-26 22:28:52 +00:00
self . _ok . setObjectName ( ' HydrusAccept ' )
2015-10-14 21:02:25 +00:00
2019-11-14 03:56:30 +00:00
self . _cancel = QW . QPushButton ( ' Cancel ' , self )
self . _cancel . clicked . connect ( self . reject )
2020-02-26 22:28:52 +00:00
self . _cancel . setObjectName ( ' HydrusCancel ' )
2015-10-14 21:02:25 +00:00
#
2019-11-14 03:56:30 +00:00
self . _namespace . setText ( namespace )
self . _regex . setText ( regex )
2015-10-14 21:02:25 +00:00
#
2019-11-14 03:56:30 +00:00
control_box = QP . HBoxLayout ( )
2015-10-14 21:02:25 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( control_box , self . _namespace , CC . FLAGS_EXPAND_BOTH_WAYS )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( control_box , ClientGUICommon . BetterStaticText ( self , ' : ' ) , CC . FLAGS_CENTER_PERPENDICULAR )
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( control_box , self . _regex , CC . FLAGS_EXPAND_BOTH_WAYS )
2015-10-14 21:02:25 +00:00
2019-11-14 03:56:30 +00:00
b_box = QP . HBoxLayout ( )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( b_box , self . _ok , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( b_box , self . _cancel , CC . FLAGS_CENTER_PERPENDICULAR )
2015-10-14 21:02:25 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2015-10-14 21:02:25 +00:00
2017-03-15 20:13:04 +00:00
intro = r ' Put the namespace (e.g. page) on the left. ' + os . linesep + r ' Put the regex (e.g. [1-9]+ \ d*(?=. {4} $)) on the right. ' + os . linesep + r ' All files will be tagged with " namespace:regex " . '
2015-10-14 21:02:25 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , ClientGUICommon . BetterStaticText ( self , intro ) , CC . FLAGS_EXPAND_PERPENDICULAR )
QP . AddToLayout ( vbox , control_box , CC . FLAGS_EXPAND_SIZER_PERPENDICULAR )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( vbox , self . _shortcuts , CC . FLAGS_ON_RIGHT )
QP . AddToLayout ( vbox , self . _regex_intro_link , CC . FLAGS_ON_RIGHT )
QP . AddToLayout ( vbox , self . _regex_practise_link , CC . FLAGS_ON_RIGHT )
QP . AddToLayout ( vbox , b_box , CC . FLAGS_ON_RIGHT )
2015-10-14 21:02:25 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2015-10-14 21:02:25 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2015-10-14 21:02:25 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2015-10-14 21:02:25 +00:00
2021-06-23 21:11:38 +00:00
ClientGUIFunctions . SetFocusLater ( self . _ok )
2015-10-14 21:02:25 +00:00
2019-11-14 03:56:30 +00:00
def EventOK ( self ) :
2015-10-14 21:02:25 +00:00
( namespace , regex ) = self . GetInfo ( )
if namespace == ' ' :
2013-07-31 21:26:38 +00:00
2019-11-14 03:56:30 +00:00
QW . QMessageBox . warning ( self , ' Warning ' , ' Please enter something for the namespace. ' )
2013-07-31 21:26:38 +00:00
2015-10-14 21:02:25 +00:00
return
2013-07-31 21:26:38 +00:00
2015-10-14 21:02:25 +00:00
try :
2013-07-31 21:26:38 +00:00
2019-01-09 22:59:03 +00:00
re . compile ( regex )
2014-03-12 22:08:23 +00:00
2015-10-14 21:02:25 +00:00
except Exception as e :
2013-07-31 21:26:38 +00:00
2015-10-14 21:02:25 +00:00
text = ' That regex would not compile! '
text + = os . linesep * 2
2019-01-09 22:59:03 +00:00
text + = str ( e )
2013-07-31 21:26:38 +00:00
2019-11-14 03:56:30 +00:00
QW . QMessageBox . critical ( self , ' Error ' , text )
2013-07-31 21:26:38 +00:00
2015-10-14 21:02:25 +00:00
return
2013-07-31 21:26:38 +00:00
2019-11-14 03:56:30 +00:00
self . done ( QW . QDialog . Accepted )
2013-07-31 21:26:38 +00:00
def GetInfo ( self ) :
2019-11-14 03:56:30 +00:00
namespace = self . _namespace . text ( )
2013-07-31 21:26:38 +00:00
2019-11-14 03:56:30 +00:00
regex = self . _regex . text ( )
2013-07-31 21:26:38 +00:00
return ( namespace , regex )
2015-10-21 21:53:10 +00:00
class DialogInputTags ( Dialog ) :
2021-02-24 22:35:18 +00:00
def __init__ ( self , parent , service_key , tag_display_type , tags , message = ' ' ) :
2015-10-21 21:53:10 +00:00
Dialog . __init__ ( self , parent , ' input tags ' )
2016-05-25 21:54:03 +00:00
self . _service_key = service_key
2021-02-24 22:35:18 +00:00
self . _tags = ClientGUIListBoxes . ListBoxTagsStringsAddRemove ( self , service_key , tag_display_type )
2015-10-21 21:53:10 +00:00
2022-03-23 20:57:10 +00:00
default_location_context = HG . client_controller . new_options . GetDefaultLocalLocationContext ( )
2022-01-19 21:28:59 +00:00
self . _tag_autocomplete = ClientGUIACDropdown . AutoCompleteDropdownTagsWrite ( self , self . EnterTags , default_location_context , service_key , null_entry_callable = self . OK , show_paste_button = True )
2015-10-21 21:53:10 +00:00
2019-11-14 03:56:30 +00:00
self . _ok = ClientGUICommon . BetterButton ( self , ' OK ' , self . done , QW . QDialog . Accepted )
2020-02-26 22:28:52 +00:00
self . _ok . setObjectName ( ' HydrusAccept ' )
2015-10-21 21:53:10 +00:00
2019-11-14 03:56:30 +00:00
self . _cancel = QW . QPushButton ( ' Cancel ' , self )
self . _cancel . clicked . connect ( self . reject )
2020-02-26 22:28:52 +00:00
self . _cancel . setObjectName ( ' HydrusCancel ' )
2015-10-21 21:53:10 +00:00
#
self . _tags . SetTags ( tags )
#
2019-11-14 03:56:30 +00:00
b_box = QP . HBoxLayout ( )
2015-10-21 21:53:10 +00:00
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( b_box , self . _ok , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( b_box , self . _cancel , CC . FLAGS_CENTER_PERPENDICULAR )
2015-10-21 21:53:10 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2015-10-21 21:53:10 +00:00
2018-04-11 22:30:40 +00:00
if message != ' ' :
2020-07-08 22:00:33 +00:00
st = ClientGUICommon . BetterStaticText ( self , message )
st . setWordWrap ( True )
QP . AddToLayout ( vbox , st , CC . FLAGS_EXPAND_PERPENDICULAR )
2018-04-11 22:30:40 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , self . _tags , CC . FLAGS_EXPAND_BOTH_WAYS )
2020-03-11 21:52:11 +00:00
QP . AddToLayout ( vbox , self . _tag_autocomplete )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( vbox , b_box , CC . FLAGS_ON_RIGHT )
2015-10-21 21:53:10 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2015-10-21 21:53:10 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2015-10-21 21:53:10 +00:00
2019-12-05 05:29:32 +00:00
size_hint . setWidth ( max ( size_hint . width ( ) , 300 ) )
2015-10-21 21:53:10 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2015-10-21 21:53:10 +00:00
2021-06-23 21:11:38 +00:00
ClientGUIFunctions . SetFocusLater ( self . _tag_autocomplete )
2015-10-21 21:53:10 +00:00
2016-05-25 21:54:03 +00:00
def EnterTags ( self , tags ) :
2015-10-28 21:29:05 +00:00
if len ( tags ) > 0 :
2015-10-21 21:53:10 +00:00
2015-10-28 21:29:05 +00:00
self . _tags . EnterTags ( tags )
2020-07-08 22:00:33 +00:00
2015-10-21 21:53:10 +00:00
def GetTags ( self ) :
return self . _tags . GetTags ( )
2017-06-07 22:05:15 +00:00
def OK ( self ) :
2015-10-28 21:29:05 +00:00
2019-11-14 03:56:30 +00:00
self . done ( QW . QDialog . Accepted )
2015-10-28 21:29:05 +00:00
2013-09-25 20:20:10 +00:00
class DialogInputUPnPMapping ( Dialog ) :
2014-04-23 20:56:12 +00:00
def __init__ ( self , parent , external_port , protocol_type , internal_port , description , duration ) :
2013-09-25 20:20:10 +00:00
2016-06-01 20:04:15 +00:00
Dialog . __init__ ( self , parent , ' configure upnp mapping ' )
2013-09-25 20:20:10 +00:00
2022-03-30 20:28:13 +00:00
self . _external_port = ClientGUICommon . BetterSpinBox ( self , min = 0 , max = 65535 )
2013-09-25 20:20:10 +00:00
2016-06-01 20:04:15 +00:00
self . _protocol_type = ClientGUICommon . BetterChoice ( self )
2019-11-14 03:56:30 +00:00
self . _protocol_type . addItem ( ' TCP ' , ' TCP ' )
self . _protocol_type . addItem ( ' UDP ' , ' UDP ' )
2013-09-25 20:20:10 +00:00
2022-03-30 20:28:13 +00:00
self . _internal_port = ClientGUICommon . BetterSpinBox ( self , min = 0 , max = 65535 )
2019-11-14 03:56:30 +00:00
self . _description = QW . QLineEdit ( self )
2022-03-30 20:28:13 +00:00
self . _duration = ClientGUICommon . BetterSpinBox ( self , min = 0 , max = 86400 )
2013-09-25 20:20:10 +00:00
2019-11-14 03:56:30 +00:00
self . _ok = ClientGUICommon . BetterButton ( self , ' OK ' , self . done , QW . QDialog . Accepted )
2020-02-26 22:28:52 +00:00
self . _ok . setObjectName ( ' HydrusAccept ' )
2013-09-25 20:20:10 +00:00
2019-11-14 03:56:30 +00:00
self . _cancel = QW . QPushButton ( ' Cancel ' , self )
self . _cancel . clicked . connect ( self . reject )
2020-02-26 22:28:52 +00:00
self . _cancel . setObjectName ( ' HydrusCancel ' )
2016-06-01 20:04:15 +00:00
#
2019-11-14 03:56:30 +00:00
self . _external_port . setValue ( external_port )
2016-06-01 20:04:15 +00:00
2019-11-14 03:56:30 +00:00
if protocol_type == ' TCP ' : self . _protocol_type . setCurrentIndex ( 0 )
elif protocol_type == ' UDP ' : self . _protocol_type . setCurrentIndex ( 1 )
2016-06-01 20:04:15 +00:00
2019-11-14 03:56:30 +00:00
self . _internal_port . setValue ( internal_port )
self . _description . setText ( description )
self . _duration . setValue ( duration )
2016-06-01 20:04:15 +00:00
#
2016-08-31 19:55:14 +00:00
rows = [ ]
2016-06-01 20:04:15 +00:00
2016-08-31 19:55:14 +00:00
rows . append ( ( ' external port: ' , self . _external_port ) )
rows . append ( ( ' protocol type: ' , self . _protocol_type ) )
rows . append ( ( ' internal port: ' , self . _internal_port ) )
rows . append ( ( ' description: ' , self . _description ) )
rows . append ( ( ' duration (0 = indefinite): ' , self . _duration ) )
2016-06-01 20:04:15 +00:00
2016-08-31 19:55:14 +00:00
gridbox = ClientGUICommon . WrapInGrid ( self , rows )
2016-06-01 20:04:15 +00:00
2019-11-14 03:56:30 +00:00
b_box = QP . HBoxLayout ( )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( b_box , self . _ok , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( b_box , self . _cancel , CC . FLAGS_CENTER_PERPENDICULAR )
2016-06-01 20:04:15 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2016-06-01 20:04:15 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , gridbox , CC . FLAGS_EXPAND_SIZER_BOTH_WAYS )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( vbox , b_box , CC . FLAGS_ON_RIGHT )
2016-06-01 20:04:15 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2016-06-01 20:04:15 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2016-06-01 20:04:15 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2013-09-25 20:20:10 +00:00
2021-06-23 21:11:38 +00:00
ClientGUIFunctions . SetFocusLater ( self . _ok )
2013-09-25 20:20:10 +00:00
def GetInfo ( self ) :
2019-11-14 03:56:30 +00:00
external_port = self . _external_port . value ( )
2019-07-24 21:39:02 +00:00
protocol_type = self . _protocol_type . GetValue ( )
2019-11-14 03:56:30 +00:00
internal_port = self . _internal_port . value ( )
description = self . _description . text ( )
duration = self . _duration . value ( )
2013-09-25 20:20:10 +00:00
2014-04-23 20:56:12 +00:00
return ( external_port , protocol_type , internal_port , description , duration )
2013-09-25 20:20:10 +00:00
2016-03-23 19:42:56 +00:00
class DialogSelectFromURLTree ( Dialog ) :
2013-02-19 00:11:43 +00:00
2016-03-23 19:42:56 +00:00
def __init__ ( self , parent , url_tree ) :
2013-02-19 00:11:43 +00:00
2016-03-23 19:42:56 +00:00
Dialog . __init__ ( self , parent , ' select items ' )
2019-12-11 23:18:37 +00:00
2019-11-14 03:56:30 +00:00
self . _tree = QP . TreeWidgetWithInheritedCheckState ( self )
2016-03-23 19:42:56 +00:00
2019-11-14 03:56:30 +00:00
self . _ok = ClientGUICommon . BetterButton ( self , ' OK ' , self . done , QW . QDialog . Accepted )
2020-02-26 22:28:52 +00:00
self . _ok . setObjectName ( ' HydrusAccept ' )
2016-03-23 19:42:56 +00:00
2019-11-14 03:56:30 +00:00
self . _cancel = QW . QPushButton ( ' Cancel ' , self )
self . _cancel . clicked . connect ( self . reject )
2020-02-26 22:28:52 +00:00
self . _cancel . setObjectName ( ' HydrusCancel ' )
2016-03-23 19:42:56 +00:00
#
( text_gumpf , name , size , children ) = url_tree
root_name = self . _RenderItemName ( name , size )
2019-11-14 03:56:30 +00:00
root_item = QW . QTreeWidgetItem ( )
root_item . setText ( 0 , root_name )
root_item . setCheckState ( 0 , QC . Qt . Checked )
self . _tree . addTopLevelItem ( root_item )
2016-03-23 19:42:56 +00:00
self . _AddDirectory ( root_item , children )
2019-12-11 23:18:37 +00:00
2019-11-14 03:56:30 +00:00
root_item . setExpanded ( True )
2016-03-23 19:42:56 +00:00
#
2019-11-14 03:56:30 +00:00
button_hbox = QP . HBoxLayout ( )
2016-03-23 19:42:56 +00:00
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( button_hbox , self . _ok , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( button_hbox , self . _cancel , CC . FLAGS_CENTER_PERPENDICULAR )
2016-03-23 19:42:56 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2016-03-23 19:42:56 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , self . _tree , CC . FLAGS_EXPAND_BOTH_WAYS )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( vbox , button_hbox , CC . FLAGS_ON_RIGHT )
2016-03-23 19:42:56 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2016-03-23 19:42:56 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2016-03-23 19:42:56 +00:00
2019-12-05 05:29:32 +00:00
size_hint . setWidth ( max ( size_hint . width ( ) , 640 ) )
size_hint . setHeight ( max ( size_hint . height ( ) , 640 ) )
2016-03-23 19:42:56 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2016-03-23 19:42:56 +00:00
def _AddDirectory ( self , root , children ) :
for ( child_type , name , size , data ) in children :
2013-02-19 00:11:43 +00:00
2016-03-23 19:42:56 +00:00
item_name = self . _RenderItemName ( name , size )
2014-02-19 22:37:23 +00:00
2016-03-23 19:42:56 +00:00
if child_type == ' file ' :
2019-11-14 03:56:30 +00:00
item = QW . QTreeWidgetItem ( )
item . setText ( 0 , item_name )
2019-12-18 22:06:34 +00:00
item . setCheckState ( 0 , root . checkState ( 0 ) )
2019-11-14 03:56:30 +00:00
item . setData ( 0 , QC . Qt . UserRole , data )
root . addChild ( item )
2016-03-23 19:42:56 +00:00
else :
2019-11-14 03:56:30 +00:00
subroot = QW . QTreeWidgetItem ( )
subroot . setText ( 0 , item_name )
2019-12-18 22:06:34 +00:00
subroot . setCheckState ( 0 , root . checkState ( 0 ) )
2019-11-14 03:56:30 +00:00
root . addChild ( subroot )
2016-03-23 19:42:56 +00:00
self . _AddDirectory ( subroot , data )
2013-02-19 00:11:43 +00:00
2013-07-31 21:26:38 +00:00
2016-03-23 19:42:56 +00:00
def _GetSelectedChildrenData ( self , parent_item ) :
result = [ ]
2019-12-18 22:06:34 +00:00
for i in range ( parent_item . childCount ( ) ) :
2013-02-19 00:11:43 +00:00
2019-12-18 22:06:34 +00:00
child_item = parent_item . child ( i )
2013-02-19 00:11:43 +00:00
2019-12-18 22:06:34 +00:00
if child_item . checkState ( 0 ) == QC . Qt . Checked :
2013-02-19 00:11:43 +00:00
2019-12-18 22:06:34 +00:00
data = child_item . data ( 0 , QC . Qt . UserRole )
2016-03-23 19:42:56 +00:00
2019-12-18 22:06:34 +00:00
if data is not None :
2013-02-19 00:11:43 +00:00
2016-03-23 19:42:56 +00:00
result . append ( data )
2013-02-19 00:11:43 +00:00
2019-12-18 22:06:34 +00:00
result . extend ( self . _GetSelectedChildrenData ( child_item ) )
2016-03-23 19:42:56 +00:00
return result
def _RenderItemName ( self , name , size ) :
2019-01-09 22:59:03 +00:00
return name + ' - ' + HydrusData . ToHumanBytes ( size )
2016-03-23 19:42:56 +00:00
def GetURLs ( self ) :
2019-11-14 03:56:30 +00:00
root_item = self . _tree . topLevelItem ( 0 )
2016-03-23 19:42:56 +00:00
urls = self . _GetSelectedChildrenData ( root_item )
return urls
2014-08-06 20:29:17 +00:00
class DialogTextEntry ( Dialog ) :
2020-03-04 22:12:53 +00:00
def __init__ ( self , parent , message , default = ' ' , placeholder = None , allow_blank = False , suggestions = None , max_chars = None , password_entry = False , min_char_width = 72 ) :
2016-12-07 22:12:52 +00:00
if suggestions is None :
suggestions = [ ]
2014-08-06 20:29:17 +00:00
Dialog . __init__ ( self , parent , ' enter text ' , position = ' center ' )
2016-12-07 22:12:52 +00:00
self . _chosen_suggestion = None
2014-08-06 20:29:17 +00:00
self . _allow_blank = allow_blank
2017-08-02 21:32:54 +00:00
self . _max_chars = max_chars
2014-08-06 20:29:17 +00:00
2016-12-07 22:12:52 +00:00
button_choices = [ ]
for text in suggestions :
button_choices . append ( ClientGUICommon . BetterButton ( self , text , self . ButtonChoice , text ) )
2019-11-14 03:56:30 +00:00
self . _text = QW . QLineEdit ( self )
self . _text . textChanged . connect ( self . EventText )
self . _text . installEventFilter ( ClientGUICommon . TextCatchEnterEventFilter ( self . _text , self . EnterText ) )
2014-08-06 20:29:17 +00:00
2020-03-04 22:12:53 +00:00
width = ClientGUIFunctions . ConvertTextToPixelWidth ( self . _text , min_char_width )
self . _text . setMinimumWidth ( width )
2019-11-28 01:11:46 +00:00
if password_entry :
self . _text . setEchoMode ( QW . QLineEdit . Password )
2017-08-02 21:32:54 +00:00
if self . _max_chars is not None :
2019-11-14 03:56:30 +00:00
self . _text . setMaxLength ( self . _max_chars )
2017-08-02 21:32:54 +00:00
2019-11-14 03:56:30 +00:00
self . _ok = ClientGUICommon . BetterButton ( self , ' ok ' , self . done , QW . QDialog . Accepted )
2020-02-26 22:28:52 +00:00
self . _ok . setObjectName ( ' HydrusAccept ' )
2014-08-06 20:29:17 +00:00
2019-11-14 03:56:30 +00:00
self . _cancel = QW . QPushButton ( ' cancel ' , self )
self . _cancel . clicked . connect ( self . reject )
2020-02-26 22:28:52 +00:00
self . _cancel . setObjectName ( ' HydrusCancel ' )
2016-03-30 22:56:50 +00:00
#
2019-11-14 03:56:30 +00:00
self . _text . setText ( default )
2020-05-13 19:03:16 +00:00
if placeholder is not None :
self . _text . setPlaceholderText ( placeholder )
if len ( default ) > 0 :
self . _text . setSelection ( 0 , len ( default ) )
2016-03-30 22:56:50 +00:00
self . _CheckText ( )
#
2019-11-14 03:56:30 +00:00
hbox = QP . HBoxLayout ( )
2016-03-30 22:56:50 +00:00
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( hbox , self . _ok , CC . FLAGS_CENTER_PERPENDICULAR )
QP . AddToLayout ( hbox , self . _cancel , CC . FLAGS_CENTER_PERPENDICULAR )
2016-03-30 22:56:50 +00:00
2017-04-19 20:58:30 +00:00
st_message = ClientGUICommon . BetterStaticText ( self , message )
2019-11-20 23:10:46 +00:00
st_message . setWordWrap ( True )
2016-03-30 22:56:50 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2016-03-30 22:56:50 +00:00
2020-07-22 20:59:16 +00:00
QP . AddToLayout ( vbox , st_message , CC . FLAGS_EXPAND_PERPENDICULAR )
2016-12-07 22:12:52 +00:00
for button in button_choices :
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , button , CC . FLAGS_EXPAND_PERPENDICULAR )
2016-12-07 22:12:52 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , self . _text , CC . FLAGS_EXPAND_BOTH_WAYS )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( vbox , hbox , CC . FLAGS_ON_RIGHT )
2016-03-30 22:56:50 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2016-03-30 22:56:50 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2016-03-30 22:56:50 +00:00
2019-12-05 05:29:32 +00:00
size_hint . setWidth ( max ( size_hint . width ( ) , 250 ) )
2016-03-30 22:56:50 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2014-08-06 20:29:17 +00:00
2021-01-07 01:10:01 +00:00
self . _text . setFocus ( QC . Qt . OtherFocusReason )
2014-08-06 20:29:17 +00:00
def _CheckText ( self ) :
if not self . _allow_blank :
2019-11-14 03:56:30 +00:00
if self . _text . text ( ) == ' ' :
2017-08-02 21:32:54 +00:00
2019-11-14 03:56:30 +00:00
self . _ok . setEnabled ( False )
2017-08-02 21:32:54 +00:00
else :
2019-11-14 03:56:30 +00:00
self . _ok . setEnabled ( True )
2017-08-02 21:32:54 +00:00
2014-08-06 20:29:17 +00:00
2016-12-07 22:12:52 +00:00
def ButtonChoice ( self , text ) :
self . _chosen_suggestion = text
2019-11-14 03:56:30 +00:00
self . done ( QW . QDialog . Accepted )
2016-12-07 22:12:52 +00:00
2019-11-14 03:56:30 +00:00
def EventText ( self , text ) :
2014-08-06 20:29:17 +00:00
2019-11-14 03:56:30 +00:00
QP . CallAfter ( self . _CheckText )
2014-08-06 20:29:17 +00:00
2019-11-14 03:56:30 +00:00
def EnterText ( self ) :
2014-08-06 20:29:17 +00:00
2019-11-14 03:56:30 +00:00
if self . _ok . isEnabled ( ) :
2016-12-07 22:12:52 +00:00
2019-11-14 03:56:30 +00:00
self . done ( QW . QDialog . Accepted )
2016-12-07 22:12:52 +00:00
2014-08-06 20:29:17 +00:00
2016-12-07 22:12:52 +00:00
def GetValue ( self ) :
if self . _chosen_suggestion is None :
2019-11-14 03:56:30 +00:00
return self . _text . text ( )
2016-12-07 22:12:52 +00:00
else :
return self . _chosen_suggestion
2014-08-06 20:29:17 +00:00
2017-06-07 22:05:15 +00:00
class DialogYesYesNo ( Dialog ) :
def __init__ ( self , parent , message , title = ' Are you sure? ' , yes_tuples = None , no_label = ' no ' ) :
if yes_tuples is None :
yes_tuples = [ ( ' yes ' , ' yes ' ) ]
Dialog . __init__ ( self , parent , title , position = ' center ' )
self . _value = None
yes_buttons = [ ]
for ( label , data ) in yes_tuples :
yes_button = ClientGUICommon . BetterButton ( self , label , self . _DoYes , data )
2020-02-26 22:28:52 +00:00
yes_button . setObjectName ( ' HydrusAccept ' )
2017-06-07 22:05:15 +00:00
yes_buttons . append ( yes_button )
2019-11-14 03:56:30 +00:00
self . _no = ClientGUICommon . BetterButton ( self , no_label , self . done , QW . QDialog . Rejected )
2020-02-26 22:28:52 +00:00
self . _no . setObjectName ( ' HydrusCancel ' )
2017-06-07 22:05:15 +00:00
#
2019-11-14 03:56:30 +00:00
hbox = QP . HBoxLayout ( )
2017-06-07 22:05:15 +00:00
for yes_button in yes_buttons :
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( hbox , yes_button , CC . FLAGS_CENTER_PERPENDICULAR )
2017-06-07 22:05:15 +00:00
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( hbox , self . _no , CC . FLAGS_CENTER_PERPENDICULAR )
2017-06-07 22:05:15 +00:00
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2017-06-07 22:05:15 +00:00
text = ClientGUICommon . BetterStaticText ( self , message )
2019-11-20 23:10:46 +00:00
text . setWordWrap ( True )
2017-06-07 22:05:15 +00:00
2020-07-22 20:59:16 +00:00
QP . AddToLayout ( vbox , text , CC . FLAGS_EXPAND_BOTH_WAYS )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( vbox , hbox , CC . FLAGS_ON_RIGHT )
2017-06-07 22:05:15 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( vbox )
2017-06-07 22:05:15 +00:00
2019-12-05 05:29:32 +00:00
size_hint = self . sizeHint ( )
2017-06-07 22:05:15 +00:00
2019-12-05 05:29:32 +00:00
size_hint . setWidth ( max ( size_hint . width ( ) , 250 ) )
2017-06-07 22:05:15 +00:00
2019-12-05 05:29:32 +00:00
QP . SetInitialSize ( self , size_hint )
2017-06-07 22:05:15 +00:00
2021-06-23 21:11:38 +00:00
ClientGUIFunctions . SetFocusLater ( yes_buttons [ 0 ] )
2017-06-07 22:05:15 +00:00
def _DoYes ( self , value ) :
self . _value = value
2019-11-14 03:56:30 +00:00
self . done ( QW . QDialog . Accepted )
2017-06-07 22:05:15 +00:00
def GetValue ( self ) :
return self . _value