Пример #1
0
    def __init__(self,
                 value=0,
                 covered=0,
                 size=60,
                 hidden=False,
                 img_path=xdg.get_data_path('images/piece-default.png'),
                 font=xdg.get_data_path('fonts/LiberationMono-Bold.ttf')):
        """Init method for the class Piece

        Keyword arguments:
        value -- Piece numeric value. This value determines the strength
        of the piece. But here doesn't matter this, it's only the value
        putted on the piece
        covered -- Integer that shows if the piece is covered (0)
        or uncovered (1)
        size -- Size of the tile.
        img_path -- Path to the piece image.
        font -- Path to the font file that will be use to render
        the number.
        """

        self.value = value
        self.img_path = img_path
        self.size = size
        self.covered = covered
        self.hidden = hidden
        self.font = font
def parse_propierty_button_images(node):
    """
    Parses the button images
    """
    childs = node.childNodes

    erase_childs_end_of_line(childs)

    for child in childs:
        if child.hasAttribute('id'):
            attr = child.getAttribute('id')
            if attr == 'default':
                aux = child.firstChild.data
                aux.replace("\n", '')
                aux.replace(' ', '')
                default = xdg.get_data_path(aux)
            if attr == 'above':
                aux = child.firstChild.data
                aux.replace("\n", '')
                aux.replace(' ', '')

                above = xdg.get_data_path(aux)
            if attr == 'pressed':
                aux = child.firstChild.data
                aux.replace("\n", '')
                aux.replace(' ', '')
                pressed = xdg.get_data_path(aux)

    return (default, above, pressed)
def parse_propierty_button_images(node):
    """
    Parses the button images
    """
    childs = node.childNodes

    erase_childs_end_of_line(childs)

    for child in childs:
        if child.hasAttribute('id'):
            attr = child.getAttribute('id')
            if attr == 'default':
                aux = child.firstChild.data
                aux.replace("\n", '')
                aux.replace(' ', '')
                default = xdg.get_data_path(aux)
            if attr == 'above':
                aux = child.firstChild.data
                aux.replace("\n", '')
                aux.replace(' ', '')

                above = xdg.get_data_path(aux)
            if attr == 'pressed':
                aux = child.firstChild.data
                aux.replace("\n", '')
                aux.replace(' ', '')
                pressed = xdg.get_data_path(aux)

    return (default, above, pressed)
Пример #4
0
def generate_configuration_file():
    """
    This function generate the default configuration file, in case that
    the file does not exists.
    """
    impl = minidom.getDOMImplementation()
    config_xml = impl.createDocument(None, 'config', None)

    top_element = config_xml.documentElement

    se_path = config_xml.createElement('se_path')
    se_real_path = os.path.realpath(__config_base_path__) + '/teams'
    se_path.setAttribute('value', se_real_path)
    if not os.path.exists(se_real_path):
        os.mkdir(se_real_path)
        os.mkdir(se_real_path + '/rules')
        os.mkdir(se_real_path + '/formations')
        data_path = xdg.get_data_path('teams/rules')
        files = os.listdir(data_path)
        for _file in files:
            _file = data_path + '/' + _file
            shutil.copy(os.path.realpath(_file), se_real_path + '/rules')
        data_path = xdg.get_data_path('teams/formations')
        files = os.listdir(data_path)
        for _file in files:
            _file = data_path + '/' + _file
            shutil.copy(os.path.realpath(_file), se_real_path + '/formations')

    games_path = config_xml.createElement('games_path')
    games_real_path = os.path.realpath(__config_base_path__ + '/games')
    games_path.setAttribute('value', games_real_path)
    if not os.path.exists(games_real_path):
        os.mkdir(games_real_path)

    language = config_xml.createElement('language')
    language.setAttribute('value', 'es_ES')

    active_music = config_xml.createElement('music_active')
    active_music.setAttribute('value', '1')

    auto_interval_time = config_xml.createElement('auto_interval_time')
    auto_interval_time.setAttribute('value', '500')

    top_element.appendChild(se_path)
    top_element.appendChild(games_path)
    top_element.appendChild(language)
    top_element.appendChild(active_music)
    top_element.appendChild(auto_interval_time)

    file_xml = open(__file_path__, "w")

    file_xml.write(config_xml.toprettyxml())
    file_xml.close()
Пример #5
0
def generate_configuration_file():
    """
    This function generate the default configuration file, in case that
    the file does not exists.
    """
    impl = minidom.getDOMImplementation()
    config_xml = impl.createDocument(None, 'config', None)
    
    top_element = config_xml.documentElement
    
    se_path = config_xml.createElement('se_path')
    se_real_path = os.path.realpath(__config_base_path__) + '/teams'
    se_path.setAttribute('value', se_real_path)
    if not os.path.exists(se_real_path):
        os.mkdir(se_real_path)
        os.mkdir(se_real_path + '/rules')
        os.mkdir(se_real_path + '/formations')
        data_path = xdg.get_data_path('teams/rules')
        files = os.listdir(data_path)
        for _file in files:
            _file = data_path + '/' + _file
            shutil.copy(os.path.realpath(_file), se_real_path + '/rules')
        data_path = xdg.get_data_path('teams/formations')
        files = os.listdir(data_path)
        for _file in files:
            _file = data_path + '/' + _file
            shutil.copy(os.path.realpath(_file), se_real_path + '/formations')

    games_path = config_xml.createElement('games_path')
    games_real_path = os.path.realpath(__config_base_path__ + '/games')
    games_path.setAttribute('value', games_real_path)
    if not os.path.exists(games_real_path):
        os.mkdir(games_real_path)

    language = config_xml.createElement('language')
    language.setAttribute('value', 'es_ES')

    active_music = config_xml.createElement('music_active')
    active_music.setAttribute('value', '1')

    auto_interval_time = config_xml.createElement('auto_interval_time')
    auto_interval_time.setAttribute('value', '500')

    top_element.appendChild(se_path)
    top_element.appendChild(games_path)
    top_element.appendChild(language)
    top_element.appendChild(active_music)
    top_element.appendChild(auto_interval_time)

    file_xml = open(__file_path__,"w")

    file_xml.write(config_xml.toprettyxml())
    file_xml.close()
Пример #6
0
    def __init__(self,
                 team_a,
                 team_b,
                 default_piece,
                 xml_file,
                 piece_size=60,
                 board_size=8,
                 player=0):
        self.turn = 0

        self.team_a_piece = team_a[1]
        self.team_b_piece = team_b[1]
        self.default_piece = default_piece
        self.piece_size = piece_size
        self.board_size = board_size

        self.srfc_board_size = (self.board_size * self.piece_size, ) * 2
        self.player = player

        self.music = False
        if configure.load_configuration()['music_active'] == '1':
            self.music = True

        pygame.init()
        self.xml_layout = layout.Layout(xml_file, True)
        self.screen = pygame.display.set_mode(
            self.xml_layout.get_window_size())
        pygame.display.set_caption(self.xml_layout.get_window_title())
        self.srfc_board = pygame.Surface(self.srfc_board_size)

        self.xml_layout.init((team_a[1], team_a[0]), (team_b[1], team_b[0]),
                             self.srfc_board)
        self.rects = self.xml_layout.get_buttons_rects()
        self.offset = self.xml_layout.get_board_position()
        pygame.display.set_icon(self.xml_layout.get_favicon())

        self.screen.blit(self.xml_layout.get_surface(), (0, 0))
        pygame.display.flip()

        if self.music:
            music_path = xdg.get_data_path('music/walking_on_old_stones.ogg')
            pygame.mixer.music.load(music_path)
            pygame.mixer.music.play()

        img_piece_slct_path = xdg.get_data_path('images/piece-selection.png')
        img_possible_move_path = xdg.get_data_path('images/posible-move.png')

        self.piece_selected = pygame.image.load(img_piece_slct_path)
        self.possible_move = pygame.image.load(img_possible_move_path)
    def load_board(self):
        controlPartida.restaurarCampeonato()

        ambosEquipos = [(self.es_team_a, self.team_team_a), (self.es_team_b, self.team_team_b)]
        
        for equipo in ambosEquipos:
            if (not filenames.comprobar_nombre_reglas(equipo[0]) or 
                not filenames.comprobar_nombre_formacion(equipo[1])):

                return

            logging.info("Probando equipo: %s", equipo)
            try:
                probar_equipo(equipo)
            except Exception as e:
                #progress_bar_dialog.hide()
                logging.error("Algo ha fallado")
                logging.error(e)
                notificacion = notify_result.SimpleNotify(_("The rules file <b>\"%s\"</b> has errors. This quick game will be cancelled.\n\nCheck \"<i>log_gsiege</i>\" log file for details.") % equipo[0])
                notificacion.dlg_result.run()
                #progress_bar_dialog.show()

                return
            logging.info("Equipo probado")

        try:
            winner,kk = guada_board.run(
                ((self.es_team_a, self.team_team_a),
                 xdg.get_data_path('images/piece-orange.png')),
                ((self.es_team_b,self.team_team_b),
                 xdg.get_data_path('images/piece-violete.png')),

                self.fast_game, 
                self.dont_save_game,
                self.hidde_values, 
                str(int(self.num_turns))
                )
        except guada_board.GuadaFileError as e:
            raise guada_board.GuadaFileError(e.msg)
        
        # Se ha seleccionado mostrar sólo los resultados
        if self.fast_game:
            teamA = (self.es_team_a, self.team_team_a)
            teamB = (self.es_team_b, self.team_team_b)

            n = notify_result.notifyResult((teamA, teamB), winner)
            
            n.dlg_result.run()
