Exemple #1
0
 def lineHeightCallback(self, sender):
     try:
         self.lineHeight = int(sender.get())
     except Exception:
         NSBeep()
         self.sender.set(self.lineHeight)
     self.w.lineView.setLineHeight(self.lineHeight)
Exemple #2
0
 def textSizeCallback(self, sender):
     try:  # in case the user submits an empty field
         self.textSize = int(sender.get())
     except Exception:  # reset to the previous value
         NSBeep()
         self.sender.set(self.textSize)
     self.w.lineView.setPointSize(self.textSize)
Exemple #3
0
def system_bell(*args):
    try:
        from AppKit import NSBeep  #@UnresolvedImport
        NSBeep()
        return True
    except:
        return False
Exemple #4
0
 def NextMaster(self, sender=None):
     thisFont = Glyphs.font
     if thisFont:
         thisFont.masterIndex = (thisFont.masterIndex + 1) % len(
             thisFont.masters)
     else:
         NSBeep()
Exemple #5
0
 def fromevent(self, event):
     # Return configuration (keycode, modifiers) or None=clear or False=retain previous
     (keycode,
      modifiers) = (event.keycode & 0xffff, event.keycode & 0xffff0000
                    )  # Set by _acquire_poll()
     if keycode and not (modifiers &
                         (NSShiftKeyMask | NSControlKeyMask
                          | NSAlternateKeyMask | NSCommandKeyMask)):
         if keycode == 0x1b:  # Esc = retain previous
             self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE
             return False
         elif keycode in [
                 0x7f,
                 ord(NSDeleteFunctionKey),
                 ord(NSClearLineFunctionKey)
         ]:  # BkSp, Del, Clear = clear hotkey
             self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE
             return None
         elif keycode in [
                 0x13, 0x20, 0x2d
         ] or 0x61 <= keycode <= 0x7a:  # don't allow keys needed for typing in System Map
             NSBeep()
             self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE
             return None
     return (keycode, modifiers)
Exemple #6
0
 def extraSidebearingsCallback(self, sender):
     left = self.w.footer.extraSidebearingLeft
     right = self.w.footer.extraSidebearingRight
     try:
         self.extraSidebearings = [int(left.get()), int(right.get())]
     except Exception:
         NSBeep()
         left.set(self.extraSidebearings[0])
         right.set(self.extraSidebearings[1])
     self.extraGlyphsCallback()  # calls self.updateExtensionWindow()
Exemple #7
0
    def charsCallback(self, sender):
        charsContent = sender.get()
        if len(charsContent):
            self.w.button.enable(True)
            nsTextView = self.nsTextField.currentEditor(
            )  # NOTE: the field editor is only available when NSTextField is in editing mode.

            # when only one glyph is selected and copied, the contents of the clipboard are the glyph's XML
            # instead of its unicode character or its name; therefore, post-process the pasted content.
            if xmlHeader in charsContent:
                caretIndex = charsContent.index(xmlHeader)
                codepointString = re_glyphUnicode.search(charsContent)
                glyphName = re_glyphName.search(charsContent)

                if codepointString:
                    replacement = unichr(eval('0x' + codepointString.group(1)))
                elif glyphName:
                    replacement = '/' + glyphName.group(1)
                else:
                    replacement = ''

                # replace the glyph's XML by its unicode character or its name
                self.w.chars.set(re_glyph.sub(replacement, charsContent))
                # restore the location of the caret
                location = caretIndex + len(replacement)
                nsTextView.setSelectedRange_((location, 0))
                # update the variable
                charsContent = sender.get()

            caretIndex = nsTextView.selectedRanges()[0].rangeValue().location

            # Limit the number of characters
            numeralWasFound = self.stringHasNumeral(charsContent)
            if len(charsContent) > maxChars or numeralWasFound:
                NSBeep()
                if numeralWasFound:
                    self.showMessage("Sorry, numerals are not allowed.", "")
                else:
                    self.showMessage(
                        "You've reached the maximum \rnumber of characters.",
                        "The limit is %d." % maxChars)
                # restore the content of chars EditText to the previous string
                sender.set(self.previousChars)
                # restore the focus on the chars EditText and restore the location of the caret
                caretIndexAdjust = len(self.previousChars) - len(charsContent)
                self.w.getNSWindow().makeFirstResponder_(self.nsTextField)
                nsTextView.setSelectedRange_(
                    (caretIndex + caretIndexAdjust, 0))

            # update the stored string
            self.previousChars = sender.get()

        else:
            self.w.button.enable(False)
    def textView_completions_forPartialWordRange_indexOfSelectedItem_(
            self, textView, words, charRange, index):
        try:
            ts = textView.textStorage()
            token = ts.string().substringWithRange_(charRange)
            completions = blockingCallFromThread(self.complete, token)
        except:
            completions = objc.nil
            NSBeep()

        return (completions, 0)
