コード例 #1
0
ファイル: utils.py プロジェクト: ejmvar/vorta
def open_app_at_startup(enabled=True):
    """
    This function adds/removes the current app bundle from Login items in macOS
    """
    if sys.platform == 'darwin':
        from Foundation import NSDictionary

        from Cocoa import NSBundle, NSURL
        from CoreFoundation import kCFAllocatorDefault
        # CF = CDLL(find_library('CoreFoundation'))
        from LaunchServices import (LSSharedFileListCreate,
                                    kLSSharedFileListSessionLoginItems,
                                    LSSharedFileListInsertItemURL,
                                    kLSSharedFileListItemHidden,
                                    kLSSharedFileListItemLast,
                                    LSSharedFileListItemRemove)

        app_path = NSBundle.mainBundle().bundlePath()
        url = NSURL.alloc().initFileURLWithPath_(app_path)
        login_items = LSSharedFileListCreate(
            kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
        props = NSDictionary.dictionaryWithObject_forKey_(
            True, kLSSharedFileListItemHidden)

        new_item = LSSharedFileListInsertItemURL(login_items,
                                                 kLSSharedFileListItemLast,
                                                 None, None, url, props, None)
        if not enabled:
            LSSharedFileListItemRemove(login_items, new_item)
コード例 #2
0
 def awakeFromNib(self):
     smileys = SmileyManager().get_smiley_list()
     menu = self.smileyButton.menu()
     while menu.numberOfItems() > 0:
         menu.removeItemAtIndex_(0)
     bigText = NSAttributedString.alloc().initWithString_attributes_(
         " ",
         NSDictionary.dictionaryWithObject_forKey_(
             NSFont.systemFontOfSize_(16), NSFontAttributeName))
     for text, file in smileys:
         image = NSImage.alloc().initWithContentsOfFile_(file)
         if not image:
             print("cant load %s" % file)
             continue
         image.setScalesWhenResized_(True)
         image.setSize_(NSMakeSize(16, 16))
         atext = bigText.mutableCopy()
         atext.appendAttributedString_(
             NSAttributedString.alloc().initWithString_(text))
         item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
             text, "insertSmiley:", "")
         menu.addItem_(item)
         item.setTarget_(self)
         item.setAttributedTitle_(atext)
         item.setRepresentedObject_(
             NSAttributedString.alloc().initWithString_(text))
         item.setImage_(image)
