Exemplo n.º 1
0
 def OnRemoveFromAll(self, event):
     if self.selected_all_item:
         self.all_list.DeleteItem(
             self.all_list.FindItem(0, self.selected_all_item))
         res = playerdb.remove_player(self.selected_all_item)
         if res == 0:
             self.selected_all_item = None
             self.init_friend_bozo_list()
             playerdb.save_db()
     else:
         wx.Bell()
Exemplo n.º 2
0
 def OnAddBozo(self, event):
     name = wx.GetTextFromUser(message='Enter username:'******'Add bozo',
                               parent=self)
     if name:
         res = playerdb.add_player(name, PLAYER_STATUS_BOZO)
         if res == 1:
             self.remove_player(name, self.friends_list)
         if res == 0 or res == 1:
             self.insert_player(name, self.bozo_list, 1)
         playerdb.save_db()
Exemplo n.º 3
0
 def OnAddToAll(self, event):
     name = wx.GetTextFromUser(message='Enter username:'******'Add player',
                               parent=self)
     if name:
         if playerdb.get_player(name):
             return
         res = playerdb.add_player(name, PLAYER_STATUS_NEUTRAL)
         if res == 0:
             self.all_list.InsertImageStringItem(0, name, 2)
             self.all_list.SetItemData(0, calc_item_data(name))
             self.all_list.SortItems(sort_fun)
         if res == 0 or res == 1:
             self.init_friend_bozo_list()
         playerdb.save_db()
Exemplo n.º 4
0
 def OnRemoveBozo(self, event):
     name = self.bozo_list.GetStringSelection()
     if name:
         self.remove_player(name, self.bozo_list)
         p = playerdb.get_player(name)
         if p:
             p.set_status(PLAYER_STATUS_NEUTRAL)
             self.all_list.InsertImageStringItem(0, name, 3)
             self.all_list.SetItemData(0, calc_item_data(name))
             self.all_list.SortItems(sort_fun)
         else:
             playerdb.remove_player(name)
         playerdb.save_db()
     else:
         wx.Bell()
Exemplo n.º 5
0
    def OpenPlayerNotesDialog(self, name):
        p = playerdb.get_player(name)
        if not p:
            return

        if not USE_RESOURCE:
            dlg = self.res.LoadDialog(self, 'playerdb_player_dlg')
        else:
            dlg = wxPython.xrc.wxXmlResource_Get().LoadDialog(
                self, 'playerdb_player_dlg')
        grid = gamesgrid.GamesListGrid(dlg)
        if not USE_RESOURCE:
            self.res.AttachUnknownControl('games_grid', grid)
        else:
            wxPython.xrc.wxXmlResource_Get().AttachUnknownControl(
                'games_grid', grid)
        dlg.SetTitle(name)

        # Set comment
        note_edit = wxPython.xrc.XRCCTRL(dlg, 'note_edit', wx.TextCtrl)
        note_edit.SetValue(playerdb.get_player_comment(name))

        # Set status
        status_box = wxPython.xrc.XRCCTRL(dlg, 'status', wx.RadioBox)
        # Remember current status
        status = p.get_status()
        # Radiobox has another order than the friend/bozo constants
        if status == PLAYER_STATUS_FRIEND:
            status_box.SetSelection(0)
        elif status == PLAYER_STATUS_BOZO:
            status_box.SetSelection(2)

        # Set custom flags
        cf_panel = wxPython.xrc.XRCCTRL(dlg, 'custom_flags_panel', wx.Panel)
        cf_cb = []
        box = wx.StaticBox(cf_panel, -1, 'Flags')
        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
        for i in range(0, NUMBER_CUSTOM_FLAGS):
            if self.flag_categories[i][0]:
                cb = wx.CheckBox(cf_panel, 500 + i, self.flag_categories[i][1])
                cf_cb.append((cb, i))
                cb.SetValue(p.get_custom_flag(i))
                if os.name == 'nt':
                    sizer.Add(cb, 0, wx.ALL, 5)
                else:
                    sizer.Add(cb, 0, 0)
        cf_panel.SetSizer(sizer)
        # I really hate those OS checks, but the GUI layout messes up otherwise
        if os.name == 'nt':
            sizer.SetSizeHints(cf_panel)

        # Load games list
        games = find_by_player(name)
        if games:
            games = sort_games(games, 1)  # Sort by white rank
            grid.display_games(games)

        # Create graph and statistics
        plot_canvas = RankPlotCanvas(name, dlg)
        if not USE_RESOURCE:
            self.res.AttachUnknownControl('plot_canvas', plot_canvas)
        else:
            wxPython.xrc.wxXmlResource_Get().AttachUnknownControl(
                'plot_canvas', plot_canvas)
        wx.EVT_CHECKBOX(dlg, wxPython.xrc.XRCID('games_all'),
                        plot_canvas.OnAllGames)
        wx.EVT_CHECKBOX(dlg, wxPython.xrc.XRCID('games_white'),
                        plot_canvas.OnWhiteGames)
        wx.EVT_CHECKBOX(dlg, wxPython.xrc.XRCID('games_black'),
                        plot_canvas.OnBlackGames)
        plot_canvas.display_graph()
        stats = plotter.create_statistics()
        if not stats:
            stats = (0, 0, 0, 0, 0, 0)
        wxPython.xrc.XRCCTRL(dlg, 'wins',
                             wx.StaticText).SetLabel(format_align(stats[0]))
        wxPython.xrc.XRCCTRL(dlg, 'losses',
                             wx.StaticText).SetLabel(format_align(stats[1]))
        wxPython.xrc.XRCCTRL(dlg, 'wins_white',
                             wx.StaticText).SetLabel(format_align(stats[2]))
        wxPython.xrc.XRCCTRL(dlg, 'losses_white',
                             wx.StaticText).SetLabel(format_align(stats[3]))
        wxPython.xrc.XRCCTRL(dlg, 'wins_black',
                             wx.StaticText).SetLabel(format_align(stats[4]))
        wxPython.xrc.XRCCTRL(dlg, 'losses_black',
                             wx.StaticText).SetLabel(format_align(stats[5]))

        dlg.SetSize(wx.Size(380, 320))
        if dlg.ShowModal() == wx.ID_OK:
            # Transfer comment
            playerdb.set_player_comment(name, note_edit.GetValue())

            # Status
            sel = status_box.GetSelection()
            if sel == 0:
                new_status = PLAYER_STATUS_FRIEND
            elif sel == 2:
                new_status = PLAYER_STATUS_BOZO
            else:
                new_status = PLAYER_STATUS_NEUTRAL
            if new_status != status:
                p.set_status(new_status)
                self.init_lists()

            # Transfer custom flags
            for (cb, i) in cf_cb:
                p.set_custom_flag(i, cb.IsChecked())
            del cf_cb

            playerdb.save_db()
            if self.flag_filter:
                self.init_all_list()
Exemplo n.º 6
0
 def OnClose(self, event):
     playerdb.save_db()
     self.Destroy()