Пример #8
0
    def __init__(self, parent):
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/contest.glade'))
        
        self.contest_dialog = builder.get_object("contest_dialog")
        self.contest_dialog.set_transient_for(parent)

        self.files = {}
        self.teams = {}

        #---------------------------
        self.cName = 0
        self.cRules = 1
        self.cFormation = 2
        
        self.sName = _("Name")
        self.sRules = _("Rules")
        self.sFormation = _("Formation")
        
        self.list_view = builder.get_object("list_es_view")
        self.list_view.set_reorderable(False)

        self.addColumn(self.sName, self.cName)
        self.addColumn(self.sRules, self.cRules)
        self.addColumn(self.sFormation, self.cFormation)

        self.list_store = builder.get_object("list_expert_system")
        #-----------------------------

        self.file_chooser_rules = builder.get_object('file_chooser_rules')
        #self.file_chooser_rules.set_transient_for(self.players_selector)
        self.file_chooser_formation = builder.get_object('file_chooser_formation')
        #self.file_chooser_formation.set_transient_for(self.players_selector)

        self.format_contest = 'league'
        self.radio_league = builder.get_object('radio_league')
        self.radio_cup = builder.get_object('radio_cup')
        self.radio_groups = builder.get_object('radio_groups')
        self.radio_playoff = builder.get_object('radio_playoff')
        self.check_backround = builder.get_object('check_backround')
        self.check_fast = builder.get_object('check_onlyresults')

        self.back_round = False
        self.fast = False
        self.all_teams = False
        
        def_path = configure.load_configuration()['se_path']
        self.file_chooser_rules.set_current_folder(def_path + '/rules')
        self.file_chooser_formation.set_current_folder(def_path + '/formations')

        self.start_button = builder.get_object('btn_start')
        self.frame_selection_teams = builder.get_object('box_selection')
        
        self.num_turns = 120
        self.spin_turns = builder.get_object("spin_num_turns")
        self.spin_turns.set_range(50,300)
        self.spin_turns.set_increments(2,10)
        self.spin_turns.set_value(self.num_turns)
        
        builder.connect_signals(self)
Пример #9
0
    def __init__(self):
        "Constructor of the object"

        # gtk.Builder es un objeto que lee una interfaz de glade e instancia los
        # widgets descritos en el fichero
        builder = gtk.Builder()

        # Carga el fichero con la interfaz principal
        builder.add_from_file(xdg.get_data_path('glade/main.glade')) 
        
        # Guarda referencias a cada uno de los diálogos
        self.window = builder.get_object("mainWindow")
        self.about = builder.get_object("aboutdialog1")
        self.previous_games_chooser = builder.get_object("filechooserdialog1")
        self.games_chooser_warning = builder.get_object("messagedialog1")

        # Conecta el evento response a una lambda-función que oculta el cuadro
        # de diálogo
        self.games_chooser_warning.connect('response', lambda d, r: d.hide())

        # Indica que ese diálogo es un subdiálogo (sort of) de
        # previous_game_chooser
        self.games_chooser_warning.set_transient_for(self.previous_games_chooser)

        # Lo mismo, pero de la ventana principal
        self.previous_games_chooser.set_transient_for(self.window)

        # Lo mismo, pero de la ventana principal también
        self.about.set_transient_for(self.window)
        
        def_path = configure.load_configuration()['games_path']
        self.previous_games_chooser.set_current_folder(def_path)
        builder.connect_signals(self)
Пример #10
0
    def __init__(self, parent):
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/settingsDialog.glade'))

        self.settings = builder.get_object("settingsDialog")
        self.settings.set_transient_for(parent)

        self.file_chooser_games = builder.get_object("file_chs_prev_games")
        self.file_chooser_teams = builder.get_object("file_chs_se")
        self.check_active_music = builder.get_object("check_active_music")

        self.label_subfolders = builder.get_object("label_subfolders")
        self.label_logfolder = builder.get_object("label_logfolder")

        config_vars = configure.load_configuration()

        games_current_folder = config_vars['games_path'] + '..'
        teams_current_folder = config_vars['se_path'] + '..'
        
        self.file_chooser_games.set_current_folder(games_current_folder)
        self.file_chooser_games.set_filename(config_vars['games_path'])
        self.file_chooser_teams.set_current_folder(teams_current_folder)
        self.file_chooser_teams.set_filename(config_vars['se_path'])

        active = False
        if config_vars['music_active'] == '1':
            active = True
        self.check_active_music.set_active(active)

        self.scale_intervalo = builder.get_object("scale_intervalo")
        self.scale_intervalo.set_range(100, 2000)
        self.scale_intervalo.set_value(config_vars['auto_interval_time'])
        
        builder.connect_signals(self)
    def load_board(self):
        controlPartida.restaurarCampeonato()

        ambosEquipos = [(self.es_team_a, self.team_team_a),
                        (self.es_team_b, self.team_team_b)]

        for equipo in ambosEquipos:
            if (not filenames.comprobar_nombre_reglas(equipo[0])
                    or not filenames.comprobar_nombre_formacion(equipo[1])):

                return

            logging.info("Probando equipo: %s", equipo)
            try:
                probar_equipo(equipo)
            except Exception as e:
                #progress_bar_dialog.hide()
                logging.error("Algo ha fallado")
                logging.error(e)
                notificacion = notify_result.SimpleNotify(
                    _("The rules file <b>\"%s\"</b> has errors. This quick game will be cancelled.\n\nCheck \"<i>log_gsiege</i>\" log file for details."
                      ) % equipo[0])
                notificacion.dlg_result.run()
                #progress_bar_dialog.show()

                return
            logging.info("Equipo probado")

        try:
            winner, kk = guada_board.run(
                ((self.es_team_a, self.team_team_a),
                 xdg.get_data_path('images/piece-orange.png')),
                ((self.es_team_b, self.team_team_b),
                 xdg.get_data_path('images/piece-violete.png')),
                self.fast_game, self.dont_save_game, self.hidde_values,
                str(int(self.num_turns)))
        except guada_board.GuadaFileError as e:
            raise guada_board.GuadaFileError(e.msg)

        # Se ha seleccionado mostrar sólo los resultados
        if self.fast_game:
            teamA = (self.es_team_a, self.team_team_a)
            teamB = (self.es_team_b, self.team_team_b)

            n = notify_result.notifyResult((teamA, teamB), winner)

            n.dlg_result.run()
Пример #12
0
    def __init__(self, msg, title="Information"):

        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/resultNotifier.glade'))

        self.dlg_result = builder.get_object('dlg_result')
        self.dlg_result.connect('response', lambda d, r: d.hide())
        self.dlg_result.set_markup("<b>" + title + "</b>")
        self.dlg_result.format_secondary_markup(msg)
