1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-01-23 07:01:39 +00:00

Modernized progress window GUI

Following the refactoring that has been initiated in pdfmasher's
"vala" branch, I pushed more progress window logic into the
core.

The UI code is now a bit dumber than it used to be, and the core
now directly decides when the progress window is shown and
hidden. The "job finished" notification is also directly sent by the
core. Job description update logic is handled by a core gui
textfield.

Job description contsants also moved to the core, triggering
a localisation migration from "ui" to "core".
This commit is contained in:
Virgil Dupras
2013-08-03 16:27:36 -04:00
parent 8e15d89a2e
commit e5ce6680ca
33 changed files with 615 additions and 727 deletions

View File

@@ -15,6 +15,7 @@ http://www.hardcoded.net/licenses/bsd_license
#import "IgnoreListDialog.h"
#import "HSFairwareAboutBox.h"
#import "HSRecentFiles.h"
#import "HSProgressWindow.h"
@interface AppDelegateBase : NSObject
{
@@ -27,6 +28,7 @@ http://www.hardcoded.net/licenses/bsd_license
DirectoryPanel *_directoryPanel;
DetailsPanel *_detailsPanel;
IgnoreListDialog *_ignoreListDialog;
HSProgressWindow *_progressWindow;
NSWindowController *_preferencesPanel;
HSFairwareAboutBox *_aboutBox;
HSRecentFiles *_recentResults;

View File

@@ -74,6 +74,8 @@ http://www.hardcoded.net/licenses/bsd_license
_directoryPanel = [self createDirectoryPanel];
_detailsPanel = [self createDetailsPanel];
_ignoreListDialog = [[IgnoreListDialog alloc] initWithPyRef:[model ignoreListDialog]];
_progressWindow = [[HSProgressWindow alloc] initWithPyRef:[[self model] progressWindow] view:nil];
[_progressWindow setParentWindow:[_resultWindow window]];
_aboutBox = nil; // Lazily loaded
_preferencesPanel = nil; // Lazily loaded
[[[self directoryPanel] window] makeKeyAndOrderFront:self];
@@ -197,7 +199,6 @@ http://www.hardcoded.net/licenses/bsd_license
/* Delegate */
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[ProgressController mainProgressController] setWorker:model];
[model initialRegistrationSetup];
[model loadSession];
}

View File

