def hutchTriggerChanged(self, hutch_opened): if hutch_opened: if not BlissWidget.isInstanceRoleServer(): logging.getLogger().info("%s: HUTCH IS OPENED, YOU LOSE CONTROL", self.name()) self.takeControlButton.setEnabled(False) else: logging.getLogger().info("%s: HUTCH IS OPENED, TAKING CONTROL OVER REMOTE USERS", self.name()) self.instanceServer.takeControl() else: if not BlissWidget.isInstanceRoleServer(): logging.getLogger().info("%s: HUTCH IS CLOSED, YOU ARE ALLOWED TO TAKE CONTROL AGAIN", self.name()) self.takeControlButton.setEnabled(True)
def setSession(self, session_id, prop_code=None, prop_number=None, prop_id=None, expiration=None, orig_prop_code=None, is_inhouse=None): self.externalUserInfoDialog.clearUserInfo() if prop_code is not None and prop_number is not None and prop_code != '' and prop_number != '': if self.instanceServer is not None: try: proposal_dict={ "code":orig_prop_code,\ "alias": prop_code,\ "number":prop_number,\ "session":int(session_id),\ "inhouse":is_inhouse } except: logging.getLogger().exception( "InstanceListBrick: problem setting session") return else: self.myProposal = proposal_dict self.instanceServer.setProposal(proposal_dict) if is_inhouse: BlissWidget.setInstanceUserId( BlissWidget.INSTANCE_USERID_INHOUSE) self.askForControlButton.hide() self.takeControlButton.show() self.takeControlButton.setEnabled( BlissWidget.isInstanceRoleServer( )) #BlissWidget.isInstanceModeMaster()) if self.hutchtrigger is not None and not BlissWidget.isInstanceModeMaster( ): hutch_opened = self.hutchtrigger.hutchIsOpened() #hutch_opened = 1-int(self.hutchtrigger.getChannelObject("status").getValue()) logging.getLogger().info( "%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) else: BlissWidget.setInstanceUserId( BlissWidget.INSTANCE_USERID_LOGGED) self.takeControlButton.hide() self.askForControlButton.show() self.askForControlButton.setEnabled( not BlissWidget.isInstanceModeMaster()) else: if self.instanceServer is not None: self.myProposal = None self.instanceServer.setProposal(None) BlissWidget.setInstanceUserId(BlissWidget.INSTANCE_USERID_UNKNOWN) self.takeControlButton.hide() self.askForControlButton.show() #self.askForControlButton.setEnabled(BlissWidget.isInstanceRoleServer() and not BlissWidget.isInstanceModeMaster()) self.askForControlButton.setEnabled(False)
def hutchTriggerChanged(self, hutch_opened): if hutch_opened: if not BlissWidget.isInstanceRoleServer(): logging.getLogger().info( "%s: HUTCH IS OPENED, YOU LOSE CONTROL", self.name()) self.takeControlButton.setEnabled(False) else: logging.getLogger().info( "%s: HUTCH IS OPENED, TAKING CONTROL OVER REMOTE USERS", self.name()) self.instanceServer.takeControl() else: if not BlissWidget.isInstanceRoleServer(): logging.getLogger().info( "%s: HUTCH IS CLOSED, YOU ARE ALLOWED TO TAKE CONTROL AGAIN", self.name()) self.takeControlButton.setEnabled(True)
def updateMirroring(self): #print "UPDATE MIRRORING",self.myProposal,self.inControl if BlissWidget.isInstanceModeSlave(): if BlissWidget.isInstanceUserIdUnknown(): if BlissWidget.isInstanceRoleServer( ) and self.inControl is not None and self.inControl[1] is None: BlissWidget.setInstanceMirror( BlissWidget.INSTANCE_MIRROR_ALLOW) else: BlissWidget.setInstanceMirror( BlissWidget.INSTANCE_MIRROR_PREVENT) elif BlissWidget.isInstanceUserIdInhouse(): BlissWidget.setInstanceMirror( BlissWidget.INSTANCE_MIRROR_ALLOW) else: try: control_is_inhouse = self.inControl[1]['inhouse'] except: control_is_inhouse = False if control_is_inhouse or self.inControl[1] is None: BlissWidget.setInstanceMirror( BlissWidget.INSTANCE_MIRROR_ALLOW) else: try: my_prop_codes = [ self.myProposal['code'], self.myProposal['alias'] ] except: my_prop_codes = [] try: control_prop_codes = [ self.inControl[1]['code'], self.inControl[1]['alias'] ] except: control_prop_codes = [] mirror = BlissWidget.INSTANCE_MIRROR_PREVENT for code in my_prop_codes: try: control_prop_codes.index(code) except: pass else: mirror = BlissWidget.INSTANCE_MIRROR_ALLOW break for code in control_prop_codes: try: my_prop_codes.index(code) except: pass else: mirror = BlissWidget.INSTANCE_MIRROR_ALLOW break BlissWidget.setInstanceMirror(mirror) else: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_PREVENT)
def hutchtriggerChanged(self, state): if not BlissWidget.isInstanceRoleServer(): # do not allow hutch trigger to be started when not in server mode return if self.instrumentationMenu.isItemChecked(self.hutchtriggerId): if state: self.hutchtriggerHO.macro(1) else: self.hutchtriggerHO.macro(0)
def updateMirroring(self): #print "UPDATE MIRRORING",self.myProposal,self.inControl if BlissWidget.isInstanceModeSlave(): if BlissWidget.isInstanceUserIdUnknown(): if BlissWidget.isInstanceRoleServer() and self.inControl is not None and self.inControl[1] is None: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_ALLOW) else: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_PREVENT) elif BlissWidget.isInstanceUserIdInhouse(): BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_ALLOW) else: try: control_is_inhouse=self.inControl[1]['inhouse'] except: control_is_inhouse=False if control_is_inhouse or self.inControl[1] is None: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_ALLOW) else: try: my_prop_codes=[self.myProposal['code'],self.myProposal['alias']] except: my_prop_codes=[] try: control_prop_codes=[self.inControl[1]['code'],self.inControl[1]['alias']] except: control_prop_codes=[] mirror=BlissWidget.INSTANCE_MIRROR_PREVENT for code in my_prop_codes: try: control_prop_codes.index(code) except: pass else: mirror=BlissWidget.INSTANCE_MIRROR_ALLOW break for code in control_prop_codes: try: my_prop_codes.index(code) except: pass else: mirror=BlissWidget.INSTANCE_MIRROR_ALLOW break BlissWidget.setInstanceMirror(mirror) else: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_PREVENT)
def setSession(self,session_id,prop_code=None,prop_number=None,prop_id=None,expiration=None,orig_prop_code=None,is_inhouse=None): self.externalUserInfoDialog.clearUserInfo() if prop_code is not None and prop_number is not None and prop_code!='' and prop_number!='': if self.instanceServer is not None: try: proposal_dict={ "code":orig_prop_code,\ "alias": prop_code,\ "number":prop_number,\ "session":int(session_id),\ "inhouse":is_inhouse } except: logging.getLogger().exception("InstanceListBrick: problem setting session") return else: self.myProposal=proposal_dict self.instanceServer.setProposal(proposal_dict) if is_inhouse: BlissWidget.setInstanceUserId(BlissWidget.INSTANCE_USERID_INHOUSE) self.askForControlButton.hide() self.takeControlButton.show() self.takeControlButton.setEnabled(BlissWidget.isInstanceRoleServer()) #BlissWidget.isInstanceModeMaster()) if self.hutchtrigger is not None and not BlissWidget.isInstanceModeMaster(): hutch_opened = self.hutchtrigger.hutchIsOpened() #hutch_opened = 1-int(self.hutchtrigger.getChannelObject("status").getValue()) logging.getLogger().info("%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) else: BlissWidget.setInstanceUserId(BlissWidget.INSTANCE_USERID_LOGGED) self.takeControlButton.hide() self.askForControlButton.show() self.askForControlButton.setEnabled(not BlissWidget.isInstanceModeMaster()) else: if self.instanceServer is not None: self.myProposal=None self.instanceServer.setProposal(None) BlissWidget.setInstanceUserId(BlissWidget.INSTANCE_USERID_UNKNOWN) self.takeControlButton.hide() self.askForControlButton.show() #self.askForControlButton.setEnabled(BlissWidget.isInstanceRoleServer() and not BlissWidget.isInstanceModeMaster()) self.askForControlButton.setEnabled(False)
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!")