Пример #13
0
    def __init__(self, msg, title = "Information"):

        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/resultNotifier.glade'))

        self.dlg_result = builder.get_object('dlg_result')
        self.dlg_result.connect('response', lambda d, r: d.hide())
        self.dlg_result.set_markup("<b>" + title + "</b>")
        self.dlg_result.format_secondary_markup(msg)
    def __init__(self, parent):
        self.es_team_a = ''
        self.team_team_a = ''
        self.es_team_b = ''
        self.team_team_b = ''
        
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/quickGame.glade'))

        def_path = configure.load_configuration()['se_path']
        def_rules_path = def_path + '/rules'
        def_formations_path = def_path + '/formations'
        builder.get_object('file_chooser_es_a').set_current_folder(def_rules_path)
        builder.get_object('file_chooser_team_a').set_current_folder(def_formations_path)
        builder.get_object('file_chooser_es_b').set_current_folder(def_rules_path)
        builder.get_object('file_chooser_team_b').set_current_folder(def_formations_path)

        self.quick_game = builder.get_object("quick_game_dialog")
        self.quick_game.set_transient_for(parent)
        #---- Initialation for the dialogs
        self.error_es_a = builder.get_object("error_no_es_a")
        self.error_es_a.connect('response', lambda d, r: d.hide())
        self.error_es_a.set_transient_for(self.quick_game)
        
        self.error_team_a = builder.get_object("error_no_team_a")
        self.error_team_a.connect('response', lambda d, r: d.hide())
        self.error_team_a.set_transient_for(self.quick_game)
        
        self.error_es_b = builder.get_object("error_no_es_b")
        self.error_es_b.connect('response', lambda d, r: d.hide())
        self.error_es_b.set_transient_for(self.quick_game)
        
        self.error_team_b = builder.get_object("error_no_team_b")
        self.error_team_b.connect('response', lambda d, r: d.hide())
        self.error_team_b.set_transient_for(self.quick_game)

        #self.result_dialog = builder.get_object("dlg_result")
        #self.result_dialog.connect('response', lambda d, r: d.hide())
        #self.result_dialog.set_transient_for(self.quick_game)

        self.dlg_bad_file = builder.get_object('dlg_bad_file')
        self.dlg_bad_file.connect('response', lambda d, r: d.hide())
        self.dlg_bad_file.set_transient_for(self.quick_game)
        

        self.num_turns = 120
        self.spin_turns = builder.get_object("spin_num_turns")
        self.spin_turns.set_range(50,300)
        self.spin_turns.set_increments(2,10)
        self.spin_turns.set_value(self.num_turns)
        #---------------
        self.fast_game = False
        self.dont_save_game = False
        self.hidde_values = False
        
        builder.connect_signals(self)
Пример #15
0
    def __init__(self, stats, team):
        self.output_file = 'tmp.png'
        line = []
        if not stats['wins'] == 0:
            line.append(('wins', stats['wins']))
        if not stats['draws'] == 0:
            line.append(('draws', stats['draws']))
        if not stats['looses'] == 0:
            line.append(('looses', stats['looses']))

        piechart.pieChart(self.output_file, line)
        
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/testResults.glade'))

        self.test_result = builder.get_object('test_result_dialog')
        self.test_result.set_title(self.test_result.get_title().replace('@team@',
                                                                        team))
        #self.tests_dialog.set_transient_for(parent)

        builder.get_object('pie_chart').set_from_file(self.output_file)

        num_games = stats['wins'] + stats['draws'] + stats['looses']
        wins = stats['wins']
        draws = stats['draws']
        looses = stats['looses']
        try:
            turns_winning = stats['turns_winning'] / wins
        except ZeroDivisionError:
            turns_winning = 0

        try:
            turns_loosing = stats['turns_losing'] / looses
        except ZeroDivisionError:
            turns_loosing = 0
            
        num_pieces = stats['num_pieces'] / num_games
        val_pieces = stats['val_pieces'] / num_games
        max_death = stats['max_death'] / num_games

        text = builder.get_object('lbl_num_games').get_label()
        builder.get_object('lbl_num_games').set_label(text.replace('@value@', str(num_games)))
        text = builder.get_object('lbl_wins').get_label()
        builder.get_object('lbl_wins').set_label(text.replace('@value@', str(wins)))
        text = builder.get_object('lbl_draws').get_label()
        builder.get_object('lbl_draws').set_label(text.replace('@value@', str(draws)))
        text = builder.get_object('lbl_looses').get_label()
        builder.get_object('lbl_looses').set_label(text.replace('@value@', str(looses)))
        text = builder.get_object('lbl_turns_win').get_label()
        builder.get_object('lbl_turns_win').set_label(text.replace('@value@', str(turns_winning)))
        text = builder.get_object('lbl_turns_lose').get_label()
        builder.get_object('lbl_turns_lose').set_label(text.replace('@value@', str(turns_loosing)))
        text = builder.get_object('lbl_max_piece').get_label()
        builder.get_object('lbl_max_piece').set_label(text.replace('@value@', str(max_death)))

        builder.connect_signals(self)                
 def load_board(self):
     try:
         winner = guada_board.run(((self.es_team_a,self.team_team_a),
                                   xdg.get_data_path('images/piece-orange.png')),
                                  ((self.es_team_b,self.team_team_b),
                                   xdg.get_data_path('images/piece-violete.png')),
                                  self.fast_game, self.dont_save_game,
                                  self.hidde_values, str(int(self.num_turns)))
     except guada_board.GuadaFileError as e:
         raise guada_board.GuadaFileError(e.msg)
         
     if self.fast_game:
         teamA = (self.es_team_a, self.team_team_a)
         teamB = (self.es_team_b, self.team_team_b)
         name_teamA = filenames.extract_name_expert_system(teamA)
         name_teamB = filenames.extract_name_expert_system(teamB)
         n = notify_result.notifyResult((name_teamA, name_teamB), winner)
         
         n.dlg_result.run()