Exemple #9
0
def run_timer(duration):
    dur = duration
    while dur >= 0:

        timeformat = "\r%d Seconds left" % dur
        sys.stdout.write(timeformat)
        sys.stdout.flush()
        time.sleep(1)
        dur -= 1
    print "Done"
    NSBeep()
Exemple #10
0
 def removeButtonCallback(self, sender):
     eventList = self.w.list
     selection = eventList.getSelection()
     toRemove = []
     for index in selection:
         data = eventList[index]
         if data["locked"]:
             NSBeep()
             continue
         toRemove.append(index)
     for index in reversed(toRemove):
         del eventList[index]
Exemple #11
0
 def outlineView_setObjectValue_forTableColumn_byItem_(
         self, view, value, col, item):
     assert col.identifier() == "value"
     if item.value == value:
         return
     try:
         obj = eval(value, {})
     except:
         NSBeep()
         print("XXX Error:", sys.exc_info())
         print("XXX      :", repr(value))
     else:
         item.setValue_(obj)
Exemple #12
0
    def textView_doCommandBySelector_(self, textView, selector):
        assert (textView == self.textView)
        NSLog("textView_doCommandBySelector_: " + selector)

        if (selector == 'insertNewline:'):
            indent = self.current_indent_string()
            if (indent):
                line = indent + self.current_line()
            else:
                line = self.current_line()

            if (self.is_complete(self.current_block())):
                self.execute(self.current_block(), blockID=self.currentBlockID)
                self.start_new_block()

                return True

            return False

        elif (selector == 'moveUp:'):
            prevBlock = self.get_history_previous(self.current_block())
            if (prevBlock != None):
                self.replace_current_block_with_string(textView, prevBlock)
            else:
                NSBeep()
            return True

        elif (selector == 'moveDown:'):
            nextBlock = self.get_history_next()
            if (nextBlock != None):
                self.replace_current_block_with_string(textView, nextBlock)
            else:
                NSBeep()
            return True

        elif (selector == 'moveToBeginningOfParagraph:'):
            textView.setSelectedRange_(
                NSMakeRange(self.current_block_range().inputRange.location, 0))
            return True
        elif (selector == 'moveToEndOfParagraph:'):
            textView.setSelectedRange_(NSMakeRange(
                            self.current_block_range().inputRange.location + \
                            self.current_block_range().inputRange.length, 0))
            return True
        elif (selector == 'deleteToEndOfParagraph:'):
            if(textView.selectedRange().location <= \
                self.current_block_range().location):
                raise NotImplemented()

            return False  # don't actually handle the delete

        elif (selector == 'insertTab:'):
            if (len(self.current_line().strip()) == 0):  #only white space
                return False
            else:
                self.textView.complete_(self)
                return True

        elif (selector == 'deleteBackward:'):
            #if we're at the beginning of the current block, ignore
            if(textView.selectedRange().location == \
                self.current_block_range().inputRange.location):
                return True
            else:
                for r in self.blockRanges.itervalues():
                    deleteRange = textView.selectedRange
                    if (deleteRange.length == 0):
                        deleteRange.location -= 1
                        deleteRange.length = 1
                    r.update_ranges_for_deletion(deleteRange)
                return False
        return False
