Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve issue 16 #26

Merged
merged 4 commits into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 88 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def __init__(self, parent, UpdateUI, get_type):
self.box_id = -1
self.xy_magnifier = []
self.show_scale_proportion = 0
self.key_status = {"shift": 0, "ctrl": 0, "alt": 0}
self.indextablegui = None
self.aboutgui = None
self.icon = wx.Icon(get_resource_path(
'mulimgviewer.ico'), wx.BITMAP_TYPE_ICO)
self.SetIcon(self.icon)
Expand Down Expand Up @@ -326,13 +329,15 @@ def delete_box(self, event):
self.SetStatusText_(["delete all box", "-1", "-1", "-1"])

def up_img(self, event):
speed = self.get_speed(name="pixel")

if self.select_img_box.Value:
if self.box_id != -1:
box_point = self.xy_magnifier[self.box_id][0:4]
show_scale = self.xy_magnifier[self.box_id][4:6]
x, y = self.get_center_box(box_point)
x = x+0
y = y-1
y = y-speed
self.xy_magnifier[self.box_id][0:4] = self.move_box_point(
x, y, show_scale)
self.refresh(event)
Expand All @@ -343,19 +348,21 @@ def up_img(self, event):
self.position[1] = int(
self.scrolledWindow_img.GetScrollPos(wx.VERTICAL)/self.Uint[1])
if self.position[1] > 0:
self.position[1] -= 1
self.position[1] -= speed
self.scrolledWindow_img.Scroll(
self.position[0]*self.Uint[0], self.position[1]*self.Uint[1])
self.SetStatusText_(["Up", "-1", "-1", "-1"])

def down_img(self, event):
speed = self.get_speed(name="pixel")

if self.select_img_box.Value:
if self.box_id != -1:
box_point = self.xy_magnifier[self.box_id][0:4]
show_scale = self.xy_magnifier[self.box_id][4:6]
x, y = self.get_center_box(box_point)
x = x+0
y = y+1
y = y+speed
self.xy_magnifier[self.box_id][0:4] = self.move_box_point(
x, y, show_scale)
self.refresh(event)
Expand All @@ -366,7 +373,7 @@ def down_img(self, event):
self.position[1] = int(
self.scrolledWindow_img.GetScrollPos(wx.VERTICAL)/self.Uint[1])
if (self.position[1]-1)*self.Uint[1] < size[1]:
self.position[1] += 1
self.position[1] += speed
self.scrolledWindow_img.Scroll(
self.position[0]*self.Uint[0], self.position[1]*self.Uint[1])
else:
Expand All @@ -375,12 +382,14 @@ def down_img(self, event):
self.SetStatusText_(["Down", "-1", "-1", "-1"])

def right_img(self, event):
speed = self.get_speed(name="pixel")

if self.select_img_box.Value:
if self.box_id != -1:
box_point = self.xy_magnifier[self.box_id][0:4]
show_scale = self.xy_magnifier[self.box_id][4:6]
x, y = self.get_center_box(box_point)
x = x+1
x = x+speed
y = y+0
self.xy_magnifier[self.box_id][0:4] = self.move_box_point(
x, y, show_scale)
Expand All @@ -392,7 +401,7 @@ def right_img(self, event):
self.position[1] = int(
self.scrolledWindow_img.GetScrollPos(wx.VERTICAL)/self.Uint[1])
if (self.position[0]-1)*self.Uint[0] < size[0]:
self.position[0] += 1
self.position[0] += speed
self.scrolledWindow_img.Scroll(
self.position[0]*self.Uint[0], self.position[1]*self.Uint[1])
else:
Expand All @@ -401,12 +410,14 @@ def right_img(self, event):
self.SetStatusText_(["Right", "-1", "-1", "-1"])

def left_img(self, event):
speed = self.get_speed(name="pixel")

