def serverInitialized(self,started,server_id=None):
        if started:
            #BlissWidget.setInstanceUserId(BlissWidget.INSTANCE_USERID_UNKNOWN)
            BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_SERVER)
            BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_MASTER)

            self.initName(server_id[0])
            self.haveControl(True,gui_only=True)
            #self.giveControl.setChecked(False)
            #self.allowTimeoutControl.setChecked(False)
        else:
            #BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_SERVERSTARTING)
            #BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_MASTER)
            msg_dialog=QMessageBox("mxCuBE",\
                "Couldn't start the multiple instances server!",\
                QMessageBox.Critical,QMessageBox.Ok,QMessageBox.NoButton,\
                QMessageBox.NoButton,self) # Application name (mxCuBE) is hardwired!!!
            msg_dialog.setButtonText(QMessageBox.Ok,"Quit")
            s=self.font().pointSize()
            f=msg_dialog.font()
            f.setPointSize(s)
            msg_dialog.setFont(f)
            msg_dialog.updateGeometry()
            msg_dialog.exec_loop()
            os._exit(1)
Example #2
0
    def serverInitialized(self, started, server_id=None):
        if started:
            #BlissWidget.setInstanceUserId(BlissWidget.INSTANCE_USERID_UNKNOWN)
            BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_SERVER)
            BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_MASTER)

            self.initName(server_id[0])
            self.haveControl(True, gui_only=True)
            #self.giveControl.setChecked(False)
            #self.allowTimeoutControl.setChecked(False)
        else:
            #BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_SERVERSTARTING)
            #BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_MASTER)
            msg_dialog=QMessageBox("mxCuBE",\
                "Couldn't start the multiple instances server!",\
                QMessageBox.Critical,QMessageBox.Ok,QMessageBox.NoButton,\
                QMessageBox.NoButton,self) # Application name (mxCuBE) is hardwired!!!
            msg_dialog.setButtonText(QMessageBox.Ok, "Quit")
            s = self.font().pointSize()
            f = msg_dialog.font()
            f.setPointSize(s)
            msg_dialog.setFont(f)
            msg_dialog.updateGeometry()
            msg_dialog.exec_loop()
            os._exit(1)
 def serverClosed(self,server_id):
     self.listBox.clear()
     self.connections={}
     BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_CLIENTCONNECTING)
     BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE)
     msg_event=MsgDialogEvent(QMessageBox.Warning,\
         "The server application closed the connection!",\
         self.font().pointSize())
     qApp.postEvent(self,msg_event)
     QTimer.singleShot(InstanceListBrick.RECONNECT_TIME,self.reconnectToServer)
    def clientInitialized(self,connected,server_id=None,my_nickname=None,quiet=False):
        if connected is None:
            BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_CLIENTCONNECTING)
            BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE)
        elif not connected:
            if not quiet:
                msg_event=MsgDialogEvent(QMessageBox.Warning,\
                    "Couldn't connect to the server application!",\
                    self.font().pointSize())
                qApp.postEvent(self,msg_event)
                
            QTimer.singleShot(InstanceListBrick.RECONNECT_TIME,self.reconnectToServer)
        else:
            BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_CLIENT)
            BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE)

            server_print=self.instanceServer.idPrettyPrint(server_id)

            if self.clientIcon is None:
                item=QListBoxText(self.listBox,server_print)
            else:
                item=QListBoxPixmap(self.listBox,self.serverIcon,server_print)
            self.nickname.setText(my_nickname)
            self.connections[server_id[0]]=(item,server_id[1])
            item.setSelectable(False)
            self.haveControl(False,gui_only=True)
            self.initName(my_nickname)
            #self.giveControl.setChecked(False)

            # workaround for the remote access problem
            # (have to disable video display when DC is running)
            camera_brick = None

            for w in qt.QApplication.allWidgets():
                if isinstance(w, BaseComponents.BlissWidget):
                    if "CameraBrick" in str(w.__class__):
                        camera_brick = w
                        camera_brick.installEventFilter(self)
                        break

            # find the video brick, make sure it is hidden when collecting data
            # and that it is shown again when DC is finished
            def disable_video(w=camera_brick):
                w.disable_update()
            self.__disable_video=disable_video
            def enable_video(w=camera_brick):
                w.enable_update()
            self.__enable_video=enable_video
            dispatcher.connect(self.__disable_video, "collect_started")
            dispatcher.connect(self.__enable_video, "collect_finished")

            msg_event=MsgDialogEvent(QMessageBox.Information,\
                "Successfully connected to the server application.",\
                self.font().pointSize())
            qApp.postEvent(self,msg_event)
Example #5
0
 def serverClosed(self, server_id):
     self.listBox.clear()
     self.connections = {}
     BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_CLIENTCONNECTING)
     BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE)
     msg_event=MsgDialogEvent(QMessageBox.Warning,\
         "The server application closed the connection!",\
         self.font().pointSize())
     qApp.postEvent(self, msg_event)
     QTimer.singleShot(InstanceListBrick.RECONNECT_TIME,
                       self.reconnectToServer)
    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!")
Example #7
0
    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!")
Example #8
0
    def clientInitialized(self,
                          connected,
                          server_id=None,
                          my_nickname=None,
                          quiet=False):
        if connected is None:
            BlissWidget.setInstanceRole(
                BlissWidget.INSTANCE_ROLE_CLIENTCONNECTING)
            BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE)
        elif not connected:
            if not quiet:
                msg_event=MsgDialogEvent(QMessageBox.Warning,\
                    "Couldn't connect to the server application!",\
                    self.font().pointSize())
                qApp.postEvent(self, msg_event)

            QTimer.singleShot(InstanceListBrick.RECONNECT_TIME,
                              self.reconnectToServer)
        else:
            BlissWidget.setInstanceRole(BlissWidget.INSTANCE_ROLE_CLIENT)
            BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE)

            server_print = self.instanceServer.idPrettyPrint(server_id)

            if self.clientIcon is None:
                item = QListBoxText(self.listBox, server_print)
            else:
                item = QListBoxPixmap(self.listBox, self.serverIcon,
                                      server_print)
            self.nickname.setText(my_nickname)
            self.connections[server_id[0]] = (item, server_id[1])
            item.setSelectable(False)
            self.haveControl(False, gui_only=True)
            self.initName(my_nickname)
            #self.giveControl.setChecked(False)

            # workaround for the remote access problem
            # (have to disable video display when DC is running)
            camera_brick = None

            for w in qt.QApplication.allWidgets():
                if isinstance(w, BaseComponents.BlissWidget):
                    if "CameraBrick" in str(w.__class__):
                        camera_brick = w
                        camera_brick.installEventFilter(self)
                        break

            # find the video brick, make sure it is hidden when collecting data
            # and that it is shown again when DC is finished
            def disable_video(w=camera_brick):
                w.disable_update()

            self.__disable_video = disable_video

            def enable_video(w=camera_brick):
                w.enable_update()

            self.__enable_video = enable_video
            dispatcher.connect(self.__disable_video, "collect_started")
            dispatcher.connect(self.__enable_video, "collect_finished")

            msg_event=MsgDialogEvent(QMessageBox.Information,\
                "Successfully connected to the server application.",\
                self.font().pointSize())
            qApp.postEvent(self, msg_event)