Example #1
0
def labels_from_video(video_url):
    video = read_video(video_url)
    points = [0]
    points.extend(
        visual_filter_cuts_base(
            Label(
                input_url=video_url,
                input_start_point=0,
                input_final_point=video.duration
            ),
            video.url))
    points.append(video.duration)
    p = [points[0]]
    points[1:-1] = [
        points[i] for i in range(1, len(points) - 1)
        if points[i] - p[0] >= args.labels_min_length and
            points[-1] - points[i] >= args.labels_min_length and
            not p.remove(p[0]) and not p.append(points[i])
    ]
    return [
        Label(
            output_start_point=points[i],
            output_final_point=points[i + 1]
        )
        for i in range(len(points) - 1)
    ]
Example #2
0
 def make_score_labels(self):
     self.labels = pg.sprite.Group()
     centerx = prepare.SCREEN_RECT.centerx
     title = Label("High Scores", {"midtop": (centerx, 10)}, self.labels, font_size=64, text_color=(225, 111, 4))
     top = 80
     for score in self.high_scores:
         label = Label("{}".format(score), {"midtop": (centerx, top)}, self.labels, font_size=48)
         top += 60
Example #3
0
 def label_from_template(self, *keys: List[str]):
     label_info = dict()
     for key in keys:
         label_info.update(self._label_templates.get(key, None))
     try:
         return Label(**label_info)
     except Exception:
         print(
             f"Labeler.label_from_template() Exception: "
             f"arguments passed to Label() object not correct.\n"
             f"An empty Label() object has been returned."
         )
     return Label()
    def __init__(self, name, topleft, width, height, fill_color, line_color,
                 line_weight, header_text_font, header_text_size,
                 header_text_color):
        """"
        ARGS

        name: the name of the field the header controls
        topleft: the topleft screen position of the table
        width: the width of the field the header controls
        height: the height of the header's rect
        fill_color: color to fill the header's rect with
        line_color: the line color of the SortableTable
        """
        self.image = pg.Surface((width, height))
        self.image.fill(fill_color)
        center = (width // 2), height // 2
        self.field_name = name
        label = Label(name, {"center": center},
                      font_path=header_text_font,
                      font_size=header_text_size,
                      text_color=header_text_color)
        label.draw(self.image)
        pg.draw.rect(self.image, line_color, ((0, 0), (width, height)),
                     line_weight)
        self.rect = self.image.get_rect(topleft=topleft)
        self.direction = -1
        self.selected = False
Example #5
0
def create_label(n):
    random.seed(n + random.randint(0, sys.maxsize))
    retries = args.visual_filter_retries
    while True:
        label, label_changed = change_label(n)
        if not label_changed:
            break
        if args.increment:
            cache_input(label, n)
            duration = label.output_final_point - label.output_start_point
            cache_label = Label(
                output_start_point=label.output_start_point,
                output_final_point=label.output_final_point,
                input_url=args.video_cache % (n + 1),
                input_start_point=0,
                input_final_point=duration
            )
            cache_video = Video(
                url=args.video_cache % (n + 1),
                duration=duration
            )
            accept = visual_filter(cache_label, cache_video.url)
        else:
            accept = visual_filter(label, videos[label.input_url].url)
        if accept or retries == 0:
            labels.labels[n] = label
            break
        retries -= 1
    if label_changed:
        write_labels()
    if args.increment and not os.path.isfile(args.video_cache % (n + 1)):
        cache_input(label, n)
    return label
 def startup(self, persistent):
     self.persist = persistent
     self.score = 0
     self.score_label = Label("{}".format(self.score),
                                        {"topleft": (5, 5)}, font_size=64)
     self.world.reset()
     pg.mouse.set_visible(False)
Example #7
0
 def __init__(self):
     super(Splash, self).__init__()
     self.labels = pg.sprite.Group()
     Label("Splash Screen", {"midbottom": prepare.SCREEN_RECT.center},
           self.labels,
           text_color="gold4",
           font_size=96)
    def __init__(self, data_dict, field_widths, field_height, field_text_font,
                 field_text_size, field_text_color):
        """
        ARGS

        data_dict: an OrderedDict of field_name: value pairs
        field_widths: list of the widths for each field (ordered to match the order of keys in data_dict)
        field_height: the height of a field's rect
        text_color: color that field values should be rendered in
        """
        self.data = data_dict
        left, top = 0, 0
        total_width = sum(field_widths)
        self.image = pg.Surface((total_width, field_height)).convert_alpha()
        self.image.fill((0, 0, 0, 0))
        right = left
        for width, field_name in zip(field_widths, data_dict):
            right += width
            value = data_dict[field_name]
            label = Label("{}".format(value),
                          {"midright": (right - 3, top + (field_height // 2))},
                          text_color=field_text_color,
                          font_size=field_text_size,
                          font_path=field_text_font)
            label.draw(self.image)
        self.rect = self.image.get_rect()
Example #9
0
 def __init__(self):
     super(Splash, self).__init__()
     self.next_state = "GAMEPLAY"
     self.labels = pg.sprite.Group()
     Label("Splash Screen", {"midbottom": prepare.SCREEN_RECT.center},
           self.labels,
           font_path=prepare.FONTS["weblysleekuisb"],
           text_color="gold4",
           font_size=96)
Example #10
0
 def make_labels(self, frequencies):
     self.labels = pg.sprite.Group()
     names = ["WOLD", "WMLW", "WEDM", "WTCH"]
     cx, top = prepare.SCREEN_RECT.centerx, 20
     for name, num in zip(names, frequencies):
         Label("{} {}".format(name, num), {"midtop": (cx, top)},
               self.labels,
               font_size=24,
               text_color="antiquewhite",
               font_path=prepare.FONTS["weblysleekuisl"])
         top += 30
Example #11
0
def create_labels():
    if (args.labels_from_chords_chroma or args.labels_from_chords_cnn):
        args.labels_from_chords = True
    if (args.labels_from_beats_detection
            or args.labels_from_beats_detection_crf
            or args.labels_from_beats_tracking
            or args.labels_from_beats_tracking_dbn):
        args.labels_from_beats = True
    if (args.labels_from_notes_rnn or args.labels_from_notes_cnn):
        args.labels_from_notes = True
    if (not args.labels_from_chords and not args.labels_from_beats
            and not args.labels_from_notes and not args.labels_from_onsets):
        args.labels_from_chords = True
        args.labels_from_beats = True
    points = sorted(
        set([
            0, *(points_from_chords(args.audio_output)
                 if args.labels_from_chords else []), *(points_from_beats(
                     args.audio_output) if args.labels_from_beats else []),
            *(points_from_notes(args.audio_output) if args.labels_from_notes
              else []), *(points_from_onsets(args.audio_output)
                          if args.labels_from_onsets else []),
            duration(args.audio_output)
        ]))
    if args.output_max_length:
        points[:] = [p for p in points if p < args.output_max_length
                     ] + [args.output_max_length]
    if args.labels_joints and args.labels_joints > 1:
        points[:] = points[:-1:args.labels_joints] + [points[-1]]
    if args.labels_splits and args.labels_splits > 1:
        points[:] = [
            points[i] + (points[i + 1] - points[i]) * j / args.labels_splits
            for i in range(len(points) - 1) for j in range(args.labels_splits)
        ] + [points[-1]]
    if args.labels_max_length:
        points[:] = [
            points[i] + j * args.labels_max_length
            for i in range(len(points) - 1)
            for j in range(1 + int((points[i + 1] - points[i]) /
                                   args.labels_max_length))
        ]
    if args.labels_min_length:
        p = [points[0]]
        points[1:-1] = [
            points[i] for i in range(1,
                                     len(points) - 1)
            if points[i] - p[0] >= args.labels_min_length and points[-1] -
            points[i] >= args.labels_min_length and not p.remove(p[0])
            and not p.append(points[i])
        ]
    return [
        Label(output_start_point=points[i], output_final_point=points[i + 1])
        for i in range(len(points) - 1)
    ]
Example #12
0
 def autolabel(self, var_name, unit):
     label_info = self._label_templates.get(unit, None)
     if label_info is not None:
         var_parse = re.match(
             label_info["symbol"] + r"_?([a-zA-Z0-9]+)", var_name
         )
         if var_parse:
             label_info.update(
                 self._label_templates.get(var_parse.group(1).title(), {})
             )
         try:
             return Label(**label_info)
         except Exception:
             print(
                 f"Labeler.autolabel() Exception: "
                 f"arguments passed to Label() object not correct.\n"
                 f"Continuing with empty Label() object "
                 f"for variable --> {var_name}"
             )
     return Label()
Example #13
0
 def __init__(self):
     super(Hunting, self).__init__()
     self.world_surf = pg.Surface(prepare.WORLD_SIZE).convert()
     self.world_rect = self.world_surf.get_rect()
     self.background = make_background(prepare.WORLD_SIZE)
     self.all_sprites = pg.sprite.LayeredDirty()
     self.colliders = pg.sprite.Group()
     self.ui = pg.sprite.Group()
     self.noise_detector = NoiseDetector((10, 80), self.ui)
     self.hunter = Hunter(self.world_rect.center, 0, self.noise_detector,
                          self.all_sprites)
     self.turkeys = self.add_turkeys()
     self.bullets = pg.sprite.Group()
     self.make_trees()
     hx, hy = self.hunter.rect.center
     self.ammo_crate = AmmoCrate((hx - 50, hy - 50), self.colliders,
                                 self.all_sprites)
     self.all_sprites.clear(self.world_surf, self.background)
     self.leaves = pg.sprite.Group()
     self.roasts = pg.sprite.Group()
     self.flocks = pg.sprite.Group()
     self.animations = pg.sprite.Group()
     self.rustle_sounds = [
         prepare.SFX["rustle{}".format(x)] for x in range(1, 21)
     ]
     self.wind_gust()
     style = {
         "font_path": prepare.FONTS["pretzel"],
         "font_size": 24,
         "text_color": (58, 41, 18)
     }
     self.shell_label = Label("{}".format(self.hunter.shells),
                              {"topleft": (50, 10)}, **style)
     self.roasts_label = Label("{}".format(self.hunter.roasts),
                               {"topleft": (50, 50)}, **style)
     Icon((20, 3), "shell", self.ui)
     Icon((10, 45), "roast", self.ui)
     self.add_flock()
Example #14
0
def order_print_barcode(request, order_pk):
    order = models.Orders.objects.get(pk=order_pk)

    MESSAGE_TAGS = {messages.ERROR: 'danger'}

    printer_id = request.GET.get('printer')

    p_label = Label()
    p_label.set_order_id(order_pk)
    p_label.set_labelprinter_id(printer_id)

    not_err, msg = p_label.print_label()

    if not_err:
        messages.info(request, msg)
    else:
        messages.error(request,
                       'Error when printer label [%s]' % msg,
                       extra_tags='danger')
Example #15
0
def change_label(n):
    l = labels.labels[n]
    output_duration = l.output_final_point - l.output_start_point
    input_url = l.input_url if (
        l.input_url is not None and (
        os.path.isfile(l.input_url) or
        validators.url(l.input_url))) else (
        next_input_url(n))
    input_duration = l.input_final_point - l.input_start_point
    input_start_point = l.input_start_point if (
        input_url is None or
        l.input_start_point >= 0) else (
        next_input_start_point(
            n,
            duration(input_url),
            output_duration))
    input_final_point = l.input_final_point if (
        input_url is None or
        l.input_start_point >= 0 and
        l.input_final_point >= 0 and
        abs(output_duration - input_duration) < 0.01) else (
        next_input_final_point(
            n,
            duration(input_url),
            output_duration,
            input_start_point))
    label_changed = (
        input_url != l.input_url or
        input_start_point != l.input_start_point or
        input_final_point != l.input_final_point)
    return Label(
        l.output_start_point,
        l.output_final_point,
        input_url,
        input_start_point,
        input_final_point
        ), label_changed
 def add_clay_score(self):
     lbl = Label("{}".format(int(self.clay_score)),{"topleft": (50, 5)}, font_size=64)
     lbl.rect = pg.mouse.get_pos()
     self.clay_scores.append(lbl)
Example #17
0
 def fget(self):
     from labels import Label
     return [Label(self.__api, x['label']) for x in self.__raw.labels]