if self.select_img_box.Value:
if self.box_id != -1:
box_point = self.xy_magnifier[self.box_id][0:4]
show_scale = self.xy_magnifier[self.box_id][4:6]
x, y = self.get_center_box(box_point)
x = x-1
x = x-speed
y = y+0
self.xy_magnifier[self.box_id][0:4] = self.move_box_point(
x, y, show_scale)
Expand All @@ -418,7 +429,7 @@ def left_img(self, event):
self.position[1] = int(
self.scrolledWindow_img.GetScrollPos(wx.VERTICAL)/self.Uint[1])
if self.position[0] > 0:
self.position[0] -= 1
self.position[0] -= speed
self.scrolledWindow_img.Scroll(
self.position[0]*self.Uint[0], self.position[1]*self.Uint[1])
self.SetStatusText_(["Left", "-1", "-1", "-1"])
Expand Down Expand Up @@ -531,6 +542,12 @@ def img_left_move(self, event):
RGBA = self.ImgManager.img.getpixel((int(x), int(y)))
self.m_statusBar1.SetStatusText(str(x)+","+str(y)+"/"+str(RGBA), 0)

# focus img
if self.indextablegui or self.aboutgui:
pass
else:
self.img_panel.Children[0].SetFocus()

def img_left_release(self, event):
if self.magnifier.Value != False:
self.start_flag = 0
Expand Down Expand Up @@ -616,14 +633,18 @@ def get_center_box(self, box, more=False):

def img_wheel(self, event):
# https://wxpython.org/Phoenix/docs/html/wx.MouseEvent.html

# zoom
i_cur = 0
status_toggle = [self.magnifier, self.rotation, self.flip]
if status_toggle[i_cur].Value:
if status_toggle[i_cur].Value and (self.key_status["ctrl"] == 1):
if event.GetWheelDelta() >= 120:
speed = self.get_speed(name="scale")

if event.GetWheelRotation() > 0:
self.show_scale_proportion = self.show_scale_proportion+0.1
self.show_scale_proportion = self.show_scale_proportion+speed
else:
self.show_scale_proportion = self.show_scale_proportion-0.1
self.show_scale_proportion = self.show_scale_proportion-speed

if self.show_scale_proportion > 0:
show_scale = [1*(1+self.show_scale_proportion),
Expand All @@ -638,12 +659,54 @@ def img_wheel(self, event):
round(show_scale[0], 2))+","+str(round(show_scale[1], 2))

self.refresh(event)

else:
pass
else:
pass

# move
if self.key_status["ctrl"] == 0 and event.GetWheelDelta() >= 120:
if event.WheelAxis == 0:
if event.GetWheelRotation() > 0:
self.up_img(event)
else:
self.down_img(event)
else:
if event.GetWheelRotation() > 0:
self.right_img(event)
else:
self.left_img(event)

def key_down_detect(self, event):
if event.GetKeyCode() == wx.WXK_CONTROL:
self.key_status["ctrl"] = 1
elif event.GetKeyCode() == wx.WXK_SHIFT:
if self.key_status["shift"] == 0:
self.key_status["shift"] = 1
elif self.key_status["shift"] == 1:
self.key_status["shift"] = 0

def key_up_detect(self, event):
if event.GetKeyCode() == wx.WXK_CONTROL:
self.key_status["ctrl"] = 0
elif event.GetKeyCode() == wx.WXK_SHIFT:
pass

def get_speed(self, name="pixel"):
if name == "pixel":
if self.key_status["shift"] == 1:
speed = 5
else:
speed = 1
elif name == "scale":
if self.key_status["shift"] == 1:
speed = 0.5
else:
speed = 0.1
else:
speed = None
return speed

def magnifier_fc(self, event):
self.start_flag = 0
self.show_scale.Value = "1,1"
Expand Down Expand Up @@ -804,6 +867,7 @@ def set_img_layout(self):
self.show_crop.Value, # 18
self.parallel_to_sequential.Value, # 19
self.one_img.Value, # 20
self.box_position, # 21
self.checkBox_orientation.Value]

