Esempio n. 1
0
 def go(self):
     button = self.win.run()
     if button==gtk.RESPONSE_OK:
         fields = []
         fields2 = []
         iter = self.model2.get_iter_root()
         while iter:
             fields.append(self.model2.get_value(iter, 1).replace('/.id','.id'))
             fields2.append(self.model2.get_value(iter, 0))
             iter = self.model2.iter_next(iter)
         action = self.wid_action.get_active_text()
         self.parent.present()
         self.win.destroy()
         import_comp = self.wid_import_compatible.get_active()
         result = datas_read(self.ids, self.model, fields, self.fields_data, context=self.context)
         if result.get('warning',False):
             common.message_box(_('Exportation Error !'), unicode(result.get('warning',False)))
             return False
         result = result.get('datas',[])
         if import_comp:
             fields2 = fields
         if action == _('Open in Excel'):
             open_excel(fields2, result)
         else:
             fname = common.file_selection(_('Save As...'),
                     parent=self.parent, action=gtk.FILE_CHOOSER_ACTION_SAVE)
             if fname:
                 export_csv(fname, fields2, result, self.wid_write_field_names.get_active())
         return True
     else:
         self.parent.present()
         self.win.destroy()
         return False
Esempio n. 2
0
    def mainloop(self):
        """
        main game loop
        """

        # make start sound
        make_sound(2)

        self.snake.start()

        # main loop
        while self.game_over:
            pygame.time.delay(50)
            self.clock.tick(60)

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    # pygame.quit()
                    sys.exit()

            # redraw game objects
            self.redraw()

            # snake eats snack
            if self.snake.head.pos == self.snack.pos:
                make_sound(1)
                self.snake.addCube()
                while True:
                    snack_pos = (random.randrange(N_ROWS),
                                 random.randrange(N_ROWS))
                    if not (snack_pos in list(
                            map(lambda x: x.pos, self.snake.body))):
                        break
                self.snack = Cube(self.surface, snack_pos, SNACK_COLOR)

            # snake eats its tail
            if self.snake.self_eat():
                make_sound(3)
                self.score.append(len(self.snake.body))
                msg = 'Your score is {0} [record is {1}]'.format(
                    self.score[-1], max(self.score))
                message_box('You lost!', msg + '\nPlay again')
                self.snake.reset(SNAKE_POS0)
            else:
                # move snake
                self.snake.check_keys()
Esempio n. 3
0
 def go(self):
     button = self.win.run()
     if button == gtk.RESPONSE_OK:
         fields = []
         fields2 = []
         iter = self.model2.get_iter_root()
         while iter:
             fields.append(
                 self.model2.get_value(iter, 1).replace('/.id', '.id'))
             fields2.append(self.model2.get_value(iter, 0))
             iter = self.model2.iter_next(iter)
         action = self.wid_action.get_active()
         self.parent.present()
         self.win.destroy()
         import_comp = self.wid_import_compatible.get_active()
         result = datas_read(self.ids,
                             self.model,
                             fields,
                             self.fields_data,
                             context=self.context)
         if result.get('warning', False):
             common.message_box(_('Exportation Error !'),
                                unicode(result.get('warning', False)))
             return False
         result = result.get('datas', [])
         if import_comp:
             fields2 = fields
         if len(self.wid_action.get_model()
                ) > 1 and self.wid_action.get_active() == 0:
             open_excel(fields2, result)
         else:
             fname = common.file_selection(
                 _('Save As...'),
                 parent=self.parent,
                 action=gtk.FILE_CHOOSER_ACTION_SAVE)
             if fname:
                 export_csv(fname, fields2, result,
                            self.wid_write_field_names.get_active())
         return True
     else:
         self.parent.present()
         self.win.destroy()
         return False
