Exemplo n.º 1
0
    def get_bands(self, channels, downsample=1, shape=None):
        """downsample!=False will make all bands having shape of smallest // downsample."""
        if channels == ['_map_mask_']:
            arrays = [self.map_mask]
        else:
            arrays = [self.bands[self.chan_dict[c]].copy() for c in channels]

        if not shape:
            if not downsample:
                return arrays

            shapes = np.array([a.shape for a in arrays])
            x = shapes[:, 0].min()
            y = shapes[:, 1].min()

            if downsample != 1:
                x //= downsample
                y //= downsample
        else:
            x, y = shape

        if (x, y, tuple(channels)) in self._buffer_for_get_bands:
            return copy_list(self._buffer_for_get_bands[(x, y,
                                                         tuple(channels))])

        for i in range(len(arrays)):
            a = arrays[i]
            no_interpolation = True

            if a.shape[0] % x <= x // 100:
                a = a[::a.shape[0] // x][:x]
            elif a.shape[0] % x >= x - x // 100:
                a = a[::a.shape[0] // x + 1][:x]
            else:
                no_interpolation = False

            if a.shape[1] % y <= y // 100:
                a = a[:, ::a.shape[1] // y][:, :y]
            elif a.shape[1] % y >= y - y // 100:
                a = a[:, ::a.shape[1] // y + 1][:, :y]
            else:
                no_interpolation = False

            if not no_interpolation:
                a = interp2d(np.linspace(0, 1, a.shape[1]),
                             np.linspace(0, 1, a.shape[0]),
                             a,
                             kind='cubic')(np.linspace(0, 1, y),
                                           np.linspace(0, 1, x))

            arrays[i] = a

        self._buffer_for_get_bands[(x, y, tuple(channels))] = copy_list(arrays)
        return arrays
Exemplo n.º 2
0
 def animate(self):
     l=utils.copy_list(g.top); k=g.aim; g.aim=0
     for i in range(len(l)):
          g.top=l[:i+1]; self.display()
          pygame.display.flip(); pygame.time.wait(700)
     g.top=utils.copy_list(g.nos)
     mx=1
     for i in range(g.nos_k): mx*=g.max_n
     for i in range(15):
         g.aim=random.randint(5,mx); self.display()
         pygame.display.flip(); pygame.time.wait(150)
     g.aim=k
     pygame.event.clear()
Exemplo n.º 3
0
 def which(self):
     l = utils.copy_list(self.pieces)
     for i in range(self.total):
         pce = l.pop()
         img = pce.img
         if utils.mouse_on_img(img, (pce.cx, pce.cy)):
             if pce.group > 0:
                 lst = utils.copy_list(self.pieces)
                 for pce1 in lst:
                     if pce1.group == pce.group: self.top(pce1)
             else:
                 self.top(pce)
             return pce
     return None
Exemplo n.º 4
0
 def reset(self):
     g.state = 1
     g.top = utils.copy_list(g.nos)
     g.buffr = []
     buttons.off(['plus', 'times', 'equals'])
     buttons.off('back')
     self.mouse_init()
Exemplo n.º 5
0
 def reset(self):
     g.state = 1
     g.top = utils.copy_list(g.nos)
     g.buffr = []
     buttons.off(['plus', 'times', 'equals'])
     buttons.off('back')
     self.mouse_init()
Exemplo n.º 6
0
 def save(self):
     self.owners_save = []
     for square in self.squares:
         self.owners_save.append(square.owner)
     self.golds_save = []
     for edge in self.edges:
         self.golds_save.append(edge.gold)
     self.counts_save = utils.copy_list(self.counts)
Exemplo n.º 7
0
 def next_card(self):
     if self.rest == []:  # ensure no cards are lost!
         fresh = utils.copy_list(self.deck)
         fresh = utils.shuffle(fresh)
         for n in fresh:
             if n not in self.yes: self.rest.append(n)
     n = self.rest.pop()
     return n
Exemplo n.º 8
0
 def setup(self):
     self.yes = []
     self.rest = utils.copy_list(self.deck)
     self.rest = utils.shuffle(self.rest)
     self.display_last = 0
     self.ms = pygame.time.get_ticks()
     g.state = 1
     g.display_last = 0
     g.perfect = True
Exemplo n.º 9
0
    def __init__(self, application, request, **kwargs):
        super(BaseHandler, self).__init__(application, request, **kwargs)
        logger.debug('base init')

        # 请求 client 的相关信息
        self.client = None
        self.analytics = AnalyticsData()
        self.response = {'headers': HTTPHeaders(), 'body': ''}
        # 拷贝一份中间件的列表
        self.middleware_list = copy_list(self.application.middleware_list)
Exemplo n.º 10
0
 def good(self):
     l = utils.copy_list(self.yes)
     if self.ok == 1:
         n = l.pop()
         return ok1(self.rule, n)
     else:
         n2 = l.pop()
         n1 = l.pop()
         return ok2(self.rule, n1, n2,
                    len(self.yes) - 1)
Exemplo n.º 11
0
    def __init__(self, application, request, **kwargs):
        super(BaseHandler, self).__init__(application, request, **kwargs)
        logger.debug('base init')

        # 请求 client 的相关信息
        self.client = None
        self.analytics = AnalyticsData()
        self.endpoint_response = None
        # 拷贝一份中间件的列表
        self.middleware_list = copy_list(self.application.middleware_list)
Exemplo n.º 12
0
 def restore(self):
     ind = 0
     for square in self.squares:
         square.owner = self.owners_save[ind]
         ind += 1
     ind = 0
     for edge in self.edges:
         edge.gold = self.golds_save[ind]
         ind += 1
     self.counts = utils.copy_list(self.counts_save)
Exemplo n.º 13
0
    def __init__(self, application, request, **kwargs):
        super(BaseHandler, self).__init__(application, request, **kwargs)
        logger.debug('base init')

        # 请求 client 的相关信息
        self.client = None
        self.analytics = AnalyticsData()
        self.endpoint_response = None
        # 拷贝一份中间件的列表
        self.middleware_list = copy_list(self.application.middleware_list)
Exemplo n.º 14
0
 def new1(self):
     g.nos = self.gen_nos()
     g.aim = self.gen_aim()
     g.top = utils.copy_list(g.nos)
     g.buffr = []
     buttons.off(['plus', 'times', 'equals'])
     buttons.off('back')
     g.state = 1
     self.mouse_init()
     self.anim_start()
     self.scored = False
Exemplo n.º 15
0
 def new1(self):
     g.nos = self.gen_nos()
     g.aim = self.gen_aim()
     g.top = utils.copy_list(g.nos)
     g.buffr = []
     buttons.off(['plus', 'times', 'equals'])
     buttons.off('back')
     g.state = 1
     self.mouse_init()
     self.anim_start()
     self.scored = False
Exemplo n.º 16
0
    def __init__(self, application, request, **kwargs):
        super(BaseHandler, self).__init__(application, request, **kwargs)
        logger.debug('base init')

        # 请求 client 的相关信息
        self.client = None
        # 对应的 API Handler, 可能是内置的, 也可能是后端的 API
        self.real_api_handler = None
        self.analytics = AnalyticsData()
        # 拷贝一份中间件的列表
        self.middleware_list = copy_list(self.application.middleware_list)
        self.builtin_endpoints = self.application.builtin_endpoints
Exemplo n.º 17
0
 def which(self):
     l = utils.copy_list(self.pieces)
     for i in range(35):
         pce = l.pop()
         img = pce.img
         if utils.mouse_on_img(img, (pce.x, pce.y)):
             if not pce.fixed:
                 if pce.group > 0:
                     self.top_gp(pce.group)
                 else:
                     self.top(pce)
                 return pce
     return None
Exemplo n.º 18
0
 def do_button(self, bu):
     if bu == 'cyan':
         g.pattern += 1
         if g.pattern == self.num_patterns + 1:
             g.pattern = 1
         g.help1 = 0
         g.help2 = 0
         self.get_goal()
         self.tu.win = False
         g.finale = False
         g.show_help = False
         self.tu.changed = True
         self.tu.clear()
         if self.sugar:
             self.cyan_button.set_sensitive(False)
         else:
             buttons.off('cyan')
         self.mouse_1st_no()  # to 1st number
     elif bu == 'black':
         self.tu.current = utils.copy_list(g.numbers)
         self.tu.setup(self.colors[0])
         g.show_help = False
     elif bu == 'green':
         self.tu.between_levels = False
         g.show_help = False
         if self.tu.changed:
             self.tu.current = utils.copy_list(g.numbers)
             self.tu.setup(self.colors[0])
             self.tu.changed = False
             self.tu.running = True
         elif self.tu.win or self.tu.crashed:
             self.tu.setup(self.colors[0])
             self.tu.running = True
         else:
             if self.tu.step_count == 0:
                 self.tu.ms = pygame.time.get_ticks()
             self.tu.running = True
     elif bu == 'red':
         self.tu.running = False
Exemplo n.º 19
0
 def do_button(self, bu):
     if bu == 'cyan':
         g.pattern += 1
         if g.pattern == 123:
             g.pattern = 1
         g.help1 = 0
         g.help2 = 0
         self.get_goal()
         self.tu.win = False
         g.finale = False
         g.show_help = False
         self.tu.changed = True
         self.tu.clear()
         if self.sugar:
             self.cyan_button.set_sensitive(False)
         else:
             buttons.off('cyan')
         self.mouse_1st_no()  # to 1st number
     elif bu == 'black':
         self.tu.current = utils.copy_list(g.numbers)
         self.tu.setup(self.colors[0])
         g.show_help = False
     elif bu == 'green':
         self.tu.between_levels = False
         g.show_help = False
         if self.tu.changed:
             self.tu.current = utils.copy_list(g.numbers)
             self.tu.setup(self.colors[0])
             self.tu.changed = False
             self.tu.running = True
         elif self.tu.win or self.tu.crashed:
             self.tu.setup(self.colors[0])
             self.tu.running = True
         else:
             if self.tu.step_count == 0:
                 self.tu.ms = pygame.time.get_ticks()
             self.tu.running = True
     elif bu == 'red':
         self.tu.running = False
Exemplo n.º 20
0
 def gen_aim(self):
     l=utils.copy_list(g.nos)
     #shuffle nos
     lt=utils.shuffle(l)
     #generate answer
     buff=""
     r=random.randint(1,2) # for level 1
     while True:
         n=lt[0]; lt.remove(n); buff+=str(n)
         if len(lt)==0: break
         if g.level>1: r=random.randint(0,2)
         if g.signs[r]=='=':
             n=eval(buff); buff=""; lt.append(n); lt=utils.shuffle(lt)
         else:
             buff=buff+g.signs[r]
     return eval(buff)
Exemplo n.º 21
0
 def help2(self):
     self.tu.current = utils.copy_list(g.numbers)
     self.tu.crashed = False
     g.help1 = 0
     looking = True
     while looking:
         g.help1 += 1
         ind = g.help1 - 1
         if g.numbers[ind] != g.goal[ind]:
             g.numbers[ind] = g.goal[ind]
             self.tu.current[ind] = g.goal[ind]
             g.show_help = True
             self.tu.changed = True
             g.help2 += 1
             looking = False
         if g.help1 > 4:
             g.show_help = True
             looking = False
Exemplo n.º 22
0
 def help2(self):
     self.tu.current = utils.copy_list(g.numbers)
     self.tu.crashed = False
     g.help1 = 0
     looking = True
     while looking:
         g.help1 += 1
         ind = g.help1 - 1
         if g.numbers[ind] != g.goal[ind]:
             g.numbers[ind] = g.goal[ind]
             self.tu.current[ind] = g.goal[ind]
             g.show_help = True
             self.tu.changed = True
             g.help2 += 1
             looking = False
         if g.help1 > 4:
             g.show_help = True
             looking = False
Exemplo n.º 23
0
 def gen_aim(self):
     l = utils.copy_list(g.nos)
     #shuffle nos
     lt = utils.shuffle(l)
     #generate answer
     buff = ""
     r = random.randint(1, 2)  # for level 1
     while True:
         n = lt[0]
         lt.remove(n)
         buff += str(n)
         if len(lt) == 0:
             break
         if g.level > 1:
             r = random.randint(0, 2)
         if g.signs[r] == '=':
             n = eval(buff)
             buff = ""
             lt.append(n)
             lt = utils.shuffle(lt)
         else:
             buff = buff + g.signs[r]
     return eval(buff)
Exemplo n.º 24
0
    def run(self, restore=False):
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                return
            elif event.type == pygame.VIDEORESIZE:
                pygame.display.set_mode(event.size, pygame.RESIZABLE)
                break
        self.g_init()
        if not self.journal:
            utils.load()
        load_save.retrieve()
        if restore:
            self.restore_pattern()
        else:
            g.delay = (3 - g.level) * 400
        self.tu = my_turtle.TurtleClass()
        self.tu.current = [1, 1, 1, 3, 2]
        self.get_goal()
        if g.pattern == 1:
            self.tu.current = utils.copy_list(g.goals[0])
        self.tu.setup(self.colors[0])
        g.numbers = utils.copy_list(self.tu.current)
        # buttons
        x = g.sx(7.3)
        y = g.sy(16.5)
        dx = g.sy(2.6)

        if not self.sugar:
            buttons.Button("cyan", (x, y), True)
            x += dx
            buttons.off('cyan')
            buttons.Button("green", (x, y), True)
            x += dx
            buttons.Button("red", (x, y), True)
            x += dx
            buttons.Button("black", (x, y), True)
            x += dx
            self.slider = slider.Slider(g.sx(23.5), g.sy(21), 3, utils.YELLOW)

        self.mouse_1st_no()  # to 1st number
        if self.canvas is not None:
            self.canvas.grab_focus()
        ctrl = False
        pygame.key.set_repeat(600, 120)
        key_ms = pygame.time.get_ticks()
        going = True
        while going:
            if self.journal:
                # Pump Gtk messages.
                while Gtk.events_pending():
                    Gtk.main_iteration()

            # Pump PyGame messages.
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    if not self.journal:
                        utils.save()
                    going = False
                elif event.type == pygame.MOUSEMOTION:
                    g.pos = event.pos
                    g.redraw = True
                    if self.canvas is not None:
                        self.canvas.grab_focus()
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    g.redraw = True
                    if g.big:
                        g.big = False
                    else:
                        bu = buttons.check()
                        if bu != '':
                            self.do_button(bu)
                            self.flush_queue()
                        elif not self.sugar:
                            if utils.mouse_on_img1(g.magician, g.magician_c):
                                self.help2()
                            elif utils.mouse_in(g.x1, g.y0, g.x1 + g.bw,
                                                g.y0 + g.bw):
                                self.big_pic()
                            elif self.slider.mouse():
                                g.delay = (3 - g.level) * 400
                            else:
                                g.show_help = False
                                self.check_nos(event.button)
                        else:
                            g.show_help = False
                            self.check_nos(event.button)
                elif event.type == pygame.KEYDOWN:
                    # throttle keyboard repeat
                    if pygame.time.get_ticks() - key_ms > 110:
                        key_ms = pygame.time.get_ticks()
                        if ctrl:
                            if event.key == pygame.K_q:
                                if not self.journal:
                                    utils.save()
                                going = False
                                break
                            else:
                                ctrl = False
                        if event.key in (pygame.K_LCTRL, pygame.K_RCTRL):
                            ctrl = True
                            break
                        self.do_key(event.key)
                        g.redraw = True
                        self.flush_queue()
                elif event.type == pygame.KEYUP:
                    ctrl = False
            if not going:
                break
            if self.tu.running:
                self.tu.move()
            if not g.crash_drawn:
                g.crash_drawn = True
                g.redraw = True
            if g.redraw:
                self.display()
                if g.version_display:
                    utils.version_display()
                g.screen.blit(g.pointer, g.pos)
                pygame.display.flip()
                g.redraw = False
            g.clock.tick(40)
Exemplo n.º 25
0
 def top_gp(self, gp):
     lst = utils.copy_list(self.pieces)
     for pce in lst:
         if pce.group == gp: self.top(pce)
Exemplo n.º 26
0
 def new1(self):
     g.nos=self.gen_nos();g.aim=self.gen_aim()
     g.top=utils.copy_list(g.nos); g.buffr=[]
     buttons.off(['back','plus','times','equals'])
     g.correct=False
     self.animate()
Exemplo n.º 27
0
    def run(self, restore=False):
        self.g_init()
        if not self.journal:
            utils.load()
        load_save.retrieve()
        if restore:
            self.restore_pattern()
        else:
            g.delay = (3 - g.level) * 400
        self.tu = my_turtle.TurtleClass()
        self.tu.current = [1, 1, 1, 3, 2]
        self.get_goal()
        if g.pattern == 1:
            self.tu.current = utils.copy_list(g.goal)
        self.tu.setup(self.colors[0])
        g.numbers = utils.copy_list(self.tu.current)
        #buttons
        x = g.sx(7.3)
        y = g.sy(16.5)
        dx = g.sy(2.6)

        if not self.sugar:
            buttons.Button("cyan", (x, y), True)
            x += dx
            buttons.off('cyan')
            buttons.Button("green", (x, y), True)
            x += dx
            buttons.Button("red", (x, y), True)
            x += dx
            buttons.Button("black", (x, y), True)
            x += dx
            self.slider = slider.Slider(g.sx(23.5), g.sy(21), 3, utils.YELLOW)

        self.mouse_1st_no()  # to 1st number
        if self.canvas is not None:
            self.canvas.grab_focus()
        ctrl = False
        pygame.key.set_repeat(600, 120)
        key_ms = pygame.time.get_ticks()
        going = True
        while going:
            if self.journal:
                # Pump GTK messages.
                while gtk.events_pending():
                    gtk.main_iteration()

            # Pump PyGame messages.
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    if not self.journal:
                        utils.save()
                    going = False
                elif event.type == pygame.MOUSEMOTION:
                    g.pos = event.pos
                    g.redraw = True
                    if self.canvas is not None:
                        self.canvas.grab_focus()
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    g.redraw = True
                    if g.big:
                        g.big = False
                    else:
                        bu = buttons.check()
                        if bu != '':
                            self.do_button(bu)
                            self.flush_queue()
                        elif not self.sugar:
                            if utils.mouse_on_img1(g.magician, g.magician_c):
                                self.help2()
                            elif utils.mouse_in(g.x1, g.y0, g.x1 + g.bw,
                                                g.y0 + g.bw):
                                self.big_pic()
                            elif self.slider.mouse():
                                g.delay = (3 - g.level) * 400
                            else:
                                g.show_help = False
                                self.check_nos(event.button)
                        else:
                            g.show_help = False
                            self.check_nos(event.button)
                elif event.type == pygame.KEYDOWN:
                    # throttle keyboard repeat
                    if pygame.time.get_ticks() - key_ms > 110:
                        key_ms = pygame.time.get_ticks()
                        if ctrl:
                            if event.key == pygame.K_q:
                                if not self.journal:
                                    utils.save()
                                going = False
                                break
                            else:
                                ctrl = False
                        if event.key in (pygame.K_LCTRL, pygame.K_RCTRL):
                            ctrl = True
                            break
                        self.do_key(event.key)
                        g.redraw = True
                        self.flush_queue()
                elif event.type == pygame.KEYUP:
                    ctrl = False
            if not going:
                break
            if self.tu.running:
                self.tu.move()
            if not g.crash_drawn:
                g.crash_drawn = True
                g.redraw = True
            if g.redraw:
                self.display()
                if g.version_display:
                    utils.version_display()
                g.screen.blit(g.pointer, g.pos)
                pygame.display.flip()
                g.redraw = False
            g.clock.tick(40)
Exemplo n.º 28
0
 def anim_end(self):
     if self.anim_ms is None:
         return
     g.top = utils.copy_list(g.nos)
     g.aim = self.anim_aim
     self.anim_ms = None
Exemplo n.º 29
0
 def anim_end(self):
     if self.anim_ms is None:
         return
     g.top = utils.copy_list(g.nos)
     g.aim = self.anim_aim
     self.anim_ms = None
Exemplo n.º 30
0
import utils

copied = utils.copy_list([2, 4, 6])

weather_szeged = {
    'city': 'Szeged',
    'temp': 12,
}

weather_budapest = {
    'city': 'Budapest',
    'temp': 10,
}

weather_forecast_list = [weather_szeged, weather_budapest]

weather_copy = utils.copy_list(weather_forecast_list)

weather_copy[0]['city'] = 'Swaged'

print('Eredeti lista', weather_forecast_list)
print('Másolat lista', weather_copy)
print('Eredeti Szegedi időjárás objektum', weather_szeged)

Exemplo n.º 31
0
 def reset(self):
     g.top=utils.copy_list(g.nos); g.buffr=[]
     buttons.off(['back','plus','times','equals'])