Exemplo n.º 1
0
    def _nestedRunLoopReaderUntilEOLchars_(self, eolchars):
        """
        This makes the baby jesus cry.

        I want co-routines.
        """
        app = NSApplication.sharedApplication()
        window = self.textView.window()
        self.setCharacterIndexForInput_(self.lengthOfTextView())
        # change the color.. eh
        self.textView.setTypingAttributes_({
            NSFontAttributeName:
            self.font(),
            NSForegroundColorAttributeName:
            self.codeColor(),
        })
        while True:
            event = app.nextEventMatchingMask_untilDate_inMode_dequeue_(
                NSAnyEventMask, NSDate.distantFuture(), NSDefaultRunLoopMode,
                True)
            if (event.type() == NSKeyDown) and (event.window() == window):
                eol = event.characters()
                if eol in eolchars:
                    break
            app.sendEvent_(event)
        cl = self.currentLine()
        if eol == "\r":
            self.writeCode_("\n")
        return cl + eol
Exemplo n.º 2
0
    def _writeString_forOutput_(self, s, name):
        self.textView.textStorage().appendAttributedString_(getattr(self, name+'String_')(s))

        window = self.textView.window()
        app = NSApplication.sharedApplication()
        st = time.time()
        now = time.time

        if self._autoscroll:
            self.textView.scrollRangeToVisible_((self.lengthOfTextView(), 0))

        while app.isRunning() and now() - st < 0.01:
            event = app.nextEventMatchingMask_untilDate_inMode_dequeue_(
                NSUIntegerMax,
                NSDate.dateWithTimeIntervalSinceNow_(0.01),
                NSDefaultRunLoopMode,
                True)

            if event is None:
                continue

            if (event.type() == NSKeyDown) and (event.window() == window):
                chr = event.charactersIgnoringModifiers()
                if chr == 'c' and (event.modifierFlags() & NSControlKeyMask):
                    raise KeyboardInterrupt

            app.sendEvent_(event)
Exemplo n.º 3
0
    def _nestedRunLoopReaderUntilEOLchars_(self, eolchars):
        """
        This makes the baby jesus cry.

        I want co-routines.
        """
        app = NSApplication.sharedApplication()
        window = self.textView.window()
        self.setCharacterIndexForInput_(self.lengthOfTextView())
        # change the color.. eh
        self.textView.setTypingAttributes_({
            NSFontAttributeName:self.font(),
            NSForegroundColorAttributeName:self.codeColor(),
        })
        while True:
            event = app.nextEventMatchingMask_untilDate_inMode_dequeue_(
                NSUIntegerMax,
                NSDate.distantFuture(),
                NSDefaultRunLoopMode,
                True)
            if (event.type() == NSKeyDown) and (event.window() == window):
                eol = event.characters()
                if eol in eolchars:
                    break
            app.sendEvent_(event)
        cl = self.currentLine()
        if eol == '\r':
            self.writeCode_('\n')
        return cl+eol
Exemplo n.º 4
0
    def _writeString_forOutput_(self, s, name):
        self.textView.textStorage().appendAttributedString_(
            getattr(self, name + "String_")(s))

        window = self.textView.window()
        app = NSApplication.sharedApplication()
        st = time.time()
        now = time.time

        if self._autoscroll:
            self.textView.scrollRangeToVisible_((self.lengthOfTextView(), 0))

        while app.isRunning() and now() - st < 0.01:
            event = app.nextEventMatchingMask_untilDate_inMode_dequeue_(
                NSAnyEventMask,
                NSDate.dateWithTimeIntervalSinceNow_(0.01),
                NSDefaultRunLoopMode,
                True,
            )

            if event is None:
                continue

            if (event.type() == NSKeyDown) and (event.window() == window):
                chr = event.charactersIgnoringModifiers()
                if chr == "c" and (event.modifierFlags() & NSControlKeyMask):
                    raise KeyboardInterrupt

            app.sendEvent_(event)
