def keyDown_(self, event):
     s = event.characters()
     key = s[0].upper()
     if key == chr(27):
         self.delegate.hide()
     else:
         NSView.keyDown_(self, event)
Example #2
0
 def keyDown_(self, event):
     s = event.characters()
     key = s[0].upper()
     if key == chr(27):
         if self.delegate:
             self.delegate.fullScreenViewPressedEscape()
     else:
         NSView.keyDown_(self, event)
 def drawRect_(self, rect):
     gradient = NSGradient.alloc().initWithColors_([
         NSColor.colorWithDeviceRed_green_blue_alpha_(
             121 / 256.0, 121 / 256.0, 121 / 256.0, 1),
         NSColor.colorWithDeviceRed_green_blue_alpha_(
             111 / 256.0, 111 / 256.0, 111 / 256.0, 1)
     ])
     gradient.drawInRect_angle_(rect, 90.0)
     NSView.drawRect_(self, rect)
    def initWithFrame_(self, frame):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.items = []

            self.leftButton = NSButton.alloc().initWithFrame_(
                NSMakeRect(0, 0, 20, 20))
            self.leftButton.setTarget_(self)
            self.leftButton.setAction_("scrollLeft:")
            self.leftButton.setImage_(
                NSImage.imageNamed_("NSLeftFacingTriangleTemplate"))
            self.leftButton.setHidden_(True)
            self.leftButton.cell().setBezelStyle_(NSShadowlessSquareBezelStyle)
            self.addSubview_(self.leftButton)

            self.rightButton = NSButton.alloc().initWithFrame_(
                NSMakeRect(0, 0, 20, 20))
            self.rightButton.setTarget_(self)
            self.rightButton.setAction_("scrollRight:")
            self.rightButton.setImage_(
                NSImage.imageNamed_("NSRightFacingTriangleTemplate"))
            self.rightButton.setHidden_(True)
            self.rightButton.cell().setBezelStyle_(
                NSShadowlessSquareBezelStyle)
            self.addSubview_(self.rightButton)

        return self
    def initWithFrame_oldTransfer_(self, frame, transferInfo):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.oldTransferInfo = transferInfo

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            filename = transferInfo.file_path
            if filename.endswith(".download"):
                filename = filename[:-len(".download")]

            self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(filename))

            self.nameText.setStringValue_(os.path.basename(filename))
            self.fromText.setStringValue_('To %s' % transferInfo.remote_uri if transferInfo.direction=='outgoing' else 'From %s' % transferInfo.remote_uri)

            if transferInfo.status == "completed":
                status = "%s %s Completed"%(format_size(transferInfo.file_size, 1024), unichr(0x2014))
            else:
                error = transferInfo.status

                if transferInfo.direction == "outgoing":
                    status = error
                else:
                    status = "%s of %s"%(format_size(transferInfo.bytes_transfered, 1024), format_size(transferInfo.file_size, 1024))
                    status = "%s %s %s"%(status, unichr(0x2014), error)
            self.sizeText.setStringValue_(status)
            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.relayoutForDone()
            self.done = True
        return self
    def initWithFrame_oldTransfer_(self, frame, transferInfo):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.oldTransferInfo = transferInfo

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            filename = transferInfo.file_path
            if filename.endswith(".download"):
                filename = filename[:-len(".download")]

            self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(filename))

            self.nameText.setStringValue_(os.path.basename(filename))
            self.fromText.setStringValue_('To %s from account %s' % (transferInfo.remote_uri, transferInfo.local_uri) if transferInfo.direction=='outgoing' else 'From %s to account %s' % (transferInfo.remote_uri, transferInfo.local_uri))

            time_print = format_date(transferInfo.time)
            if transferInfo.status == "completed":
                t = NSLocalizedString("Completed transfer of ", "Label")
                status = t + "%s %s" % (format_size(transferInfo.file_size, 1024), time_print)
            else:
                if transferInfo.direction == "outgoing":
                    status = '%s %s' % (transferInfo.status.title(), time_print)
                    self.retryButton.setHidden_(False)
                else:
                    #status = "%s of %s"%(format_size(transferInfo.bytes_transfered, 1024), format_size(transferInfo.file_size, 1024))
                    status = "%s %s" % (transferInfo.status.title(), time_print)

            self.sizeText.setStringValue_(status)
            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.relayoutForDone()
            self.done = True
        return self
    def initWithFrame_transfer_(self, frame, transfer):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.transfer = transfer
            NotificationCenter().add_observer(self, sender=transfer)

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            self.file_path = os.path.basename(self.transfer.ft_info.file_path)
            self.nameText.setStringValue_(self.file_path)
            self.remote_uri = self.transfer.ft_info.remote_uri
            self.local_uri = self.transfer.ft_info.local_uri

            if type(self.transfer) == OutgoingPushFileTransferHandler:
                self.fromText.setStringValue_("To:  %s" %
                                              self.transfer.account.id)
            else:
                self.fromText.setStringValue_("From:  %s" %
                                              self.transfer.account.id)
            self.revealButton.setHidden_(True)

            # XXX: there should be a better way to do this!
            tmp_folder = ApplicationData.get('.tmp_file_transfers')
            makedirs(tmp_folder, 0o700)
            tmpf = tmp_folder + "/tmpf-" + self.file_path.decode(
            ) if isinstance(self.file_path, bytes) else self.file_path
            with open(tmpf, "wb+"):
                self.updateIcon(
                    NSWorkspace.sharedWorkspace().iconForFile_(tmpf))
            unlink(tmpf)

            self.updateProgressInfo()
            self.progressBar.setIndeterminate_(True)
            self.progressBar.startAnimation_(None)

            self.checksumProgressBar.setIndeterminate_(False)
            self.checksumProgressBar.startAnimation_(None)

            if transfer.direction == 'outgoing':
                self.progressBar.setHidden_(True)
                self.checksumProgressBar.setHidden_(False)
            else:
                self.progressBar.setHidden_(False)
                self.checksumProgressBar.setHidden_(True)

            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.originalHeight = NSHeight(frame)
        return self
    def initWithSwitcher_item_(self, switcher, item):
        self = NSView.initWithFrame_(self, NSMakeRect(0, 2, 100, 18))
        if self:
            self.closeIcon.setSize_(NSMakeSize(12, 12))
            self.closeButton = NSButton.alloc().initWithFrame_(NSMakeRect(3, 5, 12, 14))
            self.closeButton.setImagePosition_(NSImageOnly)
            self.closeButton.setButtonType_(NSMomentaryChangeButton)
            self.closeButton.cell().setBezelStyle_(NSSmallSquareBezelStyle)
            self.closeButton.setBordered_(False)
            self.closeButton.setImage_(self.closeIcon)
            self.closeButton.setAutoresizingMask_(NSViewMaxXMargin|NSViewMaxYMargin)
            self.closeButton.setHidden_(True)
            self.addSubview_(self.closeButton)

            self.switcher = switcher
            self.item = item
        return self
    def initWithFrame_transfer_(self, frame, transfer):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.transfer = transfer
            NotificationCenter().add_observer(self, sender=transfer)

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            filename = self.transfer.file_path

            if type(self.transfer) == OutgoingPushFileTransferHandler:
                self.fromText.setStringValue_(u"To:  %s" % self.transfer.account.id)
            else:
                if filename.endswith(".download"):
                    filename = filename[:-len(".download")]
                self.fromText.setStringValue_(u"From:  %s" % self.transfer.account.id)
            self.nameText.setStringValue_(os.path.basename(filename))

            if os.path.exists(filename):
                self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(filename))
            else:
                tmp_folder = ApplicationData.get('.tmp_file_transfers')
                if not os.path.exists(tmp_folder):
                    os.mkdir(tmp_folder, 0700)

                tmpf = tmp_folder + "/tmpf" + os.path.splitext(filename)[1]
                open(tmpf, "w+").close()
                self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(tmpf))
                os.remove(tmpf)

            self.updateProgressInfo()
            self.progressBar.setIndeterminate_(True)
            self.progressBar.startAnimation_(None)
            self.progressBar.setHidden_(True)

            self.checksumProgressBar.setIndeterminate_(False)
            self.checksumProgressBar.startAnimation_(None)
            self.checksumProgressBar.setHidden_(False)

            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.originalHeight = NSHeight(frame)
        return self
    def initWithFrame_oldTransfer_(self, frame, transferInfo):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.oldTransferInfo = transferInfo
            self.file_path = transferInfo.file_path
            self.remote_uri = transferInfo.remote_uri
            self.local_uri = transferInfo.local_uri

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(
                self.file_path))

            self.nameText.setStringValue_(os.path.basename(self.file_path))
            self.fromText.setStringValue_(
                'To %s from account %s' %
                (transferInfo.remote_uri,
                 transferInfo.local_uri) if transferInfo.direction ==
                'outgoing' else 'From %s to account %s' %
                (transferInfo.remote_uri, transferInfo.local_uri))

            self.revealButton.setHidden_(not os.path.exists(self.file_path))

            time_print = format_date(transferInfo.time)
            if transferInfo.status == "completed":
                self.sizeText.setTextColor_(NSColor.blueColor())
                t = NSLocalizedString("Completed transfer of ", "Label")
                status = t + "%s %s" % (format_size(transferInfo.file_size,
                                                    1024), time_print)
            else:
                self.sizeText.setTextColor_(NSColor.redColor())
                status = "%s %s" % (transferInfo.status.title(), time_print)

            self.sizeText.setStringValue_(status)
            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.relayoutForDone()
            if transferInfo.direction == "outgoing" and transferInfo.status != "completed" and os.path.exists(
                    self.file_path):
                self.retryButton.setHidden_(False)
            self.done = True
        return self
    def initWithSwitcher_item_(self, switcher, item):
        self = NSView.initWithFrame_(self, NSMakeRect(0, 2, 100, 18))
        if self:
            self.closeIcon.setSize_(NSMakeSize(12, 12))
            self.closeButton = NSButton.alloc().initWithFrame_(
                NSMakeRect(3, 5, 12, 14))
            self.closeButton.setImagePosition_(NSImageOnly)
            self.closeButton.setButtonType_(NSMomentaryChangeButton)
            self.closeButton.cell().setBezelStyle_(NSSmallSquareBezelStyle)
            self.closeButton.setBordered_(False)
            self.closeButton.setImage_(self.closeIcon)
            self.closeButton.setAutoresizingMask_(NSViewMaxXMargin
                                                  | NSViewMaxYMargin)
            self.closeButton.setHidden_(True)
            self.addSubview_(self.closeButton)

            self.switcher = switcher
            self.item = item
        return self
    def initWithFrame_(self, frame):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.items = []

            self.leftButton = NSButton.alloc().initWithFrame_(NSMakeRect(0, 0, 20, 20))
            self.leftButton.setTarget_(self)
            self.leftButton.setAction_("scrollLeft:")
            self.leftButton.setImage_(NSImage.imageNamed_("NSLeftFacingTriangleTemplate"))
            self.leftButton.setHidden_(True)
            self.leftButton.cell().setBezelStyle_(NSShadowlessSquareBezelStyle)
            self.addSubview_(self.leftButton)

            self.rightButton = NSButton.alloc().initWithFrame_(NSMakeRect(0, 0, 20, 20))
            self.rightButton.setTarget_(self)
            self.rightButton.setAction_("scrollRight:")
            self.rightButton.setImage_(NSImage.imageNamed_("NSRightFacingTriangleTemplate"))
            self.rightButton.setHidden_(True)
            self.rightButton.cell().setBezelStyle_(NSShadowlessSquareBezelStyle)
            self.addSubview_(self.rightButton)

        return self
 def drawRect_(self, rect):
     gradient = NSGradient.alloc().initWithColors_(
                 [NSColor.colorWithDeviceRed_green_blue_alpha_(121/256.0, 121/256.0, 121/256.0, 1),
                  NSColor.colorWithDeviceRed_green_blue_alpha_(111/256.0, 111/256.0, 111/256.0, 1)])
     gradient.drawInRect_angle_(rect, 90.0)
     NSView.drawRect_(self, rect)
 def mouseDown_(self, event):
     if event.clickCount() == 2:
         self.activateFile_(None)
     else:
         NSView.mouseDown_(self, event)
 def mouseDown_(self, event):
     if event.clickCount() == 2:
         self.activateFile_(None)
     else:
         NSView.mouseDown_(self, event)