def awakeFromNib(self):
        # Initialise our session and selected state parameters
        self.session = None
        self.columns = [[]]
        self.selectedResource = None
        self.selectedDetails = None
        self.selectedData = None

        # Cache some useful icons
        self.fileImage = NSWorkspace.sharedWorkspace().iconForFileType_(
            NSPlainFileType)
        self.fileImage.setSize_(NSSize(16, 16))
        self.directoryImage = NSWorkspace.sharedWorkspace().iconForFile_(
            "/usr/")
        self.directoryImage.setSize_(NSSize(16, 16))

        # Initialise the toolbar
        self._toolbarItems = {}
        self._toolbarDefaultItemIdentifiers = []
        self._toolbarAllowedItemIdentifiers = []
        self.createToolbar()

        # Set up browser view
        container = self.mainSplitterView.subviews()[0]
        container.addSubview_(self.columnView)
        container.addSubview_(self.listView)
        self.currentBrowserView = None
        self.setBrowserView(self.BROWSERVIEW_COLUMNS)
        self.browser.setMaxVisibleColumns_(7)
        self.browser.setMinColumnWidth_(150)

        # Set up data view
        container = self.mainSplitterView.subviews()[1]
        container.addSubview_(self.propertiesView)
        container.addSubview_(self.dataView)
        self.currentDataView = None
        self.setDataView(self.DATAVIEW_PROPERTIES)
        self.text.setString_("")

        self.pathLabel.setStringValue_("No server specified")

        # Get preferences
        lastServer = NSUserDefaults.standardUserDefaults().stringForKey_(
            "LastServer")
        if lastServer and len(lastServer):
            self.serverText.setStringValue_(lastServer)
        lastPath = NSUserDefaults.standardUserDefaults().stringForKey_(
            "LastPath")
        if lastPath and len(lastPath):
            self.pathText.setStringValue_(lastPath)
        else:
            self.pathText.setStringValue_("/")
        lastUser = NSUserDefaults.standardUserDefaults().stringForKey_(
            "LastUser")
        if lastUser and len(lastUser):
            self.userText.setStringValue_(lastUser)
Exemple #2
0
    def draw_texture(self, texture, location, scale):
        ''' Draws the texture into this build's graphics context
        at the location, to the given scale.

        self.render() needs to a call parent of this method, in order
        to set up the Cocoa graphics context for the draw calls to work

        texture: a Texture object
        location: (tx, ty) tuple
        scale: (sx, sy) tuple
        '''

        tx, ty = location
        sx, sy = scale

        # Cache all assets so we don't frequently reload our PDFs.
        path = texture.path()
        if path in Build._asset_cache:
            tex = Build._asset_cache[path].copy()
        else:
            tex = NSImage.alloc().initWithContentsOfFile_(path)
            Build._asset_cache[path] = tex.copy()

        if isinstance(texture, TextureWithIndex):
            rep = tex.representations()[0]
            rep.setCurrentPage_(texture.index())

        # TODO: support opacity
        if (sx != 1 or sy != 1):
            #tex = tex.resize((sx, sy))
            tex.setSize_(NSSize(sx, sy))

        # Cocoa uses inverted Y-axis...
        ty_ = self.kpf.height - tex.size().height - ty
        tex.drawAtPoint_fromRect_operation_fraction_(NSPoint(tx, ty_), NSZeroRect, NSCompositeSourceOver, 1.0)
 def initWithContentRect_styleMask_backing_defer_(self, contentRect, aStyle, bufferingType, flag):
     self = objc.super(BorderlessRoundWindow, self).initWithContentRect_styleMask_backing_defer_(contentRect, aStyle, bufferingType, flag)
     if self:
         self.setStyleMask_(NSBorderlessWindowMask|NSResizableWindowMask)
         self.setOpaque_(False)
         self.setBackgroundColor_(NSColor.clearColor())
         self.setMinSize_(NSSize(100, 50))
         return self
Exemple #4
0
 def __init__(self, value=50, min_value=0, max_value=100, callback=None, dimensions=(180, 15)):
     self._slider = NSSlider.alloc().init()
     self._slider.setMinValue_(min_value)
     self._slider.setMaxValue_(max_value)
     self._slider.setDoubleValue_(value)
     self._slider.setFrameSize_(NSSize(*dimensions))
     self._slider.setTarget_(NSApp)
     self._menuitem = NSMenuItem.alloc().init()
     self._menuitem.setTarget_(NSApp)
     self._menuitem.setView_(self._slider)
     self.set_callback(callback)
Exemple #5
0
def start_taskbar():
    t = NSStatusBar.systemStatusBar()
    icon = t.statusItemWithLength_(NSVariableStatusItemLength)
    icon.setHighlightMode_(1)
    menuitems = []
    labels = ["Open", "Logout", "Quit"]
    if patch.current.current == "DEV" or patch.config.branch == "master":
        labels = ["Open", "Logout", "Restart", "Test", "Quit"]
    for label in labels:
        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            localize._X(label),
            label.lower().replace(" ", "").split(" ")[0] + ":", "")

        iconpath = os.path.join(settings.menuiconfolder,
                                label.lower() + ".icns")
        if os.path.exists(iconpath):
            img = NSImage.alloc().initByReferencingFile_(iconpath)
            img.setSize_(NSSize(16, 16))
            item.setImage_(img)
        menuitems.append(item)

    menu = NSMenu.alloc().init()
    menu.setAutoenablesItems_(True)
    icon.setMenu_(menu)
    for m in menuitems:
        menu.addItem_(m)

    def set_image(path):
        taskbarimg = NSImage.alloc().initByReferencingFile_(path)
        taskbarimg.setSize_(NSSize(18, 18))
        icon.setImage_(taskbarimg)

    # taskbar icon switching
    @event.register("api:connected")
    def set_active(*_):
        set_image(settings.taskbaricon)

    @event.register("api:disconnected")
    @event.register("api:connection_error")
    def set_inactive(*_):
        set_image(settings.taskbaricon_inactive)

    set_image(settings.taskbaricon_inactive)
    icon.setEnabled_(True)

    @login.config.register('username')
    def _():
        item = menu.itemAtIndex_(0)
        item.setTitle_(login.config.username or "Open")
Exemple #6
0
def build_menu(labels):
    menu = NSMenu.alloc().init()
    menu.setAutoenablesItems_(True)
    for label in labels:
        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            localize._X(label),
            label.lower().replace(" ", "").split(" ")[0] + ":", "")

        iconpath = os.path.join(settings.menuiconfolder,
                                label.lower() + ".icns")
        if os.path.exists(iconpath):
            img = NSImage.alloc().initByReferencingFile_(iconpath)
            img.setSize_(NSSize(16, 16))
            item.setImage_(img)
        menu.addItem_(item)
    return menu
Exemple #7
0
 def zoom(self, z):
     self.getCanvasView().scaleUnitSquareToSize_((z, z))
     self.width = z * self.width
     self.height = z * self.height
     newSize = NSSize(self.width, self.height)
     self.getCanvasView().setFrameSize_(newSize)
Exemple #8
0
 def set_image(path):
     taskbarimg = NSImage.alloc().initByReferencingFile_(path)
     taskbarimg.setSize_(NSSize(18, 18))
     icon.setImage_(taskbarimg)