コード例 #1
0
def first_run_init(app):
    yield resp.resp('window_show')
    yield resp.resp('welcome_screen')

    for aresp in resp.noopify(
            req.book_create(app,
                            profile='default',
                            book='learning',
                            hotkey=['f2'],
                            active_profile='default',
                            no_process='write')):

        yield aresp

    for aresp in resp.noopify(
            req.page_create(app,
                            profile='default',
                            book='learning',
                            program='uncrumpled',
                            init_text=init_text)):
        page_id = aresp['page_id']
        yield aresp

    for aresp in resp.noopify(
            req.book_create(app,
                            profile='default',
                            book='scratchpad',
                            hotkey=['f3'],
                            active_profile='default',
                            no_process='read')):
        yield aresp
    yield resp.resp('page_load', page_id=page_id)
コード例 #2
0
def hotkeys_reload(app, old, new):
    '''
    changes the active system hotkeys based on the profiles

    :old: old profile that has had it's hotkeys currently loaded
    :new: new profile
    '''
    if old != new:
        for hotkey in dbapi.hotkey_get_all(app.db, old):
            yield resp.resp('system_hotkey_unregister', hotkey=hotkey)
        for hotkey in dbapi.hotkey_get_all(app.db, new):
            yield resp.resp('system_hotkey_register', hotkey=hotkey)
コード例 #3
0
def ui_init(app, first_run, user_or_token=None, password=None):
    '''
    Code for startup
    '''
    # Setup default books etc
    if first_run:
        yield from first_run_init(app)

    # if data.get('new_user'):
    # yield config.new_user(data)
    # yield config.ui_config()

    # Setup the system
    sys_init(app.SYSTEM)

    # Set active profile
    profile = dbapi.profile_get_active(app.db)
    yield resp.resp('profile_set_active', profile=profile)

    # Load hotkeys
    for aresp in req.hotkeys_load_all(app, profile):
        yield aresp

    # Load keymap
    for aresp in parse_keymap(app):
        yield aresp
コード例 #4
0
def hotkeys_load(app, profile, book, hotkey):
    '''
    Load one hotkey
    '''
    if not dbapi.hotkey_get(app.db, profile, book):
        yield resp.noop(key='hotkey_not_found')
    else:
        yield resp.resp('system_hotkey_register', hotkey=hotkey)
コード例 #5
0
ファイル: cmdpane.py プロジェクト: gitter-badger/Uncrumpled
def cmdpane_item_open(app, item):
    '''
    the user has pressed enter on a result..
    '''
    result = Source().data[item]
    if result.ui:
        yield resp.resp('cmdpane_ui_build', ui=result.ui)
    else:
        import pdb
        pdb.set_trace()
コード例 #6
0
def hotkey_pressed(app, profile, program, hotkey, system_pages):
    '''
    profile -> active profile
    hotkey -> the pressed hotkey

    evaluates a hotkey, can either
    * load an existing page
    * create a page, (optionally load it)
    '''
    # TODO DELETE
    global DEVELOPING
    if hasattr(app, 'DEVELOPING'):
        DEVELOPING = app.DEVELOPING

    if DEVELOPING and program in ('python3', 'python'):
        program = 'uncrumpled'

    # Find the book that is bound to the hotkey
    hotkey = json.dumps(hotkey)
    cond = "WHERE Hotkey == '{}' AND \
                  Profile == '{}'".format(hotkey, profile)
    book = halt.load_column(app.db, 'Hotkeys', ('Book', ), cond)[0][0]

    cond = "WHERE Book == '{}' AND \
                  Profile == '{}'".format(book, profile)
    bookopts = json.loads(
        halt.load_column(app.db, 'Books', ('MashConfig', ), cond)[0][0])

    if bookopts['no_process'] == 'read':
        page_id = bookopts.get('read_page')
    else:
        page_id = page_find(app.db, profile, book, program, bookopts)

    # Potentially create and load a new page
    if not page_id:
        response = no_process(app, profile, book, program, hotkey, bookopts)
        if response:
            yield from close_open_pages(system_pages, ignore=page_id)
            create_resp = next(response)
            yield create_resp
            page_id = yield from response
            yield resp.resp('page_load', page_id=page_id)
            yield resp.resp('window_show')
        else:
            yield False
    # Open or close a page
    else:
        if system_pages.get(page_id, {}).get('is_open'):
            yield resp.resp('page_close', page_id=page_id)
            yield resp.resp('window_hide')
        # NOTE, this is a simple work around to make uncrumpled
        # be able to have notepages on it, This implementaiton limits
        # alot of options (we are not using them atm so it is ok)
        else:
            yield from close_open_pages(system_pages, ignore=page_id)
            yield resp.resp('page_load', page_id=page_id)
            yield resp.resp('window_show')
コード例 #7
0
def parse_keymap(app):
    '''
    reads the default keymap file, then the user keymap file

    pound #, can be used for comments
    '''
    for file in KEYMAP_FILES:
        data = get_contents(os.path.join(app.data_dir, file))
        for action, keybind in data.items():
            if action not in resp._UI:
                import pdb
                pdb.set_trace()
                raise Exception('{} not in supported ui'.format(action))

            hk, kwargs = get_kwargs(keybind)
            yield resp.resp('bind_add',
                            resp_id='bind_add',
                            hotkey=hk,
                            event_type=kwargs.get('event_type'),
                            command=action,
                            command_kwargs=kwargs)
コード例 #8
0
def settings_from_pageid(app, page_id, level: SettingSelector):
    data = {}
    page_settings = dbapi.page_get(app.db, page_id)
    if page_settings:
        data['page_settings'] = page_settings
    else:
        yield resp.status(key='page_not_found', code=0)
        return

    # Get the profile settings
    profile = page_settings.get('Profile')
    if level in (SettingSelector.all, SettingSelector.profile,
                 SettingSelector.book_and_profile,
                 SettingSelector.page_and_profile):
        profile_settings = dbapi.profile_get(app.db, profile)
        if profile_settings:
            data['profile_settings'] = profile_settings
        else:
            yield resp.status(key='profile_not_found',
                              code=0,
                              template={'profile': profile})
            return

    # Get the Book settings
    book = page_settings.get('Book')
    if level in (SettingSelector.all, SettingSelector.book,
                 SettingSelector.book_and_profile,
                 SettingSelector.page_and_book):
        book_settings = dbapi.book_get(app.db, profile, book)
        if book_settings:
            data['book_settings'] = book_settings
        else:
            yield resp.status(key='book_not_found',
                              code=0,
                              template={'book': book})
            return

    yield resp.resp('page_settings_view', settings=data)
コード例 #9
0
def close_open_pages(system_pages, ignore):
    for to_close, value in system_pages.items():
        if to_close != ignore:
            # TODO the fact that only open pages are closed is not tested (was causing bugs..)
            if value['is_open']:
                yield resp.resp('page_close', page_id=to_close)
コード例 #10
0
ファイル: cmdpane.py プロジェクト: gitter-badger/Uncrumpled
def cmdpane_search(app, query: str):
    input = Source().get()
    fuzzed = fzf.fuzz(query, input_list=input).splitlines()
    heads, bodies = Source().parse_results(fuzzed)
    yield resp.resp('cmdpane_search_results', headings=heads, bodies=bodies)
コード例 #11
0
def hotkeys_load_all(app, active_profile):
    '''
    only use this at startup, init system wide hotkeys for the active profile
    '''
    for hotkey in dbapi.hotkey_get_all(app.db, active_profile):
        yield resp.resp('system_hotkey_register', hotkey=hotkey)