Exemple #13
0
def beep_macos(**kwargs):
    ''' Simple system beep for MacOS. '''
    # Note: makes the terminal/app icon in the taskbar jump.
    log.debug('trying AppKit.NSBeep…')
    from AppKit import NSBeep
    NSBeep()
Exemple #14
0
    def getText(self):
        if CurrentFont() is None:
            NSBeep()
            self.showMessage("Open a font first.", "")
            return

        if not self.isConnected():
            NSBeep()
            self.showMessage("Required internet connection not found.", "")
            return

        values = {
            'chars':
            self.w.chars.get().encode('utf-8'),
            'script':
            scriptsTagDict[scriptsNameList[self.w.scriptsPopup.get()]],
            'tb':
            langsTagDict[langsNameDict[scriptsNameList[
                self.w.scriptsPopup.get()]][self.w.langsPopup.get()]]
        }

        if self.w.punctCheck.get():
            values['punct'] = True
        if self.w.figsCheck.get():
            values['figs'] = True
            if self.w.figsPopup.isVisible():
                figsOptTagsList = ["dflt", "locl"]
                values['figsOpt'] = figsOptTagsList[self.w.figsPopup.get()]
        if self.w.trimCheck.get() and self.w.trimCheck.isEnable():
            values['trim'] = True
        if self.w.caseCheck.get() and self.w.caseCheck.isEnable():
            values['case'] = True
        if self.w.casingCheck.get() and self.w.casingCheck.isEnable():
            values['casing'] = casingNameList[self.w.casingPopup.get()].lower()

        data = urlencode(values)
        data = data.encode('utf-8')
        print(data)
        request = Request(url, data)
        response = urlopen(request)
        text = response.read()
        textU = unicode(text, 'utf-8')

        if (msgStr in textU):
            textU = textU.replace(msgStr, "")
            NSBeep()
            self.showMessage(textU, "")
            return

        elif (wrnStr in textU):
            resultIndex = textU.find(rsltStr)
            secmsgIndex = textU.find(sndStr)
            frstmsgU = textU[:secmsgIndex].replace(wrnStr, "")
            scndmsgU = textU[secmsgIndex:resultIndex].replace(sndStr, "")
            textU = textU[resultIndex:].replace(rsltStr, "")
            NSBeep()
            self.showMessage(frstmsgU, scndmsgU)

        textList = textU.split()
        trimmedText = ' '.join(textList[:int(self.w.slider.get())])

        if CurrentSpaceCenter() is None:
            OpenSpaceCenter(CurrentFont(), newWindow=False)

        sp = CurrentSpaceCenter()
        print(trimmedText)
        sp.setRaw(trimmedText)

        # Toggle RTL-LTR
        try:
            sp.setLeftToRight(not self.scriptIsRTL)
            sp.setInputWritingDirection(
                'Right to Left' if self.scriptIsRTL else 'Left to Right')
        except AttributeError:
            pass

        return
Exemple #15
0
def error():
    """Generate a simple system beep."""
    NSBeep()
Exemple #16
0
    def moveTo(self, pt):
        moveTo(pt)

    def lineTo(self, pt):
        lineTo(pt)

    def curveTo(self, pt1, pt2, pt3):
        curveTo(pt1, pt2, pt3)

    def closePath(self):
        closePath()

    def endPath(self):
        closePath()

    def draw(self):
        drawPath()

    def addComponent(self, baseName, transformation):
        glyph = self.f[baseName]
        tPen = TransformPen(self, transformation)
        glyph.draw(tPen)


if CurrentFont() is not None:
    AdjustAnchors()
else:
    import vanilla.dialogs
    NSBeep()
    vanilla.dialogs.message(extensionName, "Open a font first.")
Exemple #17
0
 def showFontEditorSpaceStation(self):
     font = CurrentFont()
     if font is not None:
         FontEditorSpaceStationController(font.defaultLayer)
     else:
         NSBeep()
Exemple #18
0
def system_bell(*_args):
    NSBeep()
    return True
Exemple #19
0
 def showGlyphEditorSpaceStation(self):
     glyph = CurrentGlyph()
     if glyph is not None:
         GlyphEditorSpaceStationController(glyph)
     else:
         NSBeep()