Пример #17
0
    def __init__(self, team_a, team_b, default_piece, xml_file,
                 piece_size=60, board_size=8, player=0):
        self.turn = 0

        self.team_a_piece = team_a[1]
        self.team_b_piece = team_b[1]
        self.default_piece = default_piece
        self.piece_size = piece_size
        self.board_size = board_size

        self.srfc_board_size = (self.board_size * self.piece_size, ) * 2
        self.player = player

        self.music = False
        if configure.load_configuration()['music_active'] == '1':
            self.music = True

        pygame.init()
        self.xml_layout = layout.Layout(xml_file, True)
        self.screen = pygame.display.set_mode(
            self.xml_layout.get_window_size())
        pygame.display.set_caption(self.xml_layout.get_window_title())
        self.srfc_board = pygame.Surface(self.srfc_board_size)

        self.xml_layout.init((team_a[1], team_a[0]), (team_b[1], team_b[0]),
                             self.srfc_board)
        self.rects = self.xml_layout.get_buttons_rects()
        self.offset = self.xml_layout.get_board_position()
        pygame.display.set_icon(self.xml_layout.get_favicon())

        self.screen.blit(self.xml_layout.get_surface(), (0, 0))
        pygame.display.flip()

        if self.music:
            music_path = xdg.get_data_path('music/walking_on_old_stones.ogg')
            pygame.mixer.music.load(music_path)
            pygame.mixer.music.play()

        img_piece_slct_path = xdg.get_data_path('images/piece-selection.png')
        img_possible_move_path = xdg.get_data_path('images/posible-move.png')
        print img_piece_slct_path
        self.piece_selected = pygame.image.load(img_piece_slct_path)
        self.possible_move = pygame.image.load(img_possible_move_path)
    def __init__(self, parent):
        self.rules_computer = ''
        self.formation_computer = ''
        self.formation_player = ''

        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/humanEsDialog.glade'))

        def_path = configure.load_configuration()['se_path']
        def_rules_path = def_path + '/rules'
        def_formations_path = def_path + '/formations'

        self.human_ia_dialog = builder.get_object('human_ia_dialog')
        self.human_ia_dialog.set_transient_for(parent)

        builder.get_object('file_chooser_es_ia').set_current_folder(
            def_rules_path)
        builder.get_object('file_chooser_team_ia').set_current_folder(
            def_formations_path)
        builder.get_object('file_chooser_team').set_current_folder(
            def_formations_path)

        self.file_chooser_team_ia = builder.get_object('file_chooser_team_ia')

        self.file_chooser_es_ia = builder.get_object('file_chooser_es_ia')
        self.file_chooser_team_ia = builder.get_object('file_chooser_team_ia')

        self.error_es_ia = builder.get_object("error_no_es_ia")
        self.error_es_ia.connect('response', lambda d, r: d.hide())
        self.error_es_ia.set_transient_for(self.human_ia_dialog)

        self.error_team_ia = builder.get_object("error_no_team_ia")
        self.error_team_ia.connect('response', lambda d, r: d.hide())
        self.error_team_ia.set_transient_for(self.human_ia_dialog)

        self.error_team = builder.get_object("error_no_team")
        self.error_team.connect('response', lambda d, r: d.hide())
        self.error_team.set_transient_for(self.human_ia_dialog)

        self.dlg_bad_file = builder.get_object('dlg_bad_file')
        self.dlg_bad_file.connect('response', lambda d, r: d.hide())
        self.dlg_bad_file.set_transient_for(self.human_ia_dialog)

        self.num_turns = 120
        self.spin_turns = builder.get_object("spin_num_turns")
        self.spin_turns.set_range(50, 300)
        self.spin_turns.set_increments(1, 10)
        self.spin_turns.set_value(self.num_turns)

        self.dont_save_game = False
        self.human_team = 'A'
        self.random_computer = False
        self.label_description = builder.get_object('label_description')

        builder.connect_signals(self)
    def __init__(self, parent):
        self.rules_computer = ''
        self.formation_computer = ''
        self.formation_player = ''

        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/humanEsDialog.glade'))

        def_path = configure.load_configuration()['se_path']
        def_rules_path = def_path + '/rules'
        def_formations_path = def_path + '/formations'

        self.human_ia_dialog = builder.get_object('human_ia_dialog')
        self.human_ia_dialog.set_transient_for(parent)
        
        builder.get_object('file_chooser_es_ia').set_current_folder(def_rules_path)
        builder.get_object('file_chooser_team_ia').set_current_folder(def_formations_path)
        builder.get_object('file_chooser_team').set_current_folder(def_formations_path)
        
        self.file_chooser_team_ia = builder.get_object('file_chooser_team_ia')

        self.file_chooser_es_ia = builder.get_object('file_chooser_es_ia')
        self.file_chooser_team_ia = builder.get_object('file_chooser_team_ia')
        
        self.error_es_ia = builder.get_object("error_no_es_ia")
        self.error_es_ia.connect('response', lambda d, r: d.hide())
        self.error_es_ia.set_transient_for(self.human_ia_dialog)
        
        self.error_team_ia = builder.get_object("error_no_team_ia")
        self.error_team_ia.connect('response', lambda d, r: d.hide())
        self.error_team_ia.set_transient_for(self.human_ia_dialog)
        
        self.error_team = builder.get_object("error_no_team")
        self.error_team.connect('response', lambda d, r: d.hide())
        self.error_team.set_transient_for(self.human_ia_dialog)
        
        self.dlg_bad_file = builder.get_object('dlg_bad_file')
        self.dlg_bad_file.connect('response', lambda d, r: d.hide())
        self.dlg_bad_file.set_transient_for(self.human_ia_dialog)
        
        self.num_turns = 120
        self.spin_turns = builder.get_object("spin_num_turns")
        self.spin_turns.set_range(50,300)
        self.spin_turns.set_increments(1,10)
        self.spin_turns.set_value(self.num_turns)

        self.dont_save_game = False
        self.human_team = 'A'
        self.random_computer = False
        self.label_description = builder.get_object('label_description')

        builder.connect_signals(self)
    def __init__(self, parent, str_content):
        builder = gtk.Builder()
        progressbar_path = xdg.get_data_path('glade/progressbarDialog.glade')
        builder.add_from_file(progressbar_path)

        self.progress_bar_dialog = builder.get_object('progress_dialog')
        self.progress_bar_dialog.connect('response', lambda d, r: d.hide())
        self.progress_bar_dialog.set_transient_for(parent)

        lbl_content = builder.get_object('lbl_content')
        lbl_content.set_text(str_content)

        self.progress_bar = builder.get_object('progress_bar')
    def __init__(self, parent, str_content):
        builder = gtk.Builder()
        progressbar_path = xdg.get_data_path('glade/progressbarDialog.glade')
        builder.add_from_file(progressbar_path)

        self.progress_bar_dialog = builder.get_object('progress_dialog')
        self.progress_bar_dialog.connect('response', lambda d, r: d.hide())
        self.progress_bar_dialog.set_transient_for(parent)

        lbl_content = builder.get_object('lbl_content')
        lbl_content.set_text(str_content)

        self.progress_bar = builder.get_object('progress_bar')
Пример #22
0
    def __init__(self, value=0, covered=0, size=60, hidden=False,
                 img_path=xdg.get_data_path('images/piece-default.png'),
                 font=xdg.get_data_path('fonts/LiberationMono-Bold.ttf')):
        """Init method for the class Piece

        Keyword arguments:
        value -- Piece numeric value. This value determines the strength
        of the piece. But here doesn't matter this, it's only the value
        putted on the piece
        covered -- Integer that shows if the piece is covered (0)
        or uncovered (1)
        size -- Size of the tile.
        img_path -- Path to the piece image.
        font -- Path to the font file that will be use to render
        the number.
        """

        self.value = value
        self.img_path = img_path
        self.size = size
        self.covered = covered
        self.hidden = hidden
        self.font = font
Пример #23
0
    def __init__(self, teams, winner):
        name_teamA = teams[0]
        name_teamB = teams[1]
        
        result = ''
        
        if winner == 0:
            result = _('Draw')
        elif winner == 1:
            result = _('Wins ') + name_teamA
        else:
            result = _('Gana ') + name_teamB
            
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/resultNotifier.glade'))

        self.dlg_result = builder.get_object('dlg_result')
        self.dlg_result.connect('response', lambda d, r: d.hide())
        self.dlg_result.format_secondary_text(result)
Пример #24
0
    def __init__(self, teams, winner):
        """ Genera un nuevo diálogo de notificación de resultados.

        teams será un par cuyos elementos pueden ser cadenas con el nombre del
        equipo o un par con la ruta del fichero de formación y de reglas, de los
        que sacarán los nombres.
        """

        result = ''

        if type(teams[0]) == str:
            msg_team_a = teams[0]
            msg_team_b = teams[1]
        else:

            team_a = filenames.quitar_prefijo_multiple(teams[0])
            team_b = filenames.quitar_prefijo_multiple(teams[1])
        
            msg_team = "equipo <b>%s</b> con formación <b>%s</b>"
            msg_team_a = msg_team % team_a
            msg_team_b = msg_team % team_b
        
        if winner == 0:
            result = '<span foreground="red"><b>' + _('Draw') + '</b></span>\n'
            result += msg_team_a + '\n' + msg_team_b
        elif winner == 1:
            result  = '<span foreground="red"><b>Ganador</b>: '
            result += msg_team_a 
            result += '</span>\n'
            result +=  "Contrincante: "  + msg_team_b
        else:
            result  = '<span foreground="red"><b>Ganador</b>: '
            result += msg_team_b
            result += '</span>\n'
            result +=  "Contrincante: "  + msg_team_a
            
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/resultNotifier.glade'))

        self.dlg_result = builder.get_object('dlg_result')
        self.dlg_result.connect('response', lambda d, r: d.hide())
        self.dlg_result.format_secondary_markup(result)
Пример #25
0
    def __init__(self, teams, winner):
        """ Genera un nuevo diálogo de notificación de resultados.

        teams será un par cuyos elementos pueden ser cadenas con el nombre del
        equipo o un par con la ruta del fichero de formación y de reglas, de los
        que sacarán los nombres.
        """

        result = ''

        if type(teams[0]) == str:
            msg_team_a = teams[0]
            msg_team_b = teams[1]
        else:

            team_a = filenames.quitar_prefijo_multiple(teams[0])
            team_b = filenames.quitar_prefijo_multiple(teams[1])

            msg_team = "equipo <b>%s</b> con formación <b>%s</b>"
            msg_team_a = msg_team % team_a
            msg_team_b = msg_team % team_b

        if winner == 0:
            result = '<span foreground="red"><b>' + _('Draw') + '</b></span>\n'
            result += msg_team_a + '\n' + msg_team_b
        elif winner == 1:
            result = '<span foreground="red"><b>Ganador</b>: '
            result += msg_team_a
            result += '</span>\n'
            result += "Contrincante: " + msg_team_b
        else:
            result = '<span foreground="red"><b>Ganador</b>: '
            result += msg_team_b
            result += '</span>\n'
            result += "Contrincante: " + msg_team_a

        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/resultNotifier.glade'))

        self.dlg_result = builder.get_object('dlg_result')
        self.dlg_result.connect('response', lambda d, r: d.hide())
        self.dlg_result.format_secondary_markup(result)
