Example #1
0
def cli(paths, mode, name_regex, pixel_size, dry_run, strict, name, mmap, lazy,
        no_show):
    """
    PeepingTom command line interface.

    Opens files in napari and lands in an interactive ipython shell
    with peepingtom imported as `pt` and the initialised Peeper available as `p`.

    PATHS: any number of files or globs [default='./*']

    \b
    MODE choices:
      - lone: each datablock in a separate volume
      - zip_by_type: one of each datablock type per volume
      - bunch: all datablocks in a single volume

    \b
    EXAMPLES:
    Open a .star file as particles:
        peep particles.star
    Open particles and images from a directory:
        peep /dir/with/star_and_mrc_files/
    Match files such as MyProtein_10.star and MyProtein_001.mrc,
    and name the respective DataBlocks Protein_10 and Protein_001:
        peep /path/to/dir/MyProtein* -n 'Protein_\d+'
    """  # noqa: W605
    if not paths:
        paths = ['./*']

    if dry_run:
        files = pt.io_.find_files(paths)
        print('Files found:')
        print(*(str(file) for file in files), sep='\n')
        sys.exit()

    peeper = pt.read(
        *paths,  # noqa: F841
        name=name,
        mode=mode,
        name_regex=name_regex,
        pixel_size=pixel_size,
        strict=strict,
        mmap=mmap,
        lazy=lazy,
    )

    # set up ipython shell nicely
    banner = '''=== PeepingTom ===
initialised variables:
    - peeper
    - viewer
    '''
    sh = InteractiveShellEmbed(banner2=banner)
    sh.enable_gui('qt')
    sh.push('peeper')
    if not no_show:
        sh.run_cell('peeper.show()', silent=True)
    viewer = peeper.napari_viewer  # noqa: F841
    sh.push('viewer')
    sh()
Example #2
0
def cli(paths, mode, name_regex, pixel_size, dry_run, strict, name, lazy,
        no_show):
    """
    Blik command line interface.

    Opens files in napari and lands in an interactive ipython shell
    with blik imported and the initialised DataSet available as `dataset`.

    PATHS: any number of files or globs [default='./*']

    \b
    MODE choices:
      - lone: each datablock in a separate volume
      - zip_by_type: one of each datablock type per volume
      - bunch: all datablocks in a single volume

    \b
    EXAMPLES:
    Open a .star file as particles:
        blik particles.star
    Open particles and images from a directory:
        blik /dir/with/star_and_mrc_files/
    Match files such as MyProtein_10.star and MyProtein_001.mrc,
    and name the respective DataBlocks Protein_10 and Protein_001:
        blik /path/to/dir/MyProtein* -n 'Protein_\d+'
    """  # noqa: W605
    if not paths:
        paths = ['./*']

    if dry_run:
        from blik.io_.reading.main import find_files
        files = [str(file) for file in find_files(paths)]
        if files:
            click.echo('Files found:\n' + '\n'.join(files))
        else:
            click.echo('No files found.')
        click.get_current_context().exit()

    import blik
    from IPython.terminal.embed import InteractiveShellEmbed

    dataset = blik.read(
        *paths,  # noqa: F841
        name=name,
        mode=mode,
        name_regex=name_regex,
        pixel_size=pixel_size,
        strict=strict,
        lazy=lazy,
    )

    # set up ipython shell nicely
    banner = '''=== Blik ===
initialised variables:
    - dataset
    - viewer
    '''
    sh = InteractiveShellEmbed(banner2=banner)
    sh.enable_gui('qt')
    sh.push('dataset')
    if not no_show:
        sh.run_cell('dataset.show()', silent=True)
    viewer = dataset.napari_viewer  # noqa: F841
    sh.push('viewer')
    sh()
Example #3
0
"""
Start napari and land directly in an embedded ipython console with qt event loop.

A similar effect can be achieved more simply with `viewer.update_console(locals())`,
such as shown in https://github.com/napari/napari/blob/main/examples/update_console.py.

However, differently from `update_console`, this will start an independent
ipython console which can outlive the viewer.
"""

import napari
from IPython.terminal.embed import InteractiveShellEmbed

# any code
text = 'some text'

# initalize viewer
viewer = napari.Viewer()

# embed ipython and run the magic command to use the qt event loop
sh = InteractiveShellEmbed()
sh.enable_gui('qt')  # equivalent to using the '%gui qt' magic
sh()  # open the embedded shell

# From there, you can access the script's scope, such as the variables `text` and `viewer`
Example #4
0
        layout = QVBoxLayout()
        dialog.setLayout(layout)
        layout.addWidget(table)
        dialog.setWindowTitle(title)
        dialog.exec_()

    def __get_table_model(self, data):
        if isinstance(data, DataFrame):
            return PandasDataframeModel(data)
        elif isinstance(data, Series):
            return PandasSeriesModel(data)

    def __console(self):
        df = self.__dataframe  # noqa
        shell()

    def __action(self, label, shortcut, callback):
        action = QAction(QIcon("icon.ico"), label, self)
        action.setShortcut(shortcut)
        action.triggered.connect(callback)
        return action


if __name__ == "__main__":
    shell = InteractiveShellEmbed()
    shell.enable_gui("qt5")
    appctxt = AppContext()
    exit_code = appctxt.run()
    sys.exit(exit_code)
    set_option("precision", 1)