Esempio n. 1
0
def main(launcher_args):
    """Main function."""
    while True:
        index, filt, sel, exit = main_rofi_function(launcher_args)
        launcher_args['filter'] = filt
        launcher_args['index'] = index
        if (exit == 0):
            # This is the case where enter is pressed
            print("Main function of the script.")
            break
        elif (exit == 1):
            # This is the case where rofi is escaped (should exit)
            break
        elif (exit == 10):
            helpmsg_list = []
            helpmsg_list.append('help menu.')
            helpmsg_list.append('binding one help string.')
            helpmsg_list.append('binding two help string.')
            mbrofi.rofi_help(bindings, helpmsg_list)
        elif (exit == 11):
            # What to do if second binding is pressed
            print(bindings[1] + " was pressed!")
        elif (exit == 12):
            # What to do if second binding is pressed
            print(bindings[2] + " was pressed!")
        else:
            break
Esempio n. 2
0
def main(launcher_args):
    """Main function."""
    BFR = mbrofi.FileRepo(dirpath=BOOKMARK_DIRECTORY)
    BFR.scan_files(recursive=True)
    while True:
        answer, exit = mbrofi.rofi(BFR.filenames(), launcher_args)
        if exit == 1:
            return(0)
        index, filt, sel = answer.strip().split(';')
        print("index:", str(index))
        print("filter:", filt)
        print("selection:", sel)
        print("exit:", str(exit))
        print("------------------")

        launcher_args['filter'] = filt
        launcher_args['index'] = index
        if (exit == 0):
            # This is the case where enter is pressed
            if int(index) < 0:
                rofi_add_bookmark(book_name=filt.strip(), abort_key=BIND_NEW)
                launcher_args['filter'] = ''
                BFR.scan_files(recursive=True)
            else:
                open_bookmark(sel.strip())
                break
        elif exit == 10:
            helpmsg_list = BIND_HELPLIST
            mbrofi.rofi_help(bindings, helpmsg_list, prompt='bookmarks help:')
        elif exit == 11:
            if filt:
                rofi_add_bookmark(book_name=filt.strip(), abort_key=BIND_NEW)
                launcher_args['filter'] = ''
                BFR.scan_files(recursive=True)
            else:
                rofi_add_bookmark(abort_key=BIND_NEW)
                launcher_args['filter'] = ''
                BFR.scan_files(recursive=True)
        elif exit == 12:
            if int(index) < 0:
                print("No bookmark selected for deletion...ignoring")
                continue
            bookmark = sel.strip()
            ans = mbrofi.rofi_ask("Are you sure you want to delete bookmark " +
                                  "'" + bookmark + "'?",
                                  prompt='delete bookmark:',
                                  abort_key=BIND_DEL)
            if ans:
                del_bookmark(bookmark)
                BFR.scan_files(recursive=True)
        elif exit == 13:
            rofi_change_name_bookmark(sel.strip(), BIND_RENAME)
            BFR.scan_files(recursive=True)
        elif exit == 14:
            rofi_change_url_bookmark(sel.strip(), BIND_CHGURL)
        else:
            break
Esempio n. 3
0
def main():
    """Main function."""
    steam_only = False
    while True:
        games_list = get_installed_games()
        if steam_only:
            tmp_list = []
            for game in games_list:
                if game['runner'] == 'steam':
                    tmp_list.append(game)
            games_list = tmp_list
            launcher_args['prompt'] = "lutris (steam_only):"
        else:
            launcher_args['prompt'] = "lutris:"
        display_list = generate_entries(games_list)
        answer, exit = mbrofi.rofi(display_list, launcher_args, ['-i'])
        if exit != 1:
            index, filt, sel = answer.strip().split(';')
            launcher_args['filter'] = filt
            launcher_args['index'] = index
        else:
            break
        print("index:", str(index))
        print("filter:", filt)
        print("selection:", sel)
        print("exit:", str(exit))
        print("------------------")

        if (exit == 0):
            selected_game = games_list[int(index)]
            slug = selected_game['slug']
            cmd = []
            cmd.append(LUTRIS_EXE)
            print(selected_game)
            if slug != 'lutris':
                cmd.append('lutris:rungame/' + slug)
            Popen(cmd).communicate()
            break
        elif (exit == 1):
            # this is the case where rofi is escaped (should exit)
            break
        elif (exit == 10):
            message = "List of bindings with descriptions. Press alt-h"
            message += " to go back."
            mbrofi.rofi_help(launcher_args['bindings'],
                             BIND_HELPLIST,
                             prompt='screenshots help:',
                             message=message)
        elif (exit == 11):
            show_install_menu(BIND_INSTALL)
        elif (exit == 12):
            steam_only = (not steam_only)
        else:
            break
