Ejemplo n.º 1
0
def openSplash():
    global splash
    splash = NSWindow.alloc()
    rect = NSMakeRect(0,0,240,420)
    styleMask = 0
    splash.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False)

    # http://stackoverflow.com/questions/19437580/splash-screen-in-osx-cocoa-app

    splashImage = NSImageView.alloc().initWithFrame_(rect)
    splashImage.setImageScaling_(NSScaleToFit)
    splashImage.setImage_(NSImage.imageNamed_('ottosplash.png'))
    #[customView addSubview:splashImage];

    #splash.setContentView_(webview)
    splash.setContentView_(splashImage)
    splash.setHasShadow_(True)
    splash.setOpaque_(False)
    splash.setBackgroundColor_(NSColor.clearColor())

    # xPos = NSWidth([[splashWindow screen] frame])/2 - NSWidth([splashWindow frame])/2;
    #CGFloat yPos = NSHeight([[splashWindow screen] frame])/2 - NSHeight([splashWindow frame])/2;
    #[splashWindow setFrame:NSMakeRect(xPos, yPos, NSWidth([splashWindow frame]), NSHeight([splashWindow frame])) display:YES];
    splash.center()
    splash.orderFrontRegardless()
Ejemplo n.º 2
0
def init():
    print "init ui cocoa"
    global browserwindow
    app = NSApplication.sharedApplication()
    app.setActivationPolicy_(1)
    start_taskbar()
    app.finishLaunching()
    _browserwindow = NSWindow.alloc()
    icon = NSImage.alloc().initByReferencingFile_(settings.mainicon)
    app.setApplicationIconImage_(icon)
    
    deleg = Delegate.alloc()
    deleg.init()
    app.setDelegate_(deleg)
    
    signal.signal(signal.SIGINT, mac_sigint)
    
    from .input import BrowserDelegate
    bd = BrowserDelegate.alloc()
    bd.init()
    browserwindow = draw_browser(_browserwindow, bd)
    from .... import ui
    ui.log.debug('using cocoa')
    atexit.register(exit)
    gevent_timer(deleg)
    ui.module_initialized.set()
    sys.exit = exit
    AppHelper.runEventLoop()
Ejemplo n.º 3
0
def init():
    print "init ui cocoa"
    global browserwindow
    app = NSApplication.sharedApplication()
    app.setActivationPolicy_(1)
    start_taskbar()
    app.finishLaunching()
    _browserwindow = NSWindow.alloc()
    icon = NSImage.alloc().initByReferencingFile_(settings.mainicon)
    app.setApplicationIconImage_(icon)

    deleg = Delegate.alloc()
    deleg.init()
    app.setDelegate_(deleg)

    signal.signal(signal.SIGINT, mac_sigint)

    from .input import BrowserDelegate
    bd = BrowserDelegate.alloc()
    bd.init()
    browserwindow = draw_browser(_browserwindow, bd)
    from .... import ui
    ui.log.debug('using cocoa')
    atexit.register(exit)
    gevent_timer(deleg)
    ui.module_initialized.set()
    sys.exit = exit
    AppHelper.runEventLoop()
Ejemplo n.º 4
0
def openAbout():
    global about
    global linkpolicy
    if not about:
        about = NSWindow.alloc()
        rect = Foundation.NSMakeRect(0,0,300,370)
        styleMask = NSTitledWindowMask | NSClosableWindowMask | \
            NSResizableWindowMask | NSMiniaturizableWindowMask
        about.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False)
        about.setTitle_('About Otto')
        #about.setBackgroundColor_(NSColor.blueColor()) # not working (try it on the webview instead)

        webview = WebKit.WebView.alloc()
        webview.initWithFrame_(rect)
        webview.setFrameLoadDelegate_(NSApp.delegate())

        respath = os.environ['RESOURCEPATH']
        pageurl = Foundation.NSURL.URLWithString_('file://'+respath+'/static/html/about.html')
        aboutreq = Foundation.NSURLRequest.requestWithURL_(pageurl)
        webview.mainFrame().loadRequest_(aboutreq)

        if not linkpolicy:
            linkpolicy = LinkPolicyDelegate.alloc().init()
        webview.setPolicyDelegate_(linkpolicy)

        about.setReleasedWhenClosed_(False)
        about.setContentView_(webview)

    if not about.isVisible():
      about.center()
      #about.display()
    about.orderFrontRegardless()
    about.makeKeyAndOrderFront_(None)