Exemplo n.º 5
0
def main():
    try:
        from PyObjCTools import AppHelper
        from Cocoa import NSApplication
    except ImportError:
        raise
    app = NSApplication.sharedApplication(); app
    viewController = _initiate_the_contrller_with_an_xib()
    viewController.showWindow_(viewController)
    _bring_app_to_the_top()
    AppHelper.runEventLoop()
Exemplo n.º 6
0
def main():
    app = NSApplication.sharedApplication()

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

    win = NSWindow.alloc()
    frame = ((200.0, 300.0), (250.0, 100.0))
    win.initWithContentRect_styleMask_backing_defer_(frame, 15, 2, 0)
    win.setTitle_("HelloWorld")

    app.run()
Exemplo n.º 7
0
def main():
    app = NSApplication.sharedApplication()

    # we must keep a reference to the delegate object ourselves,
    # NSApp.setDelegate_() doesn't retain it. A local variable is
    # enough here.
    delegate = AppDelegate.alloc().init()
    NSApp().setDelegate_(delegate)

    win = NSWindow.alloc()
    frame = ((200.0, 300.0), (250.0, 100.0))
    win.initWithContentRect_styleMask_backing_defer_(frame, 15, 2, 0)
    win.setTitle_("HelloWorld")
    win.setLevel_(3)  # floating window

    hel = NSButton.alloc().initWithFrame_(((10.0, 10.0), (80.0, 80.0)))
    win.contentView().addSubview_(hel)
    hel.setBezelStyle_(4)
    hel.setTitle_("Hello!")
    hel.setTarget_(app.delegate())
    hel.setAction_("sayHello:")

    beep = NSSound.alloc()
    beep.initWithContentsOfFile_byReference_(
        "/System/Library/Sounds/Tink.Aiff", 1)
    hel.setSound_(beep)

    bye = NSButton.alloc().initWithFrame_(((100.0, 10.0), (80.0, 80.0)))
    win.contentView().addSubview_(bye)
    bye.setBezelStyle_(4)
    bye.setTarget_(app)
    bye.setAction_("stop:")
    bye.setEnabled_(1)
    bye.setTitle_("Goodbye!")

    adios = NSSound.alloc()
    adios.initWithContentsOfFile_byReference_(
        "/System/Library/Sounds/Basso.aiff", 1)
    bye.setSound_(adios)

    win.display()
    win.orderFrontRegardless()  # but this one does

    AppHelper.runEventLoop()
Exemplo n.º 8
0
def doTest():
    alertPanel = None
    modalSession = None
    app = NSApplication.sharedApplication()
    try:
        alertPanel = NSGetInformationalAlertPanel("Please wait", "Bla bla bla",
                                                  None, None, None)
        modalSession = app.beginModalSessionForWindow_(alertPanel)

        print(modalSession, modalSession.__pointer__)
        time.sleep(1)
    finally:
        if modalSession is not None:
            app.endModalSession_(modalSession)
            modalSession = None

        if alertPanel is not None:
            NSReleaseAlertPanel(alertPanel)
            alertPanel = None
Exemplo n.º 9
0
def simpleVLCplay(player, title=_argv0, video='', timeout=None):
    '''Create a minimal NS application, drawable window and basic menu
       for the given VLC player (with media) and start the player.

       @note: This function never returns, but the VLC player and
              other Python thread(s) do run.
    '''
    if not player:
        raise ValueError('%s invalid: %r' % ('player', player))

    app = NSApplication.sharedApplication()
    nsBundleRename(NSStr(title))  # top-level menu title

    dlg = _NSDelegate.alloc().init()
    dlg.app = app
    dlg.player = player
    dlg.title = title or _argv0
    dlg.video = video or basename(player.get_media().get_mrl())
    app.setDelegate_(dlg)

    terminating(app, timeout)
    app.run()  # never returns
