2017-03-08 23:23:12 +00:00
import ClientCaches
2017-03-02 02:14:56 +00:00
import ClientConstants as CC
2017-07-12 20:03:45 +00:00
import ClientData
2017-03-02 02:14:56 +00:00
import ClientGUICommon
2017-03-08 23:23:12 +00:00
import ClientGUIDialogs
2017-08-02 21:32:54 +00:00
import ClientGUIListCtrl
2017-03-15 20:13:04 +00:00
import ClientGUIMenus
2017-03-02 02:14:56 +00:00
import ClientGUIScrolledPanels
2018-05-16 20:09:50 +00:00
import ClientGUIShortcuts
2017-12-06 22:06:56 +00:00
import ClientGUITime
2017-03-02 02:14:56 +00:00
import ClientGUITopLevelWindows
import HydrusConstants as HC
import HydrusData
2017-05-10 21:33:58 +00:00
import HydrusGlobals as HG
2017-03-02 02:14:56 +00:00
import HydrusNetworking
2018-05-16 20:09:50 +00:00
import HydrusText
2017-03-08 23:23:12 +00:00
import os
2017-03-02 02:14:56 +00:00
import wx
class BandwidthRulesCtrl ( ClientGUICommon . StaticBox ) :
def __init__ ( self , parent , bandwidth_rules ) :
ClientGUICommon . StaticBox . __init__ ( self , parent , ' bandwidth rules ' )
2017-10-18 19:41:25 +00:00
listctrl_panel = ClientGUIListCtrl . BetterListCtrlPanel ( self )
2017-03-02 02:14:56 +00:00
2018-03-14 21:01:02 +00:00
self . _listctrl = ClientGUIListCtrl . BetterListCtrl ( listctrl_panel , ' bandwidth_rules ' , 8 , 10 , [ ( ' max allowed ' , 14 ) , ( ' every ' , 16 ) ] , self . _ConvertRuleToListctrlTuples , delete_key_callback = self . _Delete , activation_callback = self . _Edit )
2017-07-27 00:47:13 +00:00
listctrl_panel . SetListCtrl ( self . _listctrl )
listctrl_panel . AddButton ( ' add ' , self . _Add )
listctrl_panel . AddButton ( ' edit ' , self . _Edit , enabled_only_on_selection = True )
listctrl_panel . AddButton ( ' delete ' , self . _Delete , enabled_only_on_selection = True )
2017-03-02 02:14:56 +00:00
#
2017-10-18 19:41:25 +00:00
self . _listctrl . AddDatas ( bandwidth_rules . GetRules ( ) )
self . _listctrl . Sort ( 0 )
2017-03-02 02:14:56 +00:00
#
2018-01-03 22:37:30 +00:00
self . Add ( listctrl_panel , CC . FLAGS_EXPAND_BOTH_WAYS )
2017-03-02 02:14:56 +00:00
def _Add ( self ) :
rule = ( HC . BANDWIDTH_TYPE_DATA , None , 1024 * 1024 * 100 )
with ClientGUITopLevelWindows . DialogEdit ( self , ' edit rule ' ) as dlg :
panel = self . _EditPanel ( dlg , rule )
dlg . SetPanel ( panel )
if dlg . ShowModal ( ) == wx . ID_OK :
new_rule = panel . GetValue ( )
2017-10-18 19:41:25 +00:00
self . _listctrl . AddDatas ( ( new_rule , ) )
2017-03-02 02:14:56 +00:00
2017-10-18 19:41:25 +00:00
self . _listctrl . Sort ( )
2017-03-02 02:14:56 +00:00
2017-10-18 19:41:25 +00:00
def _ConvertRuleToListctrlTuples ( self , rule ) :
2017-03-02 02:14:56 +00:00
( bandwidth_type , time_delta , max_allowed ) = rule
pretty_time_delta = HydrusData . ConvertTimeDeltaToPrettyString ( time_delta )
if bandwidth_type == HC . BANDWIDTH_TYPE_DATA :
pretty_max_allowed = HydrusData . ConvertIntToBytes ( max_allowed )
elif bandwidth_type == HC . BANDWIDTH_TYPE_REQUESTS :
2018-03-14 21:01:02 +00:00
pretty_max_allowed = HydrusData . ConvertIntToPrettyString ( max_allowed ) + ' requests '
2017-03-02 02:14:56 +00:00
2018-03-14 21:01:02 +00:00
sort_tuple = ( max_allowed , time_delta )
display_tuple = ( pretty_max_allowed , pretty_time_delta )
2017-10-18 19:41:25 +00:00
return ( display_tuple , sort_tuple )
2017-03-02 02:14:56 +00:00
def _Delete ( self ) :
2017-03-22 22:38:15 +00:00
with ClientGUIDialogs . DialogYesNo ( self , ' Remove all selected? ' ) as dlg :
if dlg . ShowModal ( ) == wx . ID_YES :
2017-10-18 19:41:25 +00:00
self . _listctrl . DeleteSelected ( )
2017-03-22 22:38:15 +00:00
2017-03-02 02:14:56 +00:00
def _Edit ( self ) :
2017-10-18 19:41:25 +00:00
selected_rules = self . _listctrl . GetData ( only_selected = True )
2017-03-02 02:14:56 +00:00
2017-10-18 19:41:25 +00:00
for rule in selected_rules :
2017-03-02 02:14:56 +00:00
with ClientGUITopLevelWindows . DialogEdit ( self , ' edit rule ' ) as dlg :
panel = self . _EditPanel ( dlg , rule )
dlg . SetPanel ( panel )
if dlg . ShowModal ( ) == wx . ID_OK :
edited_rule = panel . GetValue ( )
2017-10-18 19:41:25 +00:00
self . _listctrl . DeleteDatas ( ( rule , ) )
2017-03-02 02:14:56 +00:00
2017-10-18 19:41:25 +00:00
self . _listctrl . AddDatas ( ( edited_rule , ) )
2017-03-02 02:14:56 +00:00
else :
break
2017-10-18 19:41:25 +00:00
self . _listctrl . Sort ( )
2017-03-02 02:14:56 +00:00
def GetValue ( self ) :
bandwidth_rules = HydrusNetworking . BandwidthRules ( )
2017-10-18 19:41:25 +00:00
for rule in self . _listctrl . GetData ( ) :
( bandwidth_type , time_delta , max_allowed ) = rule
2017-03-02 02:14:56 +00:00
bandwidth_rules . AddRule ( bandwidth_type , time_delta , max_allowed )
return bandwidth_rules
class _EditPanel ( ClientGUIScrolledPanels . EditPanel ) :
def __init__ ( self , parent , rule ) :
ClientGUIScrolledPanels . EditPanel . __init__ ( self , parent )
self . _bandwidth_type = ClientGUICommon . BetterChoice ( self )
self . _bandwidth_type . Append ( ' data ' , HC . BANDWIDTH_TYPE_DATA )
self . _bandwidth_type . Append ( ' requests ' , HC . BANDWIDTH_TYPE_REQUESTS )
self . _bandwidth_type . Bind ( wx . EVT_CHOICE , self . EventBandwidth )
2018-03-14 21:01:02 +00:00
self . _max_allowed_bytes = BytesControl ( self )
self . _max_allowed_requests = wx . SpinCtrl ( self , min = 1 , max = 1048576 )
2017-03-02 02:14:56 +00:00
2018-03-14 21:01:02 +00:00
self . _time_delta = ClientGUITime . TimeDeltaButton ( self , min = 1 , days = True , hours = True , minutes = True , seconds = True , monthly_allowed = True )
2017-03-02 02:14:56 +00:00
#
( bandwidth_type , time_delta , max_allowed ) = rule
self . _bandwidth_type . SelectClientData ( bandwidth_type )
self . _time_delta . SetValue ( time_delta )
if bandwidth_type == HC . BANDWIDTH_TYPE_DATA :
2018-03-14 21:01:02 +00:00
self . _max_allowed_bytes . SetValue ( max_allowed )
else :
self . _max_allowed_requests . SetValue ( max_allowed )
2017-03-02 02:14:56 +00:00
2018-03-14 21:01:02 +00:00
self . _UpdateEnabled ( )
2017-03-02 02:14:56 +00:00
#
hbox = wx . BoxSizer ( wx . HORIZONTAL )
2018-03-14 21:01:02 +00:00
hbox . Add ( self . _max_allowed_bytes , CC . FLAGS_VCENTER )
hbox . Add ( self . _max_allowed_requests , CC . FLAGS_VCENTER )
2018-01-03 22:37:30 +00:00
hbox . Add ( self . _bandwidth_type , CC . FLAGS_VCENTER )
2018-03-14 21:01:02 +00:00
hbox . Add ( ClientGUICommon . BetterStaticText ( self , ' every ' ) , CC . FLAGS_VCENTER )
2018-01-03 22:37:30 +00:00
hbox . Add ( self . _time_delta , CC . FLAGS_VCENTER )
2017-03-02 02:14:56 +00:00
self . SetSizer ( hbox )
2018-03-14 21:01:02 +00:00
def _UpdateEnabled ( self ) :
2017-03-02 02:14:56 +00:00
bandwidth_type = self . _bandwidth_type . GetChoice ( )
if bandwidth_type == HC . BANDWIDTH_TYPE_DATA :
2018-03-14 21:01:02 +00:00
self . _max_allowed_bytes . Show ( )
self . _max_allowed_requests . Hide ( )
2017-03-02 02:14:56 +00:00
elif bandwidth_type == HC . BANDWIDTH_TYPE_REQUESTS :
2018-03-14 21:01:02 +00:00
self . _max_allowed_bytes . Hide ( )
self . _max_allowed_requests . Show ( )
2017-03-02 02:14:56 +00:00
2018-03-14 21:01:02 +00:00
self . Layout ( )
2017-03-02 02:14:56 +00:00
def EventBandwidth ( self , event ) :
2018-03-14 21:01:02 +00:00
self . _UpdateEnabled ( )
2017-03-02 02:14:56 +00:00
def GetValue ( self ) :
bandwidth_type = self . _bandwidth_type . GetChoice ( )
time_delta = self . _time_delta . GetValue ( )
if bandwidth_type == HC . BANDWIDTH_TYPE_DATA :
2018-03-14 21:01:02 +00:00
max_allowed = self . _max_allowed_bytes . GetValue ( )
elif bandwidth_type == HC . BANDWIDTH_TYPE_REQUESTS :
max_allowed = self . _max_allowed_requests . GetValue ( )
2017-03-02 02:14:56 +00:00
return ( bandwidth_type , time_delta , max_allowed )
2017-03-08 23:23:12 +00:00
2018-03-14 21:01:02 +00:00
class BytesControl ( wx . Panel ) :
def __init__ ( self , parent , initial_value = 65536 ) :
wx . Panel . __init__ ( self , parent )
2018-03-22 00:03:33 +00:00
self . _spin = wx . SpinCtrl ( self , min = 0 , max = 1048576 )
2018-05-16 20:09:50 +00:00
width = ClientGUICommon . ConvertTextToPixelWidth ( self . _spin , 12 )
2018-03-22 00:03:33 +00:00
self . _spin . SetSize ( ( width , - 1 ) )
2018-03-14 21:01:02 +00:00
self . _unit = ClientGUICommon . BetterChoice ( self )
self . _unit . Append ( ' B ' , 1 )
self . _unit . Append ( ' KB ' , 1024 )
self . _unit . Append ( ' MB ' , 1024 * 1024 )
self . _unit . Append ( ' GB ' , 1024 * 1024 * 1024 )
#
self . SetValue ( initial_value )
#
hbox = wx . BoxSizer ( wx . HORIZONTAL )
hbox . Add ( self . _spin , CC . FLAGS_VCENTER )
hbox . Add ( self . _unit , CC . FLAGS_VCENTER )
self . SetSizer ( hbox )
2018-04-25 22:07:52 +00:00
def Bind ( self , event_type , callback ) :
self . _spin . Bind ( wx . EVT_SPINCTRL , callback )
self . _unit . Bind ( wx . EVT_CHOICE , callback )
def Disable ( self ) :
self . _spin . Disable ( )
self . _unit . Disable ( )
def Enable ( self ) :
self . _spin . Enable ( )
self . _unit . Enable ( )
2018-03-14 21:01:02 +00:00
def GetSeparatedValue ( self ) :
return ( self . _spin . GetValue ( ) , self . _unit . GetChoice ( ) )
def GetValue ( self ) :
return self . _spin . GetValue ( ) * self . _unit . GetChoice ( )
def SetSeparatedValue ( self , value , unit ) :
return ( self . _spin . SetValue ( value ) , self . _unit . SelectClientData ( unit ) )
def SetValue ( self , value ) :
max_unit = 1024 * 1024 * 1024
unit = 1
while value % 1024 == 0 and unit < max_unit :
value / = 1024
unit * = 1024
self . _spin . SetValue ( value )
self . _unit . SelectClientData ( unit )
class NoneableBytesControl ( wx . Panel ) :
def __init__ ( self , parent , initial_value = 65536 , none_label = ' no limit ' ) :
wx . Panel . __init__ ( self , parent )
self . _bytes = BytesControl ( self )
self . _none_checkbox = wx . CheckBox ( self , label = none_label )
#
self . SetValue ( initial_value )
#
hbox = wx . BoxSizer ( wx . HORIZONTAL )
hbox . Add ( self . _bytes , CC . FLAGS_SIZER_VCENTER )
hbox . Add ( self . _none_checkbox , CC . FLAGS_VCENTER )
self . SetSizer ( hbox )
#
self . _none_checkbox . Bind ( wx . EVT_CHECKBOX , self . EventNoneChecked )
def _UpdateEnabled ( self ) :
if self . _none_checkbox . GetValue ( ) :
self . _bytes . Disable ( )
else :
self . _bytes . Enable ( )
def EventNoneChecked ( self , event ) :
self . _UpdateEnabled ( )
2018-04-25 22:07:52 +00:00
def Bind ( self , event_type , callback ) :
self . _bytes . Bind ( wx . EVT_SPINCTRL , callback )
self . _none_checkbox . Bind ( wx . EVT_CHECKBOX , callback )
2018-03-14 21:01:02 +00:00
def GetValue ( self ) :
if self . _none_checkbox . GetValue ( ) :
return None
else :
return self . _bytes . GetValue ( )
2018-03-22 00:03:33 +00:00
def SetToolTip ( self , text ) :
wx . Panel . SetToolTip ( self , text )
for c in self . GetChildren ( ) :
c . SetToolTip ( text )
2018-03-14 21:01:02 +00:00
def SetValue ( self , value ) :
if value is None :
self . _none_checkbox . SetValue ( True )
else :
self . _none_checkbox . SetValue ( False )
self . _bytes . SetValue ( value )
self . _UpdateEnabled ( )
2017-03-22 22:38:15 +00:00
class EditStringToStringDictControl ( wx . Panel ) :
def __init__ ( self , parent , initial_dict ) :
wx . Panel . __init__ ( self , parent )
2017-12-06 22:06:56 +00:00
listctrl_panel = ClientGUIListCtrl . BetterListCtrlPanel ( self )
2017-07-27 00:47:13 +00:00
2017-12-13 22:33:07 +00:00
self . _listctrl = ClientGUIListCtrl . BetterListCtrl ( listctrl_panel , ' key_to_value ' , 10 , 36 , [ ( ' key ' , 20 ) , ( ' value ' , - 1 ) ] , self . _ConvertDataToListCtrlTuples , delete_key_callback = self . _Delete , activation_callback = self . _Edit )
2017-03-22 22:38:15 +00:00
2017-07-27 00:47:13 +00:00
listctrl_panel . SetListCtrl ( self . _listctrl )
2017-12-06 22:06:56 +00:00
listctrl_panel . AddButton ( ' add ' , self . _Add )
listctrl_panel . AddButton ( ' edit ' , self . _Edit , enabled_only_on_selection = True )
listctrl_panel . AddButton ( ' delete ' , self . _Delete , enabled_only_on_selection = True )
2017-03-22 22:38:15 +00:00
#
2017-12-06 22:06:56 +00:00
self . _listctrl . AddDatas ( initial_dict . items ( ) )
self . _listctrl . Sort ( )
2017-03-22 22:38:15 +00:00
#
vbox = wx . BoxSizer ( wx . VERTICAL )
2018-01-03 22:37:30 +00:00
vbox . Add ( listctrl_panel , CC . FLAGS_EXPAND_BOTH_WAYS )
2017-03-22 22:38:15 +00:00
self . SetSizer ( vbox )
2017-12-06 22:06:56 +00:00
def _ConvertDataToListCtrlTuples ( self , data ) :
( key , value ) = data
display_tuple = ( key , value )
sort_tuple = ( key , value )
return ( display_tuple , sort_tuple )
def _Add ( self ) :
2017-03-22 22:38:15 +00:00
with ClientGUIDialogs . DialogTextEntry ( self , ' enter the key ' , allow_blank = False ) as dlg :
if dlg . ShowModal ( ) == wx . ID_OK :
key = dlg . GetValue ( )
with ClientGUIDialogs . DialogTextEntry ( self , ' enter the value ' , allow_blank = True ) as dlg :
if dlg . ShowModal ( ) == wx . ID_OK :
value = dlg . GetValue ( )
2017-12-06 22:06:56 +00:00
data = ( key , value )
2017-03-22 22:38:15 +00:00
2017-12-06 22:06:56 +00:00
self . _listctrl . AddDatas ( ( data , ) )
2017-03-22 22:38:15 +00:00
2017-12-06 22:06:56 +00:00
def _Delete ( self ) :
2017-03-22 22:38:15 +00:00
with ClientGUIDialogs . DialogYesNo ( self , ' Remove all selected? ' ) as dlg :
if dlg . ShowModal ( ) == wx . ID_YES :
2017-12-06 22:06:56 +00:00
self . _listctrl . DeleteSelected ( )
2017-03-22 22:38:15 +00:00
2017-12-06 22:06:56 +00:00
def _Edit ( self ) :
2017-03-22 22:38:15 +00:00
2017-12-06 22:06:56 +00:00
for data in self . _listctrl . GetData ( only_selected = True ) :
2017-03-22 22:38:15 +00:00
2017-12-06 22:06:56 +00:00
( key , value ) = data
2017-03-22 22:38:15 +00:00
with ClientGUIDialogs . DialogTextEntry ( self , ' edit the key ' , default = key , allow_blank = False ) as dlg :
if dlg . ShowModal ( ) == wx . ID_OK :
key = dlg . GetValue ( )
else :
2017-12-06 22:06:56 +00:00
break
2017-03-22 22:38:15 +00:00
with ClientGUIDialogs . DialogTextEntry ( self , ' edit the value ' , default = value , allow_blank = True ) as dlg :
if dlg . ShowModal ( ) == wx . ID_OK :
value = dlg . GetValue ( )
else :
2017-12-06 22:06:56 +00:00
break
2017-03-22 22:38:15 +00:00
2017-12-06 22:06:56 +00:00
self . _listctrl . DeleteDatas ( ( data , ) )
2017-03-22 22:38:15 +00:00
2017-12-06 22:06:56 +00:00
new_data = ( key , value )
2017-03-22 22:38:15 +00:00
2018-01-24 23:09:42 +00:00
self . _listctrl . AddDatas ( ( new_data , ) )
2017-12-06 22:06:56 +00:00
self . _listctrl . Sort ( )
2017-03-22 22:38:15 +00:00
def GetValue ( self ) :
2017-12-06 22:06:56 +00:00
value_dict = dict ( self . _listctrl . GetData ( ) )
2017-03-22 22:38:15 +00:00
return value_dict
2017-07-05 21:09:28 +00:00
class NetworkJobControl ( wx . Panel ) :
def __init__ ( self , parent ) :
2017-07-12 20:03:45 +00:00
wx . Panel . __init__ ( self , parent , style = wx . BORDER_DOUBLE )
2017-07-05 21:09:28 +00:00
self . _network_job = None
2017-07-12 20:03:45 +00:00
self . _download_started = False
2017-08-16 21:58:06 +00:00
self . _auto_override_bandwidth_rules = False
2017-07-12 20:03:45 +00:00
self . _left_text = ClientGUICommon . BetterStaticText ( self )
self . _right_text = ClientGUICommon . BetterStaticText ( self , style = wx . ALIGN_RIGHT )
# 512/768KB - 200KB/s
2018-05-16 20:09:50 +00:00
right_width = ClientGUICommon . ConvertTextToPixelWidth ( self . _right_text , 20 )
2017-07-05 21:09:28 +00:00
2017-07-12 20:03:45 +00:00
self . _right_text . SetMinSize ( ( right_width , - 1 ) )
self . _gauge = ClientGUICommon . Gauge ( self )
2017-07-05 21:09:28 +00:00
2017-08-16 21:58:06 +00:00
menu_items = [ ]
invert_call = self . FlipOverrideBandwidthForCurrentJob
value_call = self . CurrentJobOverridesBandwidth
check_manager = ClientGUICommon . CheckboxManagerCalls ( invert_call , value_call )
menu_items . append ( ( ' check ' , ' override bandwidth rules for this job ' , ' Tell the current job to ignore existing bandwidth rules and go ahead anyway. ' , check_manager ) )
menu_items . append ( ( ' separator ' , 0 , 0 , 0 ) )
invert_call = self . FlipAutoOverrideBandwidth
value_call = self . AutoOverrideBandwidth
check_manager = ClientGUICommon . CheckboxManagerCalls ( invert_call , value_call )
menu_items . append ( ( ' check ' , ' auto-override bandwidth rules for all jobs here after five seconds ' , ' Ignore existing bandwidth rules for all jobs under this control, instead waiting a flat five seconds. ' , check_manager ) )
self . _cog_button = ClientGUICommon . MenuBitmapButton ( self , CC . GlobalBMPs . cog , menu_items )
2017-07-05 21:09:28 +00:00
self . _cancel_button = ClientGUICommon . BetterBitmapButton ( self , CC . GlobalBMPs . stop , self . Cancel )
#
self . _Update ( )
#
2017-07-12 20:03:45 +00:00
st_hbox = wx . BoxSizer ( wx . HORIZONTAL )
2018-01-03 22:37:30 +00:00
st_hbox . Add ( self . _left_text , CC . FLAGS_EXPAND_BOTH_WAYS )
st_hbox . Add ( self . _right_text , CC . FLAGS_VCENTER )
2017-07-12 20:03:45 +00:00
left_vbox = wx . BoxSizer ( wx . VERTICAL )
2018-01-03 22:37:30 +00:00
left_vbox . Add ( st_hbox , CC . FLAGS_EXPAND_SIZER_BOTH_WAYS )
left_vbox . Add ( self . _gauge , CC . FLAGS_EXPAND_PERPENDICULAR )
2017-07-12 20:03:45 +00:00
2017-07-05 21:09:28 +00:00
hbox = wx . BoxSizer ( wx . HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox . Add ( left_vbox , CC . FLAGS_EXPAND_SIZER_BOTH_WAYS )
hbox . Add ( self . _cog_button , CC . FLAGS_VCENTER )
hbox . Add ( self . _cancel_button , CC . FLAGS_VCENTER )
2017-07-05 21:09:28 +00:00
self . SetSizer ( hbox )
2017-08-30 20:27:47 +00:00
def _OverrideBandwidthIfAppropriate ( self ) :
if self . _network_job is None or self . _network_job . NoEngineYet ( ) :
return
else :
if self . _auto_override_bandwidth_rules and HydrusData . TimeHasPassed ( self . _network_job . GetCreationTime ( ) + 5 ) :
self . _network_job . OverrideBandwidth ( )
2017-07-05 21:09:28 +00:00
def _Update ( self ) :
2017-07-27 00:47:13 +00:00
if self . _network_job is None or self . _network_job . NoEngineYet ( ) :
2017-07-05 21:09:28 +00:00
2017-07-12 20:03:45 +00:00
self . _left_text . SetLabelText ( ' ' )
self . _right_text . SetLabelText ( ' ' )
self . _gauge . SetRange ( 1 )
self . _gauge . SetValue ( 0 )
2017-07-05 21:09:28 +00:00
can_cancel = False
else :
if self . _network_job . IsDone ( ) :
can_cancel = False
else :
can_cancel = True
( status_text , current_speed , bytes_read , bytes_to_read ) = self . _network_job . GetStatus ( )
2017-07-12 20:03:45 +00:00
self . _left_text . SetLabelText ( status_text )
if not self . _download_started and current_speed > 0 :
2017-07-05 21:09:28 +00:00
2017-07-12 20:03:45 +00:00
self . _download_started = True
if self . _download_started and not self . _network_job . HasError ( ) :
speed_text = ' '
if bytes_read is not None :
if bytes_to_read is not None and bytes_read != bytes_to_read :
speed_text + = HydrusData . ConvertValueRangeToBytes ( bytes_read , bytes_to_read )
else :
speed_text + = HydrusData . ConvertIntToBytes ( bytes_read )
if current_speed != bytes_to_read : # if it is a real quick download, just say its size
speed_text + = ' ' + HydrusData . ConvertIntToBytes ( current_speed ) + ' /s '
self . _right_text . SetLabelText ( speed_text )
2017-07-05 21:09:28 +00:00
else :
2017-07-12 20:03:45 +00:00
self . _right_text . SetLabelText ( ' ' )
2017-07-05 21:09:28 +00:00
2017-07-12 20:03:45 +00:00
self . _gauge . SetRange ( bytes_to_read )
self . _gauge . SetValue ( bytes_read )
2017-07-05 21:09:28 +00:00
if can_cancel :
if not self . _cancel_button . IsEnabled ( ) :
self . _cancel_button . Enable ( )
else :
if self . _cancel_button . IsEnabled ( ) :
self . _cancel_button . Disable ( )
2017-08-16 21:58:06 +00:00
def AutoOverrideBandwidth ( self ) :
return self . _auto_override_bandwidth_rules
2017-07-05 21:09:28 +00:00
def Cancel ( self ) :
if self . _network_job is not None :
self . _network_job . Cancel ( )
def ClearNetworkJob ( self ) :
2017-08-02 21:32:54 +00:00
if self and self . _network_job is not None :
2017-07-19 21:21:41 +00:00
self . _network_job = None
2017-07-27 00:47:13 +00:00
self . _Update ( )
2018-01-03 22:37:30 +00:00
HG . client_controller . gui . UnregisterUIUpdateWindow ( self )
2017-07-19 21:21:41 +00:00
2017-07-12 20:03:45 +00:00
2017-07-05 21:09:28 +00:00
2017-08-16 21:58:06 +00:00
def CurrentJobOverridesBandwidth ( self ) :
if self . _network_job is None :
return None
else :
return not self . _network_job . ObeysBandwidth ( )
def FlipAutoOverrideBandwidth ( self ) :
self . _auto_override_bandwidth_rules = not self . _auto_override_bandwidth_rules
def FlipOverrideBandwidthForCurrentJob ( self ) :
if self . _network_job is not None :
self . _network_job . OverrideBandwidth ( )
2017-07-05 21:09:28 +00:00
def SetNetworkJob ( self , network_job ) :
2017-08-02 21:32:54 +00:00
if self and self . _network_job != network_job :
2017-07-19 21:21:41 +00:00
self . _network_job = network_job
self . _download_started = False
2018-01-03 22:37:30 +00:00
HG . client_controller . gui . RegisterUIUpdateWindow ( self )
2017-07-27 00:47:13 +00:00
2017-07-05 21:09:28 +00:00
2018-01-03 22:37:30 +00:00
def TIMERUIUpdate ( self ) :
2017-07-05 21:09:28 +00:00
2017-08-30 20:27:47 +00:00
self . _OverrideBandwidthIfAppropriate ( )
2017-08-02 21:32:54 +00:00
if HG . client_controller . gui . IShouldRegularlyUpdate ( self ) :
2017-07-05 21:09:28 +00:00
self . _Update ( )
2018-02-07 23:40:33 +00:00
class StringToStringDictButton ( ClientGUICommon . BetterButton ) :
def __init__ ( self , parent , label ) :
ClientGUICommon . BetterButton . __init__ ( self , parent , label , self . _Edit )
self . _value = { }
def _Edit ( self ) :
with ClientGUITopLevelWindows . DialogEdit ( self , ' edit string dictionary ' ) as dlg :
panel = ClientGUIScrolledPanels . EditSingleCtrlPanel ( dlg )
control = EditStringToStringDictControl ( panel , self . _value )
panel . SetControl ( control )
dlg . SetPanel ( panel )
if dlg . ShowModal ( ) == wx . ID_OK :
self . _value = control . GetValue ( )
def GetValue ( self ) :
return self . _value
def SetValue ( self , value ) :
self . _value = value
2018-05-16 20:09:50 +00:00
class TextAndPasteCtrl ( wx . Panel ) :
def __init__ ( self , parent , add_callable ) :
self . _add_callable = add_callable
wx . Panel . __init__ ( self , parent )
self . _text_input = wx . TextCtrl ( self , style = wx . TE_PROCESS_ENTER )
self . _text_input . Bind ( wx . EVT_KEY_DOWN , self . EventKeyDown )
self . _paste_button = ClientGUICommon . BetterBitmapButton ( self , CC . GlobalBMPs . paste , self . _Paste )
self . _paste_button . SetToolTip ( ' Paste multiple inputs from the clipboard. Assumes the texts are newline-separated. ' )
#
hbox = wx . BoxSizer ( wx . HORIZONTAL )
hbox . Add ( self . _text_input , CC . FLAGS_EXPAND_BOTH_WAYS )
hbox . Add ( self . _paste_button , CC . FLAGS_VCENTER )
self . SetSizer ( hbox )
def _Paste ( self ) :
raw_text = HG . client_controller . GetClipboardText ( )
try :
texts = [ text for text in HydrusText . DeserialiseNewlinedTexts ( raw_text ) if text != ' ' ]
if len ( texts ) > 0 :
self . _add_callable ( texts )
except :
wx . MessageBox ( ' I could not understand what was in the clipboard ' )
def EventKeyDown ( self , event ) :
( modifier , key ) = ClientGUIShortcuts . ConvertKeyEventToSimpleTuple ( event )
if key in ( wx . WXK_RETURN , wx . WXK_NUMPAD_ENTER ) :
text = self . _text_input . GetValue ( )
if text != ' ' :
self . _add_callable ( ( text , ) )
self . _text_input . SetValue ( ' ' )
else :
event . Skip ( )
def GetValue ( self ) :
return self . _text_input . GetValue ( )
def SetValue ( self , text ) :
self . _text_input . SetValue ( text )