예제 #1
0
def prepareResultsItem(query, result):
    """
    Prepare resuls item

    :param str query : Query
    :param str result: Result

    :return Item
    """
    value = result.decode('utf-8').split(' ')[0]
    item = Item(id=__prettyname__, icon=icon_path, completion=query.rawString)
    item.text = value
    item.subtext = result
    item.addAction(ClipAction("Copy result to clipboard", value))
    return item
예제 #2
0
def handleQuery(query):
    if not query.isTriggered:
        return

    item = Item(completion=query.rawString, icon=ICON_PATH)
    stripped = query.string.strip()

    if stripped:
        with NamedTemporaryFile() as f:
            f.write(bytes(stripped, 'utf-8'))
            f.flush()
            output = subprocess.check_output(
                ['wolframscript', '-print', '-f', f.name])
        result = str(output.strip(), 'utf-8')
        item.text = result
        item.subtext = 'Result'
        item.addAction(ClipAction('Copy result to clipboard', result))
    else:
        item.text = ''
        item.subtext = 'Type a Mathematica expression'

    return item
예제 #3
0
def buildVmItem(vm):
    item = Item(
        id=vm.__uuid__,
        icon=iconPath,
        text=vm.name,
        subtext="{vm.state}".format(vm=vm),
        completion=vm.name
    )

    if vm.state == MachineState.powered_off:  #1
        item.addAction(FuncAction(text="Start virtual machine", callable=lambda: startVm(vm)))
    if vm.state == MachineState.saved:  #2
        item.addAction(FuncAction(text="Restore virtual machine", callable=lambda: startVm(vm)))
        item.addAction(FuncAction(text="Discard saved state", callable=lambda: discardSavedVm(vm)))
    if vm.state == MachineState.aborted:  #4
        item.addAction(FuncAction(text="Start virtual machine", callable=lambda: startVm(vm)))
    if vm.state == MachineState.running:  #5
        item.addAction(FuncAction(text="Save virtual machine", callable=lambda: saveVm(vm)))
        item.addAction(FuncAction(text="Power off via ACPI event (Power button)", callable=lambda: acpiPowerVm(vm)))
        item.addAction(FuncAction(text="Turn off virtual machine", callable=lambda: stopVm(vm)))
        item.addAction(FuncAction(text="Pause virtual machine", callable=lambda: pauseVm(vm)))
    if vm.state == MachineState.paused:  #6
        item.addAction(FuncAction(text="Resume virtual machine", callable=lambda: resumeVm(vm)))

    return item