forked from onecrayon/tea-for-coda
/
TEASheetLoader.py
58 lines (46 loc) · 1.93 KB
/
TEASheetLoader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'''Generic class for TEA sheets'''
from Foundation import *
from AppKit import *
from PyObjCTools import AppHelper
import objc
import tea_actions as tea
class TEASheetLoader(NSObject):
customSheet = objc.IBOutlet()
def initController_forBundle_(self, controller, bundle):
# Store the controller and context for later reference
self.controller = controller
self.context = tea.get_context(controller, self)
def loadNib_forController_inBundle_(self, nibName, controller, bundle):
self.initController_forBundle_(controller, bundle)
# Load the sheet
if not self.customSheet:
# We have to load from the bundle because this class isn't
# recognized as belonging to the TEAforCoda bundle
bundle.loadNibFile_externalNameTable_withZone_(
nibName,
NSDictionary.dictionaryWithObject_forKey_(self, NSNibOwner),
None
)
tea.log(repr(self.customSheet))
tea.log(repr(self.context.window()))
NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(
self.customSheet,
self.context.window(),
self,
'sheetDidEnd:returnCode:contextInfo:',
None
)
tea.log('loaded !!!')
# Retain the class to make sure it sticks around for the window events
self.retain()
@objc.IBAction
def doSubmitSheet_(self, sender):
NSApp.endSheet_returnCode_(self.customSheet, 1)
@objc.IBAction
def cancel_(self, sender):
NSApp.endSheet_returnCode_(self.customSheet, 0)
def windowWillClose_(self, notification):
'''Delegate method to auto-release everything'''
# Unless we retain then self-release, we'll lose the window to the
# default garbage collector; this delegate method is automatic
self.autorelease()