def haveControl(self,have_control,gui_only=False): #print "INSTANCELISTBRICK.HAVECONTROL",have_control,gui_only if not gui_only: if have_control: BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_MASTER) else: BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE) if have_control: if self.xmlrpc_server: gevent.spawn_later(1, self.xmlrpc_server.open) self.inControl=None self.takeControlButton.setEnabled(False) self.askForControlButton.setEnabled(False) self.listBox.setSelectionMode(QListBox.Single) self.listBox.clearSelection() i=self.listBox.firstItem() while i is not None: i.setSelectable(False) i=next(i) self.listBox.setSelectionMode(QListBox.NoSelection) else: if self.xmlrpc_server: self.xmlrpc_server.close() if BlissWidget.isInstanceUserIdLogged(): self.askForControlButton.setEnabled(True) elif BlissWidget.isInstanceUserIdInhouse(): if self.hutchtrigger is not None: hutch_opened = self.hutchtrigger.hutchIsOpened() #hutch_opened = 1-int(self.hutchtrigger.getChannelObject("status").getValue()) logging.getLogger().debug("%s: hutch is %s, %s 'Take control' button", self.name(), hutch_opened and "opened" or "close", hutch_opened and "disabling" or "enabling") self.takeControlButton.setEnabled(1-hutch_opened) #elif BlissWidget.isInstanceRoleServer(): # self.askForControlButton.setEnabled(True) if BlissWidget.isInstanceRoleServer(): self.takeControlButton.setEnabled(True) if not gui_only: if have_control: try: frombl = os.environ['SMIS_BEAMLINE_NAME'] #user = os.environ['SMIS_BEAMLINE_NAME'] #frombl = user.replace(' ','-') except (KeyError,TypeError,ValueError,AttributeError): frombl = 'ID??' try: proposal="%s-%d" % (self.myProposal["code"],self.myProposal["number"]) except: proposal="unknown" is_local=BlissWidget.isInstanceLocationLocal() if is_local: control_place="LOCAL" else: control_place="EXTERNAL" email_subject="[MX REMOTE ACCESS] %s control is %s (proposal %s)" % (frombl,control_place,proposal) email_toaddrs=self["controlEmails"] email_fromaddrs="*****@*****.**" % frombl msg_event=UserInfoDialogEvent("I've gained control of the application.",\ email_fromaddrs,email_toaddrs,email_subject,is_local,\ self.font().pointSize()) logging.getLogger('user_level_log').warning("You have gained control of the application.") #qApp.postEvent(self,msg_event) else: msg_event=MsgDialogEvent(QMessageBox.Warning,\ "I've lost control of the application!",\ self.font().pointSize()) logging.getLogger('user_level_log').warning("You have lost control of the application!")
def haveControl(self, have_control, gui_only=False): #print "INSTANCELISTBRICK.HAVECONTROL",have_control,gui_only if not gui_only: if have_control: BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_MASTER) else: BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE) if have_control: if self.xmlrpc_server: gevent.spawn_later(1, self.xmlrpc_server.open) self.inControl = None self.takeControlButton.setEnabled(False) self.askForControlButton.setEnabled(False) self.listBox.setSelectionMode(QListBox.Single) self.listBox.clearSelection() i = self.listBox.firstItem() while i is not None: i.setSelectable(False) i = next(i) self.listBox.setSelectionMode(QListBox.NoSelection) else: if self.xmlrpc_server: self.xmlrpc_server.close() if BlissWidget.isInstanceUserIdLogged(): self.askForControlButton.setEnabled(True) elif BlissWidget.isInstanceUserIdInhouse(): if self.hutchtrigger is not None: hutch_opened = self.hutchtrigger.hutchIsOpened() #hutch_opened = 1-int(self.hutchtrigger.getChannelObject("status").getValue()) logging.getLogger().debug( "%s: hutch is %s, %s 'Take control' button", self.name(), hutch_opened and "opened" or "close", hutch_opened and "disabling" or "enabling") self.takeControlButton.setEnabled(1 - hutch_opened) #elif BlissWidget.isInstanceRoleServer(): # self.askForControlButton.setEnabled(True) if BlissWidget.isInstanceRoleServer(): self.takeControlButton.setEnabled(True) if not gui_only: if have_control: try: frombl = os.environ['SMIS_BEAMLINE_NAME'] #user = os.environ['SMIS_BEAMLINE_NAME'] #frombl = user.replace(' ','-') except (KeyError, TypeError, ValueError, AttributeError): frombl = 'ID??' try: proposal = "%s-%d" % (self.myProposal["code"], self.myProposal["number"]) except: proposal = "unknown" is_local = BlissWidget.isInstanceLocationLocal() if is_local: control_place = "LOCAL" else: control_place = "EXTERNAL" email_subject = "[MX REMOTE ACCESS] %s control is %s (proposal %s)" % ( frombl, control_place, proposal) email_toaddrs = self["controlEmails"] email_fromaddrs = "*****@*****.**" % frombl msg_event=UserInfoDialogEvent("I've gained control of the application.",\ email_fromaddrs,email_toaddrs,email_subject,is_local,\ self.font().pointSize()) logging.getLogger('user_level_log').warning( "You have gained control of the application.") #qApp.postEvent(self,msg_event) else: msg_event=MsgDialogEvent(QMessageBox.Warning,\ "I've lost control of the application!",\ self.font().pointSize()) logging.getLogger('user_level_log').warning( "You have lost control of the application!")