Esempio n. 4
0
    def mainloop(self):
        """
        main loop
        """
        while self.game_over:
            self.clock.tick(10)
            pygame.time.delay(150)

            # redraw game objects
            self.redraw()

            # define which player is in this turn
            player = self.game_turn % 2

            # ball position ('-1' means incorrect position )
            col_placed_ball = -1
            if self.id_player is not None and player!=self.id_player: # show opponent move if exist
                # try to get data from the server
                try:
                    players = self.net.send("get")
                    col_placed_ball = players.get_move(player)
                    if col_placed_ball!=-1:
                        # reset move in server
                        self.net.send('reset')
                except Exception as e:
                    self.game_over = False
                    print("Couldn't get game: ", e)
                pygame.event.clear()
            else:
                # show new unplaced ball
                x,y = pygame.mouse.get_pos()
                col = int(x // GRID_STEP[0])
                put_ball(self.surface, self.balls[player], (x,y), isLimited=True)

                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        # pygame.quit()
                        sys.exit()
                    if event.type==pygame.MOUSEMOTION:
                        pass
                    if event.type==pygame.MOUSEBUTTONDOWN:
                        col_placed_ball = col

            # refresh image
            pygame.display.flip()
            pygame.display.update()

            # ball is placed, check winner
            if col_placed_ball!=-1:
                isPlaced,self.game_matrix,self.winner = placer_pion(player, col_placed_ball, self.game_matrix)
                if isPlaced:
                    if player == self.id_player:
                        # send to server
                        self.net.send(str(col_placed_ball))
                    if self.winner:
                        make_sound(2)

                        # redraw game objects to show winner combinations
                        self.redraw()

                        # add text
                        self.surface.blit(myfont.render(MESSAGE.WON.format(PLAYERS[player],self.game_turn),True, ((255,0,0),(255,255,0))[player]),(10,10))

                        # refresh image
                        pygame.display.flip()
                        pygame.display.update()

                        if self.id_player is not None:  # network game
                            if player==self.id_player:
                                message_box(MESSAGE.YOUWON.format(self.game_turn), MESSAGE.AGAIN)
                            else:
                                message_box(MESSAGE.YOULOST.format(self.game_turn), MESSAGE.AGAIN)
                            # reset game
                            self.net.send('reset')
                        else:
                            message_box(MESSAGE.WON.format(PLAYERS[player],self.game_turn), MESSAGE.AGAIN)

                        self.restart()
                    else:
                        self.game_turn += 1
Esempio n. 5
0
        res = rpc.session.rpc_exec_auth('/object', 'execute', model, 'import_data', f, datas, 'init', '', False, context)
    except Exception, e:
        common.warning(str(e), _('XML-RPC error !'), parent=parent)
        return False
    result = res[0]
    if result>=0:
        if result == 1:
            common.message(_('Imported one object !'))
        else:
            common.message(_('Imported %d objects !') % (result,))
    else:
        d = ''
        for key,val in res[1].items():
            d+= ('\t%s: %s\n' % (str(key),str(val)))
        error = _(u'Error trying to import this record:\n%s\nError Message:\n%s\n\n%s') % (d,res[2],res[3])
        common.message_box(_('Importation Error !'), unicode(error))
    return True

class win_import(object):
    def __init__(self, model, fields, preload = [], parent=None, local_context=None):
        self.glade = glade.XML(common.terp_path("openerp.glade"), 'win_import',
                gettext.textdomain())
        self.glade.get_widget('import_csv_combo').set_active(0)
        self.win = self.glade.get_widget('win_import')
        self.model = model
        self.fields_data = {}
        self.invert = False
        self.context = local_context or {}
        if parent is None:
            parent = service.LocalService('gui.main').window
        self.win.set_transient_for(parent)
Esempio n. 6
0
    def mainloop(self):
        """
        main loop
        """
        while self.game_over:
            pygame.time.delay(150)
            self.clock.tick(10)

            # redraw game objects
            self.redraw()

            # define which player is in this turn
            player = self.game_turn % 2

            # show new unplaced ball
            x, y = pygame.mouse.get_pos()
            col = int(x // GRID_STEP[0])
            cur_ball = self.balls[player]
            y = (GRID_STEP[1] - cur_ball.get_height()) / 2
            x -= cur_ball.get_width() / 2
            x = 0 if x < 0 else x
            x = x if x < DISPLAY_SIZE[0] - cur_ball.get_width(
            ) else DISPLAY_SIZE[0] - cur_ball.get_width()
            self.surface.blit(cur_ball, (x, y))

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    # pygame.quit()
                    sys.exit()
                if event.type == pygame.MOUSEMOTION:
                    pass
                if event.type == pygame.MOUSEBUTTONDOWN:
                    isPlaced, self.game_matrix, self.winner = placer_pion(
                        player, col, self.game_matrix)
                    if isPlaced:
                        if self.winner:
                            make_sound(2)

                            # redraw game objects to show winner combinations
                            self.redraw()

                            self.surface.blit(
                                myfont.render(
                                    MESSAGE.WON.format(PLAYERS[player],
                                                       self.game_turn), True,
                                    ((255, 0, 0), (255, 255, 0))[player]),
                                (10, 10))

                            # refresh image
                            pygame.display.flip()
                            pygame.display.update()

                            message_box(
                                MESSAGE.WON.format(PLAYERS[player],
                                                   self.game_turn),
                                MESSAGE.AGAIN)
                            self.restart()

                            break
                        else:
                            self.game_turn += 1

            # refresh image
            pygame.display.flip()
            pygame.display.update()