如何使用pyobjc在主窗口中加载视图?

时间:2010-11-22 00:32:02

标签: python cocoa pyobjc

我有一个包含7个按钮的工具栏的窗口,该窗口有一个空的子视图,当按下预先加载的淡入淡出时,它们应该从任何按钮放置所选视图。我的代码示例https://github.com/jyr/opentumblr-cocoa/blob/master/DashboardController.py

1 个答案:

答案 0 :(得分:0)

我在https://gist.github.com/718610中的解决方案:

"""
En una ventana muestra 7 vistas seleccionadas desde una barra de herramientas
"""

from Foundation import *
from AppKit import *
import objc

class DashboardController (NSViewController):

    def show(self):
        self.window = NSWindow.alloc().init()
        self.DashboardViewController = NSViewController.alloc().initWithNibName_bundle_("Dashboard", None)
        self.dashboardView = self.DashboardViewController.view()
    show = classmethod(show)

    def resetSubviews(self):
        for i in range(1, len(self.dashboardView.subviews())):
            self.dashboardView.subviews().removeObjectAtIndex_(i)

    @objc.IBAction
    def audio_(self, sender):
        self.resetSubviews()
        self.AudioViewController = NSViewController.alloc().initWithNibName_bundle_("Audio", None)
        self.audioView = self.AudioViewController.view()
        self.dashboardView.addSubview_(self.audioView)

    @objc.IBAction
    def chat_(self, sender):
        self.resetSubviews()
        self.ChatViewController = NSViewController.alloc().initWithNibName_bundle_("Chat", None)
        self.chatView = self.ChatViewController.view()
        self.dashboardView.addSubview_(self.chatView)

    @objc.IBAction
    def link_(self, sender):
        self.resetSubviews()
        self.LinkViewController = NSViewController.alloc().initWithNibName_bundle_("Link", None)
        self.linkView = self.LinkViewController.view()
        self.dashboardView.addSubview_(self.linkView)

    @objc.IBAction
    def logout_(self, sender):
        NSApp().terminate_(self)

    @objc.IBAction
    def photo_(self, sender):
        self.resetSubviews()
        self.PhotoViewController = NSViewController.alloc().initWithNibName_bundle_("Photo", None)
        self.photoView = self.PhotoViewController.view()
        self.dashboardView.addSubview_(self.photoView)

    @objc.IBAction
    def quote_(self, sender):
        self.resetSubviews()
        self.QuoteViewController = NSViewController.alloc().initWithNibName_bundle_("Quote", None)
        self.quoteView = self.QuoteViewController.view()
        self.dashboardView.addSubview_(self.quoteView)

    @objc.IBAction
    def text_(self, sender):
        self.resetSubviews()
        self.TextViewController = NSViewController.alloc().initWithNibName_bundle_("Text", None)
        self.textView = self.TextViewController.view()
        self.dashboardView.addSubview_(self.textView)

    @objc.IBAction
    def video_(self, sender):
        self.resetSubviews()
        self.VideoViewController = NSViewController.alloc().initWithNibName_bundle_("Video", None)
        self.videoView = self.VideoViewController.view()
        self.dashboardView.addSubview_(self.videoView)