예제 #1
0
    def doDisplay(self, sender):
        NSLog("doDisplay called")        
        
        s = SafeDepositBox()
        Thread(target=s.s3bucket.proc_queue, args=(s.prefix_to_ignore, 
                                                   s.enc_service)).start()
        s.start()
        
        self.counter = 0
		
        self.statusbar = NSStatusBar.systemStatusBar()
        # Create the statusbar item
        self.statusitem = self.statusbar.statusItemWithLength_(NSVariableStatusItemLength)

        # Load all images
        path = NSBundle.mainBundle().pathForImageResource_("safe3.png")
        self.image = NSImage.alloc().initWithContentsOfFile_(path)
        print self.image

        # Set initial image
        self.statusitem.setImage_(self.image)

        # Let it highlight upon clicking
        self.statusitem.setHighlightMode_(1)

        # Set a tooltip
        self.statusitem.setToolTip_('Safe Deposit Box 0.1\n(Yay! Values in Technology =)')

        self._build_menu(sender)

        self.timer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_(
            start_time, 
            1.0, 
            self, 
            'tick:', 
            None, 
            True)
            
        NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
        self.timer.fire()
        self.statusitem.setToolTip_('Safe Deposit Box 0.1\n(Yay! Values in Technology =)')

        # Build a very simple menu
        self._build_menu(notification)

        # Get the timer going
        self.timer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_(start_time, 1.0, self, 'tick:', None, True)
        NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
        self.timer.fire()

    def sync_(self, notification):
        print "sync"

    def tick_(self, notification):
        self.counter += 1
        self._build_menu(self.counter)
        print self.state

if __name__ == "__main__":
    from SafeDepositBox import SafeDepositBox
    from S3BucketPolicy import string_to_dns
    from threading import Thread
    s = SafeDepositBox()
    Thread(target=s.s3bucket.proc_queue, args=(s.prefix_to_ignore, s.enc_service)).start()
    s.start()

    app = NSApplication.sharedApplication()
    delegate = StatusBar.alloc().init()
    app.setDelegate_(delegate)
    AppHelper.runEventLoop()