class glyphsGit ( NSObject, GlyphsPluginProtocol ): sheetLabel = objc.IBOutlet() _view = objc.IBOutlet() sheetTextarea = objc.IBOutlet() sheetButton = objc.IBOutlet() _sheetPanel = objc.IBOutlet() sheetPanel = objc.ivar() objc.synthesize("sheetPanel") oldCwd = "" def loadPlugin( self ): """ You can add an observer like in the example. Do all initializing here. """ try: NSBundle.loadNibNamed_owner_( "GlyphsGitDialog", self ) selector = objc.selector( self.documentWasSaved, signature="v@:@" ) NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, selector, "GSDocumentWasSavedSuccessfully", None ) mainMenu = NSApplication.sharedApplication().mainMenu() s = objc.selector(self.showRevisions,signature='v@:') self.revisionMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("View revision history", s, "" ) self.revisionMenuItem.setTarget_(self) index = 0 numberOfSeperators = 0 for menuItem in mainMenu.itemAtIndex_(1).submenu().itemArray(): if menuItem.isSeparatorItem(): numberOfSeperators += 1 if numberOfSeperators == 2: break index += 1; mainMenu.itemAtIndex_(1).submenu().insertItem_atIndex_(self.revisionMenuItem, index) return None except Exception, err: self.logToConsole( "init: %s" % traceback.format_exc() )
class TestSynthesizeHelper(NSObject): objc.synthesize("someTitle", copy=True) objc.synthesize("stringValue", copy=False) objc.synthesize("read", readwrite=False) objc.synthesize("write", ivarName="_do_write")
class AppController(NSObject): mainWindow = objc.IBOutlet() taskCreationDialog = objc.IBOutlet() priorityPopup = objc.IBOutlet() eventCreationDialog = objc.IBOutlet() calendarData = objc.IBOutlet() calItemTitle = objc.ivar() calItemStartDate = objc.ivar() calItemEndDate = objc.ivar() objc.synthesize("calItemTitle", copy=True) objc.synthesize("calItemStartDate", copy=True) objc.synthesize("calItemEndDate", copy=True) @objc.IBAction def showTaskCreationDialog_(self, sender): # Set default values for the title, start date and priority # Cocoa bindings will clear out the related fields in the sheet self._.calItemTitle = None self._.calItemStartDate = NSDate.date() NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_( self.taskCreationDialog, self.mainWindow, self, "didEndSheet:returnCode:contextInfo:", None, ) @objc.IBAction def showEventCreationDialog_(self, sender): # Set default values for the title and start/end date # Cocoa bindings will clear out the related fields in the sheet self._.calItemTitle = None self._.calItemStartDate = NSDate.date() self._.calItemEndDate = NSDate.dateWithTimeIntervalSinceNow_(3600) NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_( self.eventCreationDialog, self.mainWindow, self, "didEndSheet:returnCode:contextInfo:", None, ) # Called when the "Add" button is pressed on the event/task entry sheet # This starts the sheet dismissal process @objc.IBAction def dismissDialog_(self, sender): NSApp.endSheet_(sender.window()) @objc.selectorFor( NSApplication.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_ ) def didEndSheet_returnCode_contextInfo_(self, sheet, returnCode, contextInfo): # Find out which calendar was selected for the new event/task # We do this using the calendarData array controller which is bound to # the calendar popups in the sheet selectedCalendar = None count = len(self.calendarData.selectedObjects()) if count > 0: selectedCalendarUID = self.calendarData.selectedObjects()[0].uid() selectedCalendar = CalCalendarStore.defaultCalendarStore().calendarWithUID_( selectedCalendarUID ) # Create an event/task based on which sheet was used if sheet is self.taskCreationDialog: if self._.calItemTitle is None: self._.calItemTitle = "My Task" self.createNewTaskWithCalendar_title_priority_dueDate_( selectedCalendar, self._.calItemTitle, self.priorityPopup.selectedTag(), self._.calItemStartDate, ) else: if self._.calItemTitle is None: self._.calItemTitle = "My Event" self.createNewEventWithCalendar_title_startDate_endDate_( selectedCalendar, self._.calItemTitle, self._.calItemStartDate, self._.calItemEndDate, ) # Dismiss the sheet sheet.orderOut_(self) def createNewEventWithCalendar_title_startDate_endDate_( self, calendar, title, startDate, endDate ): # Create a new CalEvent object newEvent = CalEvent.event() # Set the calendar, title, start date and end date on the new event # using the parameters passed to this method newEvent._.calendar = calendar newEvent._.title = title newEvent._.startDate = startDate newEvent._.endDate = endDate # Save the new event to the calendar store (CalCalendarStore) and # return it res, err = CalCalendarStore.defaultCalendarStore().saveEvent_span_error_( newEvent, 0, None ) if res: return newEvent NSLog("error:%@", err.localizedDescription()) return None def createNewTaskWithCalendar_title_priority_dueDate_( self, calendar, title, priority, dueDate ): # Create a new CalTask object newTask = CalTask.task() # Set the calendar, title, priority and due date on the new task # using the parameters passed to this method newTask._.calendar = calendar newTask._.title = title newTask._.priority = priority newTask._.dueDate = dueDate # Save the new task to the calendar store (CalCalendarStore) and # return it res, err = CalCalendarStore.defaultCalendarStore().saveTask_error_( newTask, None ) if res: return newTask NSLog("error:%@", err.localizedDescription()) return None
class TestSynthesizeHelper(NSObject): objc.synthesize('someTitle', copy=True) objc.synthesize('stringValue', copy=False) objc.synthesize('read', readwrite=False) objc.synthesize('write', ivarName='_do_write')
class VLCVideoView(NSView): objc.synthesize('delegate', copy=True) objc.synthesize('backColor', copy=True) objc.synthesize('hasVideo', copy=True) #Initialize the VLCVideoView object. If running in 64-bit on SnowLeopard, it expects a CGRect rather than an NSRect @objc.signature("@@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}") # @objc.signature("@@:{CGRect={CGPoint=dd}{CGSize=dd}}") def initWithFrame_(self, rect): self = super(VLCVideoView, self).initWithFrame_(rect) if self is None: return None self._delegate = None self._backColor = NSColor.blackColor() self._fillScreen = NO self._hasVideo = NO self.setStretchesVideo_(NO) self.setAutoresizesSubviews_(YES) #probably need to figure out how to assign an appropriate layoutManager, but for now it's None self.layoutManager = None return self @objc.signature("@@:") def backColor(self): return self._backColor @objc.signature("c@:") def hasVideo(self): return self._hasVideo @objc.signature("@@:") def delegate(self): return self._delegate @objc.signature("v@:") def dealloc(self): self._delegate = None self._backColor = None if self.layoutManager: self.layoutManager.release() super(VLCVideoView, self).dealloc() @objc.signature("v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}") def drawRect_(self, aRect): self.lockFocus() self.backColor().set() NSRectFill(aRect) self.unlockFocus() @objc.signature("c@:") def isOpaque(self): return YES @objc.signature("c@:") def fillScreen(self): if self.layoutManager: return self.layoutManager.fillScreenEntirely() return NO @objc.signature("v@:c") def setFillScreen_(self, fillScreen): #need to implement return NO @objc.signature( "v@:{CALayer=#{_CALayerIvars=iII^{__CFArray}@^{_CALayerState}^{_CALayerState}^{_CALayerAnimation}[3^{_CALayerTransaction}]}}" ) def addVoutLayer_(self, aLayer): CATransaction.begin() self.setWantsLayer_(YES) rootLayer = self.layer() aLayer.name = u"vlcopengllayer" if self.layoutManager: self.layoutManager.setOriginalVideoSize_(aLayer.bounds().size()) rootLayer.setLayoutManager_(layoutManager) rootLayer.insertSublayer_atIndex_(aLayer, 0) aLayer.setNeedsDisplayOnBoundsChange_(True) CATransaction.commit() self._hasVideo = YES @objc.signature("v@:@") def removeVoutLayer_(self, voutLayer): CATransaction.begin() voutLayer.removeFromSuperlayer() CATransaction.commit() self._hasVideo = NO @objc.signature("v@:c") def setStretchesVideo_(self, value): self._stretchesVideo = value @objc.signature("v@:@") def addVoutSubview_(self, aView): aView.setFrame_(self.bounds()) self.addSubview_(aView) aView.setAutoresizingMask_((NSViewHeightSizable | NSViewWidthSizable)) @objc.signature("v@:@") def removeVoutSubview_(self, view): #not doing anything right now pass @objc.signature("c@:") def stretchesVideo(self): return self._stretchesVideo @objc.signature("v@:@") def didAddSubview_(self, subview): pass