Skip to content

Commit

Permalink
Added abort button on local import and url downloader pages (#1455)
Browse files Browse the repository at this point in the history
* added abort button to the local import page

* added abort button to the url import page

* use RemoveFileSeedsByStatus instead of RemoveFileSeeds
  • Loading branch information
Minnowo authored Oct 14, 2023
1 parent f2292d1 commit 26d1184
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
32 changes: 27 additions & 5 deletions hydrus/client/gui/pages/ClientGUIManagementPanels.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
from hydrus.client.gui.widgets import ClientGUIMenuButton
from hydrus.client.importing import ClientImporting
from hydrus.client.importing import ClientImportWatchers
from hydrus.client.importing import ClientImportLocal
from hydrus.client.importing import ClientImportSimpleURLs
from hydrus.client.importing.options import FileImportOptions
from hydrus.client.importing.options import PresentationImportOptions
from hydrus.client.media import ClientMedia
Expand Down Expand Up @@ -1173,8 +1175,12 @@ def __init__( self, parent, page, controller, management_controller: ClientGUIMa

self._pause_button = ClientGUICommon.BetterBitmapButton( self._import_queue_panel, CC.global_pixmaps().file_pause, self.Pause )
self._pause_button.setToolTip( 'pause/play imports' )

self._abort_button = ClientGUICommon.BetterBitmapButton( self._import_queue_panel, CC.global_pixmaps().stop, self.Abort )
self._abort_button.setToolTip( 'abort imports' )

self._hdd_import = self._management_controller.GetVariable( 'hdd_import' )

self._hdd_import: ClientImportLocal.HDDImport = self._management_controller.GetVariable( 'hdd_import' )

file_import_options = self._hdd_import.GetFileImportOptions()

Expand All @@ -1196,6 +1202,7 @@ def __init__( self, parent, page, controller, management_controller: ClientGUIMa

QP.AddToLayout( hbox, self._current_action, CC.FLAGS_CENTER_PERPENDICULAR_EXPAND_DEPTH )
QP.AddToLayout( hbox, self._pause_button, CC.FLAGS_CENTER_PERPENDICULAR )
QP.AddToLayout( hbox, self._abort_button, CC.FLAGS_CENTER_PERPENDICULAR )

self._import_queue_panel.Add( hbox, CC.FLAGS_EXPAND_SIZER_PERPENDICULAR )
self._import_queue_panel.Add( self._file_seed_cache_control, CC.FLAGS_EXPAND_PERPENDICULAR )
Expand Down Expand Up @@ -1240,7 +1247,11 @@ def CheckAbleToClose( self ):

raise HydrusExceptions.VetoException( 'This page is still importing.' )

def Abort( self ):

self._hdd_import.AbortImport()

self._UpdateImportStatus()

def Pause( self ):

Expand Down Expand Up @@ -3197,7 +3208,7 @@ def __init__( self, parent, page, controller, management_controller: ClientGUIMa

ManagementPanelImporter.__init__( self, parent, page, controller, management_controller )

self._simple_downloader_import = self._management_controller.GetVariable( 'simple_downloader_import' )
self._simple_downloader_import: ClientImportSimpleURLs.SimpleDownloaderImport = self._management_controller.GetVariable( 'simple_downloader_import' )

#

Expand All @@ -3209,7 +3220,6 @@ def __init__( self, parent, page, controller, management_controller: ClientGUIMa

self._pause_files_button = ClientGUICommon.BetterBitmapButton( self._import_queue_panel, CC.global_pixmaps().file_pause, self.PauseFiles )
self._pause_files_button.setToolTip( 'pause/play files' )

self._current_action = ClientGUICommon.BetterStaticText( self._import_queue_panel, ellipsize_end = True )
self._file_seed_cache_control = ClientGUIFileSeedCache.FileSeedCacheStatusControl( self._import_queue_panel, self._controller, self._page_key )
self._file_download_control = ClientGUINetworkJobControl.NetworkJobControl( self._import_queue_panel )
Expand Down Expand Up @@ -3672,10 +3682,13 @@ def __init__( self, parent, page, controller, management_controller: ClientGUIMa

self._pause_button = ClientGUICommon.BetterBitmapButton( self._import_queue_panel, CC.global_pixmaps().file_pause, self.Pause )
self._pause_button.setToolTip( 'pause/play files' )

self._abort_button = ClientGUICommon.BetterBitmapButton( self._import_queue_panel, CC.global_pixmaps().stop, self.Abort)
self._abort_button.setToolTip( 'abort files' )

self._file_download_control = ClientGUINetworkJobControl.NetworkJobControl( self._import_queue_panel )

self._urls_import = self._management_controller.GetVariable( 'urls_import' )
self._urls_import: ClientImportSimpleURLs.URLsImport = self._management_controller.GetVariable( 'urls_import' )

self._file_seed_cache_control = ClientGUIFileSeedCache.FileSeedCacheStatusControl( self._import_queue_panel, self._controller, page_key = self._page_key )

Expand Down Expand Up @@ -3707,8 +3720,12 @@ def __init__( self, parent, page, controller, management_controller: ClientGUIMa
self._import_options_button.SetNoteImportOptions( note_import_options )

#
hbox = QP.HBoxLayout()

self._import_queue_panel.Add( self._pause_button, CC.FLAGS_ON_RIGHT )
QP.AddToLayout( hbox, self._pause_button, CC.FLAGS_ON_RIGHT )
QP.AddToLayout( hbox, self._abort_button, CC.FLAGS_ON_RIGHT )

self._import_queue_panel.Add( hbox, CC.FLAGS_ON_RIGHT )
self._import_queue_panel.Add( self._file_seed_cache_control, CC.FLAGS_EXPAND_PERPENDICULAR )
self._import_queue_panel.Add( self._file_download_control, CC.FLAGS_EXPAND_PERPENDICULAR )

Expand Down Expand Up @@ -3810,6 +3827,11 @@ def CheckAbleToClose( self ):
raise HydrusExceptions.VetoException( 'This page is still importing.' )


def Abort( self ):

self._urls_import.AbortImport()

self._UpdateImportStatus()

def Pause( self ):

Expand Down
21 changes: 21 additions & 0 deletions hydrus/client/importing/ClientImportLocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ def _UpdateSerialisableInfo( self, version, old_serialisable_info ):
return ( 3, new_serialisable_info )


def _EmptyFileSeedCache( self, status: typing.Collection[int] = (CC.STATUS_UNKNOWN,) ):

self._file_seed_cache.RemoveFileSeedsByStatus( status )

time.sleep( ClientImporting.DID_SUBSTANTIAL_FILE_WORK_MINIMUM_SLEEP_TIME )


def _WorkOnFiles( self ):

Expand Down Expand Up @@ -366,6 +372,21 @@ def PausePlay( self ):

self._SerialisableChangeMade()

def AbortImport( self ):

if self.CurrentlyWorking():

self.PausePlay()

self._EmptyFileSeedCache()

self._paused = False

with self._lock:

self._files_status = 'aborted'




def SetFileImportOptions( self, file_import_options: FileImportOptions.FileImportOptions ):
Expand Down
20 changes: 20 additions & 0 deletions hydrus/client/importing/ClientImportSimpleURLs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import threading
import time
import typing
import urllib.parse

from hydrus.core import HydrusConstants as HC
Expand Down Expand Up @@ -1007,6 +1008,11 @@ def _UpdateSerialisableInfo( self, version, old_serialisable_info ):
return ( 4, new_serialisable_info )


def _EmptyFileSeedCache( self, status: typing.Collection[int] = (CC.STATUS_UNKNOWN,) ):

self._file_seed_cache.RemoveFileSeedsByStatus( status )

time.sleep( ClientImporting.DID_SUBSTANTIAL_FILE_WORK_MINIMUM_SLEEP_TIME )

def _WorkOnFiles( self ):

Expand Down Expand Up @@ -1241,6 +1247,20 @@ def PausePlay( self ):

self._SerialisableChangeMade()


def AbortImport( self ):

if self.CurrentlyWorking():

self.PausePlay()

self._EmptyFileSeedCache()

self._paused = False

with self._lock:

self._files_status = 'aborted'


def PendURLs( self, urls, filterable_tags = None, additional_service_keys_to_tags = None ):
Expand Down

0 comments on commit 26d1184

Please sign in to comment.