Example #1
0
 def _get_fake_triangle(cache=[]):
     if not cache:
         cache.append(
             tkinter.PhotoImage(width=images.get('triangle').width(),
                                height=images.get('triangle').height()))
         atexit.register(cache.clear)
     return cache[0]
Example #2
0
 def getImageBasedOnDirection(self):
     if self.direction == entities.Direction.NORTH:
         return images.get('projectile_north')
     elif self.direction == entities.Direction.EAST:
         return images.get('projectile_east')
     elif self.direction == entities.Direction.SOUTH:
         return images.get('projectile_south')
     elif self.direction == entities.Direction.WEST:
         return images.get('projectile_west')
Example #3
0
    def renderLives(self, targetSurface):
        startLocation = Vector(0, 240 - 12)
        tankImage = images.get('tank1')

        for _ in range(gamecontroller.getLives()):
            targetSurface.blit(tankImage, startLocation.toIntTuple())
            startLocation = startLocation.add(Vector(16, 0))
Example #4
0
    def renderPlayerHitpoints(self, targetSurface):
        image = images.get('ui_heart')
        startLocation = Vector(220, 240 - 11)

        for _ in range(gamecontroller.getPlayerTank().getHitpoints()):
            targetSurface.blit(image, startLocation.toIntTuple())
            startLocation = startLocation.add(Vector(8, 0))
Example #5
0
    def renderWeaponPower(self, targetSurface):
        image = images.get('ui_weaponpower')
        startLocation = Vector(175, 240 - 11)

        for _ in range(gamecontroller.getPlayerTank().getWeapon().getLevel()):
            targetSurface.blit(image, startLocation.toIntTuple())
            startLocation = startLocation.add(Vector(7, 0))
Example #6
0
    def __init__(self, id, app, spawnNode, endNode, map, canvas):
        self.id = id
        self.app = app

        self.spawnNode = spawnNode
        self.endNode = endNode

        self.map = map

        self.path = {}

        self.canvas = canvas

        self.isTurning = False

        self.time = 0

        self.ended = False

        for i in range(4):
            if self.map[c.add(self.spawnNode, c.steps[i])] == c.road(i):
                self.direction = i

                self.x = (self.spawnNode[0] * c.nodeSize) + c.offsets[i][0]
                self.y = (self.spawnNode[1] * c.nodeSize) + c.offsets[i][1]

                if i == 0:
                    self.y += (c.nodeSize - c.carSize)
                elif i == 3:
                    self.x += (c.nodeSize - c.carSize)

        self.canvasObject = self.canvas.create_image(self.x, self.y, image = img.get('car'), anchor = NW)

        self.path = self.findPath(self.spawnNode, self.direction, self.path)
 def drawMap(self):
     for i in range(self.mapLength):
         for j in range(self.mapHeight):
             if self.map[(i, j)] == 'U':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('undefined'),
                                          anchor=NW)
             elif self.map[(i, j)] == 'S':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('spawn'),
                                          anchor=NW)
             elif self.map[(i, j)] == 'H':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('horizontalRoad'),
                                          anchor=NW)
             elif self.map[(i, j)] == 'V':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('verticalRoad'),
                                          anchor=NW)
             elif self.map[(i, j)] == 'L':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('light'),
                                          anchor=NW)
             elif self.map[(i, j)] == '1':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('neCorner'),
                                          anchor=NW)
             elif self.map[(i, j)] == '2':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('seCorner'),
                                          anchor=NW)
             elif self.map[(i, j)] == '3':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('swCorner'),
                                          anchor=NW)
             elif self.map[(i, j)] == '4':
                 self.canvas.create_image(i * c.nodeSize,
                                          j * c.nodeSize,
                                          image=img.get('nwCorner'),
                                          anchor=NW)
             else:
                 print("Invalid Map Value at (" + str(i) + ", " + str(j) +
                       ')')
Example #8
0
 def display(self, screen, location = None):
     if not self.loaded:
         config.log_e('Grid is not loaded!')
         return
     for tile in self.tiles:
         for i in range(3):
             image = images.get(self.tiles[tile][i+1])
             if image is not None: screen.blit(image, self.tiles[tile]['coords'])
Example #9
0
def images_page():
    args = dict(request.args.items())
    imgs = images.get(args)
    if not imgs:
        return render_template('images_not_found.html', menu=menu, title=u'Images not found')
    backto = [args['event'], args['year']] + ([args['country']] if 'user' in args else [])
    title = u'Images of %sWiki Loves %s %s in %s' % (args['user'] + u' in ' if 'user' in args else u'',
        args['event'].capitalize(), args['year'], args['country'])
    return render_template('images.html', menu=menu, title=title, images=imgs, backto=backto)