Ejemplo n.º 5
0
def openSplash():
    global splash
    splash = NSWindow.alloc()
    rect = NSMakeRect(0,0,240,420)
    styleMask = 0
    splash.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False)

    # http://stackoverflow.com/questions/19437580/splash-screen-in-osx-cocoa-app

    splashImage = NSImageView.alloc().initWithFrame_(rect)
    splashImage.setImageScaling_(NSScaleToFit)
    splashImage.setImage_(NSImage.imageNamed_('ottosplash.png'))
    #[customView addSubview:splashImage];

    #splash.setContentView_(webview)
    splash.setContentView_(splashImage)
    splash.setHasShadow_(True)
    splash.setOpaque_(False)
    splash.setBackgroundColor_(NSColor.clearColor())

    # xPos = NSWidth([[splashWindow screen] frame])/2 - NSWidth([splashWindow frame])/2;
    #CGFloat yPos = NSHeight([[splashWindow screen] frame])/2 - NSHeight([splashWindow frame])/2;
    #[splashWindow setFrame:NSMakeRect(xPos, yPos, NSWidth([splashWindow frame]), NSHeight([splashWindow frame])) display:YES];
    splash.center()
    splash.orderFrontRegardless()
Ejemplo n.º 6
0
    def dp_it(cls):
        # Create a new application instance ...
        pu_app = NSApplication.sharedApplication()

        # ... and create its delgate.  Note the use of the
        # Objective C constructors below, because Delegate
        # is a subcalss of an Objective C class, NSObject
        pu_delegate = WDelegate.alloc().init()
        # Tell the application which delegate object to use.
        pu_app.setDelegate_(pu_delegate)

        # Now we can can start to create the window ...
        pu_frame = ((0, 0), (350.0, 100.0))
        # (Don't worry about these parameters for the moment. They just specify
        # the type of window, its size and position etc)
        pu_window = NSWindow.alloc(
        ).initWithContentRect_styleMask_backing_defer_(pu_frame, 15, 2, 0)
        # ... tell it which delegate object to use (here it happens
        # to be the same delegate as the application is using)...
        pu_window.setDelegate_(pu_delegate)
        # ... and set some properties. Unicode strings are preferred.
        pu_window.setTitle_(GC_TONO_NM)
        # All set. Now we can show the window ...
        pu_window.center()
        pu_window.orderFrontRegardless()

        # ... and start the application
        AppHelper.runEventLoop()
Ejemplo n.º 7
0
def openAbout():
    global about
    global aboutpolicy
    if not about:
        about = NSWindow.alloc()
        rect = Foundation.NSMakeRect(0,0,300,370)
        styleMask = NSTitledWindowMask | NSClosableWindowMask | \
            NSResizableWindowMask | NSMiniaturizableWindowMask
        about.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False)
        about.setTitle_('About Otto')
        #about.setBackgroundColor_(NSColor.blueColor()) # not working (try it on the webview instead)

        webview = WebKit.WebView.alloc()
        webview.initWithFrame_(rect)
        webview.setFrameLoadDelegate_(NSApp.delegate())

        respath = os.environ['RESOURCEPATH']
        print 'respath =', respath
        pageurl = Foundation.NSURL.URLWithString_('file://'+respath+'/static/html/about.html')
        aboutreq = Foundation.NSURLRequest.requestWithURL_(pageurl)
        webview.mainFrame().loadRequest_(aboutreq)

        aboutpolicy = AboutPolicyDelegate.alloc().init()
        webview.setPolicyDelegate_(aboutpolicy)

        about.setReleasedWhenClosed_(False)
        about.setContentView_(webview)

    if not about.isVisible():
      about.center()
      #about.display()
    about.orderFrontRegardless()
    about.makeKeyAndOrderFront_(None)
Ejemplo n.º 8
0
def openMainWindow():
    global win
    global linkpolicy
    global selectfolderdelegate

    if win:
        #win.orderFrontRegardless()
        win.makeKeyAndOrderFront_(None)
        return

    #if win:
    #    del win

    # http://stackoverflow.com/questions/7221699/how-to-load-user-css-in-a-webkit-webview-using-pyobjc

    rect = Foundation.NSMakeRect(0,0,1020,800)
    win = NSWindow.alloc()
    styleMask = NSTitledWindowMask | NSClosableWindowMask | \
        NSResizableWindowMask | NSMiniaturizableWindowMask
    win.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False)
    win.setTitle_('Otto Audio Jukebox')
    win.center()
    win.setFrameAutosaveName_('mainWindow')
    win.setCollectionBehavior_(NSWindowCollectionBehaviorFullScreenPrimary)
    #win.setBackgroundColor_(NSColor.blackColor().set())  # doesn't seem to do anything

    webview = WebKit.WebView.alloc()
    webview.initWithFrame_(rect)

    #webview.preferences().setUserStyleSheetEnabled_(objc.YES)
    #print webview.preferences().userStyleSheetEnabled()
    #cssurl = Foundation.NSURL.URLWithString_('static/css/webview.css')
    #webview.preferences().setUserStyleSheetLocation_(cssurl)
    #print webview.preferences().userStyleSheetLocation()

    #webview.setCustomUserAgent_('Otto')
    webview.setApplicationNameForUserAgent_('Otto_OSX')  # client uses this to tell if they are running in our webview
    #anfua = webview.applicationNameForUserAgent()
    #print '%%%%%%%%%%%%%%%% appnameforUA', anfua
    #cua = webview.customUserAgent()
    #print '%%%%%%%%%%%%%%%% customUA', cua

    selectfolderdelegate = SelectFolderDelegate.alloc().init()
    webview.setUIDelegate_(selectfolderdelegate)

    pageurl = Foundation.NSURL.URLWithString_('http://localhost:8778/')
    req = Foundation.NSURLRequest.requestWithURL_(pageurl)
    webview.mainFrame().loadRequest_(req)
    #print '$$$$$$$$$$$$$$$$$$$$', webview.stringByEvaluatingJavaScriptFromString_('window.otto = window.otto || {}; otto.app = true;')

    if not linkpolicy:
        linkpolicy = LinkPolicyDelegate.alloc().init()
    webview.setPolicyDelegate_(linkpolicy)

    win.setReleasedWhenClosed_(False)
    win.setContentView_(webview)
    #win.display()
    win.orderFrontRegardless()
    win.makeKeyAndOrderFront_(None)
