From 8e15d89a2eeb5d635f07c967a3e182101140a1ca Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 3 Aug 2013 11:12:31 -0400 Subject: [PATCH] Updated cocoalib subtree. --- cocoalib/cocoa/inter.py | 32 ++++++++++++ cocoalib/controllers/HSProgressWindow.h | 28 ++++++++++ cocoalib/controllers/HSProgressWindow.m | 68 +++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 cocoalib/controllers/HSProgressWindow.h create mode 100644 cocoalib/controllers/HSProgressWindow.m diff --git a/cocoalib/cocoa/inter.py b/cocoalib/cocoa/inter.py index beb29298..625f2c5f 100644 --- a/cocoalib/cocoa/inter.py +++ b/cocoalib/cocoa/inter.py @@ -243,6 +243,38 @@ class PyTable(PyGUIObject): def update_selection(self): self.callback.updateSelection() +class ProgressWindowView(GUIObjectView): + def setProgress_(self, progress: int): pass + def showWindow(self): pass + def closeWindow(self): pass + +class PyProgressWindow(PyGUIObject): + def jobdescTextField(self) -> pyref: + return self.model.jobdesc_textfield + + def progressdescTextField(self) -> pyref: + return self.model.progressdesc_textfield + + def pulse(self): + self.model.pulse() + + def cancel(self): + self.model.cancel() + + #--- Python -> Cocoa + @dontwrap + def set_progress(self, last_progress): + self.callback.setProgress_(last_progress) + + @dontwrap + def show(self): + self.callback.showWindow() + + @dontwrap + def close(self): + self.callback.closeWindow() + + class BaseAppView: def showMessage_(self, msg: str): pass diff --git a/cocoalib/controllers/HSProgressWindow.h b/cocoalib/controllers/HSProgressWindow.h new file mode 100644 index 00000000..e186ebe5 --- /dev/null +++ b/cocoalib/controllers/HSProgressWindow.h @@ -0,0 +1,28 @@ +/* +Copyright 2013 Hardcoded Software (http://www.hardcoded.net) + +This software is licensed under the "BSD" License as described in the "LICENSE" file, +which should be included with this package. The terms are also available at +http://www.hardcoded.net/licenses/bsd_license +*/ + +#import +#import "HSGUIController.h" +#import "HSTextField.h" +#import "Worker.h" +#import "PyProgressWindow.h" + +@interface HSProgressWindow : HSGUIController +{ + NSInteger progress; + HSTextField *jobdescTextField; + HSTextField *progressdescTextField; +} + +- (id)initWithPyRef:(PyObject *)aPyRef view:(NSView *)aView; +- (PyProgressWindow *)model; + +- (void)setProgress:(NSInteger)aProgress; +- (void)showWindow; +- (void)closeWindow; +@end \ No newline at end of file diff --git a/cocoalib/controllers/HSProgressWindow.m b/cocoalib/controllers/HSProgressWindow.m new file mode 100644 index 00000000..47cda1db --- /dev/null +++ b/cocoalib/controllers/HSProgressWindow.m @@ -0,0 +1,68 @@ +/* +Copyright 2013 Hardcoded Software (http://www.hardcoded.net) + +This software is licensed under the "BSD" License as described in the "LICENSE" file, +which should be included with this package. The terms are also available at +http://www.hardcoded.net/licenses/bsd_license +*/ + +#import "HSProgressWindow.h" +#import "ProgressController.h" +#import "Utils.h" + +@implementation HSProgressWindow +- (id)initWithPyRef:(PyObject *)aPyRef view:(NSView *)aView +{ + self = [self initWithPyRef:aPyRef wrapperClass:[PyProgressWindow class] callbackClassName:@"ProgressWindowView" view:aView]; + [[ProgressController mainProgressController] setWorker:self]; + jobdescTextField = [[HSTextField alloc] initWithPyRef:[[self model] jobdescTextField] view:[[ProgressController mainProgressController] descText]]; + progressdescTextField = [[HSTextField alloc] initWithPyRef:[[self model] progressdescTextField] view:[[ProgressController mainProgressController] statusText]]; + return self; +} + +- (PyProgressWindow *)model +{ + return (PyProgressWindow *)model; +} + +/* Public */ +- (void)setProgress:(NSInteger)aProgress +{ + progress = aProgress; +} + +- (void)showWindow +{ + [[ProgressController mainProgressController] show]; +} + +- (void)closeWindow +{ + [[ProgressController mainProgressController] hide]; +} + +/* Worker */ + +- (NSNumber *)getJobProgress +{ + [[self model] pulse]; + return [NSNumber numberWithInt:progress]; +} + +- (NSString *)getJobDesc +{ + // Our desc label is updated independently. + return nil; +} + +- (void)cancelJob +{ + [[self model] cancel]; +} + +- (void)jobCompleted:(NSString *)jobid +{ + // With the new hscommon.gui.progress_window, this call is done from within the core. Do nothing. +} + +@end