Esempio n. 4
0
def main(launcher_args, upload):
    """Main function."""
    delay = 0
    opts, types, geoms = get_options()
    while True:
        entries = generate_entries(opts, delay)
        if upload:
            launcher_args['prompt'] = prompt_name + '(upload):'
        else:
            launcher_args['prompt'] = prompt_name + '(noupload):'
        # Run rofi and parse output
        answer, exit = mbrofi.rofi(entries, launcher_args, ['-i'])
        if exit == 1:
            return (False, False, False, 1)
        index, filt, sel = answer.strip().split(';')
        launcher_args['filter'] = filt
        launcher_args['index'] = index
        selected_opt = opts[int(index)]
        selected_type = types[int(index)]
        selected_geom = geoms[int(index)]
        if (exit == 0):
            imgname = sshot(selected_opt, selected_type, selected_geom, delay)
            if upload and imgname:
                pasteurl = mbrofi.upload_ptpb(SCREENSHOT_DIRECTORY,
                                              imgname,
                                              notify_bool=True,
                                              name="Screenshot")
                if pasteurl:
                    pasteurl = pasteurl.strip()
                    mbrofi.clip(pasteurl)
            break
        elif (exit == 1):
            # This is the case where rofi is escaped (should exit)
            break
        elif (exit == 10):
            """show help"""
            mbrofi.rofi_help(bindings, BIND_HELPLIST)
        elif (exit == 11):
            """add delay"""
            tmp_delay = add_delay(BIND_DELAY)
            if tmp_delay is not None:
                delay = tmp_delay
        elif (exit == 12):
            """toggle upload"""
            upload = (not upload)
        elif (exit == 13):
            """interactive mode"""
            imgname = sshot(selected_opt, selected_type, selected_geom, delay)
            if imgname:
                screenshots.main()
            break
        else:
            break
Esempio n. 5
0
def main(launcher_args):
    """Main function."""
    while True:
        active = CLIENT.get_active_connections()
        adapter = choose_adapter(CLIENT)
        max_name_l = 20
        max_sec_l = 15
        max_str_l = 3
        if adapter:
            aps, active_ap, active_ap_con = create_ap_list(adapter, active)
            apname_list = []
            for ap in aps:
                bars = str(ap.get_strength()).rjust(3)
                is_active = ap.get_bssid() == active_ap.get_bssid()
                line = ""
                line += ssid_to_utf8(ap)[:max_name_l].ljust(max_name_l)
                line += " | " + bars[:max_str_l].ljust(max_str_l)
                line += " | " + ap_security(ap)[:max_sec_l].ljust(max_sec_l)
                line += " | "
                if is_active:
                    line += "(active)"
                apname_list.append(line)
        else:
            apname_list = []

        answer, exit = mbrofi.rofi(apname_list, launcher_args)
        if exit == 1:
            break

        index, filt, sel = answer.strip().split(';')
        launcher_args['filter'] = filt
        launcher_args['index'] = index

        if (exit == 0):
            print(ssid_to_utf8(aps[int(index)]))
        elif (exit == 10):
            helpmsg_list = BIND_HELPLIST
            mbrofi.rofi_help(bindings, helpmsg_list, prompt='network help:')
        elif (exit == 11):
            continue
        else:
            break
