Example #1
0
    def __set_border_color(self, color):

        r, g, b, a = utils.parse_color(color)
        for cnt in range(8):
            self.__images[cnt].set_from_color(r, g, b, a)

        self.__redraw_frame()
    def doGTFSRTPolling(self):
        print("doGTFSRTPolling", time.ctime())
        r = self.session.get(self.gtfsrtFeedURL)

        if r.status_code != 200:
            print("GTFS RT feed returned with " + str(r.status_code))
            return
        feedmsg = gtfs_realtime_pb2.FeedMessage()
        try:
            feedmsg.ParseFromString(r.content)
            for entity in feedmsg.entity:
                if not entity.HasField('vehicle'):
                    continue
                # Don't send message if route_id is missing from entity
                # HasField() function does not work as expected, therefore we need check it like this
                if "route_id" not in map(lambda x: x.name, entity.vehicle.trip.DESCRIPTOR.fields):
                    continue

                nfeedmsg = gtfs_realtime_pb2.FeedMessage()
                nfeedmsg.header.gtfs_realtime_version = "1.0"
                nfeedmsg.header.incrementality = nfeedmsg.header.DIFFERENTIAL
                nfeedmsg.header.timestamp = int(time.time())
                nent = nfeedmsg.entity.add()

                nent.CopyFrom(entity)

                trip_id = entity.vehicle.trip.trip_id
                route_id = utils.parse_route_id(self.feedName, entity.vehicle.trip.route_id, trip_id, self.OTPData)
                direction_id = utils.parse_direction_id(self.feedName, entity.vehicle.trip.direction_id, trip_id, self.OTPData)
                trip_headsign = entity.vehicle.vehicle.label
                # headsigns with / cause problems in topics
                if '/' in trip_headsign:
                    trip_headsign = ''
                latitude = "{:.6f}".format(entity.vehicle.position.latitude) # Force coordinates to have 6 numbers
                latitude_head = latitude[:2]
                longitude = "{:.6f}".format(entity.vehicle.position.longitude)
                longitude_head = longitude[:2]
                geohash_head = latitude_head + ";" + longitude_head
                geohash_firstdeg = latitude[3] + "" + longitude[3]
                geohash_seconddeg = latitude[4] + "" + longitude[4]
                geohash_thirddeg = latitude[5] + "" + longitude[5]
                stop_id = entity.vehicle.stop_id
                start_time = entity.vehicle.trip.start_time[0:5] # hh:mm
                vehicle_id = entity.vehicle.vehicle.id
                short_name = utils.parse_short_name(self.feedName, trip_id, route_id, self.OTPData)
                color = utils.parse_color(self.feedName, trip_id, route_id, self.OTPData)
                mode = utils.parse_mode(self.feedName, trip_id, route_id, self.OTPData)

                # gtfsrt/vp/<feed_name>/<agency_id>/<agency_name>/<mode>/<route_id>/<direction_id>/<trip_headsign>/<trip_id>/<next_stop>/<start_time>/<vehicle_id>/<geohash_head>/<geohash_firstdeg>/<geohash_seconddeg>/<geohash_thirddeg>/<short_name>/<color>/
                # GTFS RT feed used for testing was missing some information so those are empty
                full_topic = '{0}/{1}///{2}/{3}/{4}/{5}/{6}/{7}/{8}/{9}/{10}/{11}/{12}/{13}/{14}/{15}/'.format(
                    self.baseMqttTopic, self.feedName, mode, route_id, direction_id,
                    trip_headsign, trip_id, stop_id, start_time, vehicle_id, geohash_head, geohash_firstdeg,
                    geohash_seconddeg, geohash_thirddeg, short_name, color)

                sernmesg = nfeedmsg.SerializeToString()
                self.client.publish(full_topic, sernmesg)
        except:
            print(r.content)
            raise
Example #3
0
    def _setp_value(self, key, value):

        import utils
        r, g, b, alpha = utils.parse_color(value)
        self.__colorpicker.set_color(gtk.gdk.Color(r << 8, g << 8, b << 8))
        self.__colorpicker.set_alpha((alpha << 8) + alpha)
        self._set_config(value)
        self._setp(key, value)
Example #4
0
 def validate_arguments(self):
     errors = [e for e in self.validator.iter_errors(self.args)]
     if len(errors) > 0:
         raise ParseError(errors)
     if 'color' in self.args.keys():
         try:
             self.color = parse_color(self.args['color'])
         except ValueError:
             errors = ['color must be an hex or in rgb format']
             raise ParseError(errors)
     self.start = self.args['start'] if 'start' in self.args.keys(
     ) else None
     self.end = self.args['end'] if 'end' in self.args.keys() else None
     self.section_id = self.args['section_id']
Example #5
0
    def __init__(self, name, parent):

        self.__frame_widths = [Unit.ZERO] * 4
        self.__images = []


        ContainerTarget.__init__(self, name, parent)
        self.__table = gtk.Table(3, 3)
        self.__table.set_direction(gtk.TEXT_DIR_LTR)
        self.__table.show()

        r, g, b, a = utils.parse_color("black")
        for x, y in ((0, 1), (1, 0), (2, 1), (1, 2),
                     (0, 0), (2, 0), (2, 2), (0, 2)):
            img = Tiling()
            img.set_from_color(r, g, b, a)
            img.show()
            self.__table.attach(img, x, x + 1, y, y + 1)
            self.__images.append(img)

        self.__box = gtk.HBox()
        self.__box.show()
        self.__table.attach(self.__box, 1, 2, 1, 2)

        self._register_property("border-uris", TYPE_LIST,
                                self._setp_border_uris, self._getp)
        self._register_property("border-width", TYPE_UNIT_LIST,
                                self._setp_border_width, self._getp)
        self._register_property("color", TYPE_STRING,
                                self._setp_border_color, self._getp)

        self.set_prop("border-width",
                      [Unit.Unit(2, Unit.UNIT_PX), Unit.Unit(2, Unit.UNIT_PX),
                       Unit.Unit(2, Unit.UNIT_PX), Unit.Unit(2, Unit.UNIT_PX)])
        self._setp("color", "black")


        # watch for geometry changes
        self.add_observer(self.__on_observe_size)
Example #6
0
    def __set_color(self, color):

        r, g, b, a = utils.parse_color(color)
        w, h = self.__layout.size_request()
        self.__image.set_from_color(r, g, b, a)
        self.__image.tile(w, h)
Example #7
0
    def __set_color(self, color):

        self.__color = utils.parse_color(color)