Skip to content

Commit 5796b94

Browse files
committed
panel implementation
1 parent 9ead262 commit 5796b94

File tree

2 files changed

+74
-53
lines changed

2 files changed

+74
-53
lines changed

spikeinterface_gui/backend_panel.py

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import param
22
import panel as pn
3-
3+
import numpy as np
4+
from copy import copy
45

56
from .viewlist import possible_class_views
67
from .layout_presets import get_layout_description
@@ -182,7 +183,48 @@ def listen_setting_changes(view):
182183
for setting_data in view._settings:
183184
view.settings._parameterized.param.watch(view.on_settings_changed, setting_data["name"])
184185

186+
def get_size_top_row(initial_row, initial_col, is_zone_array, original_zone_array):
187+
188+
if original_zone_array[initial_row][initial_col] == False:
189+
return 0,0
190+
191+
num_rows = is_zone_array[initial_row][initial_col]*1
192+
num_cols = num_rows
193+
194+
num_rows += (not is_zone_array[1][initial_col])*1
195+
196+
if num_rows == 1:
197+
for zone in is_zone_array[0,1+initial_col:]:
198+
if zone == True:
199+
break
200+
num_cols += 1
201+
elif num_rows == 2:
202+
for zone1, zone2 in np.transpose(is_zone_array[:,1+initial_col:]):
203+
if zone1 == True or zone2 == True:
204+
break
205+
num_cols += 1
206+
207+
is_zone_array[initial_row:initial_row+num_rows,initial_col:initial_col+num_cols] = True
185208

209+
return num_rows, num_cols
210+
211+
def get_size_bottom_row(initial_row, initial_col, is_zone_array, original_zone_array):
212+
213+
if original_zone_array[initial_row][initial_col] == False:
214+
return 0,0
215+
216+
num_rows = is_zone_array[initial_row][initial_col]*1
217+
if num_rows == 0:
218+
return 0, 0
219+
num_cols = num_rows
220+
221+
for zone in is_zone_array[1,1+initial_col:]:
222+
if zone == True:
223+
break
224+
else:
225+
num_cols += 1
226+
227+
return num_rows, num_cols
186228

187229
class PanelMainWindow:
188230

@@ -285,52 +327,18 @@ def create_main_layout(self):
285327

286328
all_zones = [f'zone{a}' for a in range(1,9)]
287329
is_zone = [(layout_zone.get(zone) is not None) and (len(layout_zone.get(zone)) > 0) for zone in all_zones]
288-
289-
# Get number of columns and rows per sub-region
290-
num_cols_12 = max(is_zone[0]*1 + is_zone[1]*1, is_zone[4]*1 + is_zone[5]*1)
291-
num_cols_56 = num_cols_12
292-
num_cols_37 = (is_zone[2] or is_zone[6])*1
293-
294-
num_rows_12 = ((is_zone[0] or is_zone[1])*1 - (is_zone[4] or is_zone[5])*1) + 1
295-
296-
# Do sub-regions [1,2], [4,5] [3][7] and [5][8] separately. For each, find out if
297-
# both zones are present. If they are, place both in sub-region. If not, place one.
298-
299-
row_slice_12 = slice(0,num_rows_12)
300-
if (is_zone[0] and is_zone[1]):
301-
gs[row_slice_12, slice(0,1)] = layout_zone.get('zone1')
302-
gs[row_slice_12, slice(1,2)] = layout_zone.get('zone2')
303-
elif (is_zone[0] and not is_zone[1]):
304-
gs[row_slice_12, slice(0,num_cols_12)] = layout_zone.get('zone1')
305-
elif (is_zone[1] and not is_zone[0]):
306-
gs[row_slice_12, slice(0,num_cols_12)] = layout_zone.get('zone2')
307-
308-
row_slice_56 = slice(num_rows_12, 2)
309-
if (is_zone[4] and is_zone[5]):
310-
gs[row_slice_56, slice(0,1)] = layout_zone.get('zone5')
311-
gs[row_slice_56, slice(1,2)] = layout_zone.get('zone6')
312-
elif (is_zone[4] and not is_zone[5]):
313-
gs[row_slice_56, slice(0,num_cols_56)] = layout_zone.get('zone5')
314-
elif (is_zone[5] and not is_zone[4]):
315-
gs[row_slice_56, slice(0,num_cols_56)] = layout_zone.get('zone6')
316-
317-
col_slice_37 = slice(num_cols_12,num_cols_12+1)
318-
if is_zone[2] and is_zone[6]:
319-
gs[slice(0, 1), col_slice_37] = layout_zone.get('zone3')
320-
gs[slice(1, 2), col_slice_37] = layout_zone.get('zone7')
321-
elif is_zone[2] and not is_zone[6]:
322-
gs[slice(0, 2), col_slice_37] = layout_zone.get('zone3')
323-
elif is_zone[6] and not is_zone[2]:
324-
gs[slice(0, 2), col_slice_37] = layout_zone.get('zone7')
325-
326-
col_slice_48 = slice(num_cols_12+num_cols_37,num_cols_12+num_cols_37+1)
327-
if is_zone[3] and is_zone[7]:
328-
gs[slice(0, 1), col_slice_48] = layout_zone.get('zone4')
329-
gs[slice(1, 2), col_slice_48] = layout_zone.get('zone8')
330-
elif is_zone[3] and not is_zone[7]:
331-
gs[slice(0, 2), col_slice_48] = layout_zone.get('zone4')
332-
elif is_zone[7] and not is_zone[3]:
333-
gs[slice(0, 2), col_slice_48] = layout_zone.get('zone8')
330+
is_zone_array = np.reshape(is_zone, (2,4))
331+
original_zone_array = copy(is_zone_array)
332+
333+
for zone_index in range(8):
334+
row = zone_index // 4
335+
col = zone_index % 4
336+
if row == 0:
337+
num_rows, num_cols = get_size_top_row(row, col, is_zone_array, original_zone_array)
338+
elif row == 1:
339+
num_rows, num_cols = get_size_bottom_row(row, col, is_zone_array, original_zone_array)
340+
if num_rows > 0 and num_cols > 0:
341+
gs[slice(row, row + num_rows), slice(col,col+num_cols)] = layout_zone.get(f'zone{zone_index+1}')
334342

335343
self.main_layout = gs
336344

spikeinterface_gui/layout_presets.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22
from spikeinterface_gui.viewlist import possible_class_views
33

44
"""
5-
A preset need 8 zones like this:
5+
A preset depends on eight zones.
66
7-
+-----------------+-----------------+
8-
| [zone1 zone2] | [zone3 | [zone4 |
9-
+-----------------+ | +
10-
| [zone5 zone6] | zone7] | zone8] |
11-
+-----------------+-----------------+
7+
+---------------+--------------+
8+
| zone1 zone2 zone3 zone4 |
9+
+ + +
10+
| zone5 zone6 zone7 zone8 |
11+
+---------------+--------------+
1212
13+
If a zone has free space below it or to the right of it, it will try to use it.
14+
E.g. suppose your layout is only non-empty in zones 1, 4, 5, 6 and 7:
15+
16+
+---------------+--------------+
17+
| zone1 zone4 |
18+
+ + +
19+
| zone5 zone6 zone7 |
20+
+---------------+--------------+
21+
22+
Then zone1 will stretch right-wards to make a three-zone view. Zone4 will stretch
23+
downwards to make a long two-zone view.
24+
25+
If there is not a unique way to fill the gaps, some space will be left unused.
1326
"""
1427
_presets = {}
1528

0 commit comments

Comments
 (0)