Esempio n. 1
0
    def observable_update(self, o, e=None):
        if isinstance(e, SpaceHaulControllerEvent):
            if e.event_type == "select" and isinstance(e.o, Ship):
                e.o.add_observer(self)
                self.ship_change_comm.signal.emit(e.o)

            elif e.event_type == "unselect" and isinstance(e.o, Ship):
                e.o.remove_observer(self)
                self.ship_change_comm.signal.emit(
                    Ship(-1, "", Location(0, 0, 0)))

        elif isinstance(o, Ship):
            # the selected star changed attributes
            self.ship_change_comm.signal.emit(o)
Esempio n. 2
0
    def _kafka_event_ship(self, msg):
        self.log_kafka("KAFKA EVENT [SHIP]")

        incoming_ship = Ship.from_dict(msg.value, self.star_list())

        # if we have the ship, update it, else create it
        found_ship = False

        for ship in self.ships():
            if ship.ship_id() == incoming_ship.ship_id():
                found_ship = True
                self.log_kafka("we already have this ship, do update")
                ship.update_from_ship(incoming_ship)

        if not found_ship:
            # add it
            self.log_kafka("did not find ship, add it")
            self.ship_list().add_ship(incoming_ship)
Esempio n. 3
0
    return stars


if __name__ == "__main__":
    print("Publishing a star to kafka...")

    gummerton = Star(1, "Gummerton", Location(-600000, 100, 0))
    new_gumbria = Star(2, "New Gumbria", Location(500000, -600000, 0))
    gummi_glen = Star(3, "Gummi Glen", Location(300000, 300000, 0))
    stars = [
        gummerton,
        new_gumbria,
        gummi_glen
    ]

    gss_toadie = Ship(1, "GSS Toadie", Location(gummerton.location().x, gummerton.location().y, gummerton.location().z))
    print("first gss_toadie.location()", gss_toadie.location())
    ships = [
        gss_toadie
    ]

    stars = create_random_stars(2, (700000, 700000, 0), 100000)
    gss_toadie.set_location(stars[0].location())

    topic_name = "quickstart-events"
    producer = KafkaProducer(bootstrap_servers="localhost:9092")

    for s in stars:
        j = s.to_json()
        print("Producer sending JSON [{0}]".format(j))
        producer.send(topic_name, value=j.encode('utf-8'), headers=[("type", b'star')])
Esempio n. 4
0
 def ship_change(self, ship: Ship):
     if ship.ship_id() == -1:
         self.name_label.setText("")
     else:
         self.name_label.setText(ship.name())
Esempio n. 5
0
 def ship_add(self, ship: Ship):
     ship.add_observer(self)
     self.my_layout.addWidget(
         ShipListShipWidget(self, self.controller, ship))
Esempio n. 6
0
 def add_ship(self, ship: Ship):
     # watch the ship for updates
     ship.add_observer(self)
     self.repaint()