Skip to content

Commit

Permalink
Merge pull request #715 from slaclab/ESROGUE-463
Browse files Browse the repository at this point in the history
Auto expand small lists
  • Loading branch information
ruck314 authored Jul 23, 2020
2 parents 7ee7937 + 8908462 commit 954996b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion python/pyrogue/pydm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pydm
import pyrogue.pydm.data_plugins.rogue_plugin

def runPyDM(serverList='localhost:9090', root=None, ui=None, title=None,sizeX=800,sizeY=1000):
def runPyDM(serverList='localhost:9090', root=None, ui=None, title=None,sizeX=800,sizeY=1000,maxListExpand=5):

if root is not None:

Expand All @@ -35,6 +35,7 @@ def runPyDM(serverList='localhost:9090', root=None, ui=None, title=None,sizeX=80
args.append(f"sizeX={sizeX}")
args.append(f"sizeY={sizeY}")
args.append(f"title='{title}'")
args.append(f"maxListExpand={maxListExpand}")

app = pydm.PyDMApplication(ui_file=ui,
command_line_args=args,
Expand Down
14 changes: 10 additions & 4 deletions python/pyrogue/pydm/pydmTop.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def __init__(self, parent=None, args=[], macros=None):
self.setStyleSheet("*[dirty='true']\
{background-color: orange;}")

self.sizeX = None
self.sizeY = None
self.title = None
self.sizeX = None
self.sizeY = None
self.title = None
self.maxExp = None

for a in args:
if 'sizeX=' in a:
Expand All @@ -39,6 +40,8 @@ def __init__(self, parent=None, args=[], macros=None):
self.sizeY = int(a.split('=')[1])
if 'title=' in a:
self.title = a.split('=')[1]
if 'maxListExpand' in a:
self.maxExp = int(a.split('=')[1])

if self.title is None:
self.title = "Rogue Server: {}".format(os.getenv('ROGUE_SERVERS'))
Expand All @@ -48,6 +51,9 @@ def __init__(self, parent=None, args=[], macros=None):
if self.sizeY is None:
self.sizeY = 1000

if self.maxExp is None:
self.maxExp = 5

self.setWindowTitle(self.title)

vb = QVBoxLayout()
Expand All @@ -56,7 +62,7 @@ def __init__(self, parent=None, args=[], macros=None):
self.tab = QTabWidget()
vb.addWidget(self.tab)

var = VariableTree(parent=None, init_channel=Channel)
var = VariableTree(parent=None, init_channel=Channel, maxListExpand=self.maxExp)
self.tab.addTab(var,'Variables')

cmd = CommandTree(parent=None, init_channel=Channel)
Expand Down
14 changes: 12 additions & 2 deletions python/pyrogue/pydm/widgets/variable_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def _setup(self,noExpand):
dev=val,
noExpand=noExpand)

# Auto expand list variables
for k,v in self._avars.items():
v._autoExpand()

def _expand(self):
if self._dummy is None:
return
Expand All @@ -111,7 +115,7 @@ def __init__(self,*, path, top, parent, name):
self._dummy = None
self._path = path
self._list = []
self._depth = parent._depth+1
self._depth = parent._depth+1

self._lab = QLabel(parent=None, text=self._name + ' (0)')

Expand All @@ -136,6 +140,10 @@ def _expand(self):
self._dummy = None
self._setup()

def _autoExpand(self):
if len(self._list) <= self._top._maxListExpand:
self.setExpanded(True)

def addNode(self,node):
self._list.append(node)
self._lab.setText(self._name + ' ({})'.format(len(self._list)))
Expand Down Expand Up @@ -215,7 +223,7 @@ def __init__(self,*,path,top,parent,variable):


class VariableTree(PyDMFrame):
def __init__(self, parent=None, init_channel=None, incGroups=None, excGroups=['Hidden']):
def __init__(self, parent=None, init_channel=None, incGroups=None, excGroups=['Hidden'], maxListExpand=5):
PyDMFrame.__init__(self, parent, init_channel)

self._node = None
Expand All @@ -225,6 +233,8 @@ def __init__(self, parent=None, init_channel=None, incGroups=None, excGroups=['H
self._excGroups = excGroups
self._tree = None

self._maxListExpand = maxListExpand

self._colWidths = [250,50,75,200,50]

def connection_changed(self, connected):
Expand Down

0 comments on commit 954996b

Please sign in to comment.