@@ -42,9 +42,6 @@ http://www.hardcoded.net/licenses/bsd_license
[matches setTarget:self];
[matches setDoubleAction:@selector(openClicked)];
[self adjustUIToLocalization];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobStarted:) name:JobStarted object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobInProgress:) name:JobInProgress object:nil];
return self;
}
@@ -340,22 +337,6 @@ http://www.hardcoded.net/licenses/bsd_license
previewPanel = nil;
}
- (void)jobInProgress:(NSNotification *)aNotification
{
[Dialogs showMessage:NSLocalizedString(@"A previous action is still hanging in there. You can't start a new one yet. Wait a few seconds, then try again.", @"")];
}
- (void)jobStarted:(NSNotification *)aNotification
{
[[self window] makeKeyAndOrderFront:nil];
NSDictionary *ui = [aNotification userInfo];
NSString *desc = [ui valueForKey:@"desc"];
[[ProgressController mainProgressController] setJobDesc:desc];
NSString *jobid = [ui valueForKey:@"jobid"];
[[ProgressController mainProgressController] setJobId:jobid];
[[ProgressController mainProgressController] showSheetForParent:[self window]];
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
return ![[ProgressController mainProgressController] isShown];

View File

@@ -1,3 +1,4 @@
from cocoa.inter import PyTextField, PyProgressWindow
from .deletion_options import PyDeletionOptions
from .details_panel import PyDetailsPanel
from .directory_outline import PyDirectoryOutline

View File

@@ -1,23 +1,8 @@
import logging
from objp.util import pyref, dontwrap
from jobprogress import job
import cocoa
from cocoa import install_exception_hook, install_cocoa_logger, proxy
from cocoa import install_exception_hook, install_cocoa_logger, patch_threaded_job_performer, proxy
from cocoa.inter import PyFairware, FairwareView
from hscommon.trans import trget
from core.app import JobType
tr = trget('ui')
JOBID2TITLE = {
JobType.Scan: tr("Scanning for duplicates"),
JobType.Load: tr("Loading"),
JobType.Move: tr("Moving"),
JobType.Copy: tr("Copying"),
JobType.Delete: tr("Sending to Trash"),
}
class DupeGuruView(FairwareView):
def askYesNoWithPrompt_(self, prompt: str) -> bool: pass
@@ -26,16 +11,14 @@ class DupeGuruView(FairwareView):
def selectDestFileWithPrompt_extension_(self, prompt: str, extension: str) -> str: pass
class PyDupeGuruBase(PyFairware):
FOLLOW_PROTOCOLS = ['Worker']
@dontwrap
def _init(self, modelclass):
logging.basicConfig(level=logging.WARNING, format='%(levelname)s %(message)s')
install_exception_hook()
install_cocoa_logger()
patch_threaded_job_performer()
appdata = proxy.getAppdataPath()
self.model = modelclass(self, appdata)
self.progress = cocoa.ThreadedJobPerformer()
#---Sub-proxies
def detailsPanel(self) -> pyref:
@@ -56,6 +39,9 @@ class PyDupeGuruBase(PyFairware):
def ignoreListDialog(self) -> pyref:
return self.model.ignore_list_dialog
def progressWindow(self) -> pyref:
return self.model.progress_window
def deletionOptions(self) -> pyref:
return self.model.deletion_options
@@ -157,31 +143,6 @@ class PyDupeGuruBase(PyFairware):
def setCopyMoveDestType_(self, copymove_dest_type: int):
self.model.options['copymove_dest_type'] = copymove_dest_type
#---Worker
def getJobProgress(self) -> object: # NSNumber
try:
return self.progress.last_progress
except AttributeError:
# I have *no idea* why this can possible happen (last_progress is always set by
# create_job() *before* any threaded job notification, which shows the progress panel,
# is sent), but it happens anyway, so there we go. ref: #106
return -1
def getJobDesc(self) -> str:
try:
return self.progress.last_desc
except AttributeError:
# see getJobProgress
return ''
def cancelJob(self):
self.progress.job_cancelled = True
def jobCompleted_(self, jobid: str):
result = self.model._job_completed(jobid, self.progress.last_error)
if not result:
self.progress.reraise_if_error()
#--- model --> view
@dontwrap
def open_path(self, path):
@@ -191,18 +152,6 @@ class PyDupeGuruBase(PyFairware):
def reveal_path(self, path):
proxy.revealPath_(str(path))
@dontwrap
def start_job(self, jobid, func, args=()):
try:
j = self.progress.create_job()
args = tuple([j] + list(args))
self.progress.run_threaded(func, args=args)
except job.JobInProgressError:
proxy.postNotification_userInfo_('JobInProgress', None)
else:
ud = {'desc': JOBID2TITLE[jobid], 'jobid':jobid}
proxy.postNotification_userInfo_('JobStarted', ud)
@dontwrap
def ask_yes_no(self, prompt):
return self.callback.askYesNoWithPrompt_(prompt)

View File

@@ -50,7 +50,8 @@ def build(ctx):
'views/HSTableView', 'views/HSOutlineView', 'views/NSIndexPathAdditions',
'views/NSTableViewAdditions',
'controllers/HSColumns', 'controllers/HSGUIController', 'controllers/HSTable',
'controllers/HSOutline', 'controllers/HSPopUpList', 'controllers/HSSelectableList']
'controllers/HSOutline', 'controllers/HSPopUpList', 'controllers/HSSelectableList',
'controllers/HSTextField', 'controllers/HSProgressWindow']
cocoalib_src = [cocoalib_node.find_node(usename + '.m') for usename in cocoalib_uses] + cocoalib_node.ant_glob('autogen/*.m')
project_folders = ['autogen', 'base', ctx.env.DGEDITION]
project_src = sum([ctx.srcnode.ant_glob('%s/*.m' % folder) for folder in project_folders], [])