Skip to content

Commit

Permalink
docs and prettier import
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Aug 17, 2021
1 parent ea10ce8 commit 084c39b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
13 changes: 7 additions & 6 deletions impy/viewer/keybinds.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from impy.viewer.widgets.dialog import ProjectionDialog
from ..arrays import LabeledArray
from ..core import array as ip_array
from .utils import *
from .widgets import DuplicateDialog
import numpy as np
from napari.layers.utils._link_layers import link_layers, unlink_layers
import napari

from .utils import *
from .widgets import DuplicateDialog, ProjectionDialog

from ..arrays import LabeledArray
from ..core import array as ip_array

# Shift, Control, Alt, Meta, Up, Down, Left, Right, PageUp, PageDown, Insert,
# Delete, Home, End, Escape, Backspace, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10,
# F11, F12, Space, Enter, Tab
Expand Down Expand Up @@ -336,7 +337,7 @@ def proj(viewer:"napari.Viewer"):
@bind_key
def duplicate_layer(viewer:"napari.Viewer"):
"""
Duplicate selected layer(s).
Duplicate the selected layer.
"""
layer = get_a_selected_layer(viewer)

Expand Down
9 changes: 7 additions & 2 deletions impy/viewer/widgets/dialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from __future__ import annotations
from impy.utils.axesop import find_first_appeared
from PyQt5.QtWidgets import QVBoxLayout
from qtpy.QtWidgets import QDialog, QPushButton, QLabel, QGridLayout, QCheckBox, QLineEdit, QComboBox, QHBoxLayout
import napari
import numpy as np
Expand All @@ -9,6 +7,7 @@
from ..utils import add_labeledarray, copy_layer, front_image, add_labels
from ..._const import SetConst
from ...utils.slicer import axis_targeted_slicing
from ...utils.axesop import find_first_appeared

def close_anyway(func):
@wraps(func)
Expand Down Expand Up @@ -85,6 +84,9 @@ def _add_widgets(self):


class DuplicateDialog(QDialog):
"""
This dialog is opened when an image layer is duplicated.
"""
def __init__(self, viewer:"napari.Viewer", layer):
self.viewer = viewer
self.layer = layer
Expand Down Expand Up @@ -169,6 +171,9 @@ def _add_widgets(self):
return None

class ProjectionDialog(QDialog):
"""
This dialog is opened when an image layer is projected.
"""
def __init__(self, viewer:"napari.Viewer", layer):
self.viewer = viewer
self.layer = layer
Expand Down
8 changes: 6 additions & 2 deletions impy/viewer/widgets/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from ...core import imread

class Explorer(QWidget):
"""
A Read-only explorer widget. Capable of filter, set working directory, copy path and open file in the viewer.
By default QTreeView supports real time update on file change.
"""
def __init__(self, viewer:"napari.Viewer", path:str=""):
super().__init__(viewer.window._qt_window)
self.viewer = viewer
Expand Down Expand Up @@ -92,7 +96,7 @@ def __init__(self, parent, path:str):

self.show()

def _set_file_model(self, path):
def _set_file_model(self, path:str):
self.file_system.setRootPath(path)
self.setModel(self.file_system)
self.setRootIndex(self.file_system.index(path))
Expand Down Expand Up @@ -173,7 +177,7 @@ def keyPressEvent(self, event):
return super().keyPressEvent(event)

@property
def selected(self):
def selected(self) -> QModelIndex:
inds = self.selectionModel().selectedIndexes()
if len(inds) > 0:
index = inds[0]
Expand Down
5 changes: 5 additions & 0 deletions impy/viewer/widgets/textedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def read_txt(viewer:"napari.Viewer", path:str):
return viewer.window.add_dock_widget(text, area="right", name=title)

class TxtFileWidget(QWidget):
"""
A read-only text viewer widget with JSON-like highlight. Capable of search lines.
"""
def __init__(self, viewer:"napari.Viewer", title:str=None):
super().__init__(viewer.window._qt_window)
self.viewer = viewer
Expand Down Expand Up @@ -103,6 +106,8 @@ def _():
self.layout().addWidget(wid)

def change_wrap_mode(self):
# line wrap mode = 0 -> No wrap
# line wrap mode = 1 -> wrapped
mode = self.txtviewer.lineWrapMode()
self.txtviewer.setLineWrapMode(1-mode)
return None
Expand Down

0 comments on commit 084c39b

Please sign in to comment.