コード例 #3
0
def open_app_at_startup(enabled=True):
    """
    This function adds/removes the current app bundle from Login items in macOS or most Linux desktops
    """
    if sys.platform == 'darwin':
        from Foundation import NSDictionary

        from Cocoa import NSBundle, NSURL
        from CoreFoundation import kCFAllocatorDefault
        # CF = CDLL(find_library('CoreFoundation'))
        from LaunchServices import (LSSharedFileListCreate,
                                    kLSSharedFileListSessionLoginItems,
                                    LSSharedFileListInsertItemURL,
                                    kLSSharedFileListItemHidden,
                                    kLSSharedFileListItemLast,
                                    LSSharedFileListItemRemove)

        app_path = NSBundle.mainBundle().bundlePath()
        url = NSURL.alloc().initFileURLWithPath_(app_path)
        login_items = LSSharedFileListCreate(
            kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
        props = NSDictionary.dictionaryWithObject_forKey_(
            True, kLSSharedFileListItemHidden)

        new_item = LSSharedFileListInsertItemURL(login_items,
                                                 kLSSharedFileListItemLast,
                                                 None, None, url, props, None)
        if not enabled:
            LSSharedFileListItemRemove(login_items, new_item)

    elif sys.platform.startswith('linux'):
        autostart_path = Path.home() / '.config' / 'autostart'

        if not autostart_path.exists():
            autostart_path.mkdir()

        autostart_file_path = autostart_path / 'vorta.desktop'

        if enabled:
            if Path('/.flatpak-info').exists():
                # Vorta runs as flatpak
                autostart_file_path.write_text(
                    LINUX_STARTUP_FILE.format(
                        'flatpak run com.borgbase.vorta'))
            else:
                autostart_file_path.write_text(
                    LINUX_STARTUP_FILE.format('vorta'))

        else:
            if autostart_file_path.exists():
                autostart_file_path.unlink()
コード例 #4
0
 def awakeFromNib(self):
     smileys = SmileyManager().get_smiley_list()
     menu = self.smileyButton.menu()
     while menu.numberOfItems() > 0:
         menu.removeItemAtIndex_(0)
     bigText = NSAttributedString.alloc().initWithString_attributes_(" ", NSDictionary.dictionaryWithObject_forKey_(NSFont.systemFontOfSize_(16), NSFontAttributeName))
     for text, file in smileys:
         image = NSImage.alloc().initWithContentsOfFile_(file)
         if not image:
             print "cant load %s"%file
             continue
         image.setScalesWhenResized_(True)
         image.setSize_(NSMakeSize(16, 16))
         atext = bigText.mutableCopy()
         atext.appendAttributedString_(NSAttributedString.alloc().initWithString_(text))
         item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(text, "insertSmiley:", "")
         menu.addItem_(item)
         item.setTarget_(self)
         item.setAttributedTitle_(atext)
         item.setRepresentedObject_(NSAttributedString.alloc().initWithString_(text))
         item.setImage_(image)
コード例 #5
0
ファイル: autostart.py プロジェクト: ipwog/vorta
def open_app_at_startup(enabled=True):
    """
    This function adds/removes the current app bundle from Login items in macOS or most Linux desktops
    """
    if sys.platform == 'darwin':
        from Foundation import NSDictionary

        from Cocoa import NSBundle, NSURL
        from CoreFoundation import kCFAllocatorDefault
        # CF = CDLL(find_library('CoreFoundation'))
        from LaunchServices import (LSSharedFileListCreate,
                                    kLSSharedFileListSessionLoginItems,
                                    LSSharedFileListInsertItemURL,
                                    kLSSharedFileListItemHidden,
                                    kLSSharedFileListItemLast,
                                    LSSharedFileListItemRemove)

        app_path = NSBundle.mainBundle().bundlePath()
        url = NSURL.alloc().initFileURLWithPath_(app_path)
        login_items = LSSharedFileListCreate(
            kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
        props = NSDictionary.dictionaryWithObject_forKey_(
            True, kLSSharedFileListItemHidden)

        new_item = LSSharedFileListInsertItemURL(login_items,
                                                 kLSSharedFileListItemLast,
                                                 None, None, url, props, None)
        if not enabled:
            LSSharedFileListItemRemove(login_items, new_item)
    elif sys.platform.startswith('linux'):
        config_path = QtCore.QStandardPaths.writableLocation(
            QtCore.QStandardPaths.ConfigLocation)
        autostart_file_path = Path(config_path) / 'autostart' / 'vorta.desktop'
        if enabled:
            dir_entry_point = get_setuptools_script_dir()
            autostart_file_path.write_text(
                LINUX_STARTUP_FILE.format(dir_entry_point))
        else:
            if autostart_file_path.exists():
                autostart_file_path.unlink()
コード例 #6
0
    def idealWidth(self):
        attribs = NSDictionary.dictionaryWithObject_forKey_(NSFont.systemFontOfSize_(11), NSFontAttributeName)
        size = self.label.sizeWithAttributes_(attribs)

        return size.width + 14 + 20
コード例 #7
0
ファイル: DebugWindow.py プロジェクト: uditha-atukorala/blink
 def append_error_line(self, textView, line):
     red = NSDictionary.dictionaryWithObject_forKey_(NSColor.redColor(), NSForegroundColorAttributeName)
     textView.textStorage().appendAttributedString_(NSAttributedString.alloc().initWithString_attributes_(line+"\n", red))
     textView.scrollRangeToVisible_(NSMakeRange(textView.textStorage().length()-1, 1))
コード例 #8
0
    def show(self):
        BlinkLogger().log_debug('Show %s' % self)
        self.active = True

        if self.captureSession is None:
            # Find a video camera
            device = self.getDevice()

            if not device:
                return

            self.captureSession = AVCaptureSession.alloc().init()
            if self.captureSession.canSetSessionPreset_(
                    AVCaptureSessionPresetHigh):
                self.captureSession.setSessionPreset_(
                    AVCaptureSessionPresetHigh)

            NSWorkspace.sharedWorkspace().notificationCenter(
            ).addObserver_selector_name_object_(
                self, "computerDidWake:", NSWorkspaceDidWakeNotification, None)
            NSWorkspace.sharedWorkspace().notificationCenter(
            ).addObserver_selector_name_object_(
                self, "computerWillSleep:", NSWorkspaceWillSleepNotification,
                None)

            max_resolution = (0, 0)
            BlinkLogger().log_debug(
                "%s camera provides %d formats" %
                (device.localizedName(), len(device.formats())))
            for desc in device.formats():
                m = self.resolution_re.match(repr(desc))
                if m:
                    data = m.groupdict()
                    width = int(data['width'])
                    height = int(data['height'])
                    BlinkLogger().log_debug(
                        "Supported resolution: %dx%d %.2f" %
                        (width, height, width / float(height)))
                    if width > max_resolution[0]:
                        max_resolution = (width, height)

            width, height = max_resolution
            if width == 0 or height == 0:
                width = 1280
                height = 720
                BlinkLogger().log_info(
                    "Error: %s camera does not provide any supported video format"
                    % device.localizedName())
            else:
                if NSApp.delegate(
                ).contactsWindowController.sessionControllersManager.isMediaTypeSupported(
                        'video'):
                    BlinkLogger().log_info(
                        "Opened %s camera at %0.fx%0.f resolution" %
                        (SIPApplication.video_device.real_name, width, height))

            self.aspect_ratio = width / float(
                height) if width > height else height / float(width)

            self.captureDeviceInput = AVCaptureDeviceInput.alloc(
            ).initWithDevice_error_(device, None)
            if self.captureDeviceInput:
                try:
                    self.captureSession.addInput_(self.captureDeviceInput[0])
                except ValueError as e:
                    BlinkLogger().log_info(
                        'Failed to add camera input to capture session: %s' %
                        str(e))
                    return
            else:
                BlinkLogger().log_info('Failed to aquire input %s' % self)
                return

            self.setWantsLayer_(True)
            self.videoPreviewLayer = AVCaptureVideoPreviewLayer.alloc(
            ).initWithSession_(self.captureSession)
            self.layer().addSublayer_(self.videoPreviewLayer)
            self.videoPreviewLayer.setFrame_(self.layer().bounds())
            self.videoPreviewLayer.setAutoresizingMask_(
                kCALayerWidthSizable | kCALayerHeightSizable)
            self.videoPreviewLayer.setBackgroundColor_(
                CGColorGetConstantColor(kCGColorBlack))
            self.videoPreviewLayer.setVideoGravity_(
                AVLayerVideoGravityResizeAspectFill)

            self.videoPreviewLayer.setCornerRadius_(5.0)
            self.videoPreviewLayer.setMasksToBounds_(True)

            self.setMirroring()

            self.stillImageOutput = AVCaptureStillImageOutput.new()
            pixelFormat = NSNumber.numberWithInt_(kCVPixelFormatType_32BGRA)
            self.stillImageOutput.setOutputSettings_(
                NSDictionary.dictionaryWithObject_forKey_(
                    pixelFormat, kCVPixelBufferPixelFormatTypeKey))

            self.captureSession.addOutput_(self.stillImageOutput)

        if self.captureSession and self.videoPreviewLayer:
            BlinkLogger().log_info('Start aquire local video %s' % self)
            self.videoPreviewLayer.setBackgroundColor_(
                NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 0.4))
            self.captureSession.startRunning()
コード例 #9
0
    def updateButtons(self):
        for button in (self.holdButton, self.hangupButton, self.chatButton, self.infoButton, self.muteButton, self.aspectButton, self.contactsButton, self.fullscreenButton, self.myvideoButton, self.pauseButton):

            lightGrayTitle = NSAttributedString.alloc().initWithString_attributes_(button.label(), NSDictionary.dictionaryWithObject_forKey_(NSColor.lightGrayColor(), NSForegroundColorAttributeName))
            button.setLabel_(lightGrayTitle)
コード例 #10
0
    def idealWidth(self):
        attribs = NSDictionary.dictionaryWithObject_forKey_(
            NSFont.systemFontOfSize_(11), NSFontAttributeName)
        size = self.label.sizeWithAttributes_(attribs)

        return size.width + 14 + 20
コード例 #11
0
ファイル: autostart.py プロジェクト: borgbase/vorta
def open_app_at_startup(enabled=True):
    """
    On macOS, this function adds/removes the current app bundle from Login items
    while on Linux it adds a .desktop file at ~/.config/autostart
    """
    if sys.platform == 'darwin':
        from Foundation import NSDictionary

        from Cocoa import NSBundle, NSURL
        from CoreFoundation import kCFAllocatorDefault
        # CF = CDLL(find_library('CoreFoundation'))
        from LaunchServices import (LSSharedFileListCreate,
                                    kLSSharedFileListSessionLoginItems,
                                    LSSharedFileListInsertItemURL,
                                    kLSSharedFileListItemHidden,
                                    kLSSharedFileListItemLast,
                                    LSSharedFileListItemRemove)

        app_path = NSBundle.mainBundle().bundlePath()
        url = NSURL.alloc().initFileURLWithPath_(app_path)
        login_items = LSSharedFileListCreate(
            kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
        props = NSDictionary.dictionaryWithObject_forKey_(
            True, kLSSharedFileListItemHidden)

        new_item = LSSharedFileListInsertItemURL(login_items,
                                                 kLSSharedFileListItemLast,
                                                 None, None, url, props, None)
        if not enabled:
            LSSharedFileListItemRemove(login_items, new_item)

    elif sys.platform.startswith('linux'):
        from appdirs import user_config_dir
        from pathlib import Path

        is_flatpak = Path('/.flatpak-info').exists()

        with open(
                Path(__file__).parent /
                "assets/metadata/com.borgbase.Vorta.desktop") as desktop_file:
            desktop_file_text = desktop_file.read()

        # Find XDG_CONFIG_HOME unless when running in flatpak
        if is_flatpak:
            autostart_path = Path.home() / '.config' / 'autostart'
        else:
            autostart_path = Path(user_config_dir("autostart"))

        if not autostart_path.exists():
            autostart_path.mkdir(parents=True, exist_ok=True)

        autostart_file_path = autostart_path / 'vorta.desktop'

        if enabled:
            # Replace command for flatpak if appropriate and start in background
            desktop_file_text = desktop_file_text.replace(
                "Exec=vorta", "Exec=flatpak run com.borgbase.Vorta --daemonize"
                if is_flatpak else "Exec=vorta --daemonize")
            # Add autostart delay
            desktop_file_text += (AUTOSTART_DELAY)

            autostart_file_path.write_text(desktop_file_text)
        elif autostart_file_path.exists():
            autostart_file_path.unlink()
コード例 #12
0
    def __init__(self, sessionController):

        self.notification_center = NotificationCenter()
        self.notification_center.add_observer(
            self, name='CFGSettingsObjectDidChange')

        self.sessionController = None
        self.audio_stream = None
        self.video_stream = None
        self.chat_stream = None

        self.add_session(sessionController)
        self.add_audio_stream()
        self.add_video_stream()
        self.add_chat_stream()

        self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(
            1.0, self, "updateTimer:", None, True)
        NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer,
                                                     NSModalPanelRunLoopMode)
        NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer,
                                                     NSDefaultRunLoopMode)
        NSBundle.loadNibNamed_owner_("SessionInfoPanel", self)

        sessionBoxTitle = NSAttributedString.alloc(
        ).initWithString_attributes_(
            NSLocalizedString("SIP Session", "Label"),
            NSDictionary.dictionaryWithObject_forKey_(
                NSColor.orangeColor(), NSForegroundColorAttributeName))
        self.sessionBox.setTitle_(sessionBoxTitle)

        audioBoxTitle = NSAttributedString.alloc().initWithString_attributes_(
            NSLocalizedString("Audio Stream", "Label"),
            NSDictionary.dictionaryWithObject_forKey_(
                NSColor.orangeColor(), NSForegroundColorAttributeName))
        self.audioBox.setTitle_(audioBoxTitle)

        videoBoxTitle = NSAttributedString.alloc().initWithString_attributes_(
            NSLocalizedString("Video Stream", "Label"),
            NSDictionary.dictionaryWithObject_forKey_(
                NSColor.orangeColor(), NSForegroundColorAttributeName))
        self.videoBox.setTitle_(videoBoxTitle)

        chatBoxTitle = NSAttributedString.alloc().initWithString_attributes_(
            NSLocalizedString("Chat Stream", "Label"),
            NSDictionary.dictionaryWithObject_forKey_(
                NSColor.orangeColor(), NSForegroundColorAttributeName))
        self.chatBox.setTitle_(chatBoxTitle)

        settings = SIPSimpleSettings()

        self.audio_rtt_graph.setLineWidth_(1.0)
        self.audio_rtt_graph.setLineSpacing_(1.0)
        self.audio_rtt_graph.setAboveLimit_(
            settings.gui.rtt_threshold)  # if higher show red color
        self.audio_rtt_graph.setMinimumHeigth_(settings.gui.rtt_threshold)

        self.audio_packet_loss_rx_graph.setLineWidth_(1.0)
        self.audio_packet_loss_rx_graph.setLineSpacing_(1.0)
        self.audio_packet_loss_rx_graph.setAboveLimit_(
            3)  # if higher than 3% show red color
        self.audio_packet_loss_rx_graph.setLineColor_(NSColor.greenColor())
        self.audio_packet_loss_rx_graph.setMinimumHeigth_(5)

        self.audio_packet_loss_tx_graph.setLineWidth_(1.0)
        self.audio_packet_loss_tx_graph.setLineSpacing_(1.0)
        self.audio_packet_loss_tx_graph.setAboveLimit_(
            3)  # if higher than 3% show red color
        self.audio_packet_loss_tx_graph.setLineColor_(NSColor.greenColor())
        self.audio_packet_loss_tx_graph.setMinimumHeigth_(5)

        self.rx_speed_graph.setLineWidth_(1.0)
        self.rx_speed_graph.setLineSpacing_(0.0)
        self.rx_speed_graph.setLineColor_(NSColor.greenColor())
        self.rx_speed_graph.setMinimumHeigth_(100000)
        self.rx_speed_graph.setAboveLimit_(120000)

        self.tx_speed_graph.setLineWidth_(1.0)
        self.tx_speed_graph.setLineSpacing_(0.0)
        self.tx_speed_graph.setLineColor_(NSColor.blueColor())
        self.tx_speed_graph.setMinimumHeigth_(100000)
        self.tx_speed_graph.setAboveLimit_(120000)

        self.video_rx_speed_graph.setLineWidth_(1.0)
        self.video_rx_speed_graph.setLineSpacing_(0.0)
        self.video_rx_speed_graph.setLineColor_(NSColor.greenColor())
        self.video_rx_speed_graph.setMinimumHeigth_(100000)
        self.video_rx_speed_graph.setAboveLimit_(99999999)

        self.video_tx_speed_graph.setLineWidth_(1.0)
        self.video_tx_speed_graph.setLineSpacing_(0.0)
        self.video_tx_speed_graph.setLineColor_(NSColor.blueColor())
        self.video_tx_speed_graph.setMinimumHeigth_(100000)
        self.video_tx_speed_graph.setAboveLimit_(99999999)

        self.resetSession()
        self.updatePanelValues()