Ejemplo n.º 9
0
 def __init__(self, position, size):
     frame = ((position.x, position.y), (size.width, size.height))
     self.window = NSWindow.alloc()
     self.window.initWithContentRect_styleMask_backing_defer_(frame, NSTitledWindowMask | NSClosableWindowMask, 2,
                                                              False)
     self.window.setLevel_(3)
     self.window.setDelegate_(Delegate.instance())
     self.window.setContentSize_((size.width, size.height))
Ejemplo n.º 10
0
    def setupUI(self):
        self.statusbar = NSStatusBar.systemStatusBar()
        # Create the statusbar item
        self.statusitem = self.statusbar.statusItemWithLength_(NSVariableStatusItemLength)
        # Set initial image
        raw_data = base64.b64decode(''.join(GOAGENT_ICON_DATA.strip().splitlines()))
        self.image_data = NSData.dataWithBytes_length_(raw_data, len(raw_data))
        self.image = NSImage.alloc().initWithData_(self.image_data)
        self.statusitem.setImage_(self.image)
        # Let it highlight upon clicking
        self.statusitem.setHighlightMode_(1)
        # Set a tooltip
        self.statusitem.setToolTip_(GOAGENT_TITLE)

        # Build a very simple menu
        self.menu = NSMenu.alloc().init()
        # Show Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Show', 'show:', '')
        self.menu.addItem_(menuitem)
        # Hide Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Hide', 'hide2:', '')
        self.menu.addItem_(menuitem)
        # Rest Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Reload', 'reset:', '')
        self.menu.addItem_(menuitem)
        # Default event
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'exit:', '')
        self.menu.addItem_(menuitem)
        # Bind it to the status item
        self.statusitem.setMenu_(self.menu)

        # Console window
        frame = NSMakeRect(0,0,550,350)
        self.console_window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(frame, NSClosableWindowMask|NSTitledWindowMask, NSBackingStoreBuffered, False)
        self.console_window.setTitle_(GOAGENT_TITLE)
        self.console_window.setDelegate_(self)

        # Console view inside a scrollview
        self.scroll_view = NSScrollView.alloc().initWithFrame_(frame)
        self.scroll_view.setBorderType_(NSNoBorder)
        self.scroll_view.setHasVerticalScroller_(True)
        self.scroll_view.setHasHorizontalScroller_(False)
        self.scroll_view.setAutoresizingMask_(NSViewWidthSizable|NSViewHeightSizable)

        self.console_view = NSTextView.alloc().initWithFrame_(frame)
        self.console_view.setVerticallyResizable_(True)
        self.console_view.setHorizontallyResizable_(True)
        self.console_view.setAutoresizingMask_(NSViewWidthSizable)

        self.scroll_view.setDocumentView_(self.console_view)

        contentView = self.console_window.contentView()
        contentView.addSubview_(self.scroll_view)

        # Hide dock icon
        NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
