Skip to content

Commit ab7cc38

Browse files
committed
add the shortcut key for auto zoom
1 parent 3526fc8 commit ab7cc38

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

handyview/canvas.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ def keyPressEvent(self, event):
119119
elif event.key() == QtCore.Qt.Key_V:
120120
self.compare_folders(-1)
121121

122+
elif event.key() == QtCore.Qt.Key_Z:
123+
if modifiers == QtCore.Qt.ControlModifier:
124+
# cancel auto zoom
125+
self.target_zoom_width = 0
126+
else:
127+
self.auto_zoom()
128+
122129
elif event.key() == QtCore.Qt.Key_Space:
123130
if modifiers == QtCore.Qt.ShiftModifier:
124131
self.dir_browse(10)
@@ -332,3 +339,8 @@ def toggle_bg_color(self):
332339
self.qview_bg_color = 'white'
333340
for qscene in self.qscenes:
334341
qscene.setBackgroundBrush(QtCore.Qt.white)
342+
343+
def auto_zoom(self):
344+
target_zoom_width = self.qimg.width() * self.qviews[0].zoom
345+
self.target_zoom_width = int(target_zoom_width)
346+
return self.target_zoom_width

handyview/db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def get_init_path_list(self):
4848
self.recursive_scan_folder = True
4949
self.path_list[0] = list(scandir(self.init_path, suffix=FORMATS, recursive=True, full_path=True))
5050
self.init_path = self.path_list[0][0]
51+
else:
52+
self.recursive_scan_folder = False
5153

5254
# fix the path pattern passed from windows system when double click
5355
self.init_path = self.init_path.replace('\\', '/')

handyview/handyviewer.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ def add_dock_window(self):
242242
# slots: open and history
243243
# ---------------------------------------
244244
def open_file_dialog(self):
245+
# Compare folder should be set in Main Cavans
246+
if self.canvas_type != 'main':
247+
self.switch_main_canvas()
248+
245249
if self.center_canvas.tabs.currentIndex() == 2: # video
246250
self.center_canvas.canvas_video.open_files()
247251
else:
@@ -362,8 +366,9 @@ def clear_compare(self):
362366
def switch_main_canvas(self):
363367
if self.canvas_type != 'main':
364368
self.hvdb.interval = 0
365-
self.center_canvas.canvas = Canvas(self, self.hvdb)
366-
self.setCentralWidget(self.center_canvas.canvas)
369+
# TODO: create a new one, which is ugly
370+
self.center_canvas = CenterWidget(self, self.hvdb)
371+
self.setCentralWidget(self.center_canvas)
367372
self.add_dock_window()
368373
self.canvas_type = 'main'
369374

@@ -436,15 +441,15 @@ def set_fingerprint(self):
436441
# slots: auto zoom
437442
# ---------------------------------------
438443
def auto_zoom(self):
439-
target_zoom_width = self.center_canvas.canvas.qimg.width() * self.center_canvas.canvas.qviews[0].zoom
440-
self.center_canvas.canvas.target_zoom_width = int(target_zoom_width)
444+
self.center_canvas.canvas.auto_zoom()
441445

442446
def auto_zoom_dialog(self):
443-
target_zoom_width = self.center_canvas.canvas.qimg.width() * self.center_canvas.canvas.qviews[0].zoom
447+
target_zoom_width = self.center_canvas.canvas.auto_zoom()
444448
target_zoom_width, ok = QInputDialog.getText(self, 'Auto Zoom', 'Fix image width: (0 for cancelling auto zoom)',
445-
QLineEdit.Normal, str(int(target_zoom_width)))
449+
QLineEdit.Normal, str(target_zoom_width))
446450
if ok:
447451
self.center_canvas.canvas.target_zoom_width = int(target_zoom_width)
452+
self.center_canvas.canvas.show_image(init=False)
448453

449454

450455
def create_new_window(init_path=None):

handyview/instruction_text.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
C: (Compare): switch images under single-view compare mode
2222
V: Switch images under single-view compare mode
2323
C and V are a pair, similar to Direction key ← →, but switch among folders
24-
Space : Next image
24+
Z: Auto zoom
25+
Shift + Z: Cancel auto zoom
26+
Space: Next image
2527
Backspace: Previous image
28+
Tab: Switch the focused views
2629
'''
2730
instruct_text_cn = r'''
2831
▶ 滚轮操作
@@ -47,6 +50,9 @@
4750
C: (Compare) 单视图比较模式下, 图像切换
4851
V: 单视图比较模式下, 图像切换.
4952
C和V是一对, 类似左右方向键切换, 只是在多个folder间切换
53+
Z: 自动缩放
54+
Shift + Z: 取消自动缩放
5055
Space: 图像切换, 下一张图像
5156
Backspace: 图像切换, 上一张图像
57+
Tab: 改变激活的图片查看窗口
5258
'''

0 commit comments

Comments
 (0)