Пример #26
0
    def __init__(self):
        "Constructor of the object"
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/main.glade')) 
        
        self.window = builder.get_object("mainWindow")
        self.about = builder.get_object("aboutdialog1")
        self.previous_games_chooser = builder.get_object("filechooserdialog1")
        self.games_chooser_warning = builder.get_object("messagedialog1")

        
        self.games_chooser_warning.connect('response', lambda d, r: d.hide())
        self.games_chooser_warning.set_transient_for(self.previous_games_chooser)

        self.previous_games_chooser.set_transient_for(self.window)
        self.about.set_transient_for(self.window)
        
        def_path = configure.load_configuration()['games_path']
        self.previous_games_chooser.set_current_folder(def_path)
        builder.connect_signals(self)
Пример #27
0
    def __init__(self, parent):
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/tree.glade'))

        self.players_selector = builder.get_object("players_selector")
        self.players_selector.set_transient_for(parent)

        #---------------------------
        self.cName = 0
        self.cRules = 1
        self.cFormation = 2

        self.sName = "Name"
        self.sRules = "Rules"
        self.sFormation = "Formation"

        self.list_view = builder.get_object("list_es_view")
        self.list_view.set_reorderable(False)

        self.addColumn(self.sName, self.cName)
        self.addColumn(self.sRules, self.cRules)
        self.addColumn(self.sFormation, self.cFormation)

        self.list_store = builder.get_object("list_expert_system")
        #-----------------------------

        self.file_chooser_rules = builder.get_object('file_chooser_rules')
        #self.file_chooser_rules.set_transient_for(self.players_selector)
        self.file_chooser_formation = builder.get_object(
            'file_chooser_formation')
        #self.file_chooser_formation.set_transient_for(self.players_selector)

        def_path = configure.load_configuration()['se_path']
        self.file_chooser_rules.set_current_folder(def_path + '/rules')
        self.file_chooser_formation.set_current_folder(def_path +
                                                       '/formations')

        builder.connect_signals(self)
    def __init__ (self, parent):
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/tree.glade'))

        self.players_selector = builder.get_object('players_selector')
        self.players_selector.set_transient_for(parent)

        self.files = {}
        self.teams = {}

        # ---- Building the table
        self.cName = 0
        self.cRules = 1
        self.cFormation = 2

        self.sName = 'Name'
        self.sRules = 'Rules'
        self.sFormation = 'Formation'
        
        self.list_view = builder.get_object("list_es_view")
        self.list_view.set_reorderable(False)

        self.add_column(self.sName, self.cName)
        self.add_column(self.sRules, self.cRules)
        self.add_column(self.sFormation, self.cFormation)

        self.list_store = builder.get_object('list_expert_system')
        # -----
        
        self.file_chooser_rules = builder.get_object('file_chooser_rules')
        self.file_chooser_formation = builder.get_object('file_chooser_formation')
        
        def_path = configure.load_configuration()['se_path']
        self.file_chooser_rules.set_current_folder(def_path + '/rules')
        self.file_chooser_formation.set_current_folder(def_path + '/formations')
        
        builder.connect_signals(self)
Пример #29
0
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Copyright (C) 2010, Pablo Recio Quijano
#----------------------------------------------------------------------

import os
import logging

from guadaboard import guada_board
from resistencia import xdg
from resistencia.contest import controlPartida

_pieceA = xdg.get_data_path('images/piece-orange.png')
_pieceB = xdg.get_data_path('images/piece-violete.png')


class Error(Exception):
    """Base class for exceptions in this module."""
    pass


class RoundError(Error):
    """Exception raised for errors in the round iteration

    Attributes:
        msg  -- explanation of the error
    """
    def __init__(self, msg):
Пример #30
0
    def __init__(self, parent):
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/contest.glade'))

        self.contest_dialog = builder.get_object("contest_dialog")
        self.contest_dialog.set_transient_for(parent)

        self.files = {}
        self.teams = {}

        #---------------------------
        self.cName = 0
        self.cRules = 1
        self.cFormation = 2

        self.sName = _("Name")
        self.sRules = _("Rules")
        self.sFormation = _("Formation")

        self.list_view = builder.get_object("list_es_view")
        self.list_view.set_reorderable(False)

        self.addColumn(self.sName, self.cName)
        self.addColumn(self.sRules, self.cRules)
        self.addColumn(self.sFormation, self.cFormation)
        self.addColumn(_("Description"), 3)

        self.list_store = builder.get_object("list_expert_system")
        #-----------------------------

        self.file_chooser_rules = builder.get_object('file_chooser_rules')
        #self.file_chooser_rules.set_transient_for(self.players_selector)
        self.file_chooser_formation = builder.get_object(
            'file_chooser_formation')
        #self.file_chooser_formation.set_transient_for(self.players_selector)

        self.format_contest = 'league'
        self.radio_league = builder.get_object('radio_league')
        self.radio_cup = builder.get_object('radio_cup')
        self.radio_groups = builder.get_object('radio_groups')
        self.radio_playoff = builder.get_object('radio_playoff')
        self.check_backround = builder.get_object('check_backround')
        self.check_fast = builder.get_object('check_onlyresults')

        self.back_round = False
        self.fast = False
        self.all_teams = False

        self.def_path = configure.load_configuration()['se_path']
        self.file_chooser_rules.set_current_folder(self.def_path + '/rules')
        self.file_chooser_formation.set_current_folder(self.def_path +
                                                       '/formations')

        self.start_button = builder.get_object('btn_start')
        self.frame_selection_teams = builder.get_object('box_selection')

        self.num_turns = 120
        self.spin_turns = builder.get_object("spin_num_turns")
        self.spin_turns.set_range(50, 300)
        self.spin_turns.set_increments(2, 10)
        self.spin_turns.set_value(self.num_turns)

        self.check_default_formations = builder.get_object(
            'check_default_formations')

        builder.connect_signals(self)
def parse_propierty_image(node):
    """
    Parses an image
    """
    return xdg.get_data_path(_parse_propierty_data_string(node))
def init_human_game(player_formation,
                    computer_team,
                    player_as,
                    number_turns,
                    dont_save=False):
    """
    Intialize the clips environment
    """

    player_num = 0
    team_a = None
    team_b = None
    name_team_a = ''
    name_team_b = ''

    team_a_piece = xdg.get_data_path('images/piece-orange.png')
    team_b_piece = xdg.get_data_path('images/piece-violete.png')
    default_piece = xdg.get_data_path('images/piece-default.png')

    formacion_temporal_player = None
    formacion_temporal_pc = None

    formacion_temporal_player = parsear_fichero_formacion(player_formation)
    player_formation = formacion_temporal_player
    formacion_temporal_pc = parsear_fichero_formacion(computer_team[1])

    computer_team = (computer_team[0], formacion_temporal_pc)

    if player_as == 'A':
        player_num = 1
        team_a = player_formation
        team_b = computer_team
        name_team_a = filenames.extract_simple_name_es((None, team_a))
        name_team_b = filenames.extract_name_expert_system(team_b)
    else:
        player_num = -1
        team_b = player_formation
        team_a = computer_team
        name_team_b = filenames.extract_simple_name_es((None, team_b))
        name_team_a = filenames.extract_name_expert_system(team_a)

    aux_team_a = (name_team_a, team_a_piece)
    aux_team_b = (name_team_b, team_b_piece)

    clips.Eval('(reset)')
    clips.Eval('(clear)')

    clips.EngineConfig.Strategy = clips.RANDOM_STRATEGY

    random.seed()
    clips.Eval("(seed %d)" % random.randint(0, 9999))

    funciones.LoadFunctions(clips)
    f1.init_world(clips, number_turns)

    try:
        f1.LoadFunctions(clips)
    except Exception:
        print clips.ErrorStream.Read()
        exit(-1)

    mover.LoadFunctions(clips)
    texto.LoadFunctions(clips)
    traducirF.LoadFunctions(clips)
    traducirM.LoadFunctions(clips)

    if player_num == 1:
        int_team = mirroring.interactive_formation(team_a)
        temp_team = mirroring.mirroring_team(team_b[1])

        try:
            clips.Load(int_team)
        except clips.ClipsError:
            os.remove(int_team)
            raise FileError(_('Error parsing the file ') + team_a)

        try:
            clips.Load(temp_team)
        except clips.ClipsError:
            os.remove(temp_team)
            raise FileError(_('Error parsing the file ') + team_b[1])

        os.remove(int_team)
        os.remove(temp_team)

        fB.LoadFunctions(clips)
        temp_rules = mirroring.mirroring_rules(team_b[0])
        try:
            clips.Load(temp_rules)
        except clips.ClipsError:
            os.remove(temp_rules)
            raise FileError(_('Error parsing the file ') + team_b[0])
        os.remove(temp_rules)
    else:
        try:
            clips.Load(team_a[1])
        except clips.ClipsError:
            raise FileError(_('Error parsing the file ') + team_a[1])

        int_team = mirroring.interactive_formation(team_b)
        temp_team = mirroring.mirroring_team(int_team)

        try:
            clips.Load(temp_team)
        except clips.ClipsError:
            os.remove(temp_team)
            raise FileError(_('Error parsing the file ') + team_a[1])
        os.remove(temp_team)

        fA.LoadFunctions(clips)
        try:
            clips.Load(team_a[0])
        except clips.ClipsError:
            raise FileError(_('Error parsing the file ') + team_a[0])

    interaccion.LoadFunctions(clips, player_as)

    interaccion.interaction_object = r_intact.HumanInteraction(
        aux_team_a, aux_team_b, default_piece, player_num, number_turns)

    clips.Reset()  # restart the environment

    clips.Run()  # start the simulation

    interaccion.interaction_object.finish()

    _stream = clips.StdoutStream.Read()  # print the output

    # print _stream
    # print interaccion.interaction_object.define_winner()

    if not dont_save:
        _rename_output_file(_generate_file_name(name_team_a, name_team_b))

    if os.path.isfile("resultado.txt"):
        os.remove('resultado.txt')

    os.remove(formacion_temporal_pc)
    os.remove(formacion_temporal_player)

    clips.Eval('(reset)')
    clips.Eval('(clear)')