Ejemplo n.º 11
0
def openNotices():
    global notices
    if not notices:
        notices = NSWindow.alloc()
        rect = Foundation.NSMakeRect(100,100,570,800)
        styleMask = NSTitledWindowMask | NSClosableWindowMask | \
            NSResizableWindowMask | NSMiniaturizableWindowMask
        notices.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False)
        notices.setFrameTopLeftPoint_( NSPoint(300, NSHeight(notices.screen().frame()) - 200) )
        notices.setTitle_('Otto Notices')
        #notices.setFrameAutosaveName_('noticesWindow')

        scrollview = NSScrollView.alloc().initWithFrame_(notices.contentView().frame())
        contentSize = scrollview.contentSize()
 
        scrollview.setBorderType_(NSNoBorder)
        scrollview.setHasVerticalScroller_(True)
        scrollview.setHasHorizontalScroller_(False)
        scrollview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable)

        textview = NSTextView.alloc()
        textview.initWithFrame_( NSMakeRect(0, 0, contentSize.width, contentSize.height) )
        textview.setMaxSize_(NSMakeSize(FLT_MAX, FLT_MAX))
        textview.setVerticallyResizable_(True)
        textview.setHorizontallyResizable_(False)
        textview.setAutoresizingMask_(NSViewWidthSizable)
        textview.textContainer().setContainerSize_(NSMakeSize(contentSize.width, FLT_MAX))
        textview.textContainer().setWidthTracksTextView_(True)
        textview.setEditable_(False)
        textview.setSelectable_(True)
        #textview.setBackgroundColor_(NSColor.blueColor())

        scrollview.setDocumentView_(textview)

        respath = os.environ['RESOURCEPATH']
        try:
            with codecs.open( os.path.join(respath, 'THIRD-PARTY-NOTICES'), 'r', 'utf-8') as f:
                noticestext = f.read()
        except IOError:
            noticestext = 'Could not read THIRD-PARTY-NOTICES file.'
        storage = textview.textStorage()
        nsstring = NSAttributedString.alloc().initWithString_(noticestext)
        storage.insertAttributedString_atIndex_(nsstring, 0)

        notices.setReleasedWhenClosed_(False)
        notices.setContentView_(scrollview)

    #if not notices.isVisible():
    #  notices.center()
    #  #notices.display()
    notices.orderFrontRegardless()
    notices.makeKeyAndOrderFront_(None)
    def createWindow(self) -> NSWindow:
        style = (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable
                 | NSWindowStyleMaskMiniaturizable
                 | NSWindowStyleMaskResizable)

        window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
            NSMakeRect(10, 10, 800, 600),  # Initial
            style,
            NSBackingStoreBuffered,
            False)
        window.setTitle_("My App")
        window.setLevel_(NSStatusWindowLevel)
        window.setFrameAutosaveName_("main-window")

        return window
Ejemplo n.º 13
0
    def test_020_do_parse_args(self):

        s = u'/Users/donb/Ashley+Roberts/'
        map ( lambda x: x == 2 , ('1', 'b', '4') )
    
        app = NSApplication.sharedApplication()
        obj = app
        
        # print "type(app) is", type(NSApplication), type(NSObject)
        
        printB("test_020", obj)

        printB("test_020 (second run)", obj)

        printB("test_020 (third run)", obj)
        
        win = NSWindow.alloc()

        win_frame = ((100.0, 350.0), (1000.0, 639.0))        
    
        # deferCreation
    
        # Specifies whether the window server creates a window device for the window immediately. 
        # When YES, the window server defers creating the window device until the window is moved onscreen. All display messages sent to the window or its views are postponed until the window is created, just before it’s moved onscreen.

        deferCreation = objc.YES
        # deferCreation = objc.NO

        win.initWithContentRect_styleMask_backing_defer_ (
                            win_frame, 
                                NSTitledWindowMask  |  NSClosableWindowMask | 
                                NSMiniaturizableWindowMask |    NSResizableWindowMask, # |  NSTexturedBackgroundWindowMask,
                            NSBackingStoreBuffered, 
                            deferCreation 
                        )   

        win.setTitle_ ('OpenWorld')
        win.setLevel_ (NSNormalWindowLevel) # 3)                   # floating window
        win.setCollectionBehavior_(1 << 7) # NSWindowCollectionBehaviorFullScreenPrimary

        # wf = win.frame()
        # x, y = wf.origin
        # width, height = wf.size
        # s = "origin=(x=%r y=%r) size=(width=%r height=%r)" % (x,y,width,height)

        win.setViewsNeedDisplay_(objc.NO)

        printB("Win", win, add=['frame'])
Ejemplo n.º 14
0
 def initWithImageDir_(self, imageDir):
     self = super(SickWindow, self).initWithContentRect_styleMask_backing_defer_(NSRect((0, 0), (self.WIDTH, self.HEIGHT)), NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask, NSBackingStoreBuffered, YES)
     if not self:
         return
     self.ani = None
     self.setContentView_(SickView.alloc().initWithFrame_imageDir_(NSRect((0, 0), (self.WIDTH, self.HEIGHT)), imageDir))
     self.setTitle_(u'X marks the spot')
     self.started = False
     self.fade_window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(NSRect(self.frame().origin, (self.WIDTH, self.HEIGHT)), NSBorderlessWindowMask, NSBackingStoreBuffered, YES)
     self.fade_window.setOpaque_(NO)
     self.fade_window.setLevel_(NSFloatingWindowLevel)
     self.fade_window.setIgnoresMouseEvents_(YES)
     self.fade_window.setAlphaValue_(0.0)
     self.fade_window.setContentView_(ColorView.alloc().initWithFrame_(NSRect((0, 0), (self.WIDTH, self.HEIGHT))))
     self.fade_window.orderFront_(self)
     self.fade_window.setReleasedWhenClosed_(NO)
     self.addChildWindow_ordered_(self.fade_window, NSWindowAbove)
     self.setReleasedWhenClosed_(NO)
     return self
