⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.py

📁 属性sosuo算法
💻 PY
📖 第 1 页 / 共 3 页
字号:
        for i in range(0, int(tiles)):            x = self.backgroundLeftWidth + (i * self.backgroundCenterWidth)            self.backgroundCenter.compositeToPoint_operation_( (x, 0), NSCompositeSourceOver )        NSGraphicsContext.currentContext().restoreGraphicsState()    def progressSliderWasClicked(self, slider):        if app.controller.videoDisplay.isPlaying:            self.wasPlaying = True            self.renderer.pause()        self.renderer.setProgress(slider.floatValue())        self.renderer.interactivelySeeking = True        self.refresh_(nil)            def progressSliderWasDragged(self, slider):        self.renderer.setProgress(slider.floatValue())        self.refresh_(nil)            def progressSliderWasReleased(self, slider):        self.renderer.interactivelySeeking = False        if self.wasPlaying:            self.wasPlaying = False            self.renderer.play()###############################################################################class Slider (NibClassBuilder.AutoBaseClass):    def initWithFrame_(self, frame):        self = super(Slider, self).initWithFrame_(frame)        self.value = 0.0        self.showCursor = False        self.dragging = False        self.sliderWasClicked = None        self.sliderWasDragged = None        self.sliderWasReleased = None        return self    def setFloatValue_(self, value):        self.value = value        self.setNeedsDisplay_(YES)            def floatValue(self):        return self.value    def setShowCursor_(self, showCursor):        self.showCursor = showCursor    def drawRect_(self, rect):        self.drawTrack()        if self.showCursor:            self.drawCursor()    def drawTrack(self):        pass    def drawCursor(self):        x = (self.bounds().size.width - self.cursor.size().width) * self.value        self.cursor.compositeToPoint_operation_((abs(x)+0.5, 0), NSCompositeSourceOver)    def mouseDown_(self, event):        if self.showCursor:            location = self.convertPoint_fromView_(event.locationInWindow(), nil)            if NSPointInRect(location, self.bounds()):                self.dragging = True                self.setFloatValue_(self.getValueForClickLocation(location))                if self.sliderWasClicked is not None:                    self.sliderWasClicked(self)    def mouseDragged_(self, event):        if self.showCursor and self.dragging:            location = self.convertPoint_fromView_(event.locationInWindow(), nil)            self.setFloatValue_(self.getValueForClickLocation(location))            if self.sliderWasDragged is not None:                self.sliderWasDragged(self)    def mouseUp_(self, event):        if self.showCursor:            self.dragging = False            if self.sliderWasReleased is not None:                self.sliderWasReleased(self)            self.setNeedsDisplay_(YES)    def getValueForClickLocation(self, location):        min = self.cursor.size().width / 2.0        max = self.bounds().size.width - min        span = max - min        offset = location.x        if offset < min:            offset = min        elif offset > max:            offset = max        return (offset - min) / span###############################################################################class ProgressSlider (NibClassBuilder.AutoBaseClass):        def initWithFrame_(self, frame):        self = super(ProgressSlider, self).initWithFrame_(frame)        self.grooveContourColor = NSColor.colorWithCalibratedWhite_alpha_( 0.1, 0.3 )        self.grooveFillColor = NSColor.colorWithCalibratedWhite_alpha_( 0.5, 0.3 )        self.cursor = NSImage.alloc().initWithSize_((10,10))        self.cursor.lockFocus()        path = NSBezierPath.bezierPath()        path.moveToPoint_((0, 4.5))        path.lineToPoint_((4, 8))        path.lineToPoint_((8, 4.5))        path.lineToPoint_((4, 1))        path.closePath()        NSColor.colorWithCalibratedWhite_alpha_( 51/255.0, 1.0 ).set()        path.fill()        self.cursor.unlockFocus()        return self                    def drawTrack(self):        rect = self.bounds()        rect = NSOffsetRect(rect, 0.5, 0.5)        rect.size.width -= 1        rect.size.height -= 1        self.grooveFillColor.set()        NSBezierPath.fillRect_(rect)        self.grooveContourColor.set()        NSBezierPath.strokeRect_(rect)        ###############################################################################class MetalSlider (NibClassBuilder.AutoBaseClass):    def awakeFromNib(self):        oldCell = self.cell()        newCell = MetalSliderCell.alloc().init()        newCell.setState_(oldCell.state())        newCell.setEnabled_(oldCell.isEnabled())        newCell.setFloatValue_(oldCell.floatValue())        newCell.setTarget_(oldCell.target())        newCell.setAction_(oldCell.action())        self.setCell_(newCell)###############################################################################class MetalSliderCell (NSSliderCell):    def init(self):        self = super(MetalSliderCell, self).init()        self.knob = NSImage.imageNamed_('volume_knob')        self.knobSize = self.knob.size()        return self    def knobRectFlipped_(self, flipped):        value = self.floatValue()        course = self.controlView().bounds().size.width - self.knobSize.width        origin = NSPoint(course * value, 0)        return ( origin, (self.knobSize.width, self.controlView().bounds().size.height) )    def drawKnob_(self, rect):        self.controlView().lockFocus()        location = NSPoint(rect.origin.x, rect.origin.y + rect.size.height + 1)        if self.isEnabled():            self.knob.compositeToPoint_operation_(location, NSCompositeSourceOver)        else:            self.knob.dissolveToPoint_fraction_(location, 0.5)        self.controlView().unlockFocus()###############################################################################class VideoSearchField (NibClassBuilder.AutoBaseClass):    def awakeFromNib(self):        self.setCell_(VideoSearchFieldCell.alloc().initWithCell_(self.cell()))        self.setTarget_(self)        self.setAction_('search:')        self.initFromLastEngine()            def search_(self, sender):        engine = self.selectedEngine()        query = str(self.stringValue())        if query is not '':            eventloop.addIdle(lambda:app.controller.performSearch(engine, query), 'Performing chrome search')    def initFromLastEngine(self):        self.setStringValue_(searchengines.getLastQuery())        lastEngine = searchengines.getLastEngine()        for engine in views.searchEngines:            if engine.name == lastEngine:                index = self.searchMenuTemplate().indexOfItemWithRepresentedObject_(engine)                self.searchMenuTemplate().performActionForItemAtIndex_(index)                return    def selectedEngine(self):        return self.cell().currentItem.representedObject().name        ###############################################################################class VideoSearchFieldCell (NSSearchFieldCell):        def initWithCell_(self, cell):        self = super(VideoSearchFieldCell, self).initTextCell_('')        self.setBezeled_(cell.isBezeled())        self.setBezelStyle_(cell.bezelStyle())        self.setEnabled_(cell.isEnabled())        self.setPlaceholderString_(cell.placeholderString())        self.setEditable_(cell.isEditable())        self.setSearchButtonCell_(cell.searchButtonCell())        self.setCancelButtonCell_(cell.cancelButtonCell())        self.cancelButtonCell().setTarget_(self)        self.setSearchMenuTemplate_(self.makeSearchMenuTemplate())        self.setSendsWholeSearchString_(YES)        self.setScrollable_(YES)        self.currentItem = nil        return self        def makeSearchMenuTemplate(self):        menu = NSMenu.alloc().init()        for engine in reversed(views.searchEngines):            nsitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(engine.title, 'selectEngine:', '')            nsitem.setTarget_(self)            nsitem.setImage_(_getEngineIcon(engine))            nsitem.setRepresentedObject_(engine)            menu.insertItem_atIndex_(nsitem, 0)        return menu    def selectEngine_(self, sender):        if self.currentItem is not nil:            self.currentItem.setState_(NSOffState)        self.currentItem = sender        sender.setState_(NSOnState)        engine = sender.representedObject()        self.searchButtonCell().setImage_(_getSearchIcon(engine))        def searchButtonRectForBounds_(self, bounds):        return NSRect(NSPoint(8.0, 3.0), NSSize(25.0, 16.0))            def searchTextRectForBounds_(self, bounds):        cancelButtonBounds = super(VideoSearchFieldCell, self).cancelButtonRectForBounds_(bounds)        searchButtonBounds = self.searchButtonRectForBounds_(bounds)        x = searchButtonBounds.origin.x + searchButtonBounds.size.width + 2        width = bounds.size.width - x - cancelButtonBounds.size.width        return ((x, 3.0), (width, 16.0))###############################################################################def _getEngineIcon(engine):    engineIconPath = resources.path('images/search_icon_%s.png' % engine.name)    return NSImage.alloc().initByReferencingFile_(engineIconPath)searchIcons = dict()def _getSearchIcon(engine):    if engine.name not in searchIcons:        searchIcons[engine.name] = _makeSearchIcon(engine)    return searchIcons[engine.name]        def _makeSearchIcon(engine):    popupRectangle = NSImage.imageNamed_('search_popup_rectangle')    popupRectangleSize = popupRectangle.size()    engineIconPath = resources.path('images/search_icon_%s.png' % engine.name)    engineIcon = NSImage.alloc().initByReferencingFile_(engineIconPath)    engineIconSize = engineIcon.size()    searchIconSize = (engineIconSize.width + popupRectangleSize.width + 2, engineIconSize.height)    searchIcon = NSImage.alloc().initWithSize_(searchIconSize)        searchIcon.lockFocus()    try:        engineIcon.compositeToPoint_operation_((0,0), NSCompositeSourceOver)        popupRectangleX = engineIconSize.width + 2        popupRectangleY = (engineIconSize.height - popupRectangleSize.height) / 2        popupRectangle.compositeToPoint_operation_((popupRectangleX, popupRectangleY), NSCompositeSourceOver)    finally:        searchIcon.unlockFocus()    return searchIcon    ###############################################################################

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -