-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathui.lua
57 lines (46 loc) · 1.96 KB
/
ui.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- global ui object
-- holds ui state and defines listeners and functions for manipulating it
local ui = {}
-- connect all buttons to actions
ui.classes = {widget.pushButton_1, widget.pushButton_2, widget.pushButton_3, widget.pushButton_4, widget.pushButton_5}
ui.currentId = 1
state.request = {x=0, y=0}
-- set current class to learn
for i,button in ipairs(ui.classes) do
button.text = state.classes[i]
qt.connect(qt.QtLuaListener(button),
'sigMousePress(int,int,QByteArray,QByteArray,QByteArray)',
function (...)
ui.currentId = i
ui.currentClass = state.classes[i]
end)
end
-- connect mouse pos
widget.frame.mouseTracking = true
qt.connect(qt.QtLuaListener(widget.frame),
'sigMouseMove(int,int,QByteArray,QByteArray)',
function (x,y)
ui.mouse = {x=x,y=y}
end)
-- issue learning request
qt.connect(qt.QtLuaListener(widget),
'sigMousePress(int,int,QByteArray,QByteArray,QByteArray)',
function (...)
if ui.mouse then
state.request = {}
local no_features = state.network.modules[state.network_table[ui.currentId].i].output:size(1)
local x_features = state.network.modules[state.network_table[ui.currentId].i].output:size(2)
local y_features = state.network.modules[state.network_table[ui.currentId].i].output:size(3)
local rows = math.floor(math.sqrt(no_features))
local cols = math.ceil(no_features/rows)
--calculate which feature map
local x_row = math.floor((ui.mouse.x - options.eye * window_zoom - 20)/((x_features+1)*options.zoom_f))
local y_col = math.floor((ui.mouse.y-30)/((y_features+1)*options.zoom_f))
state.request = {x=x_row, y=y_col}
end
end)
ui.resize = true
widget.windowTitle = title
widget:show()
-- return ui
return ui