This module is the middle layer between the kernel of a one player game and its
representation on pygame.
"""

import os.path
import time

import gtk

from guadaboard import dyn_game

from libguadalete import file_parser
from resistencia import xdg
from resistencia.gui import notify_result

__default_layout__ = xdg.get_data_path('layouts/main-layout.xml')


def _find_element_matrix(board, element):
    """
    Check the existence of the element on a matrix.
    """
    _sum = 0
    for line in board:
        _sum += line.count(element)

    return not _sum == 0


def _define_winner(board):
    """
This module is the middle layer between the kernel of a one player game and its
representation on pygame.
"""

import os.path
import time

import gtk

from guadaboard import dyn_game

from libguadalete import file_parser
from resistencia import xdg
from resistencia.gui import notify_result

__default_layout__ = xdg.get_data_path('layouts/main-layout.xml')


def _find_element_matrix(board, element):
    """
    Check the existence of the element on a matrix.
    """
    _sum = 0
    for line in board:
        _sum += line.count(element)

    return not _sum == 0


def _define_winner(board):
    """
def init_human_game(player_formation, computer_team, player_as,
                    number_turns, dont_save=False):
    """
    Intialize the clips environment
    """
    
    
    player_num = 0
    team_a = None
    team_b = None
    name_team_a = ''
    name_team_b = ''

    team_a_piece = xdg.get_data_path('images/piece-orange.png')
    team_b_piece = xdg.get_data_path('images/piece-violete.png')
    default_piece = xdg.get_data_path('images/piece-default.png')

    formacion_temporal_player = None
    formacion_temporal_pc = None

    formacion_temporal_player = parsear_fichero_formacion(player_formation)
    player_formation = formacion_temporal_player
    formacion_temporal_pc = parsear_fichero_formacion(computer_team[1])

    computer_team = (computer_team[0], formacion_temporal_pc)

    if player_as == 'A':
        player_num = 1
        team_a = player_formation
        team_b = computer_team
        name_team_a = filenames.extract_simple_name_es((None, team_a))
        name_team_b = filenames.extract_name_expert_system(team_b)
    else:
        player_num = -1
        team_b = player_formation
        team_a = computer_team
        name_team_b = filenames.extract_simple_name_es((None, team_b))
        name_team_a = filenames.extract_name_expert_system(team_a)

    
    

    aux_team_a = (name_team_a, team_a_piece)
    aux_team_b = (name_team_b, team_b_piece)

    clips.Eval('(reset)')
    clips.Eval('(clear)')

    clips.EngineConfig.Strategy = clips.RANDOM_STRATEGY

    random.seed()
    clips.Eval("(seed %d)" % random.randint(0, 9999))

    funciones.LoadFunctions(clips)
    f1.init_world(clips, number_turns)

    try:
        f1.LoadFunctions(clips)
    except Exception:
        print clips.ErrorStream.Read()
        exit(-1)
    
    mover.LoadFunctions(clips)
    texto.LoadFunctions(clips)
    traducirF.LoadFunctions(clips)
    traducirM.LoadFunctions(clips)

    
    
    if player_num == 1:
        int_team = mirroring.interactive_formation(team_a)
        temp_team = mirroring.mirroring_team(team_b[1])

        try:
            clips.Load(int_team)
        except clips.ClipsError:
            os.remove(int_team)
            raise FileError(_('Error parsing the file ') + team_a)

        try:
            clips.Load(temp_team)
        except clips.ClipsError:
            os.remove(temp_team)
            raise FileError(_('Error parsing the file ') + team_b[1])

        os.remove(int_team)
        os.remove(temp_team)

        fB.LoadFunctions(clips)
        temp_rules = mirroring.mirroring_rules(team_b[0])
        try:
            clips.Load(temp_rules)
        except clips.ClipsError:
            os.remove(temp_rules)
            raise FileError(_('Error parsing the file ') + team_b[0])
        os.remove(temp_rules)
    else:
        try:
            clips.Load(team_a[1])
        except clips.ClipsError:
            raise FileError(_('Error parsing the file ') + team_a[1])

        int_team = mirroring.interactive_formation(team_b)
        temp_team = mirroring.mirroring_team(int_team)

        try:
            clips.Load(temp_team)
        except clips.ClipsError:
            os.remove(temp_team)
            raise FileError(_('Error parsing the file ') + team_a[1])
        os.remove(temp_team)

        fA.LoadFunctions(clips)
        try:
            clips.Load(team_a[0])
        except clips.ClipsError:
            raise FileError(_('Error parsing the file ') + team_a[0])

    interaccion.LoadFunctions(clips, player_as)

    
    interaccion.interaction_object = r_intact.HumanInteraction(
        aux_team_a, aux_team_b, default_piece, player_num, number_turns)

    
    clips.Reset()  # restart the environment

    
    clips.Run()  # start the simulation

    
    interaccion.interaction_object.finish()

    
    _stream = clips.StdoutStream.Read()  # print the output

    # print _stream
    # print interaccion.interaction_object.define_winner()

    if not dont_save:
        _rename_output_file(_generate_file_name(name_team_a, name_team_b))
        
    if os.path.isfile("resultado.txt"):
        os.remove('resultado.txt')

    
    os.remove(formacion_temporal_pc)
    os.remove(formacion_temporal_player)
    
    clips.Eval('(reset)')
    clips.Eval('(clear)')
