コード例 #1
0
ファイル: obci_gui.py プロジェクト: BrainTech/openbci
    def set_nearby_machines(self, machines, current_hostname, current_ip):
        self.nearby_machines.clearContents()
        self.nearby_machines.setRowCount(len(machines))
        for i, (ip, hostname) in enumerate(list(machines.iteritems())):
            ip_w = QTableWidgetItem(ip)
            ip_w.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
            self.nearby_machines.setItem(i, 0, ip_w)

            hn_w = QTableWidgetItem(hostname)
            hn_w.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
            self.nearby_machines.setItem(i, 1, hn_w)

            st_w = QTableWidgetItem()
            st_w.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
            if (str(ip) == str(current_ip) or str(current_ip) == net.lo_ip())\
                    and str(hostname) == str(current_hostname):
                font = QFont()
                font.setWeight(QFont.Black)
                hn_w.setFont(font)
                ip_w.setFont(font)
                st_w.setText('Connected')
                st_w.setFont(font)
            self.nearby_machines.setItem(i, 2, st_w)

        if machines:
            self.nearby_machines.setCurrentItem(self.nearby_machines.item(0, 0))
        else:
            self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
コード例 #2
0
ファイル: obciLauncher.py プロジェクト: karolaug/openbci
    def set_nearby_machines(self, machines, current_hostname, current_ip):
        self.nearby_machines.clearContents()
        self.nearby_machines.setRowCount(len(machines))
        for i, (ip, hostname) in enumerate(list(machines.iteritems())):
            ip_w = QTableWidgetItem(ip)
            ip_w.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
            self.nearby_machines.setItem(i, 0, ip_w)

            hn_w = QTableWidgetItem(hostname)
            hn_w.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
            self.nearby_machines.setItem(i, 1, hn_w)

            st_w = QTableWidgetItem()
            st_w.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
            if (str(ip) == str(current_ip) or str(current_ip) == net.lo_ip())\
                                 and str(hostname) == str(current_hostname):
                font = QFont()
                font.setWeight(QFont.Black)
                hn_w.setFont(font)
                ip_w.setFont(font)
                st_w.setText('Connected')
                st_w.setFont(font)
            self.nearby_machines.setItem(i, 2, st_w)



        if machines:
            self.nearby_machines.setCurrentItem(self.nearby_machines.item(0,0))
        else:
            self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
コード例 #3
0
ファイル: obci_script.py プロジェクト: karolaug/openbci
def client_server_prep(cmdargs=None,
                       client_class=obci_client.OBCIClient,
                       server_ip=None,
                       start_srv=True,
                       zmq_ctx=None):

    directory = os.path.abspath(settings.DEFAULT_SANDBOX_DIR)
    if not os.path.exists(directory):
        print "obci directory not found: {0}".format(directory)
        raise OBCISystemError()

    client = None
    srv = None

    os.chdir(directory)

    srv_rep_port = net.server_rep_port()
    srv_pub_port = net.server_pub_port()
    if server_ip:
        rep_addrs = ['tcp://' + server_ip + ':' + srv_rep_port]
        pub_addrs = ['tcp://' + server_ip + ':' + srv_pub_port]
    else:
        rep_addrs = ['tcp://*:' + srv_rep_port]
        pub_addrs = ['tcp://*:' + srv_pub_port]

    if not server_process_running() and not start_srv:
        disp.view(
            "Start obci_server (command: obci srv) before performing other tasks"
        )
        return None

    if not server_process_running() and\
            (not server_ip or server_ip == net.lo_ip())\
            and start_srv:
        print "will launch server"
        args = argv() if cmdargs else []
        if rep_addrs and pub_addrs:
            args += ['--rep-addresses'] + rep_addrs + ['--pub-addresses'
                                                       ] + pub_addrs
        srv = launch_obci_server(args)
        if not srv:
            disp.view("Could not launch OBCI Server")
            return None
        disp.view("OBCI server launched. PID: {0}".format(srv.pid))

    if not server_ip:
        rep_addrs = ['tcp://localhost:' + srv_rep_port]

    res, client = connect_client(rep_addrs,
                                 client_class=client_class,
                                 zmq_ctx=zmq_ctx)

    if res is None:
        disp.view("Could not connect to OBCI Server")
        client = None

    return client
コード例 #4
0
 def nearby_machines(self):
     nearby_machines = {}
     if not self._cached_nearby_machines:
         res = self.client.send_list_nearby_machines()
         if res is not None:
             self._cached_nearby_machines = res.nearby_machines
     for mach in self._cached_nearby_machines.values():
         nearby_machines[mach["ip"]] = mach["hostname"]
     if not nearby_machines:
         nearby_machines[net.lo_ip()] = socket.gethostname()
     return nearby_machines
コード例 #5
0
ファイル: obci_script.py プロジェクト: karolaug/openbci
def client_server_prep(cmdargs=None, client_class=obci_client.OBCIClient, server_ip=None, start_srv=True, zmq_ctx=None):

    directory = os.path.abspath(settings.DEFAULT_SANDBOX_DIR)
    if not os.path.exists(directory):
        print "obci directory not found: {0}".format(directory)
        raise OBCISystemError()

    client = None
    srv = None

    os.chdir(directory)

    srv_rep_port = net.server_rep_port()
    srv_pub_port = net.server_pub_port()
    if server_ip:
        rep_addrs = ['tcp://'+server_ip+':'+srv_rep_port]
        pub_addrs = ['tcp://'+server_ip+':'+srv_pub_port]
    else:
        rep_addrs = ['tcp://*:' + srv_rep_port]
        pub_addrs = ['tcp://*:' + srv_pub_port]

    if not server_process_running() and not start_srv:
        disp.view("Start obci_server (command: obci srv) before performing other tasks")
        return None

    if not server_process_running() and\
            (not server_ip or server_ip == net.lo_ip())\
            and start_srv:
        print "will launch server"
        args = argv() if cmdargs else []
        if rep_addrs and pub_addrs:
            args += ['--rep-addresses'] + rep_addrs + ['--pub-addresses'] + pub_addrs
        srv = launch_obci_server(args)
        if not srv:
            disp.view("Could not launch OBCI Server")
            return None
        disp.view("OBCI server launched. PID: {0}".format(srv.pid))


    if not server_ip:
        rep_addrs = ['tcp://localhost:'+srv_rep_port]

    res, client = connect_client(rep_addrs, client_class=client_class, zmq_ctx=zmq_ctx)

    if res is None:
        disp.view("Could not connect to OBCI Server")
        client = None

    return client