hydrus/hydrus/client/gui/ClientGUIPanels.py

223 lines
6.6 KiB
Python
Raw Normal View History

2023-09-06 19:49:46 +00:00
from hydrus.core import HydrusConstants as HC
2020-04-22 21:00:35 +00:00
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
2024-02-14 21:20:24 +00:00
from hydrus.client import ClientGlobals as CG
2023-12-06 22:13:50 +00:00
from hydrus.client.gui import ClientGUIDialogsMessage
2020-04-22 21:00:35 +00:00
from hydrus.client.gui import QtPorting as QP
2021-03-17 21:59:28 +00:00
from hydrus.client.gui.widgets import ClientGUICommon
2017-03-02 02:14:56 +00:00
2019-07-10 22:38:30 +00:00
class IPFSDaemonStatusAndInteractionPanel( ClientGUICommon.StaticBox ):
def __init__( self, parent, service_callable ):
ClientGUICommon.StaticBox.__init__( self, parent, 'ipfs daemon' )
self._is_running = False
self._nocopy_enabled = False
self._service_callable = service_callable
self._running_status = ClientGUICommon.BetterStaticText( self )
self._check_running_button = ClientGUICommon.BetterButton( self, 'check daemon', self._CheckRunning )
self._nocopy_status = ClientGUICommon.BetterStaticText( self )
self._check_nocopy = ClientGUICommon.BetterButton( self, 'check nocopy', self._CheckNoCopy )
self._enable_nocopy = ClientGUICommon.BetterButton( self, 'enable nocopy', self._EnableNoCopy )
2019-11-14 03:56:30 +00:00
self._check_running_button.setEnabled( False )
self._check_nocopy.setEnabled( False )
2019-07-10 22:38:30 +00:00
#
2019-11-14 03:56:30 +00:00
gridbox = QP.GridLayout( cols = 2 )
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
gridbox.setColumnStretch( 1, 1 )
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( gridbox, self._check_running_button, CC.FLAGS_EXPAND_BOTH_WAYS )
2020-07-29 20:52:44 +00:00
QP.AddToLayout( gridbox, self._running_status, CC.FLAGS_CENTER_PERPENDICULAR )
2019-11-14 03:56:30 +00:00
QP.AddToLayout( gridbox, self._check_nocopy, CC.FLAGS_EXPAND_BOTH_WAYS )
2020-07-29 20:52:44 +00:00
QP.AddToLayout( gridbox, self._nocopy_status, CC.FLAGS_CENTER_PERPENDICULAR )
2019-11-14 03:56:30 +00:00
QP.AddToLayout( gridbox, self._enable_nocopy, CC.FLAGS_EXPAND_BOTH_WAYS )
QP.AddToLayout( gridbox, ( 20, 20 ), CC.FLAGS_CENTER_PERPENDICULAR )
2019-07-10 22:38:30 +00:00
self.Add( gridbox, CC.FLAGS_EXPAND_BOTH_WAYS )
#
self._CheckRunning()
def _CheckNoCopy( self ):
2021-06-09 20:28:09 +00:00
def qt_clean_up( result, nocopy_available ):
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
if not self or not QP.isValid( self ):
2019-07-10 22:38:30 +00:00
return
2019-11-14 03:56:30 +00:00
self._nocopy_status.setText( result )
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
self._check_nocopy.setEnabled( True )
2019-07-10 22:38:30 +00:00
2021-06-09 20:28:09 +00:00
self._nocopy_enabled = nocopy_available
2019-07-10 22:38:30 +00:00
if self._nocopy_enabled:
2019-11-14 03:56:30 +00:00
self._enable_nocopy.setEnabled( False )
2019-07-10 22:38:30 +00:00
else:
2019-11-14 03:56:30 +00:00
self._enable_nocopy.setEnabled( True )
2019-07-10 22:38:30 +00:00
def do_it( service ):
2022-08-03 20:59:51 +00:00
result = ''
nocopy_available = False
2019-07-10 22:38:30 +00:00
try:
2021-06-09 20:28:09 +00:00
nocopy_available = service.GetNoCopyAvailable()
2019-07-10 22:38:30 +00:00
2021-06-09 20:28:09 +00:00
if nocopy_available:
2019-07-10 22:38:30 +00:00
2021-06-09 20:28:09 +00:00
result = 'Nocopy is available.'
2019-07-10 22:38:30 +00:00
else:
2021-06-09 20:28:09 +00:00
result = 'Nocopy is not available.'
2019-07-10 22:38:30 +00:00
except Exception as e:
result = 'Problem: {}'.format( str( e ) )
2021-06-09 20:28:09 +00:00
nocopy_available = False
2019-07-10 22:38:30 +00:00
finally:
2021-06-09 20:28:09 +00:00
QP.CallAfter( qt_clean_up, result, nocopy_available )
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
self._check_nocopy.setEnabled( False )
2019-07-10 22:38:30 +00:00
2023-09-06 19:49:46 +00:00
self._nocopy_status.setText( 'checking' + HC.UNICODE_ELLIPSIS )
2019-07-10 22:38:30 +00:00
service = self._service_callable()
2024-02-14 21:20:24 +00:00
CG.client_controller.CallToThread( do_it, service )
2019-07-10 22:38:30 +00:00
def _CheckRunning( self ):
2019-11-14 03:56:30 +00:00
def qt_clean_up( result, is_running ):
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
if not self or not QP.isValid( self ):
2019-07-10 22:38:30 +00:00
return
2019-11-14 03:56:30 +00:00
self._running_status.setText( result )
2019-07-10 22:38:30 +00:00
self._is_running = is_running
2019-11-14 03:56:30 +00:00
self._check_running_button.setEnabled( True )
2019-07-10 22:38:30 +00:00
if self._is_running:
2019-11-14 03:56:30 +00:00
self._check_nocopy.setEnabled( True )
2019-07-10 22:38:30 +00:00
self._CheckNoCopy()
def do_it( service ):
2022-08-03 20:59:51 +00:00
result = ''
is_running = False
2019-07-10 22:38:30 +00:00
try:
version = service.GetDaemonVersion()
result = 'Running version {}.'.format( version )
is_running = True
except Exception as e:
result = 'Problem: {}'.format( str( e ) )
is_running = False
finally:
2019-11-14 03:56:30 +00:00
QP.CallAfter( qt_clean_up, result, is_running )
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
self._check_running_button.setEnabled( False )
self._check_nocopy.setEnabled( False )
self._enable_nocopy.setEnabled( False )
2019-07-10 22:38:30 +00:00
2023-09-06 19:49:46 +00:00
self._running_status.setText( 'checking' + HC.UNICODE_ELLIPSIS )
2019-07-10 22:38:30 +00:00
service = self._service_callable()
2024-02-14 21:20:24 +00:00
CG.client_controller.CallToThread( do_it, service )
2019-07-10 22:38:30 +00:00
def _EnableNoCopy( self ):
2019-11-14 03:56:30 +00:00
def qt_clean_up( success ):
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
if not self or not QP.isValid( self ):
2019-07-10 22:38:30 +00:00
return
if success:
self._CheckNoCopy()
else:
2023-12-06 22:13:50 +00:00
ClientGUIDialogsMessage.ShowCritical( self, 'Error', 'Unfortunately, was unable to set nocopy configuration.' )
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
self._enable_nocopy.setEnabled( True )
2019-07-10 22:38:30 +00:00
def do_it( service ):
2022-08-03 20:59:51 +00:00
success = False
2019-07-10 22:38:30 +00:00
try:
success = service.EnableNoCopy( True )
except Exception as e:
message = 'Problem: {}'.format( str( e ) )
2023-12-06 22:13:50 +00:00
ClientGUIDialogsMessage.ShowCritical( self, 'Error', message )
2019-07-10 22:38:30 +00:00
success = False
finally:
2019-11-14 03:56:30 +00:00
QP.CallAfter( qt_clean_up, success )
2019-07-10 22:38:30 +00:00
2019-11-14 03:56:30 +00:00
self._enable_nocopy.setEnabled( False )
2019-07-10 22:38:30 +00:00
service = self._service_callable()
2024-02-14 21:20:24 +00:00
CG.client_controller.CallToThread( do_it, service )
2019-07-10 22:38:30 +00:00