Ejemplo n.º 15
0
    def preferences(self, _):
        if 'prefController' not in self.__dict__:
            # Initialize preference window
            rect = NSMakeRect(0, 0, 500, 500)
            window = NSWindow.alloc(
            ).initWithContentRect_styleMask_backing_defer_(
                rect, NSTitledWindowMask | NSClosableWindowMask,
                NSBackingStoreBuffered, False)
            window.setTitle_('Preference')
            window.center()
            self.prefController = PreferenceController.alloc().initWithWindow_(
                window)
            self.prefController.window().makeKeyWindow()
            # self.prefController.window().setLevel_(NSFloatingWindowLevel)
            self.prefController.window().orderFront_(self)
            self.prefController.setSettingChangedCallback_withArgs_(
                self.reloadSettings, [])

        if not self.prefController.window().isVisible():
            self.prefController.window().makeKeyAndOrderFront_(self)
Ejemplo n.º 16
0
def openLicense():
    global license
    if not license:
        license = NSWindow.alloc()
        rect = Foundation.NSMakeRect(100,100,570,440)
        #styleMask = NSTitledWindowMask | NSClosableWindowMask | \
        #    NSResizableWindowMask | NSMiniaturizableWindowMask
        styleMask = NSTitledWindowMask | NSClosableWindowMask | \
            NSMiniaturizableWindowMask
        license.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False)
        license.setTitle_('Otto License')
        #license.setBackgroundColor_(NSColor.blueColor()) # not working
        #license.setFrameAutosaveName_('licenseWindow')
        license.setFrameTopLeftPoint_( NSPoint(200, NSHeight(license.screen().frame()) - 100) )

        textview = NSTextView.alloc()
        textview.initWithFrame_(rect)
        textview.setEditable_(False)
        textview.setSelectable_(True)

        respath = os.environ['RESOURCEPATH']
        try:
            with codecs.open( os.path.join(respath, 'LICENSE'), 'r', 'utf-8') as f:
                licensetext = f.read()
        except IOError:
            licensetext = 'Could not read LICENSE file.'
        storage = textview.textStorage()
        nsstring = NSAttributedString.alloc().initWithString_(licensetext)
        storage.insertAttributedString_atIndex_(nsstring, 0)

        license.setReleasedWhenClosed_(False)
        license.setContentView_(textview)

    #if not license.isVisible():
    #  license.center()
    #  #license.display()
    license.orderFrontRegardless()
    license.makeKeyAndOrderFront_(None)
Ejemplo n.º 17
0
        def _run_progress(comm_queue, message_txt, title_txt, use_bar):
            from AppKit import NSBundle, NSApplication, NSWindow, NSApp, NSScreen, NSMakeRect, NSMakePoint, NSProgressIndicator, NSWindow, \
                               NSTitledWindowMask, NSBackingStoreBuffered, NSProgressIndicatorPreferredAquaThickness, NSTextField, \
                               NSStatusWindowLevel, NSProgressIndicatorBarStyle, NSProgressIndicatorSpinningStyle, NSObject, \
                               NSApplicationDefined, NSEvent, NSTimer, NSSmallControlSize

            class MainController(NSObject):
                timer = None

                def kickRunLoop(self):
                    event = NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(NSApplicationDefined, \
                                    NSMakePoint(0,0), 0, 0.0, 0, None, 0, 0, 0)
                    NSApp.postEvent_atStart_(event, True)

                def checkProcess_(self, timer):
                    if not comm_queue.empty():
                        # We Get Signal, Take Off Every Zig - er, time to shut down this forked process
                        # Clear the queue
                        while not comm_queue.empty():
                            ignore = comm_queue.get_nowait()
                        NSApp.stop_(None)
                        # After you stop the runloop, the app has to receive another event to determine the runloop stopped ...
                        self.kickRunLoop()

                def run(self):
                    # You could adjust the 1.0 here to how ever many seconds you wanted to wait between checks to terminate
                    self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                        1.0, self, self.checkProcess_, None, True)
                    NSApp.activateIgnoringOtherApps_(True)
                    NSApp.run()

            # Evil hack to make this process not show in the Dock
            bundle = NSBundle.mainBundle()
            info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
            info['LSUIElement'] = '1'
            # Create our NSApplication instance
            app = NSApplication.sharedApplication()
            # Create a window, size doesn't matter now, we're going to resize it in the end
            window = NSWindow.alloc(
            ).initWithContentRect_styleMask_backing_defer_(
                NSMakeRect(0, 0, 500, 500), NSTitledWindowMask,
                NSBackingStoreBuffered, True)
            # Build the window from the bottom up
            # Create the progress indicator, placement doesn't matter, will be set later
            progress = NSProgressIndicator.alloc().init()
            if use_bar:
                progress.setStyle_(NSProgressIndicatorBarStyle)
            else:
                progress.setStyle_(NSProgressIndicatorSpinningStyle)
            progress.setUsesThreadedAnimation_(True)
            progress.setIndeterminate_(True)
            progress.startAnimation_(None)
            # Create the text, which will define the width of everything else - size doesn't matter at first...
            message = NSTextField.alloc().initWithFrame_(
                NSMakeRect(20, 50, 20, 20))
            message.setStringValue_(message_txt)
            message.setBezeled_(False)
            message.setDrawsBackground_(False)
            message.setEditable_(False)
            message.setSelectable_(False)
            # Resize the field to fit the text
            message.sizeToFit()
            window.contentView().addSubview_(message)
            # Now we can calculate the width
            # Fix the window geometry
            # A default NSAlert is 420x150, let's aim for something with similar geometry!
            frame = NSMakeRect(0, 0, max(420,
                                         message.frame().size.width + 40), 110)
            screen = NSScreen.mainScreen()
            screenFrame = screen.frame()
            # Fix the progressbar geometry
            if use_bar:
                # Set the bar to stretch the width of the dialog
                progress.setFrame_(
                    NSMakeRect(20, 20, frame.size.width - 40,
                               NSProgressIndicatorPreferredAquaThickness))
            else:
                # Center the spinning wheel at the bottom
                progress.setControlSize_(NSSmallControlSize)
                progress.setFrame_(
                    NSMakeRect((frame.size.width / 2) - 8, 20, 16, 16))
            window.contentView().addSubview_(progress)
            # Pleasant centering, 2/3rds of the way up, in the middle
            highCenterPoint = NSMakePoint(
                (screenFrame.size.width / 2) - (frame.size.width / 2),
                1.3 * (screenFrame.size.height / 2) - (frame.size.height / 2))
            window.setFrame_display_animate_(frame, True, False)
            window.setFrameOrigin_(highCenterPoint)
            window.makeKeyAndOrderFront_(None)
            window.setLevel_(NSStatusWindowLevel)
            window.setTitle_(title_txt)
            window.display()
            controller = MainController.alloc().init()
            controller.run()