コード例 #13
0
    def __init__(self, sessionController):

        self.notification_center = NotificationCenter()
        self.notification_center.add_observer(self, name='CFGSettingsObjectDidChange')

        self.sessionController = None
        self.audio_stream = None
        self.video_stream = None
        self.chat_stream = None

        self.add_session(sessionController)
        self.add_audio_stream()
        self.add_video_stream()
        self.add_chat_stream()

        self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, "updateTimer:", None, True)
        NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode)
        NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
        NSBundle.loadNibNamed_owner_("SessionInfoPanel", self)

        sessionBoxTitle = NSAttributedString.alloc().initWithString_attributes_(NSLocalizedString("SIP Session", "Label"), NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName))
        self.sessionBox.setTitle_(sessionBoxTitle)

        audioBoxTitle = NSAttributedString.alloc().initWithString_attributes_(NSLocalizedString("Audio Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName))
        self.audioBox.setTitle_(audioBoxTitle)

        videoBoxTitle = NSAttributedString.alloc().initWithString_attributes_(NSLocalizedString("Video Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName))
        self.videoBox.setTitle_(videoBoxTitle)

        chatBoxTitle = NSAttributedString.alloc().initWithString_attributes_(NSLocalizedString("Chat Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName))
        self.chatBox.setTitle_(chatBoxTitle)

        settings = SIPSimpleSettings()

        self.audio_rtt_graph.setLineWidth_(1.0)
        self.audio_rtt_graph.setLineSpacing_(1.0)
        self.audio_rtt_graph.setAboveLimit_(settings.gui.rtt_threshold) # if higher show red color
        self.audio_rtt_graph.setMinimumHeigth_(settings.gui.rtt_threshold)

        self.audio_packet_loss_graph.setLineWidth_(1.0)
        self.audio_packet_loss_graph.setLineSpacing_(1.0)
        self.audio_packet_loss_graph.setAboveLimit_(3) # if higher than 3% show red color
        self.audio_packet_loss_graph.setLineColor_(NSColor.greenColor())
        self.audio_packet_loss_graph.setMinimumHeigth_(5)

        self.rx_speed_graph.setLineWidth_(1.0)
        self.rx_speed_graph.setLineSpacing_(0.0)
        self.rx_speed_graph.setLineColor_(NSColor.greenColor())
        self.rx_speed_graph.setMinimumHeigth_(100000)
        self.rx_speed_graph.setAboveLimit_(120000)

        self.tx_speed_graph.setLineWidth_(1.0)
        self.tx_speed_graph.setLineSpacing_(0.0)
        self.tx_speed_graph.setLineColor_(NSColor.blueColor())
        self.tx_speed_graph.setMinimumHeigth_(100000)
        self.tx_speed_graph.setAboveLimit_(120000)

        self.video_rx_speed_graph.setLineWidth_(1.0)
        self.video_rx_speed_graph.setLineSpacing_(0.0)
        self.video_rx_speed_graph.setLineColor_(NSColor.greenColor())
        self.video_rx_speed_graph.setMinimumHeigth_(100000)
        self.video_rx_speed_graph.setAboveLimit_(1200000)

        self.video_tx_speed_graph.setLineWidth_(1.0)
        self.video_tx_speed_graph.setLineSpacing_(0.0)
        self.video_tx_speed_graph.setLineColor_(NSColor.blueColor())
        self.video_tx_speed_graph.setMinimumHeigth_(100000)
        self.video_tx_speed_graph.setAboveLimit_(1200000)

        self.resetSession()
        self.updatePanelValues()