Skip to content

Commit

Permalink
minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Schott committed Oct 10, 2018
1 parent 0fb9afa commit 1d771b1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mercury_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ def setupUi(self, Form):
self.lineEdit = [None]*self.ntabs
self.label = [None]*self.ntabs

# create a tab for each module
# create a tab with combobox and text box for each module
# the tab number i corresonds to the mercury module number
for i in range(0, self.ntabs):
self.tab[i] = QtWidgets.QWidget()
self.tab[i].setObjectName('tab_%s' % str(i))
Expand All @@ -626,15 +627,19 @@ def setupUi(self, Form):

self.tabWidget.addTab(self.tab[i], self.mercury.modules[i].nick)

# fill combobox with information
# fill combobox with information, set callbacks for updates
for i in range(0, self.ntabs):
attr = dir(self.mercury.modules[i])
EXEPT = ['read', 'write', 'query', 'CAL_INT', 'EXCT_TYPES',
'TYPES', 'clear_cache']
readings = [x for x in attr if not (x.startswith('_') or x in EXEPT)]
self.comboBox[i].addItems(readings)
self._get_reading(i)
callback = lambda: self._get_reading(None)

def callback(x, i=i):
"""Callback to get readings from selection in combobox_i."""
self._get_reading(i)

self.comboBox[i].currentIndexChanged.connect(callback)

# add tab widget to main grid
Expand All @@ -650,9 +655,7 @@ def setupUi(self, Form):
self._get_alarms(i)

def _get_reading(self, i):

if i is None:
i = int(self.sender().objectName()[-1])
""" Gets readings of selected variable in combobox_i."""

self.getreading = ('self.mercury.modules[%s].%s'
% (i, self.comboBox[i].currentText()))
Expand Down

0 comments on commit 1d771b1

Please sign in to comment.