Example #10
0
def images_page():
    args = dict(request.args.items())
    imgs = images.get(args)
    if not imgs:
        return render_template('images_not_found.html', menu=menu, title=u'Images not found')
    backto = [args['event'], args['year']] + ([args['country']] if 'user' in args else [])
    title = u'Images of %s%s %s in %s' % (args['user'] + u' in ' if 'user' in args else u'',
                                          get_event_name(args['event']),
                                          args['year'], args['country'])
    return render_template('images.html', menu=menu, title=title, images=imgs, backto=backto)
Example #11
0
    def renderTileGrid(self, surface, dataArray, location):
        image = images.get('brick')
        width = len(dataArray[0])
        height = len(dataArray)

        for y in range(height):
            line = dataArray[y]
            for x in range(width):
                if line[x] == 'X':
                    surface.blit(image, ((x + location[0]) * 8, (y + location[1]) * 8))
Example #12
0
    def __init__(self, type, turretOffsets):
        self.baseImages = { \
            Direction.NORTH: images.get(f'tank{type}_base_north'), \
            Direction.EAST: images.get(f'tank{type}_base_east'), \
            Direction.SOUTH: images.get(f'tank{type}_base_south'), \
            Direction.WEST: images.get(f'tank{type}_base_west')}

        self.turretImages = { \
            Direction.NORTH: images.get(f'tank{type}_turret_north'), \
            Direction.EAST: images.get(f'tank{type}_turret_east'), \
            Direction.SOUTH: images.get(f'tank{type}_turret_south'), \
            Direction.WEST: images.get(f'tank{type}_turret_west')}

        self.turretOffsets = turretOffsets
Example #13
0
 def updateImage(self):
     if self.state == 0:
         self.canvas.create_image(self.node[0] * c.nodeSize,
                                  self.node[1] * c.nodeSize,
                                  image=img.get('horizontalLight'),
                                  anchor=NW)
     elif self.state == 1:
         self.canvas.create_image(self.node[0] * c.nodeSize,
                                  self.node[1] * c.nodeSize,
                                  image=img.get('verticalLight'),
                                  anchor=NW)
     elif self.state == 2:
         self.canvas.create_image(self.node[0] * c.nodeSize,
                                  self.node[1] * c.nodeSize,
                                  image=img.get('neCornerLight'),
                                  anchor=NW)
     elif self.state == 3:
         self.canvas.create_image(self.node[0] * c.nodeSize,
                                  self.node[1] * c.nodeSize,
                                  image=img.get('seCornerLight'),
                                  anchor=NW)
     elif self.state == 4:
         self.canvas.create_image(self.node[0] * c.nodeSize,
                                  self.node[1] * c.nodeSize,
                                  image=img.get('swCornerLight'),
                                  anchor=NW)
     elif self.state == 5:
         self.canvas.create_image(self.node[0] * c.nodeSize,
                                  self.node[1] * c.nodeSize,
                                  image=img.get('nwCornerLight'),
                                  anchor=NW)
Example #14
0
def render():
    buffer.fill((0, 0, 0))

    buffer.blit(images.get('base'), (baseLocation[0] * playfield.blockSize,
                                     baseLocation[1] * playfield.blockSize))
    playfield.renderLayer(0, buffer, (0, 0))
    playfield.renderLayer(1, buffer, (0, 0))

    for tankSpawner in tankSpawners:
        buffer.blit(images.get('tank1_base'),
                    (tankSpawner[0] * playfield.blockSize,
                     tankSpawner[1] * playfield.blockSize))

    buffer.blit(images.get('tank3_base'),
                (playerStartLocation[0] * playfield.blockSize,
                 playerStartLocation[1] * playfield.blockSize))
    drawGrid(buffer)

    pygame.transform.scale(buffer, (640, 480), screen)
    #screen.blit(buffer, (0,0))

    pygame.display.flip()
Example #15
0
    def setTileType(self, tileType):
        self.image = None
        self.tileType = tileType
        self.blocksMovement = False
        self.blocksProjectiles = False
        self.layer = 0

        if tileType == TileType.BRICK:
            self.image = images.get('brick')
            self.blocksMovement = True
            self.blocksProjectiles = True
        elif tileType == TileType.CONCRETE:
            self.image = images.get('concrete')
            self.blocksMovement = True
            self.blocksProjectiles = True
        elif tileType == TileType.WATER:
            self.image = images.get('water')
            self.blocksMovement = True
            self.blocksProjectiles = False
        elif tileType == TileType.TREE:
            self.image = images.get('tree')
            self.layer = 1
Example #16
0
    def renderBaseHitpoints(self, targetSurface):
        image = images.get('ui_basehealth')
        startLocation = Vector(270, 240 - 15)
        x = startLocation.x
        y = startLocation.y

        for i in range(gamecontroller.getBase().getHitpoints()):
            targetSurface.blit(image, (x, y))

            x += 10
            if i == 4:
                x = startLocation.x
                y += 7
