def modifier_equipe(self, event): num = self.grille.selection() dlg = dlgeq.DialogueEquipe( self, dlgeq.STYLE_MOFIFIER, choix=[int(e) for e in tournoi.tournoi().equipes()], numero_affiche=num, completion=self.config.get_typed('TOURNOI', 'joueur_completion')) ret = dlg.ShowModal() if ret == wx.ID_OK: info = dlg.donnees() equipe = tournoi.tournoi().equipe(info['numero']) equipe.suppr_joueurs() for joueur in info['joueurs']: equipe.ajout_joueur(joueur[0], joueur[1], joueur[2]) equipe.joker = info['joker'] # Rafraichir self.enregistrer_auto() wx.PostEvent(self, evt.RafraichirEvent(self.GetId(), 'etat')) wx.PostEvent(self, evt.RafraichirEvent(self.GetId(), 'classement')) wx.PostEvent( self, evt.RafraichirEvent(self.GetId(), 'equipe_' + str(equipe.numero))) dlg.Destroy()
def test_date_chargement(): d = datetime.now() d1 = tournoi.tournoi().date_chargement - timedelta( 0, 0, tournoi.tournoi().date_chargement.microsecond) d2 = d - timedelta(0, 0, d.microsecond) assert d1 == d2
def __init__(self, parent, manches, chapeaux=[]): grid.Grid.__init__(self, parent, wx.ID_ANY) self.equipes_par_manche = tournoi.tournoi().equipes_par_manche self.CreateGrid(0, self.equipes_par_manche + 2) self.SetColAttr(0, self.attribut('piquet')) self.SetColAttr(self.GetNumberCols() - 1, self.attribut('info')) for i in range(self.GetNumberCols()): if 0 < i < self.GetNumberCols() - 1: self.SetColAttr(i, self.attribut('equipe')) self.SetColSize(i, 50) # cases selectionnées self.select1 = None self.select2 = None # self.SetGridLineColour(wx.Colour(255, 255, 255)) self.SetColMinimalAcceptableWidth(1) self.SetRowLabelSize(0) for i in range(self.GetNumberCols()): if i == 0: self.SetColLabelValue(i, u"Piquet") elif i == self.GetNumberCols() - 1: self.SetColLabelValue(self.GetNumberCols() - 1, u"Information") else: self.SetColLabelValue(i, u"") self.EnableDragColSize(False) self.EnableDragRowSize(False) # Mise à jour self.maj(manches, chapeaux, tournoi.tournoi().statistiques()) self.Bind(grid.EVT_GRID_CELL_LEFT_CLICK, self._selection_equipe) self.Bind(wx.EVT_SIZE, self.Layout, self)
def ouvrir(self, fichier): self.shell.interp.locals['trb'] = tournoi.charger_tournoi(fichier) # Rafraichir self.barre_bouton.chg_partie(tournoi.tournoi().nb_parties()) self.grille.effacer() self.grille.ajout_equipe(*tournoi.tournoi().equipes()) wx.PostEvent(self, evt.RafraichirEvent(self.GetId())) self.SetTitle("%s - %s" % (tourbillon.__nom__, fichier)) logger.info(u"Chargé, prêt à jouer mon commandant!")
def complet(self): if self.combo is True: return True else: if self.ctl_numero.GetValue() != u"": try: tournoi.tournoi().equipe(int(self.ctl_numero.GetValue())) return False except: return True else: return False
def afficher_partie_suiv(self, event): if tournoi.tournoi() is None: self.barre_bouton.chg_partie() else: try: tournoi.tournoi().partie(self.barre_bouton.numero() + 1) self.barre_bouton.chg_partie(self.barre_bouton.numero() + 1) except ValueError, e: self.barre_etat.SetStatusText(unicode(e)) # Rafraichir wx.PostEvent(self, evt.RafraichirEvent(self.GetId()))
def alias_ouvrir(self, args_s=''): u""" Charger un tournoi. options: <fichier> : fichier à charger """ if args_s == '': args_s = question(u"Fichier: ", False) if args_s != '': self.locals['trb'] = tournoi.charger_tournoi(args_s) print tournoi.tournoi() print "NOTE: vous pouvez acceder au tournoi via la variable 'trb'"
def __init__(self, config): Alias.__init__(self) self.config = config self.nom = '__cli__' self.locals = { 'intf': self, 'trb': tournoi.tournoi(), 'cfg': config, 'cst': cst } self._inter = Interpreteur(self, self.locals) self._inter.charger_historique(config.get('INTERFACE', 'historique')) joueur.charger_historique(config.get('TOURNOI', 'historique')) # interpreter prompt. try: sys.ps1 except AttributeError: sys.ps1 = TERM.formater("{NORMAL}>>> ") try: sys.ps2 except AttributeError: sys.ps2 = TERM.formater("{BLUE}... ") print u"%s Copyright © 2010 La Billonnière." % tourbillon.__nom__ print u""" This program comes with ABSOLUTELY NO WARRANTY; This is a free software, and you are welcome to redistribute it under certain conditions; type `%licence' for details. """ print print images.entete(terminal=True)
def _selection_equipe(self, event): num = self.entrees[0].numero() for manche in self.tirage: if num in manche: break i = 1 for equipe in manche: m = tournoi.tournoi().equipe(equipe).resultat(self.numero_partie) if equipe == num: self.entrees[0].chg_points(m.points) else: self.entrees[i].chg_numero(equipe) self.entrees[i].chg_points(m.points) i += 1 # Piquet (identique pour toutes les équipes) piquet = m.piquet self.lbl_piquet.SetLabel(u"Piquet %s" % piquet) self.Layout() if m.statut == cst.M_EN_COURS: self.chx_fin.SetValue(True) self.chx_fin.Disable() else: self.chx_fin.SetValue(False)
def grille_double_click(self, event): """ Ouvre le fenêtre correspondant à l'activitée en cours pour l'équipe selectionnée: - "Ajout de Joueur" si le tournoi n'est pas commencé - "Entrer les Résultats" si le tournoi est commencé """ if tournoi.tournoi() is not None: if self.grille.selection() is not None: statut = tournoi.tournoi().statut if statut == cst.T_INSCRIPTION or ( statut == cst.T_ATTEND_TIRAGE and tournoi.tournoi().nb_parties() == 0): self.modifier_equipe(event) else: self.entrer_resultats(event)
def _maj(self, event): partie = tournoi.tournoi().partie( int(self.ctl_numero.GetStringSelection())) d = {} for m in partie.manches(): piquet = tournoi.tournoi().equipe(m[0]).resultat( partie.numero).piquet d[piquet] = m self.grille.maj( d, [eq.numero for eq in partie.chapeaux()], tournoi.tournoi().statistiques(partie_limite=partie.numero - 1)) for i in range(self.grille.GetNumberRows()): self.grille.verifier_ligne(i) if self.grille.GetNumberRows() < 30: self.Fit()
def imprimer(self, event): partie = tournoi.tournoi().partie_courante() if partie: num = partie.numero + 1 else: num = 1 dlg = DialogueImprimerTirage(self.GetParent(), num, self.grille) dlg.Print()
def test_nom_prenom_joueurs(): for equipe in tournoi.tournoi().equipes(): ind_joueur = 0 for joueur in equipe.joueurs(): eq_ref = EQUIPES[equipe.numero] assert joueur.prenom == eq_ref[ind_joueur][0] assert joueur.nom == eq_ref[ind_joueur][1] assert joueur.age == eq_ref[ind_joueur][2] ind_joueur += 1
def __init__(self, parent, numero_affiche=1): wx.Dialog.__init__(self, parent, wx.ID_ANY, title=u"Tirages", style=wx.DEFAULT_DIALOG_STYLE | wx.CENTER_ON_SCREEN | wx.RESIZE_BORDER | wx.STAY_ON_TOP) self.CenterOnParent() self.txt_phrase = wx.StaticText(self, wx.ID_ANY, u"Tirage de la partie n° ") self.ctl_numero = wx.Choice( self, wx.ID_ANY, choices=[ unicode(partie.numero) for partie in tournoi.tournoi().parties() ]) self.ctl_numero.SetSelection( self.ctl_numero.FindString(unicode(numero_affiche))) # Choix box_chx = wx.BoxSizer(wx.HORIZONTAL) box_chx.Add(self.txt_phrase, 0, wx.ALIGN_CENTER_VERTICAL) box_chx.Add(self.ctl_numero, 0, wx.ALIGN_CENTER_VERTICAL) # Grille self.grille = GrilleManchesCtrl(self, {}, chapeaux=[]) # Boutons self.btn_ok = wx.Button(self, id=wx.ID_OK, label=u"Fermer", size=(100, -1)) self.btn_imprimer = wx.Button(self, id=wx.ID_PREVIEW_PRINT, label=u"Imprimer...", size=(100, -1)) box_btn = wx.BoxSizer(wx.HORIZONTAL) box_btn.Add(self.btn_ok, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 20) box_btn.Add(self.btn_imprimer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 20) # Assembler self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(box_chx, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 20) self.sizer.Add(self.grille, 1, wx.EXPAND | wx.ALL, 5) self.sizer.AddSizer((10, 10), 0, wx.EXPAND) self.sizer.AddSizer(box_btn, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 20) self.SetSizer(self.sizer) self.Layout() self._maj(None) self.Bind(wx.EVT_CHOICE, self._maj, self.ctl_numero) self.Bind(wx.EVT_BUTTON, self.imprimer, self.btn_imprimer)
def __init__(self, parent, equipe): wx.Dialog.__init__(self, parent, wx.ID_ANY, title=u"Tournoi en cours", style=wx.DEFAULT_DIALOG_STYLE | wx.CENTER_ON_SCREEN, pos=wx.DefaultPosition, size=wx.DefaultSize) self.SetMinSize((500, 220)) self.SetSize(wx.Size(500, 200)) self.CenterOnParent() texte = u"La partie n° %s est en cours, pour toutes les parties précédentes l'équipe\n\ sera considérée comme forfait, choisissez l'état de l'équipe n° %s pour la\n\ partie en cours:" % (tournoi.tournoi().partie_courante().numero, equipe) self.txt_info = wx.StaticText(self, wx.ID_ANY, texte, size=wx.Size(-1, 200)) self.chx_etat = wx.Choice(self, ID_NUMERO, choices=[cst.FORFAIT, cst.CHAPEAU]) self.chk_cree_manche = wx.CheckBox( self, wx.ID_ANY, "Créer une manche avec les équipes chapeaux si possible.") # Boutons self.btn_ok = wx.Button(self, id=wx.ID_OK, label=u"Valider", size=(100, -1)) self.btn_ok.SetDefault() self.btn_annule = wx.Button(self, id=wx.ID_CANCEL, label=u"Annuler", size=(100, -1)) box_btn = wx.BoxSizer(wx.HORIZONTAL) box_btn.AddSpacer((50, 50), 1, wx.EXPAND) box_btn.Add(self.btn_annule, 0, wx.EAST | wx.ALIGN_CENTER_VERTICAL, 30) box_btn.Add(self.btn_ok, 0, wx.EAST | wx.ALIGN_CENTER_VERTICAL, 15) # Assembler box = wx.BoxSizer(wx.VERTICAL) box.Add(self.txt_info, 1, wx.ALL, 20) box.Add(self.chx_etat, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) box.Add(self.chk_cree_manche, 1, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 20) box.AddSizer(box_btn, 0, wx.EXPAND) self.SetSizer(box) self.Layout() self.Bind(wx.EVT_CHOICE, self.modif_etat, self.chx_etat) self.Bind(wx.EVT_CHECKBOX, self.modif_option, self.chk_cree_manche)
def imprimer(self, event): avec_victoires = self.config.get_typed('TOURNOI', 'CLASSEMENT_VICTOIRES') avec_joker = self.config.get_typed('TOURNOI', 'CLASSEMENT_JOKER') avec_duree = self.config.get_typed('TOURNOI', 'CLASSEMENT_DUREE') dlg = dlgim.DialogueImprimer( self, tournoi.tournoi().classement(avec_victoires, avec_joker, avec_duree)) dlg.Print()
def _maj(self, event): num = int(self.txt_numero.numero()) equipe = tournoi.tournoi().equipe(num) i = 0 for joueur in equipe.joueurs(): self.entrees[i].chg_joueur(joueur.prenom, joueur.nom, joueur.age) i += 1 self.spin_joker.SetValue(equipe.joker) if event: event.Skip()
def __init__(self, parent, title): wiz.PyWizardPage.__init__(self, parent) self.next = self.prev = None self.sizer, self.txt_msg = ajout_page_titre(self, u"Selection des équipes") self.liste = ListeEquipesCtrl(self, self.GetParent().config) self.liste.ajout_equipes(tournoi.tournoi().equipes()) self.liste.SetSize(wx.Size(600, 300)) self._cocher_tout(None) self.btn_cocher_tout = wx.BitmapButton(self, wx.ID_ANY, images.bitmap('check_on.png')) self.btn_cocher_tout.SetToolTipString( u"Sélectionner toutes les équipes") self.btn_decocher_tout = wx.BitmapButton( self, wx.ID_ANY, images.bitmap('check_off.png')) self.btn_decocher_tout.SetToolTipString( u"Dessélectionner toutes les équipes") self.sizer.Add(self.liste, 1, wx.EXPAND | wx.ALL, 5) box_btn = wx.BoxSizer(wx.HORIZONTAL) box_btn.Add(self.btn_cocher_tout) box_btn.Add(self.btn_decocher_tout) self.sizer.AddSizer(box_btn, 0, wx.LEFT, 5) # Décocher les équipes forfait de la partie précédente if tournoi.tournoi().partie_courante() is not None: forfaits = tournoi.tournoi().partie_courante().forfaits() else: forfaits = [] i = 0 while i < self.liste.GetItemCount(): if int(self.liste.GetItemText(i)) in forfaits: self.liste.CheckItem(i, False) i = i + 1 self.Bind(wx.EVT_BUTTON, self._cocher_tout, self.btn_cocher_tout) self.Bind(wx.EVT_BUTTON, self._decocher_tout, self.btn_decocher_tout) self.Bind(evt.EVT_LIST_ITEM_CHECKED, self.verifier, self.liste)
def GetNext(self): if utils.nb_chapeaux_necessaires( len(self.equipes()), tournoi.tournoi().equipes_par_manche) != 0: # Page chapeaux self.next.GetNext().SetPrev(self.next) return self.next else: # Page tirage self.next.GetNext().SetPrev(self) return self.next.GetNext()
def _tourner(self, event): """ Tourner d'un pas les données. """ if self._compteur < self.GetNumberRows(): i = 0 while i < self.GetNumberRows(): for j in range(4): self.SetCellTextColour(i, 0, wx.Colour(0, 0, 200)) self.SetCellTextColour(i, 1, wx.Colour(126, 126, 126)) self.SetCellTextColour(i, 3, wx.Colour(0, 0, 0)) if i < self.GetNumberRows() - 1: self.SetCellValue(i, j, self.GetCellValue(i + 1, j)) else: if self._compteur < len(self.manches): equipe = self.manches[self._compteur][0] adversaires = self.manches[self._compteur][1:] # Equipe self.SetCellValue(i, 0, unicode(equipe)) # Adversaires if adversaires: self.SetCellValue( i, 1, " - ".join( [unicode(num) for num in adversaires])) else: self.SetCellValue(i, 1, u"C") self.SetCellTextColour( i, 1, images.couleur(cst.CHAPEAU)) # Piquet piquet = tournoi.tournoi().equipe(equipe).resultat( tournoi.tournoi().partie_courante( ).numero).piquet if not piquet: piquet = "-" self.SetCellValue(i, 3, unicode(piquet)) else: self.SetCellValue(i, j, u"") i += 1 self._compteur += 1 else: self._timer.Stop()
def __init__(self, parent, classement): printout.PrintTable.__init__(self, parent) self.data = [] for equipe, place in classement: self.data.append([ place, equipe.numero, " / ".join([unicode(joueur) for joueur in equipe.joueurs()]), equipe.victoires(), equipe.points(), equipe.chapeaux(), equipe.min_billon(), equipe.max_billon(), equipe.moyenne_billon(), grl.unicode_timedelta(equipe.moyenne_duree()) ]) self.SetLandscape() self.SetRowLineSize(0, 2) self.SetRowSpacing(5, 5) self.text_font = { "Name": "Arial", "Size": 14, "Colour": [0, 0, 0], "Attr": [1, 0, 0] } self.label = [] # Titre des colonnes self.set_column = [] # Dimension des colonnes i = 0 for titre, largeur in TITRES: self.label.append(titre) self.set_column.append(largeur) if i == 2: self.SetColAlignment(i, wx.ALIGN_LEFT) else: self.SetColAlignment(i, wx.ALIGN_CENTRE) i += 1 self.SetColTextColour(0, wx.NamedColour('RED')) self.SetColTextColour(1, wx.NamedColour('BLUE')) self.SetColTextColour(2, wx.NamedColour('BLUE')) self.SetHeader(u"Tournoi de Billon du %s" % tournoi.tournoi().debut.strftime('%d/%m/%Y'), colour=wx.NamedColour('BLACK')) self.SetHeader(u"Imprimé le : ", type="Date & Time", align=wx.ALIGN_RIGHT, indent=-0.5, colour=wx.NamedColour('BLUE')) self.SetFooter(u"Page ", colour=wx.NamedColour('BLACK'), type="Num")
def enregister_demande(self): """ Demander à l'utilisateur s'il veux enregristrer le tournoi courrant. """ continuer = wx.ID_OK if tournoi.tournoi() is not None: if tournoi.tournoi().modifie: dlg = wx.MessageDialog( self, u"Le tournoi en cours n'est pas enregistré, si vous cliquez sur NON, les données seront perdues.", caption=u"Voulez-vous enregistrer le tournoi en cours?", style=wx.CANCEL | wx.YES | wx.NO | wx.ICON_QUESTION) ret = dlg.ShowModal() dlg.Destroy() if ret == wx.ID_YES: continuer = self.enregistrer_sous(None) elif ret == wx.ID_CANCEL: continuer = wx.ID_CANCEL return continuer
def styles(): t = tournoi.tournoi() if t is None: etat = None else: if t.statut == cst.T_INSCRIPTION and t.nb_equipes() == 0: etat = '0 equipe' elif t.statut == cst.T_ATTEND_TIRAGE and t.nb_parties() == 0: etat = '0 partie' else: etat = t.statut return STYLES_MENU[etat]
def supprimer_partie(self, event): num = self.barre_bouton.numero() dlg = dlgpa.DialogueSupprimerPartie( self, map(int, tournoi.tournoi().parties()), num) ret = dlg.ShowModal() if ret == wx.ID_OK: tournoi.tournoi().suppr_partie(int(dlg.numero())) if tournoi.tournoi().nb_parties() == 0: self.barre_bouton.chg_partie(0) elif tournoi.tournoi().nb_parties() >= num: self.barre_bouton.chg_partie(num) else: self.barre_bouton.chg_partie(tournoi.tournoi().nb_parties()) # Rafraichir self.enregistrer_auto() wx.PostEvent(self, evt.RafraichirEvent(self.GetId())) logger.info( u"La partie n°%s, c'est ce qu'on appelle un 'coupourin'." % dlg.numero()) dlg.Destroy()
def grille_contexte(self, event): """ Ouvre le menu contextuel """ if tournoi.tournoi() is not None: if self.grille.selection() is not None: menu = barres.cree_contexte_menu() self.PopupMenu( menu, wx.GetMousePosition() - self.GetPosition() - (self.grille.GetPosition().x / 2, self.grille.GetPosition().y / 2)) menu.Destroy()
def chg_tirage(self, tirage, chapeaux=[]): if self.grille is not None: self.sizer.Remove(self.grille) d = {} piquets = tournoi.tournoi().piquets() for m in tirage: d[piquets.pop(0)] = m self.grille = GrilleManchesCtrl(self, d, chapeaux) self.Bind(grid.EVT_GRID_CELL_LEFT_CLICK, self.verifier) self.sizer.Insert(3, self.grille, 1, wx.EXPAND | wx.ALL, 5) self.Layout() self.grille.Layout()
def demarrer_arreter_tirage(self, event): if self._generateur is not None: if self._generateur.isAlive(): self._generateur.stop() self._generateur.join() self.txt_msg.chg_texte(u"") else: self._generateur = None if self._generateur is None: self.txt_msg.chg_texte(u"") self.txt_progression.Clear() self.bar_progression.SetValue(0) font = self.txt_progression.GetFont() font.SetFaceName("Courier") self.txt_progression.SetFont(font) # Statistiques des équipes (hors FORFAITS) statistiques = tournoi.tournoi().statistiques( self.GetParent().forfaits()) # Pre chapeaux chapeaux = self.GetParent().page2.chapeaux() # Création du thread tirage self._generateur = tirages.creer_generateur( tirages.TIRAGES.items()[ self.chx_algorithme.GetCurrentSelection()][0], tournoi.tournoi().equipes_par_manche, statistiques, chapeaux, self.progression_event) # Configuration du tirage config = self.GetParent().config.get_options( tirages.TIRAGES.items()[ self.chx_algorithme.GetCurrentSelection()][0]) self._generateur.configurer(**config) # Démarrer le tirage self._generateur.start() self.verifier(None)
def alias_demarrer(self, _args_s=''): u""" Démarrer une nouvelle partie avec le tirage précédement fait. """ tirage = self.locals.get('tir') if not tirage: print u"Pas de tirage réalisé." return partie = tournoi.tournoi().ajout_partie() partie.demarrer( dict((i, tirage.tirage[i]) for i in range(len(tirage.tirage))), tirage.chapeaux) self.locals.pop('tir')
def alias_nouveau(self, _args_s=''): u""" Commencer un nouveau tournoi. options: <joueurs> : nombre de joueurs par équipes <manches> : nombre d'équipes par manche <points> : nombre de points par manche """ joueurs_par_equipe = question(u"Nombre de joueurs par équipe: ") if joueurs_par_equipe != '': self.config.set('TOURNOI', 'joueurs_par_equipe', str(int(float(joueurs_par_equipe)))) equipes_par_manche = question(u"Nombre d'équipes par manche: ") if equipes_par_manche != '': self.config.set('TOURNOI', 'equipes_par_manche', str(int(float(equipes_par_manche)))) points_par_manche = question(u"Points par manche: ") if points_par_manche != '': self.config.set('TOURNOI', 'points_par_manche', str(int(float(points_par_manche)))) equipes_par_manche = self.config.getint("TOURNOI", "equipes_par_manche") joueurs_par_equipe = self.config.getint("TOURNOI", "joueurs_par_equipe") points_par_manche = self.config.getint("TOURNOI", "points_par_manche") self.locals['trb'] = tournoi.nouveau_tournoi(equipes_par_manche, points_par_manche, joueurs_par_equipe) print tournoi.tournoi() print "NOTE: vous pouvez acceder au tournoi via la variable 'trb'"
def ajout_equipes(self, liste_equipes): selection = [ int(self.GetItemText(i)) for i in range(self.GetItemCount()) if self.IsChecked(i) ] self.DeleteAllItems() classement = {} avec_victoires = self.config.get_typed('TOURNOI', 'CLASSEMENT_VICTOIRES') avec_joker = self.config.get_typed('TOURNOI', 'CLASSEMENT_JOKER') avec_duree = self.config.get_typed('TOURNOI', 'CLASSEMENT_DUREE') classement.update(tournoi.tournoi().classement(avec_victoires, avec_joker, avec_duree)) for num in liste_equipes: equipe = tournoi.tournoi().equipe(int(num)) self.Append([ unicode(equipe.numero), u", ".join([unicode(joueur) for joueur in equipe.joueurs()]), unicode(equipe.victoires()), unicode(equipe.points()), unicode(equipe.chapeaux()), unicode(classement[equipe]) ]) # Cocher si l'équipe étaient cochées avant effacement if int(num) in selection: self.CheckItem(self.GetItemCount() - 1) self.SetColumnWidth(0, wx.LIST_AUTOSIZE) self.SetColumnWidth(1, wx.LIST_AUTOSIZE) self.SetColumnWidth(2, 70) self.SetColumnWidth(3, 70) self.SetColumnWidth(4, 70) self.SetColumnWidth(5, 70) self.Refresh()