def show_img(self):
Expand All @@ -819,8 +883,9 @@ def show_img(self):
self.ImgManager.input_path, self.ImgManager.type, parallel_to_sequential)
self.show_img_init()
self.ImgManager.set_action_count(action_count)
self.index_table.show_id_table(
self.ImgManager.name_list, self.ImgManager.layout_params)
if self.index_table_gui:
self.index_table_gui.show_id_table(
self.ImgManager.name_list, self.ImgManager.layout_params)
except:
pass

Expand Down Expand Up @@ -852,6 +917,7 @@ def show_img(self):
wx.Size(self.img_size[0]+100, self.img_size[1]+100))
self.img_last = wx.StaticBitmap(parent=self.img_panel,
bitmap=bmp)
self.img_panel.Children[0].SetFocus()
self.img_panel.Children[0].Bind(
wx.EVT_LEFT_DOWN, self.img_left_click)
self.img_panel.Children[0].Bind(
Expand All @@ -864,6 +930,10 @@ def show_img(self):
wx.EVT_RIGHT_DOWN, self.img_right_click)
self.img_panel.Children[0].Bind(
wx.EVT_MOUSEWHEEL, self.img_wheel)
self.img_panel.Children[0].Bind(
wx.EVT_KEY_DOWN, self.key_down_detect)
self.img_panel.Children[0].Bind(
wx.EVT_KEY_UP, self.key_up_detect)

# status
if self.ImgManager.type == 2 or ((self.ImgManager.type == 0 or self.ImgManager.type == 1) and self.parallel_sequential.Value):
Expand Down Expand Up @@ -948,8 +1018,8 @@ def auto_layout(self, frame_resize=False):
self.Refresh()

def about_gui(self, event):
about = About(None)
about.Show(True)
self.aboutgui = About(None)
self.aboutgui.Show(True)

def index_table_gui(self, event):
if self.ImgManager.img_num != 0:
Expand All @@ -961,10 +1031,10 @@ def index_table_gui(self, event):
self.SetStatusText_(
["-1", "-1", "index_table.txt saving...", "-1"])
if self.ImgManager.type == 3:
self.index_table = IndexTable(
self.indextablegui = IndexTable(
None, self.ImgManager.path_list, self.ImgManager.layout_params, self.ImgManager.dataset_mode, self.out_path_str, self.ImgManager.type, self.parallel_sequential.Value)
else:
self.index_table = IndexTable(
self.indextablegui = IndexTable(
None, self.ImgManager.name_list, self.ImgManager.layout_params, self.ImgManager.dataset_mode, self.out_path_str, self.ImgManager.type, self.parallel_sequential.Value)
if self.ImgManager.dataset_mode:
self.SetStatusText_(
Expand Down
7 changes: 6 additions & 1 deletion main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__( self, parent ):

fgSizer4.Add( self.m_staticText1, 0, wx.ALL, 5 )

self.img_panel = wx.Panel( self.scrolledWindow_img, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,-1 ), wx.TAB_TRAVERSAL )
self.img_panel = wx.Panel( self.scrolledWindow_img, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,-1 ), wx.BORDER_NONE )
fgSizer4.Add( self.img_panel, 1, wx.EXPAND |wx.ALL, 5 )


Expand Down Expand Up @@ -349,6 +349,11 @@ def __init__( self, parent ):
self.line_width = wx.TextCtrl( self.scrolledWindow_set, wx.ID_ANY, u"2", wx.DefaultPosition, wx.Size( 40,-1 ), 0 )
wSizer7.Add( self.line_width, 0, wx.ALL, 5 )

box_positionChoices = [ u"middle bottom", u"left bottom", u"right bottom", u"left top", u"right top" ]
self.box_position = wx.Choice( self.scrolledWindow_set, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, box_positionChoices, 0 )
self.box_position.SetSelection( 0 )
wSizer7.Add( self.box_position, 0, wx.ALL, 5 )


fgSizer3.Add( wSizer7, 1, wx.EXPAND, 5 )

Expand Down
Loading