Esempio n. 6
0
def main(launcher_args, igdev=[]):
    while True:
        devs = get_devices(showi=True)
        entries = get_all(devs)
        answer, exit = mbrofi.rofi(entries[0], launcher_args)
        if exit == 1:
            sys.exit(1)
        else:
            index, filt, sel = answer.strip().split(';')
            index = int(index)
        launcher_args['filter'] = filt
        launcher_args['index'] = index

        if (exit == 0):
            if (index != -1):
                dev = entries[1][index]
                if not dev.mounted:
                    print("mounting " + dev.devname + "...")
                    if (dev.mount()):
                        print("success!")
                    else:
                        mbrofi.rofi_warn("Failed to mount " + dev.devname)
                        break
                dev.get_mountpath()
                dev.open()
                break
        elif (exit == 10):
            helpmsg_list = BIND_HELPLIST
            mbrofi.rofi_help(bindings, helpmsg_list, prompt='mount help:')
        elif (exit == 12):
            if (index != -1):
                dev = entries[1][index]
                if (not dev.mounted):
                    print("Device not mounted, won't unmount.")
                    continue
                print("unmounting " + dev.devname + "...")
                ok, err = dev.unmount()
                if (ok):
                    print("success!")
                else:
                    mbrofi.rofi_warn("Failed to unmount " + dev.devname +
                                     "\n" + err)
                    break
        elif (exit == 11):
            if (index != -1):
                dev = entries[1][index]
                if (dev.mounted):
                    print("Device already mounted, won't mount.")
                    continue
                print("mounting " + dev.devname + "...")
                if (dev.mount()):
                    print("success!")
                else:
                    mbrofi.rofi_warn("Failed to mount " + dev.devname)
                    break
        elif (exit == 13):
            continue
        elif (exit == 14):
            if (index != -1):
                dev = entries[1][index]
                if not dev.mounted:
                    print("mounting " + dev.devname + "...")
                    if (dev.mount()):
                        print("success!")
                    else:
                        mbrofi.rofi_warn("Failed to mount " + dev.devname)
                        break
                dev.get_mountpath()
                dev.open()
                break
        elif (exit == 15):
            if (index != -1):
                dev = entries[1][index]
                print("ejecting " + dev.devname + "...")
                ok, err = dev.eject()
                if (ok):
                    print("success!")
                else:
                    mbrofi.rofi_warn("Failed to eject " + dev.devname +
                                     "\n" + err)
                    break
        else:
            break
Esempio n. 7
0
def main():
    """Main function."""
    SFR = mbrofi.FileRepo(dirpath=SCREENSHOT_DIRECTORY)
    SFR.scan_files(recursive=False)
    sortby = "cdate"
    sortrev = False
    sortchar = ""
    SFR.sort(sortby, sortrev)
    while True:
        if sortrev:
            sortchar = "^"
        else:
            sortchar = "v"
        launcher_args['mesg'] =  msg + " sorted by: " + \
                                sortby + "[" + sortchar + ']'
        index, filt, sel, exit = main_rofi_function(SFR.filenames())
        print("index:", str(index))
        print("filter:", filt)
        print("selection:", sel)
        print("exit:", str(exit))
        print("------------------")

        launcher_args['filter'] = filt
        launcher_args['index'] = index

        if (exit == 0):
            filepath = os.path.join(SCREENSHOT_DIRECTORY, sel)
            # This is the case where enter is pressed
            if os.path.isfile(filepath):
                mbrofi.xdg_open(filepath)
            break
        elif (exit == 1):
            # this is the case where rofi is escaped (should exit)
            break
        elif (exit == 10):
            message = "List of bindings with descriptions. Press alt-h"
            message += " to go back. Screenshot directory: '"
            message += SCREENSHOT_DIRECTORY + "'"
            mbrofi.rofi_help(launcher_args['bindings'],
                             BIND_HELPLIST,
                             prompt='screenshots help:',
                             message=message)
        elif (exit == 11):
            print('uploading ' + sel)
            pasteurl = mbrofi.upload_ptpb(SCREENSHOT_DIRECTORY,
                                          sel,
                                          notify_bool=True,
                                          name="Screenshot")
            if pasteurl:
                pasteurl = pasteurl.strip()
                mbrofi.clip(pasteurl)
            break
        elif (exit == 12):
            filepath = os.path.join(SCREENSHOT_DIRECTORY, sel)
            print('Previewing' + filepath)
            if os.path.isfile(filepath):
                mbrofi.xdg_open(filepath)
            SFR.scan_files(recursive=False)
            SFR.sort(sortby, sortrev)
        elif (exit == 13):
            print('renaming ' + sel)
            rename_success = rename_screenshot(sel)
            if rename_success:
                SFR.scan_files(recursive=False)
                SFR.sort(sortby, sortrev)
            else:
                print("meh")
        elif (exit == 14):
            if sortby == "name":
                sortrev = (not sortrev)
            else:
                sortby = "name"
                sortrev = True
            SFR.sort(sortby, sortrev)
        elif (exit == 15):
            if sortby == "cdate":
                sortrev = (not sortrev)
            else:
                sortby = "cdate"
                sortrev = False
            SFR.sort(sortby, sortrev)
        elif (exit == 16):
            if sortby == "size":
                sortrev = (not sortrev)
            else:
                sortby = "size"
                sortrev = True
            SFR.sort(sortby, sortrev)
        else:
            break