5959from .pixelpipeline .datasources import ArraySource
6060from .volumeEditor import VolumeEditor
6161from volumina .utility import ShortcutManager
62+ from volumina .utility import preferences
6263
6364
6465class __TimerEventEater (QObject ):
@@ -269,6 +270,8 @@ def onShapeChanged():
269270 self .editor .imageViews [i ].setHudVisible (self .hudsShown [i ])
270271 self .quadview .statusBar .crosshairsCheckbox .setChecked (False )
271272
273+ self ._updateTileWidth ()
274+
272275 self .quadview .statusBar .crosshairsCheckbox .setVisible (True )
273276
274277 if self .editor .cropModel .cropZero () or None in self .editor .cropModel .get_roi_3d ()[0 ]:
@@ -324,6 +327,33 @@ def _rubberBandZoom(self):
324327 self .editor .imageViews [self .editor ._lastImageViewFocus ]._cursorBackup
325328 )
326329
330+ def _updateTileWidth (self ):
331+ tile_width = self ._getTileWidth ()
332+ self .editor .setTileWidth (tile_width )
333+
334+ def _getTileWidthConfigKeyDefault (self ):
335+ singletons_spacial = sum (1 for dim in self .editor .posModel .shape if dim == 1 )
336+ assert singletons_spacial in range (2 )
337+ if singletons_spacial == 0 :
338+ # 3D data
339+ key = "tileWidth3D"
340+ default = 256
341+ else :
342+ # 2D data
343+ key = "tileWidth"
344+ default = 512
345+ return key , default
346+
347+ def _getTileWidth (self ):
348+ key , default = self ._getTileWidthConfigKeyDefault ()
349+ tile_width = preferences .get ("ImageScene2D" , key , default = default )
350+ return tile_width
351+
352+ def _setTileWidth (self , value ):
353+ key , _ = self ._getTileWidthConfigKeyDefault ()
354+ preferences .set ("ImageScene2D" , key , value )
355+ self ._updateTileWidth ()
356+
327357 def _toggleHUDs (self , checked ):
328358 for v in self .editor .imageViews :
329359 v .setHudVisible (checked )
@@ -576,9 +606,10 @@ def changeTileWidth():
576606 dlg .setWindowTitle ("Viewer Tile Width" )
577607 dlg .setModal (True )
578608
609+ saved = self ._getTileWidth ()
579610 spinBox = QSpinBox (parent = dlg )
580611 spinBox .setRange (128 , 10 * 1024 )
581- spinBox .setValue (self . editor . imageScenes [ 0 ]. tileWidth () )
612+ spinBox .setValue (saved )
582613
583614 ctrl_layout = QHBoxLayout ()
584615 ctrl_layout .addSpacerItem (QSpacerItem (10 , 0 , QSizePolicy .Expanding ))
@@ -597,12 +628,11 @@ def changeTileWidth():
597628 dlg_layout .addWidget (button_box )
598629
599630 dlg .setLayout (dlg_layout )
631+ spinBox .setFocus ()
600632
601633 if dlg .exec_ () == QDialog .Accepted :
602- for s in self .editor .imageScenes :
603- if s .tileWidth != spinBox .value ():
604- s .setTileWidth (spinBox .value ())
605- s .reset ()
634+ if spinBox .value () != saved :
635+ self ._setTileWidth (spinBox .value ())
606636
607637 self ._viewMenu .addAction ("Set Tile Width..." ).triggered .connect (changeTileWidth )
608638
0 commit comments