Пример #36
0
    def __init__(self,
                 classification,
                 results,
                 round,
                 rounds,
                 show_classifications=True,
                 show_top_teams=False,
                 stats=None,
                 next_matches=None):  #add parent
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/results.glade'))

        self.classifications = classification
        self.results = results
        self.round = round
        self.rounds = rounds
        self.show_top_teams = show_top_teams
        self.stats = stats

        self.result_dialog = builder.get_object('dlg_results')
        title = self.result_dialog.get_title() + ' ' + str(round) + '/' + str(
            rounds)
        self.result_dialog.set_title(title)

        self.confirmation_dialog = builder.get_object('dlg_confirmation_close')
        self.confirmation_dialog.connect('response', lambda d, r: d.hide())
        self.confirmation_dialog.set_transient_for(self.result_dialog)

        self.finalround_dialog = builder.get_object('dlg_finalround')
        self.finalround_dialog.connect('response', lambda d, r: d.hide())
        self.finalround_dialog.set_transient_for(self.result_dialog)

        self.list_view_classifications = builder.get_object(
            'treeview_classification')
        self.list_view_results = builder.get_object('treeview_results')
        self.list_view_matches = builder.get_object('treeview_matches')

        if show_classifications:
            self.cPosition = 0
            self.cTeamName = 1
            self.cPuntuations = 2

            self.sPosition = 'Pos'
            self.sTeamName = _('Team name')
            self.sPuntuations = 'Punt'

            self.add_column(self.list_view_classifications, self.sPosition,
                            self.cPosition)
            self.add_column(self.list_view_classifications, self.sTeamName,
                            self.cTeamName)
            self.add_column(self.list_view_classifications, self.sPuntuations,
                            self.cPuntuations)

            if self.stats != None:
                self.cNumGanados = 3
                self.cNumEmpatados = 4
                self.cNumPerdidos = 5

                self.sNumGanados = '✓'
                self.sNumEmpatados = '='
                self.sNumPerdidos = '✗'

                self.add_column(self.list_view_classifications,
                                self.sNumGanados, self.cNumGanados)
                self.add_column(self.list_view_classifications,
                                self.sNumEmpatados, self.cNumEmpatados)
                self.add_column(self.list_view_classifications,
                                self.sNumPerdidos, self.cNumPerdidos)

        self.list_store_classifications = builder.get_object(
            'list_classification')

        if show_classifications:
            self.fill_classification()
        else:
            builder.get_object('hbox1').remove(
                builder.get_object('frame_classifications'))

        if next_matches:
            self.list_store_matches = builder.get_object('list_matches')
            self.add_column(self.list_view_matches, _("Team A"), 0)
            self.add_column(self.list_view_matches, _("Team B"), 1)

            for m in next_matches:
                n = list(m)

                if n[0] == "aux_ghost_team":
                    n[0] = _("Rests")

                if n[1] == "aux_ghost_team":
                    n[1] = _("Rests")

                self.list_store_matches.append(n)
        else:
            builder.get_object('hbox1').remove(
                builder.get_object('frame_matches'))

        self.cTeamA = 0
        self.cTeamB = 1

        self.sTeamA = _('Team A')
        self.sTeamB = _('Team B')

        self.add_column(self.list_view_results, self.sTeamA, self.cTeamA)
        self.add_column(self.list_view_results, self.sTeamB, self.cTeamB)
        self.add_column(self.list_view_results, _("Reason"), 2)

        self.list_store_results = builder.get_object('list_results')
        self.fill_results()

        self.end_contest = False

        builder.get_object('dlg_results').set_focus(
            builder.get_object('btn_results_next'))
        builder.connect_signals(self)
    def __init__(self, parent):
        self.es_team_a = ''
        self.team_team_a = ''
        self.es_team_b = ''
        self.team_team_b = ''

        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/quickGame.glade'))

        def_path = configure.load_configuration()['se_path']
        def_rules_path = def_path + '/rules'
        def_formations_path = def_path + '/formations'
        builder.get_object('file_chooser_es_a').set_current_folder(
            def_rules_path)
        builder.get_object('file_chooser_team_a').set_current_folder(
            def_formations_path)
        builder.get_object('file_chooser_es_b').set_current_folder(
            def_rules_path)
        builder.get_object('file_chooser_team_b').set_current_folder(
            def_formations_path)

        self.file_chooser_team_a = builder.get_object('file_chooser_team_a')
        self.file_chooser_team_b = builder.get_object('file_chooser_team_b')

        self.quick_game = builder.get_object("quick_game_dialog")
        self.quick_game.set_transient_for(parent)

        #---- Initialation for the dialogs
        self.error_es_a = builder.get_object("error_no_es_a")
        self.error_es_a.connect('response', lambda d, r: d.hide())
        self.error_es_a.set_transient_for(self.quick_game)

        self.error_team_a = builder.get_object("error_no_team_a")
        self.error_team_a.connect('response', lambda d, r: d.hide())
        self.error_team_a.set_transient_for(self.quick_game)

        self.error_es_b = builder.get_object("error_no_es_b")
        self.error_es_b.connect('response', lambda d, r: d.hide())
        self.error_es_b.set_transient_for(self.quick_game)

        self.error_team_b = builder.get_object("error_no_team_b")
        self.error_team_b.connect('response', lambda d, r: d.hide())
        self.error_team_b.set_transient_for(self.quick_game)

        #self.result_dialog = builder.get_object("dlg_result")
        #self.result_dialog.connect('response', lambda d, r: d.hide())
        #self.result_dialog.set_transient_for(self.quick_game)

        self.dlg_bad_file = builder.get_object('dlg_bad_file')
        self.dlg_bad_file.connect('response', lambda d, r: d.hide())
        self.dlg_bad_file.set_transient_for(self.quick_game)

        self.num_turns = 120
        self.spin_turns = builder.get_object("spin_num_turns")
        self.spin_turns.set_range(50, 300)
        self.spin_turns.set_increments(2, 10)
        self.spin_turns.set_value(self.num_turns)
        #---------------
        self.fast_game = False
        self.dont_save_game = False
        self.hidde_values = False

        self.label_desc_A = builder.get_object("label_desc_A")
        self.label_desc_B = builder.get_object("label_desc_B")

        builder.connect_signals(self)
def parse_propierty_image(node):
    """
    Parses an image
    """
    return xdg.get_data_path(_parse_propierty_data_string(node))
Пример #39
0
    def __init__(self, classification, results, round, rounds,
                 show_classifications=True, show_top_teams=False, stats = None, next_matches = None): #add parent
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/results.glade'))

        self.classifications = classification
        self.results = results
        self.round = round
        self.rounds = rounds
        self.show_top_teams = show_top_teams
        self.stats = stats

        self.result_dialog = builder.get_object('dlg_results')
        title = self.result_dialog.get_title()  + ' ' + str(round) + '/' + str(rounds)
        self.result_dialog.set_title(title)

        self.confirmation_dialog = builder.get_object('dlg_confirmation_close')
        self.confirmation_dialog.connect('response', lambda d, r: d.hide())
        self.confirmation_dialog.set_transient_for(self.result_dialog)

        self.finalround_dialog = builder.get_object('dlg_finalround')
        self.finalround_dialog.connect('response', lambda d, r: d.hide())
        self.finalround_dialog.set_transient_for(self.result_dialog)

        self.list_view_classifications = builder.get_object('treeview_classification')
        self.list_view_results = builder.get_object('treeview_results')
        self.list_view_matches = builder.get_object('treeview_matches')

        if show_classifications:
            self.cPosition = 0
            self.cTeamName = 1
            self.cPuntuations = 2
        
            self.sPosition = 'Pos'
            self.sTeamName = _('Team name')
            self.sPuntuations = 'Punt'

            self.add_column(self.list_view_classifications,
                            self.sPosition, self.cPosition)
            self.add_column(self.list_view_classifications,
                            self.sTeamName, self.cTeamName)
            self.add_column(self.list_view_classifications,
                            self.sPuntuations, self.cPuntuations)

            if self.stats != None:
                self.cNumGanados = 3
                self.cNumEmpatados = 4
                self.cNumPerdidos = 5

                self.sNumGanados = '✓'
                self.sNumEmpatados = '='
                self.sNumPerdidos = '✗'

                self.add_column(self.list_view_classifications, self.sNumGanados, self.cNumGanados)
                self.add_column(self.list_view_classifications, self.sNumEmpatados, self.cNumEmpatados)
                self.add_column(self.list_view_classifications, self.sNumPerdidos, self.cNumPerdidos)

        self.list_store_classifications = builder.get_object('list_classification')
        
        if show_classifications:
            self.fill_classification()
        else:
            builder.get_object('hbox1').remove(builder.get_object('frame_classifications'))

        if next_matches:
            self.list_store_matches = builder.get_object('list_matches')
            self.add_column(self.list_view_matches, _("Team A"), 0)
            self.add_column(self.list_view_matches, _("Team B"), 1)

            for m in next_matches:
                n = list(m)

                if n[0] == "aux_ghost_team":
                    n[0] = _("Rests")

                if n[1] == "aux_ghost_team":
                    n[1] = _("Rests")

                self.list_store_matches.append(n)
        else:
            builder.get_object('hbox1').remove(builder.get_object('frame_matches'))

        self.cTeamA = 0
        self.cTeamB = 1

        self.sTeamA = _('Team A')
        self.sTeamB = _('Team B')

        self.add_column(self.list_view_results, self.sTeamA, self.cTeamA)
        self.add_column(self.list_view_results, self.sTeamB, self.cTeamB)
        self.add_column(self.list_view_results, _("Reason"), 2)

        self.list_store_results = builder.get_object('list_results')
        self.fill_results()

        self.end_contest = False
        
        builder.get_object('dlg_results').set_focus(builder.get_object('btn_results_next'))
        builder.connect_signals(self)