Exemplo n.º 10
0
    def __init__(self):
        app = NSApplication.sharedApplication()

        self.screen_window = app.windows()[0]

        self.screen_window.setStyleMask_(0)
        self.screen_window.setHasShadow_(False)

        frame = self.screen_window.frame()
        frame.origin = self.image_window.frame().origin
        frame.origin.x += 61
        frame.origin.y += 72
        self.screen_window.setFrame_display_(frame, False)

        self.image_window.makeKeyAndOrderFront_(None)
        self.image_window.addChildWindow_ordered_(self.screen_window, 1)

        image_window_frame = self.image_window.frame().copy()
        if 'TIDE_WINDOW_FRAME' in os.environ:
            left, top, width, height = (
                float(x) for x in os.environ['TIDE_WINDOW_FRAME'].split(','))
            # image_window_frame.
            print left, top, width, height

            image_window_left = left + width + 20
            image_window_top = top + height / 2 + 180

            self.image_window.cascadeTopLeftFromPoint_(
                CGPointMake(image_window_left, image_window_top))
        else:
            self.image_window.center()

        def window_did_close(notification):
            app.terminate_(None)

        NSNotificationCenter.defaultCenter(
        ).addObserverForName_object_queue_usingBlock_(
            "NSWindowDidCloseNotification", self.image_window, None,
            window_did_close)
Exemplo n.º 11
0
    def __init__(self):
        app = NSApplication.sharedApplication()

        self.screen_window = app.windows()[0]

        self.screen_window.setStyleMask_(0)
        self.screen_window.setHasShadow_(False)

        frame = self.screen_window.frame()
        frame.origin = self.image_window.frame().origin
        frame.origin.x += 61
        frame.origin.y += 72
        self.screen_window.setFrame_display_(frame, False)

        self.image_window.makeKeyAndOrderFront_(None)
        self.image_window.addChildWindow_ordered_(self.screen_window, 1)

        image_window_frame = self.image_window.frame().copy()
        if 'TIDE_WINDOW_FRAME' in os.environ:
            left, top, width, height = (float(x) for x in os.environ['TIDE_WINDOW_FRAME'].split(','))
            # image_window_frame.
            print left, top, width, height

            image_window_left = left + width + 20
            image_window_top = top + height/2 + 180

            self.image_window.cascadeTopLeftFromPoint_(CGPointMake(image_window_left, image_window_top))
        else:
            self.image_window.center()

        def window_did_close(notification):
            app.terminate_(None)

        NSNotificationCenter.defaultCenter().addObserverForName_object_queue_usingBlock_(
            "NSWindowDidCloseNotification",
            self.image_window,
            None,
            window_did_close)
Exemplo n.º 12
0
Arquivo: my.py Projeto: bbonf/dotchili
import os
import time
import subprocess
import pytz
import datetime

last_key = 0
last_break = 0

def key_pressed(char, mask):
    global last_key
    last_key = time.time()

from Cocoa import NSApplication
NSApplication.sharedApplication().delegate().register_key_hook(key_pressed)

@command('echo')
def echo(text):
    chili.ui.prompt(text)

@command('say')
def say(text):
    os.system('say %s' % text)

@every(60)
def check_breaks(done, _):
    global last_key, last_break
    if last_key < last_break:
        print 'still in break'
Exemplo n.º 13
0
def main():
    app = NSApplication.sharedApplication()
    delegate = AppDelegate.alloc().init()
    NSApp().setDelegate_(delegate)
    print 'loading'
    AppHelper.runEventLoop()
Exemplo n.º 14
0
import time
import subprocess
import pytz
import datetime

last_key = 0
last_break = 0


def key_pressed(char, mask):
    global last_key
    last_key = time.time()


from Cocoa import NSApplication
NSApplication.sharedApplication().delegate().register_key_hook(key_pressed)


@command('echo')
def echo(text):
    chili.ui.prompt(text)