Ejemplo n.º 18
0
    def __init__(self, *args, **kwds):
        if sys.platform.startswith("win"):
            kwds["style"] = wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP
        wx.Frame.__init__(self, *args, **kwds)
        self.Show()
        if wx.Platform == '__WXMAC__' and hasattr(self, 'MacGetTopLevelWindowRef'):
            try:
                from AppKit import NSWindow, NSApp, NSFloatingWindowLevel
                window_ref = self.MacGetTopLevelWindowRef()
                nsw = NSWindow.alloc().initWithWindowRef_(window_ref)
                nsw.setLevel_(NSFloatingWindowLevel)
            except ImportError:
                print "No AppKit module => can't make progress window stay on top."

        self.start_time = time.time()
        self.end_times = None
        self.current_module = None
        self.pause_start_time = None
        self.previous_pauses_duration = 0.

        # GUI stuff
        self.BackgroundColour = cellprofiler.preferences.get_background_color()
        self.tbicon = wx.TaskBarIcon()
        self.tbicon.SetIcon(get_cp_icon(), "CellProfiler2.0")
        self.SetTitle("CellProfiler %s"%(version.title_string))
        self.SetSize((640, 480))
        self.panel = wx.Panel(self, wx.ID_ANY)
        sizer = wx.BoxSizer(wx.VERTICAL)
        times_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.elapsed_control = wx.StaticText(self.panel, -1, 
                                             label=self.elapsed_label(), 
                                             style=wx.ALIGN_LEFT)
        self.remaining_control = wx.StaticText(self.panel, -1, 
                                               label=self.remaining_label(), 
                                               style=wx.ALIGN_RIGHT)
        times_sizer.Add(self.elapsed_control, 1, wx.ALIGN_LEFT | wx.ALL, 5)
        times_sizer.Add(self.remaining_control, 1, wx.ALIGN_RIGHT | wx.ALL, 5)
        sizer.Add(times_sizer, 0, wx.EXPAND)
        self.gauge = wx.Gauge(self.panel, -1, style=wx.GA_HORIZONTAL)
        self.gauge.SetValue(0)
        self.gauge.SetRange(100)
        sizer.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5)
        self.image_set_control = wx.StaticText(self.panel, -1, label=image_set_label(None, None))
        sizer.Add(self.image_set_control, 0, wx.LEFT | wx.RIGHT, 5)
        self.current_module_control = wx.StaticText(self.panel, -1, label=module_label(None))
        sizer.Add(self.current_module_control, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM, 5)
        buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.play_pause_button = wx.BitmapButton(self.panel, -1, 
                                                 bitmap=wx.BitmapFromImage(get_builtin_image('pause')))
        self.play_pause_button.SetToolTipString("Pause")
        buttons_sizer.Add(self.play_pause_button, 0, wx.ALL, 5)
        self.stop_button = wx.BitmapButton(self.panel, -1, bitmap=wx.BitmapFromImage(get_builtin_image('stop')))
        self.stop_button.SetToolTipString("Stop")
        buttons_sizer.Add(self.stop_button, 0, wx.ALL, 5)
        save_bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE,
                                               wx.ART_CMN_DIALOG, 
                                               (16,16))
        self.save_button = wx.BitmapButton(self.panel, -1, bitmap = save_bitmap)
        self.save_button.SetToolTipString("Save measurements")
        buttons_sizer.Add(self.save_button, 0, wx.ALL, 5)
        sizer.Add(buttons_sizer, 0, wx.CENTER)
        self.panel.SetSizer(sizer)
        sizer.Fit(self)

        # Timer that updates elapsed
        timer_id = wx.NewId()
        self.timer = wx.Timer(self.panel, timer_id)
        self.timer.Start(500)
        wx.EVT_TIMER(self.panel, timer_id, self.on_timer)
