Skip to content

Commit

Permalink
add the shortcut key for auto zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
xinntao committed Jun 26, 2022
1 parent 3526fc8 commit ab7cc38
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
12 changes: 12 additions & 0 deletions handyview/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ def keyPressEvent(self, event):
elif event.key() == QtCore.Qt.Key_V:
self.compare_folders(-1)

elif event.key() == QtCore.Qt.Key_Z:
if modifiers == QtCore.Qt.ControlModifier:
# cancel auto zoom
self.target_zoom_width = 0
else:
self.auto_zoom()

elif event.key() == QtCore.Qt.Key_Space:
if modifiers == QtCore.Qt.ShiftModifier:
self.dir_browse(10)
Expand Down Expand Up @@ -332,3 +339,8 @@ def toggle_bg_color(self):
self.qview_bg_color = 'white'
for qscene in self.qscenes:
qscene.setBackgroundBrush(QtCore.Qt.white)

def auto_zoom(self):
target_zoom_width = self.qimg.width() * self.qviews[0].zoom
self.target_zoom_width = int(target_zoom_width)
return self.target_zoom_width
2 changes: 2 additions & 0 deletions handyview/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def get_init_path_list(self):
self.recursive_scan_folder = True
self.path_list[0] = list(scandir(self.init_path, suffix=FORMATS, recursive=True, full_path=True))
self.init_path = self.path_list[0][0]
else:
self.recursive_scan_folder = False

# fix the path pattern passed from windows system when double click
self.init_path = self.init_path.replace('\\', '/')
Expand Down
17 changes: 11 additions & 6 deletions handyview/handyviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def add_dock_window(self):
# slots: open and history
# ---------------------------------------
def open_file_dialog(self):
# Compare folder should be set in Main Cavans
if self.canvas_type != 'main':
self.switch_main_canvas()

if self.center_canvas.tabs.currentIndex() == 2: # video
self.center_canvas.canvas_video.open_files()
else:
Expand Down Expand Up @@ -362,8 +366,9 @@ def clear_compare(self):
def switch_main_canvas(self):
if self.canvas_type != 'main':
self.hvdb.interval = 0
self.center_canvas.canvas = Canvas(self, self.hvdb)
self.setCentralWidget(self.center_canvas.canvas)
# TODO: create a new one, which is ugly
self.center_canvas = CenterWidget(self, self.hvdb)
self.setCentralWidget(self.center_canvas)
self.add_dock_window()
self.canvas_type = 'main'

Expand Down Expand Up @@ -436,15 +441,15 @@ def set_fingerprint(self):
# slots: auto zoom
# ---------------------------------------
def auto_zoom(self):
target_zoom_width = self.center_canvas.canvas.qimg.width() * self.center_canvas.canvas.qviews[0].zoom
self.center_canvas.canvas.target_zoom_width = int(target_zoom_width)
self.center_canvas.canvas.auto_zoom()

def auto_zoom_dialog(self):
target_zoom_width = self.center_canvas.canvas.qimg.width() * self.center_canvas.canvas.qviews[0].zoom
target_zoom_width = self.center_canvas.canvas.auto_zoom()
target_zoom_width, ok = QInputDialog.getText(self, 'Auto Zoom', 'Fix image width: (0 for cancelling auto zoom)',
QLineEdit.Normal, str(int(target_zoom_width)))
QLineEdit.Normal, str(target_zoom_width))
if ok:
self.center_canvas.canvas.target_zoom_width = int(target_zoom_width)
self.center_canvas.canvas.show_image(init=False)


def create_new_window(init_path=None):
Expand Down
8 changes: 7 additions & 1 deletion handyview/instruction_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
C: (Compare): switch images under single-view compare mode
V: Switch images under single-view compare mode
C and V are a pair, similar to Direction key ← →, but switch among folders
Space : Next image
Z: Auto zoom
Shift + Z: Cancel auto zoom
Space: Next image
Backspace: Previous image
Tab: Switch the focused views
'''
instruct_text_cn = r'''
▶ 滚轮操作
Expand All @@ -47,6 +50,9 @@
C: (Compare) 单视图比较模式下, 图像切换
V: 单视图比较模式下, 图像切换.
C和V是一对, 类似左右方向键切换, 只是在多个folder间切换
Z: 自动缩放
Shift + Z: 取消自动缩放
Space: 图像切换, 下一张图像
Backspace: 图像切换, 上一张图像
Tab: 改变激活的图片查看窗口
'''

0 comments on commit ab7cc38

Please sign in to comment.