@command('say')
def say(text):
    os.system('say %s' % text)


@every(60)
def check_breaks(done, _):
    global last_key, last_break
Exemplo n.º 15
0
    def syncop_(self, sender):
        self.appendText_('Sync text')

    @objc.IBAction
    def asyncop_(self, sender):
        asyncio.create_task(self.asynctask())

    @objc.IBAction
    def clear_(self, sender):
        self.textview.setString_('')

    def appendText_(self, text):
        old = self.textview.string()
        self.textview.setString_(old + text + '\n')
        self.textview.scrollToEndOfDocument_(None)


if __name__ == "__main__":
    app = NSApplication.sharedApplication()
    viewController = GuiDemo.alloc().initWithWindowNibName_("guidemo")
    viewController.showWindow_(viewController)
    NSApp.activateIgnoringOtherApps_(True)

    # Configure asyncio to use CoreFoundationEventLoop
    loop = CoreFoundationEventLoop()
    asyncio.set_event_loop(loop)
    try:
        loop.run_forever()
    finally:
        loop.close()
Exemplo n.º 16
0
    def awakeFromNib(self):
        NSLog('awakeFromNib')

    def windowDidLoad(self):
        NSWindowController.windowDidLoad(self)
        NSLog('windowDidLoad')

    def windowShouldClose_(self, sender):
        NSLog('windowShouldClose')
        return True

    def windowWillClose_(self, notification):
        NSLog('windowWillClose')
        AppHelper.stopEventLoop()

    def applicationShouldTerminateAfterLastWindowClosed_(self, sender):
        NSLog('applicationShouldTerminateAfterLastWindowClosed')
        return True


if __name__ == '__main__':
    app = NSApplication.sharedApplication()

    viewController = Media.alloc().initWithWindowNibName_('Media')
    viewController.showWindow_(viewController)

    NSApp.activateIgnoringOtherApps_(True)

    AppHelper.runEventLoop()
Exemplo n.º 17
0
 def decorator(func):
     NSApplication.sharedApplication().delegate().register_hotkey(key, func)
     return func
Exemplo n.º 18
0
    args = parser.parse_args()
    
    get_arg = lambda x : x[0] if not x is None and not isinstance(x, int) \
                        and not isinstance(x, basestring) else x
    use_web_interface = get_arg(args.use_web_interface)
    monitors = get_arg(args.monitors)
    platform = get_arg(args.platform)
    frame_speed = get_arg(args.frame_speed)
    subreddit =  get_arg(args.subreddit)
    wallpaper_dir = get_arg(args.wallpaper_dir)

    if platform == "darwin":
        # Set the activation policy to NSApplicationActivationPolicyAccessory
        # so we don't show the Python dock icon when using PyObjC.
        NSApplication.sharedApplication().setActivationPolicy_(2)
        wallpaper_setter = RedditWallpaperSetterOSX(subreddit, wallpaper_dir,
                                                    frame_speed, monitors=monitors)
    elif platform == "xfce4":
        wallpaper_setter = RedditWallpaperSetterXFCE4(subreddit, wallpaper_dir,
                                                      frame_speed, monitors=monitors)
    else:
        wallpaper_setter = RedditWallpaperSetterLinux(subreddit, wallpaper_dir,
                                                      frame_speed, monitors=monitors)
    
    print "Updating wallpaper selection, please wait..."
    wallpaper_setter.update_wallpaper()
    print "Done!"

    if use_web_interface:
        # Use a separate process to kick off the web browser so that it can be
Exemplo n.º 19
0
 def report_exception(self, e):
     NSApplication.sharedApplication().delegate().alert_exception(e)
Exemplo n.º 20
0
 def decorator(func):
     NSApplication.sharedApplication().delegate().register_hotkey(key, func)
     return func
Exemplo n.º 21
0
 def report_exception(self, e):
     NSApplication.sharedApplication().delegate().alert_exception(e)