Ejemplo n.º 19
0
def main():

    app = NSApplication.sharedApplication()
    
    printB("App (init)", app, only=['acceptsFirstResponder', 'nextResponder']+
                ['activationPolicy','isActive', 'mainWindow', 'canEnterFullScreenMode','windows',
                                'currentSystemPresentationOptions', 'delegate', 'presentationOptions'])


    # oh give me a place in the dock, and allow activation…    
    app.setActivationPolicy_( NSApplicationActivationPolicyRegular    ) 
    
    # app.activateIgnoringOtherApps_(objc.YES)


    printB("App", app, only=['acceptsFirstResponder', 'nextResponder']+
                ['activationPolicy','isActive', 'mainWindow', 'canEnterFullScreenMode','windows',
                                'currentSystemPresentationOptions', 'delegate', 'presentationOptions'])


    delegate = AppDelegate.alloc().init()
    NSApp().setDelegate_(delegate)

    #
    #       Win
    #

    win = NSWindow.alloc()

    win_frame = ((100.0, 350.0), (1000.0, 639.0))        
    
    # deferCreation
    
    # Specifies whether the window server creates a window device for the window immediately. 
    # When YES, the window server defers creating the window device until the window is moved onscreen. All display messages sent to the window or its views are postponed until the window is created, just before it’s moved onscreen.

    deferCreation = objc.YES
    # deferCreation = objc.NO

    win.initWithContentRect_styleMask_backing_defer_ (
                        win_frame, 
                            NSTitledWindowMask  |  NSClosableWindowMask | 
                            NSMiniaturizableWindowMask |    NSResizableWindowMask, # |  NSTexturedBackgroundWindowMask,
                        NSBackingStoreBuffered, 
                        deferCreation 
                    )   

    win.setTitle_ ('OpenWorld')
    win.setLevel_ (NSNormalWindowLevel) # 3)                   # floating window
    win.setCollectionBehavior_(1 << 7) # NSWindowCollectionBehaviorFullScreenPrimary

    wf = win.frame()
    x, y = wf.origin
    width, height = wf.size
    s = "origin=(x=%r y=%r) size=(width=%r height=%r)" % (x,y,width,height)

    printB("Win", win, add=['frame'])
    win.setViewsNeedDisplay_(objc.NO)
    # print_setters(win)

    win_delegate = WinDelegate.alloc().init()
    win.setDelegate_(win_delegate)

    printB("WinDelegate", win_delegate)  # like AppDelegate


    AppHelper.runEventLoop()
Ejemplo n.º 20
0
    def setupUI(self):
        self.statusbar = NSStatusBar.systemStatusBar()
        # Create the statusbar item
        self.statusitem = self.statusbar.statusItemWithLength_(
            NSVariableStatusItemLength)
        # Set initial image
        raw_data = base64.b64decode(''.join(
            GOAGENT_ICON_DATA.strip().splitlines()))
        self.image_data = NSData.dataWithBytes_length_(raw_data, len(raw_data))
        self.image = NSImage.alloc().initWithData_(self.image_data)
        self.statusitem.setImage_(self.image)
        # Let it highlight upon clicking
        self.statusitem.setHighlightMode_(1)
        # Set a tooltip
        self.statusitem.setToolTip_(GOAGENT_TITLE)

        # Build a very simple menu
        self.menu = NSMenu.alloc().init()
        # Show Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Show', 'show:', '')
        self.menu.addItem_(menuitem)
        # Hide Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Hide', 'hide2:', '')
        self.menu.addItem_(menuitem)
        # Rest Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Reload', 'reset:', '')
        self.menu.addItem_(menuitem)
        # Default event
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Quit', 'exit:', '')
        self.menu.addItem_(menuitem)
        # Bind it to the status item
        self.statusitem.setMenu_(self.menu)

        # Console window
        frame = NSMakeRect(0, 0, 550, 350)
        self.console_window = NSWindow.alloc(
        ).initWithContentRect_styleMask_backing_defer_(
            frame, NSClosableWindowMask | NSTitledWindowMask,
            NSBackingStoreBuffered, False)
        self.console_window.setTitle_(GOAGENT_TITLE)
        self.console_window.setDelegate_(self)

        # Console view inside a scrollview
        self.scroll_view = NSScrollView.alloc().initWithFrame_(frame)
        self.scroll_view.setBorderType_(NSNoBorder)
        self.scroll_view.setHasVerticalScroller_(True)
        self.scroll_view.setHasHorizontalScroller_(False)
        self.scroll_view.setAutoresizingMask_(NSViewWidthSizable
                                              | NSViewHeightSizable)

        self.console_view = NSTextView.alloc().initWithFrame_(frame)
        self.console_view.setVerticallyResizable_(True)
        self.console_view.setHorizontallyResizable_(True)
        self.console_view.setAutoresizingMask_(NSViewWidthSizable)

        self.scroll_view.setDocumentView_(self.console_view)

        contentView = self.console_window.contentView()
        contentView.addSubview_(self.scroll_view)

        # Hide dock icon
        NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
