Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ask:
op = Qt.QMessageBox.question(self, "Save configuration?",
'Do you want to save the current configuration?\n(if not, any changes will be lost)',
Qt.QMessageBox.Yes | Qt.QMessageBox.No)
if op != Qt.QMessageBox.Yes:
return False
conf = self.getLocalConfig()
#make sure that no empty measurement groups are written
for mgname, mgconfig in conf.get('MntGrpConfigs', {}).items():
if mgconfig is not None and not mgconfig.get('controllers'):
Qt.QMessageBox.information(self, "Empty Measurement group",
"The measurement group '%s' is empty. Fill it (or delete it) before applying" % mgname,
Qt.QMessageBox.Ok)
self.changeActiveMntGrp(mgname)
return False
#check if the currently displayed mntgrp is changed
if self.ui.channelEditor.getQModel().isDataChanged():
self._dirtyMntGrps.add(self._localConfig['ActiveMntGrp'])
door = self.getModelObj()
door.setExperimentConfiguration(conf, mnt_grps=self._dirtyMntGrps)
self._originalConfiguration = copy.deepcopy(conf)
self._dirtyMntGrps = set()
self.ui.channelEditor.getQModel().setDataChanged(False)
self._setDirty(False)
self.emit(Qt.SIGNAL('experimentConfigurationChanged'), copy.deepcopy(conf))
return True
def onNewSequence(self):
if Qt.QMessageBox.question(self,
"New sequence",
"Do you want to save existing sequence?",
Qt.QMessageBox.Yes,
Qt.QMessageBox.No) == Qt.QMessageBox.Yes:
self.onSaveSequence()
self.tree.clearTree()
self.newSequenceAction.setEnabled(False)
self.saveSequenceAction.setEnabled(False)
self.currentMacroChanged.emit(None)
for aname, my_attr in sorted([(a.name, a) for a in list_attr]):
if allow_types and my_attr.data_type not in allow_types:
continue
if not expert and my_attr.disp_level == PyTango.DispLevel.EXPERT:
continue
label = aname == my_attr.label and aname.lower(
) or "%s (%s)" % (aname.lower(), my_attr.label)
dct[str(my_device).lower() + '/' + label] = 0
except PyTango.DevFailed as e:
self.warning('addAttrToDev(%s): %s' % (my_device, str(e)))
qmsg = Qt.QMessageBox(Qt.QMessageBox.Critical, '%s Error' %
my_device, '%s not available' % my_device, Qt.QMessageBox.Ok, self)
qmsg.show()
except Exception as e:
self.warning('addAttrToDev(%s): %s' % (my_device, str(e)))
qmsg = Qt.QMessageBox(Qt.QMessageBox.Critical, '%s Error' %
my_device, str(e), Qt.QMessageBox.Ok, self)
qmsg.show()
return dct
perspectives = self.getPerspectivesList()
if name is None:
name, ok = Qt.QInputDialog.getItem(
self, "Save Perspective",
"Store current settings as the following perspective:",
perspectives, 0, True
)
if not ok:
return
if name in perspectives:
ans = Qt.QMessageBox.question(
self, "Overwrite perspective?",
"overwrite existing perspective %s?" % str(name),
Qt.QMessageBox.Yes, Qt.QMessageBox.No
)
if ans != Qt.QMessageBox.Yes:
return
self.saveSettings(group="Perspectives/%s" % name)
self.updatePerspectivesMenu()
def _checkJsonRecorder(self):
'''Checks if JsonRecorder env var is set and offers to set it'''
door = self.getModelObj()
if 'JsonRecorder' not in door.getEnvironment():
msg = ('JsonRecorder environment variable is not set, but it '
+ 'is needed for displaying trend plots.\n'
+ 'Enable it globally for %s?') % door.getFullName()
result = Qt.QMessageBox.question(
self.parent(), 'JsonRecorder not set', msg,
Qt.QMessageBox.Yes | Qt.QMessageBox.No)
if result == Qt.QMessageBox.Yes:
door.putEnvironment('JsonRecorder', True)
self.info('JsonRecorder Enabled for %s' % door.getFullName())
import shutil
try:
bckname = "%s.orig" % fname
shutil.copy(fname, bckname)
except:
self.warning("%s will be overwritten but I could not create a backup in %s", fname, bckname)
#write the data
try:
f = open(fname, 'w')
f.write(xml)
f.close()
break
except Exception, e:
msg = 'Cannot write to %s: %s' % (fname, str(e))
self.error(msg)
Qt.QMessageBox.warning(self, "I/O problem", msg + '\nChoose a different location.', Qt.QMessageBox.Ok, Qt.QMessageBox.NoButton)
fname = None
hint = "XML_CONFIG = '%s'" % os.path.relpath(fname, self._confDirectory)
msg = 'Configuration written in %s' % fname
self.info(msg)
Qt.QMessageBox.information(self, "Configuration updated",
msg + '\nMake sure that the .py configuration file in %s contains\n%s' % (self._confDirectory, hint),
Qt.QMessageBox.Ok, Qt.QMessageBox.NoButton)
return
def getShellCommand(self,obj,wait=False):
shellCom = obj.getExtensions().get('shellCommand').replace('$NAME',obj._name).replace('$MODEL',obj._name)
if not wait and not shellCom.endswith('&'): shellCom+=' &'
if obj.noPrompt:
subprocess.call(shellCom,shell=True)
else:
yes = Qt.QMessageBox.Ok
no = Qt.QMessageBox.Cancel
result = Qt.QMessageBox.question(self.parent(),"Shell command","Would you like to call shell command '" +shellCom+ "' ?",yes, no)
if result == yes:
subprocess.call(shellCom,shell=True)
return
bckname = "%s.orig" % fname
shutil.copy(fname, bckname)
except:
self.warning(
"%s will be overwritten but I could not create a backup in %s", fname, bckname)
# write the data
try:
f = open(fname, 'w')
f.write(xml)
f.close()
break
except Exception as e:
msg = 'Cannot write to %s: %s' % (fname, str(e))
self.error(msg)
Qt.QMessageBox.warning(
self, "I/O problem", msg + '\nChoose a different location.', Qt.QMessageBox.Ok, Qt.QMessageBox.NoButton)
fname = None
hint = "XML_CONFIG = '%s'" % os.path.relpath(
fname, self._confDirectory)
msg = 'Configuration written in %s' % fname
self.info(msg)
Qt.QMessageBox.information(self, "Configuration updated",
msg + '\nMake sure that the .py configuration file in %s contains\n%s' % (
self._confDirectory, hint),
Qt.QMessageBox.Ok, Qt.QMessageBox.NoButton)
return
f.write(template)
f.close()
# if all went ok...
msg = 'Application project was successfully created.' +\
'You can find the files in: "%s"' % pdir
msg += '\nTip: You can install it with:\n\tpip install %s' % pdir
msg += '\nTip: And then run the application with:\n\t %s' % gui_name
details = ''
warnings = self.wizard().getProjectWarnings()
if warnings:
msg += '\n\nHowever, some fine-tuning may be needed. Please check the details:\n'
for _short, _long in warnings:
details += '- %s: %s\n\n' % (_short, _long)
logfile.write(msg + details)
logfile.close()
dlg = Qt.QMessageBox(Qt.QMessageBox.Information,
'Application project created', msg, Qt.QMessageBox.Ok, self)
dlg.setDetailedText(details)
dlg.exec_()
print()
print(msg + details)
print()
try:
proxy = PyTango.DeviceProxy(my_device)
timeout = proxy.get_timeout_millis()
proxy.set_timeout_millis(50)
proxy.ping()
list_attr = proxy.attribute_list_query()
proxy.set_timeout_millis(timeout)
for aname,my_attr in sorted([(a.name,a) for a in list_attr]):
if allow_types and my_attr.data_type not in allow_types: continue
if not expert and my_attr.disp_level==PyTango.DispLevel.EXPERT: continue
label = aname==my_attr.label and aname.lower() or "%s (%s)"%(aname.lower(),my_attr.label)
dct[str(my_device).lower()+'/'+label] = 0
except PyTango.DevFailed,e:
self.warning('addAttrToDev(%s): %s'%(my_device,str(e)))
qmsg = Qt.QMessageBox(Qt.QMessageBox.Critical,'%s Error'%my_device,'%s not available'%my_device,Qt.QMessageBox.Ok,self)
qmsg.show()
except Exception,e:
self.warning('addAttrToDev(%s): %s'%(my_device,str(e)))
qmsg = Qt.QMessageBox(Qt.QMessageBox.Critical,'%s Error'%my_device,str(e),Qt.QMessageBox.Ok,self)
qmsg.show()
return dct