Пример #40
0
    def __init__(self, stats, team):
        self.output_file = 'tmp.png'
        line = []
        if not stats['wins'] == 0:
            line.append(('wins', stats['wins']))
        if not stats['draws'] == 0:
            line.append(('draws', stats['draws']))
        if not stats['looses'] == 0:
            line.append(('looses', stats['looses']))

        piechart.pieChart(self.output_file, line)

        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/testResults.glade'))

        self.test_result = builder.get_object('test_result_dialog')
        self.test_result.set_title(self.test_result.get_title().replace(
            '@team@', team))
        #self.tests_dialog.set_transient_for(parent)

        builder.get_object('pie_chart').set_from_file(self.output_file)

        num_games = stats['wins'] + stats['draws'] + stats['looses']
        wins = stats['wins']
        draws = stats['draws']
        looses = stats['looses']
        try:
            turns_winning = stats['turns_winning'] / wins
        except ZeroDivisionError:
            turns_winning = 0

        try:
            turns_loosing = stats['turns_losing'] / looses
        except ZeroDivisionError:
            turns_loosing = 0

        num_pieces = stats['num_pieces'] / num_games
        val_pieces = stats['val_pieces'] / num_games
        max_death = stats['max_death'] / num_games

        text = builder.get_object('lbl_num_games').get_label()
        builder.get_object('lbl_num_games').set_label(
            text.replace('@value@', str(num_games)))
        text = builder.get_object('lbl_wins').get_label()
        builder.get_object('lbl_wins').set_label(
            text.replace('@value@', str(wins)))
        text = builder.get_object('lbl_draws').get_label()
        builder.get_object('lbl_draws').set_label(
            text.replace('@value@', str(draws)))
        text = builder.get_object('lbl_looses').get_label()
        builder.get_object('lbl_looses').set_label(
            text.replace('@value@', str(looses)))
        text = builder.get_object('lbl_turns_win').get_label()
        builder.get_object('lbl_turns_win').set_label(
            text.replace('@value@', str(turns_winning)))
        text = builder.get_object('lbl_turns_lose').get_label()
        builder.get_object('lbl_turns_lose').set_label(
            text.replace('@value@', str(turns_loosing)))
        text = builder.get_object('lbl_max_piece').get_label()
        builder.get_object('lbl_max_piece').set_label(
            text.replace('@value@', str(max_death)))

        builder.connect_signals(self)
def parse_propierty_font(node):
    """
    Parses a font
    """
    return xdg.get_data_path(_parse_propierty_data_string(node))
Пример #42
0
    def __init__(self, parent):
        self.rules_main_team = ''
        self.formation_main_team = ''
        self.files = {}
        self.teams = {}

        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/testDialog.glade'))

        self.tests_dialog = builder.get_object('tests_dialog')
        self.tests_dialog.set_transient_for(parent)

        # ---- Init file chooser buttons
        default_path = configure.load_configuration()['se_path']
        default_rules_path = default_path + '/rules'
        default_formations_path = default_path + '/formations'
        builder.get_object('btn_filechooser_rules').set_current_folder(default_rules_path)
        builder.get_object('btn_filechooser_formation').set_current_folder(default_formations_path)
        # ----

        self.num_rounds = 2
        self.spin_rounds = builder.get_object('spin_rounds')
        self.spin_rounds.set_range(2, 100)
        self.spin_rounds.set_increments(2,10)
        self.spin_rounds.set_value(self.num_rounds)
        
        self.num_turns = 120
        self.spin_turns = builder.get_object("spin_num_turns")
        self.spin_turns.set_range(50,300)
        self.spin_turns.set_increments(2,10)
        self.spin_turns.set_value(self.num_turns)

        self.all_teams = False
        self.frame_selection_teams = builder.get_object('frame_es_selection')

        self.start_button = builder.get_object('btn_apply')
        self.start_button.set_sensitive(False)
        
        #---------------------------
        self.cName = 0
        self.cRules = 1
        self.cFormation = 2
        
        self.sName = _("Name")
        self.sRules = _("Rules")
        self.sFormation = _("Formation")
        
        self.list_view = builder.get_object("list_es_view")
        self.list_view.set_reorderable(False)

        self.addColumn(self.sName, self.cName)
        self.addColumn(self.sRules, self.cRules)
        self.addColumn(self.sFormation, self.cFormation)

        self.list_store = builder.get_object("list_expert_system")
        #-----------------------------
        self.file_chooser_rules = builder.get_object('file_chooser_rules')
        self.file_chooser_formation = builder.get_object('file_chooser_formation')
        self.file_chooser_rules.set_current_folder(default_rules_path)
        self.file_chooser_formation.set_current_folder(default_formations_path)

        
        self.error_es = builder.get_object("error_no_es")
        self.error_es.connect('response', lambda d, r: d.hide())
        self.error_es.set_transient_for(self.tests_dialog)
        
        self.error_team = builder.get_object("error_no_team")
        self.error_team.connect('response', lambda d, r: d.hide())
        self.error_team.set_transient_for(self.tests_dialog)

        self.progress_bar = pbs.ProgressBarDialog(self.tests_dialog,
                                                  _('Running the test'))
        self.progress_bar_dialog = self.progress_bar.progress_bar_dialog
        
        builder.connect_signals(self)
Пример #43
0
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Copyright (C) 2010, Pablo Recio Quijano
#----------------------------------------------------------------------

from guadaboard import guada_board
from resistencia import xdg
_pieceA = xdg.get_data_path('images/piece-orange.png')
_pieceB = xdg.get_data_path('images/piece-violete.png')

class Error(Exception):
    """Base class for exceptions in this module."""
    pass

class RoundError(Error):
    """Exception raised for errors in the round iteration

    Attributes:
        msg  -- explanation of the error
    """

    def __init__(self, msg):
        self.msg = msg
def parse_propierty_font(node):
    """
    Parses a font
    """
    return xdg.get_data_path(_parse_propierty_data_string(node))
Пример #45
0
    def __init__(self, classification, results, round, rounds,
                 show_classifications=True, show_top_teams=False): #add parent
        builder = gtk.Builder()
        builder.add_from_file(xdg.get_data_path('glade/results.glade'))

        self.classifications = classification
        self.results = results
        self.round = round
        self.rounds = rounds
        self.show_top_teams = show_top_teams

        self.result_dialog = builder.get_object('dlg_results')
        title = self.result_dialog.get_title()  + ' ' + str(round) + '/' + str(rounds)
        self.result_dialog.set_title(title)
        self.confirmation_dialog = builder.get_object('dlg_confirmation_close')
        self.confirmation_dialog.connect('response', lambda d, r: d.hide())
        self.confirmation_dialog.set_transient_for(self.result_dialog)
        self.finalround_dialog = builder.get_object('dlg_finalround')
        self.finalround_dialog.connect('response', lambda d, r: d.hide())
        self.finalround_dialog.set_transient_for(self.result_dialog)

        self.list_view_classifications = builder.get_object('treeview_classification')
        self.list_view_results = builder.get_object('treeview_results')

        if show_classifications:
            self.cPosition = 0
            self.cTeamName = 1
            self.cPuntuations = 2
        
            self.sPosition = 'Pos'
            self.sTeamName = _('Team name')
            self.sPuntuations = 'Punt'

            self.add_column(self.list_view_classifications,
                            self.sPosition, self.cPosition)
            self.add_column(self.list_view_classifications,
                            self.sTeamName, self.cTeamName)
            self.add_column(self.list_view_classifications,
                            self.sPuntuations, self.cPuntuations)

        self.list_store_classifications = builder.get_object('list_classification')
        if show_classifications:
            self.fill_classification()
        else:
            builder.get_object('hbox1').remove(builder.get_object('frame_classifications'))

        self.cTeamA = 0
        self.cTeamB = 1

        self.sTeamA = _('Team A')
        self.sTeamB = _('Team B')

        self.add_column(self.list_view_results, self.sTeamA, self.cTeamA)
        self.add_column(self.list_view_results, self.sTeamB, self.cTeamB)

        self.list_store_results = builder.get_object('list_results')
        self.fill_results()

        self.end_contest = False
        
        builder.connect_signals(self)