Exemplo n.º 1
0
 def __init__(self,
              posSize,
              date=None,
              minDate=None,
              maxDate=None,
              showStepper=True,
              mode="text",
              timeDisplay="hourMinuteSecond",
              dateDisplay="yearMonthDay",
              callback=None,
              sizeStyle="regular"):
     self._setupView(self.nsDatePickerClass, posSize, callback=callback)
     self._setSizeStyle(sizeStyle)
     self._nsObject.setDrawsBackground_(True)
     self._nsObject.setBezeled_(True)
     if mode == "text" and showStepper:
         mode += "Stepper"
     style = _modeMap[mode]
     self._nsObject.setDatePickerStyle_(style)
     flag = _timeDisplayFlagMap[timeDisplay]
     flag = flag | _dateDisplayFlagMap[dateDisplay]
     self._nsObject.setDatePickerElements_(flag)
     if date is None:
         date = NSDate.date()
     self._nsObject.setDateValue_(date)
     if minDate is not None:
         self._nsObject.setMinDate_(minDate)
     if maxDate is not None:
         self._nsObject.setMaxDate_(maxDate)
Exemplo n.º 2
0
def gevent_timer(deleg):
    timer = NSTimer.alloc(
    ).initWithFireDate_interval_target_selector_userInfo_repeats_(
        NSDate.date(), 0.1, deleg, 'gevent:', None, True)
    NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSDefaultRunLoopMode)
    timer.fire()
    print "started gevent timer"
Exemplo n.º 3
0
def createCocoaKeyEvent(keyCode, down=True):
	from AppKit import NSEvent, NSApplication, NSKeyDown, NSKeyUp, NSDate
	modifierFlags = 0
	return NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_(
		NSKeyDown if down else NSKeyUp, (0, 0), modifierFlags,
		NSDate.timeIntervalSinceReferenceDate(), #theEvent.timestamp(),
		0, #theEvent.windowNumber(),
		None, # context
		None, # characters
		None, # charactersIgnoringModifiers
		False, # isARepeat
		keyCode # keyCode
	)
Exemplo n.º 4
0
def gevent_timer(deleg):
    timer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_(
        NSDate.date(), 0.1, deleg, 'gevent:', None, True)
    NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSDefaultRunLoopMode)
    timer.fire()
    print "started gevent timer"
Exemplo n.º 5
0
from AppKit import NSObject, NSApplication, NSVariableStatusItemLength, NSImage, NSMenu, NSTimer, NSDate, NSRunLoop, NSDefaultRunLoopMode, NSStatusBar, NSMenuItem, NSToolbarSeparatorItemIdentifier, NSOnState, NSOffState
from PyObjCTools import AppHelper
import signal
import subprocess
import sys, os
import json
import syslog
from pprint import pprint

start_time = NSDate.date()

class MyTray(NSObject):
    statusbar = None
    state = 'setup'
    interval = 3.0
    loop_func = "instances_"
    which_terminal = "Terminal"
    kill = False
    toggles = ['kill', 'refresh']
    toggle_images = {}
    curr_config = {}

    # Init
    def applicationDidFinishLaunching_(self, _n):
        self.statusbar = NSStatusBar.systemStatusBar()

        self.statusitem = self.statusbar.statusItemWithLength_(NSVariableStatusItemLength)
        self.image = NSImage.alloc().initByReferencingFile_("mydock.icns")
        for i in self.toggles:
            self.toggle_images[i] = NSImage.alloc().initByReferencingFile_(i+".png")
    def __init__(self):
        """
        Constructor.

        :return: None.
        """
        # Create event tap
        self._tap = Quartz.CGEventTapCreate(
            # The tap is for session events
            Quartz.kCGSessionEventTap,
            # The tap is inserted before existing event taps
            Quartz.kCGHeadInsertEventTap,
            # The tap is active filter
            Quartz.kCGEventTapOptionDefault,
            # The tap listens to all events
            Quartz.kCGEventMaskForAllEvents,
            # The tap calls this callback
            self._tap_callback,
            # User-defined data
            None)

        # Create run loop source
        run_loop_source = Quartz.CFMachPortCreateRunLoopSource(
            None, self._tap, 0)

        # Add run loop source to the current run loop
        Quartz.CFRunLoopAddSource(Quartz.CFRunLoopGetCurrent(),
                                  run_loop_source,
                                  Quartz.kCFRunLoopDefaultMode)

        # Key-down event handler
        self.KeyDown = None

        # Key-up event handler
        self.KeyUp = None

        # Mouse-down event handler
        self.MouseDown = None

        # Mouse-up event handler
        self.MouseUp = None

        # Mouse wheel event handler
        self.MouseWheel = None

        # Mouse move event handler
        self.MouseMove = None

        # Modifier states that indicate whether each modifier is on or off.
        self._modifier_states = {
            'LCTRL': 0,
            'RCTRL': 0,
            'LCMD': 0,
            'RCMD': 0,
            'LALT': 0,
            'RALT': 0,
            'LSHIFT': 0,
            'RSHIFT': 0,
            'CAPSLOCK': 0,
        }

        # Get current timestamp
        current_timestamp = NSDate.date().timeIntervalSince1970()

        # Get interval since the system boot time
        system_up_interval = NSProcessInfo.processInfo().systemUptime()

        # Get the system boot time's timestamp.
        # This is used for calculating each event's timestamp.
        self._system_up_timestamp = current_timestamp - system_up_interval
Exemplo n.º 7
0
from AppKit import NSDate
from AppKit import NSDefaultRunLoopMode
from AppKit import NSMenu
from AppKit import NSMenuItem
from AppKit import NSObject
from AppKit import NSRunLoop
from AppKit import NSStatusBar
from AppKit import NSTimer
from AppKit import NSVariableStatusItemLength
from utray import interfaces
from utray.utils import create_icon
from utray.utils import app


start_time = NSDate.date()


ICONS =  {'inactive': create_icon('inactive.png'),
          'idle': create_icon('idle.png'),
          'syncing1': create_icon('active1.png'),
          'syncing2': create_icon('active2.png'),
          'syncing3': create_icon('active3.png'),
          'conflict': create_icon('error.png')}

STATUS_ICON_MAP = {
    interfaces.STATUS_INACTIVE: 'inactive',
    interfaces.STATUS_DISABLED: 'inactive',
    interfaces.STATUS_SYNCING: 'syncing',
    interfaces.STATUS_OK: 'idle',
    interfaces.STATUS_CONFLICT: 'conflict'}