Ejemplo n.º 21
0
    def __init__(self, *args, **kwds):
        if sys.platform.startswith("win"):
            kwds["style"] = wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP
        wx.Frame.__init__(self, *args, **kwds)
        self.Show()
        if wx.Platform == '__WXMAC__' and hasattr(self,
                                                  'MacGetTopLevelWindowRef'):
            try:
                from AppKit import NSWindow, NSApp, NSFloatingWindowLevel
                window_ref = self.MacGetTopLevelWindowRef()
                nsw = NSWindow.alloc().initWithWindowRef_(window_ref)
                nsw.setLevel_(NSFloatingWindowLevel)
            except ImportError:
                print "No AppKit module => can't make progress window stay on top."

        self.start_time = time.time()
        self.end_times = None
        self.current_module = None
        self.pause_start_time = None
        self.previous_pauses_duration = 0.

        # GUI stuff
        self.BackgroundColour = cellprofiler.preferences.get_background_color()
        self.tbicon = wx.TaskBarIcon()
        self.tbicon.SetIcon(get_cp_icon(), "CellProfiler2.0")
        self.SetTitle("CellProfiler %s" % (version.title_string))
        self.SetSize((640, 480))
        self.panel = wx.Panel(self, wx.ID_ANY)
        sizer = wx.BoxSizer(wx.VERTICAL)
        times_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.elapsed_control = wx.StaticText(self.panel,
                                             -1,
                                             label=self.elapsed_label(),
                                             style=wx.ALIGN_LEFT)
        self.remaining_control = wx.StaticText(self.panel,
                                               -1,
                                               label=self.remaining_label(),
                                               style=wx.ALIGN_RIGHT)
        times_sizer.Add(self.elapsed_control, 1, wx.ALIGN_LEFT | wx.ALL, 5)
        times_sizer.Add(self.remaining_control, 1, wx.ALIGN_RIGHT | wx.ALL, 5)
        sizer.Add(times_sizer, 0, wx.EXPAND)
        self.gauge = wx.Gauge(self.panel, -1, style=wx.GA_HORIZONTAL)
        self.gauge.SetValue(0)
        self.gauge.SetRange(100)
        sizer.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5)
        self.image_set_control = wx.StaticText(self.panel,
                                               -1,
                                               label=image_set_label(
                                                   None, None))
        sizer.Add(self.image_set_control, 0, wx.LEFT | wx.RIGHT, 5)
        self.current_module_control = wx.StaticText(self.panel,
                                                    -1,
                                                    label=module_label(None))
        sizer.Add(self.current_module_control, 0,
                  wx.LEFT | wx.RIGHT | wx.BOTTOM, 5)
        buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.play_pause_button = wx.BitmapButton(
            self.panel,
            -1,
            bitmap=wx.BitmapFromImage(get_builtin_image('pause')))
        self.play_pause_button.SetToolTipString("Pause")
        buttons_sizer.Add(self.play_pause_button, 0, wx.ALL, 5)
        self.stop_button = wx.BitmapButton(self.panel,
                                           -1,
                                           bitmap=wx.BitmapFromImage(
                                               get_builtin_image('stop')))
        self.stop_button.SetToolTipString("Stop")
        buttons_sizer.Add(self.stop_button, 0, wx.ALL, 5)
        save_bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE,
                                               wx.ART_CMN_DIALOG, (16, 16))
        self.save_button = wx.BitmapButton(self.panel, -1, bitmap=save_bitmap)
        self.save_button.SetToolTipString("Save measurements")
        buttons_sizer.Add(self.save_button, 0, wx.ALL, 5)
        sizer.Add(buttons_sizer, 0, wx.CENTER)
        self.panel.SetSizer(sizer)
        sizer.Fit(self)

        # Timer that updates elapsed
        timer_id = wx.NewId()
        self.timer = wx.Timer(self.panel, timer_id)
        self.timer.Start(500)
        wx.EVT_TIMER(self.panel, timer_id, self.on_timer)