Example #17
0
def text_message_command(bot, update):
    city = update.message.text
    try:
        response, status = weather.info(city)
    except BaseException:
        bot.send_message(chat_id=update.message.chat_id,
                         text='Incorrect city. Please, try again.')
        return
    bot.send_message(chat_id=update.message.chat_id, text=response)
    try:
        photo = images.get([city, status])
        bot.send_photo(chat_id=update.message.chat_id, photo=photo)
    except BaseException:
        return
Example #18
0
    def _on_click(self, event):
        if self.identify(event.x, event.y) != 'label':
            # something else than the top label was clicked
            return

        # find the right edge of the label
        right = event.x
        while self.identify(right, event.y) == 'label':
            right += 1
        if event.x + images.get('closebutton').width() >= right:
            # the close button was clicked
            tab = self.tabs()[self.index('@%d,%d' % (event.x, event.y))]
            if tab.can_be_closed():
                self.close_tab(tab)
Example #19
0
    def add_tab(self, tab, select=True):
        # append a Tab to this tab manager.
        assert tab not in self.tabs(), "cannot add the same tab twice"
        for existing_tab in self.tabs():
            if tab.equivalent(existing_tab):
                if select:
                    self.select(existing_tab)
                return existing_tab

        self.add(tab,
                 text=tab.title,
                 image=images.get('closebutton'),
                 compound='right')
        if select:
            self.select(tab)

        # the update() is needed in some cases because virtual events
        # don't run if the widget isn't visible yet
        self.update()
        self.event_generate('<<NewTab>>', data=tab)
        return tab
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("tenant_id", help="tenant_id")
    parser.add_argument("project_id", help="project_id")
    parser.add_argument("gcp_project", help="Google Cloud Platform project_id")
    args = parser.parse_args()

    tenant_id = args.tenant_id
    project_id = args.project_id
    offset = 0
    limit = 100

    logger.info('Starting export for tenant: %s, project: %s', tenant_id, project_id)

    total = count(tenant_id, project_id)

    logger.info('%s image(s) to export', total)

    while offset < total:
        logger.debug('About to fetch image batch: offset: %s, limit: %s', offset, limit)
        api_response = get(tenant_id, project_id, offset=offset, limit=limit)
        items = api_response.items
        logger.debug('Got batch with %s image(s)', len(items))
        images = []

        for image in items:
            image_to_dict = image.to_dict()
            exif_annotations_dict = image_to_dict.pop('exif_annotations', dict())

            del image_to_dict['annotations']
            del image_to_dict['vision_annotations']

            if exif_annotations_dict:
                image_to_dict['exif_annotations'] = [dict(key=k, value=v) for k, v in exif_annotations_dict.items()]
            images.append(image_to_dict)

        stream_data(args.gcp_project, tenant_id, 'image', images)
        offset += limit

    logger.info('Images exported and stored')
Example #21
0
 def __init__(self):
     self.setImage(images.get('paddle'))
Example #22
0
 def on_errorvar_changed(*junk):
     if errorvar.get():
         triangle_label['image'] = images.get('triangle')
     else:
         triangle_label['image'] = self._get_fake_triangle()
Example #23
0
 def __init__(self):
     super().__init__(images.get('powerup_destroyall'))
Example #24
0
    def renderOutline(self, surface):
        image = images.get('concrete')
        screenSize = (int(320 / 8), int(240 / 8))

        self.drawCenteredRectangle(surface, image, 20, 6, screenSize)
Example #25
0
 def createExplosion(self):
     image = images.get('explosion')
     entities.manager.add(
         entities.effect.Effect(image, self.getCenterLocation(), 300))
Example #26
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("tenant_id", help="tenant_id")
    parser.add_argument("project_id", help="project_id")
    parser.add_argument("output_bucket", help="Target bucket")
    parser.add_argument("gcp_project",
                        help="Google Cloud Plataform project_id")
    args = parser.parse_args()

    tenant_id = args.tenant_id
    project_id = args.project_id
    offset = 0
    limit = 100
    bucket_name = args.output_bucket

    logger.info('Starting export for tenant: %s, project: %s', tenant_id,
                project_id)

    storage_client = storage.Client(args.gcp_project)
    bucket = storage_client.get_bucket(bucket_name)
    blob_name = 'image-export/{tenant_id}/{project_id}/{export_id}.json'.format(
        tenant_id=tenant_id,
        project_id=project_id,
        export_id=str(uuid.uuid4()))
    blob = storage.Blob(blob_name, bucket)
    total = count(tenant_id, project_id)

    logger.info('%s image(s) to export', total)

    # gzip_stream = gzip.GzipFile(fileobj=stream, mode='rw')
    # blob.content_encoding = 'gzip'

    # TODO find a way to stream data to GCS instead of buffering in memory
    with tempfile.NamedTemporaryFile() as tmp_file:
        while offset < total:
            logger.debug('About to fetch image batch: offset: %s, limit: %s',
                         offset, limit)
            api_response = get(tenant_id,
                               project_id,
                               offset=offset,
                               limit=limit)
            items = api_response.items
            logger.debug('Got batch with %s image(s)', len(items))
            for image in items:
                logger.debug('Writing image: %s', image.id)

                image_to_dict = image.to_dict()

                del image_to_dict['annotations']
                # del image_to_dict['vision_annotations']

                exif_annotations_dict = image_to_dict.pop(
                    'exif_annotations', {})
                if exif_annotations_dict:
                    image_to_dict['exif_annotations'] = [
                        dict(key=k, value=v)
                        for k, v in exif_annotations_dict.items()
                    ]

                vision_annotations_dict = image_to_dict.pop(
                    'vision_annotations', {})
                if vision_annotations_dict:
                    image_to_dict['vision_annotations'] = json.loads(
                        vision_annotations_dict)

                tmp_file.write(
                    _to_bytes(json.dumps(image_to_dict) + '\n',
                              encoding='utf-8'))
            offset += limit

        content_type = 'application/json'
        ret_val = blob.upload_from_file(tmp_file,
                                        content_type=content_type,
                                        client=storage_client,
                                        rewind=True)
        logger.debug('Temporary file uploaded: %s', ret_val)

    logger.info('Images exported and stored on: %s', blob.path)
Example #27
0
 def __init__(self):
     self.setImage(images.get('ball'))
Example #28
0
 def __init__(self):
     self.setImage(images.get('block-gray1'))
     self.hitpoints = 2
Example #29
0
 def __init__(self):
     super().__init__(images.get('powerup_weapon'))
Example #30
0
 def hitByBall(self, ball):
     Block.hitByBall(self, ball)
     if self.hitpoints == 1:
         self.setImage(images.get('block-gray2'))
Example #31
0
    def __init__(self, parent, textwidget, **kwargs):
        super().__init__(parent, **kwargs)
        self._textwidget = textwidget

        self.grid_columnconfigure(2, minsize=30)
        self.grid_columnconfigure(3, weight=1)

        textwidget.tag_config('find_highlight',
                              foreground='black',
                              background='yellow')

        self.find_entry = self._add_entry(0, "Find:")
        find_var = self.find_entry['textvariable'] = tk.StringVar()
        find_var.trace('w', self.highlight_all_matches)
        self.find_entry.lol = find_var  # because cpython gc

        self.replace_entry = self._add_entry(1, "Replace with:")

        self.find_entry.bind('<Shift-Return>', self._go_to_previous_match)
        self.find_entry.bind('<Return>', self._go_to_next_match)

        buttonframe = ttk.Frame(self)
        buttonframe.grid(row=2, column=0, columnspan=4, sticky='we')

        self.previous_button = ttk.Button(buttonframe,
                                          text="Previous match",
                                          command=self._go_to_previous_match)
        self.next_button = ttk.Button(buttonframe,
                                      text="Next match",
                                      command=self._go_to_next_match)
        self.replace_this_button = ttk.Button(buttonframe,
                                              text="Replace this match",
                                              command=self._replace_this)
        self.replace_all_button = ttk.Button(buttonframe,
                                             text="Replace all",
                                             command=self._replace_all)

        self.previous_button.pack(side='left')
        self.next_button.pack(side='left')
        self.replace_this_button.pack(side='left')
        self.replace_all_button.pack(side='left')
        self._update_buttons()

        self.full_words_var = tk.BooleanVar()
        self.full_words_var.trace('w', self.highlight_all_matches)
        self.ignore_case_var = tk.BooleanVar()
        self.ignore_case_var.trace('w', self.highlight_all_matches)

        ttk.Checkbutton(self,
                        text="Full words only",
                        variable=self.full_words_var).grid(row=0,
                                                           column=3,
                                                           sticky='w')
        ttk.Checkbutton(self,
                        text="Ignore case",
                        variable=self.ignore_case_var).grid(row=1,
                                                            column=3,
                                                            sticky='w')

        self.statuslabel = ttk.Label(self)
        self.statuslabel.grid(row=3, column=0, columnspan=4, sticky='we')

        ttk.Separator(self, orient='horizontal').grid(row=4,
                                                      column=0,
                                                      columnspan=4,
                                                      sticky='we')

        closebutton = ttk.Label(self, cursor='hand2')
        closebutton.place(relx=1, rely=0, anchor='ne')
        closebutton.bind('<Button-1>', self.hide)

        closebutton['image'] = images.get('closebutton')

        textwidget.bind('<<Selection>>', self._update_buttons, add=True)
Example #32
0
 def __init__(self):
     self.tile = images.get("bggrid")