1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00
This commit is contained in:
Shlomi Fish 2017-04-17 14:04:04 +03:00
parent a8984338bf
commit 40dcd6633c
2 changed files with 56 additions and 63 deletions

View file

@ -23,24 +23,32 @@
# imports # imports
import os, sys, time import sys
import gtk, gobject, pango import time
import gtk
import gobject
import pango
import gtk.glade import gtk.glade
# PySol imports # PySol imports
from pysollib.mygettext import _, n_ from pysollib.mygettext import _
from pysollib.mfxutil import format_time from pysollib.mfxutil import format_time
from pysollib.settings import TOP_TITLE, TITLE from pysollib.settings import TITLE
from pysollib.stats import PysolStatsFormatter from pysollib.stats import PysolStatsFormatter
# Toolkit imports # Toolkit imports
from tkwidget import MfxDialog, MfxMessageDialog from tkwidget import MfxMessageDialog
if sys.version_info > (3,):
def cmp(a, b):
return ((b > a)-(a > b))
# ************************************************************************ # ************************************************************************
# * # *
# ************************************************************************ # ************************************************************************
class StatsFormatter(PysolStatsFormatter): class StatsFormatter(PysolStatsFormatter):
def __init__(self, app, store): def __init__(self, app, store):
@ -123,13 +131,10 @@ class Game_StatsDialog:
# #
games = app.gdb.getGamesIdSortedByName() games = app.gdb.getGamesIdSortedByName()
n = 0 n = 0
current = 0
for id in games: for id in games:
won, lost = self.app.stats.getStats(self.player, id) won, lost = self.app.stats.getStats(self.player, id)
if won+lost > 0 or id == gameid: if won+lost > 0 or id == gameid:
gi = app.gdb.get(id) gi = app.gdb.get(id)
if id == gameid:
current = n
self.games[n] = gi self.games[n] = gi
self.games_id.append(id) self.games_id.append(id)
n += 1 n += 1
@ -137,7 +142,7 @@ class Game_StatsDialog:
self.widgets_tree = gtk.glade.XML(glade_file) self.widgets_tree = gtk.glade.XML(glade_file)
# #
table = self.widgets_tree.get_widget('current_game_table') table = self.widgets_tree.get_widget('current_game_table')
combo = self._createGameCombo(table, 1, 0, self._currentComboChanged) self._createGameCombo(table, 1, 0, self._currentComboChanged)
# total # total
self._createText('total') self._createText('total')
drawing = self.widgets_tree.get_widget('total_drawingarea') drawing = self.widgets_tree.get_widget('total_drawingarea')
@ -148,7 +153,7 @@ class Game_StatsDialog:
drawing.connect('expose_event', self._drawingExposeEvent, 'session') drawing.connect('expose_event', self._drawingExposeEvent, 'session')
# top 10 # top 10
table = self.widgets_tree.get_widget('top_10_table') table = self.widgets_tree.get_widget('top_10_table')
combo = self._createGameCombo(table, 1, 0, self._top10ComboChanged) self._createGameCombo(table, 1, 0, self._top10ComboChanged)
self._createTop() self._createTop()
self._updateTop(gameid) self._updateTop(gameid)
# all games stat # all games stat
@ -175,7 +180,6 @@ class Game_StatsDialog:
self.status = -1 self.status = -1
dialog.destroy() dialog.destroy()
def _translateLabels(self): def _translateLabels(self):
# mnemonic # mnemonic
for n in ( for n in (
@ -219,7 +223,6 @@ class Game_StatsDialog:
s = _(w.get_label()) s = _(w.get_label())
w.set_markup('<b>%s</b>' % s) w.set_markup('<b>%s</b>' % s)
def _createGameCombo(self, table, x, y, callback): def _createGameCombo(self, table, x, y, callback):
combo = gtk.combo_box_new_text() combo = gtk.combo_box_new_text()
combo.show() combo.show()
@ -239,7 +242,6 @@ class Game_StatsDialog:
combo.set_active(current) combo.set_active(current)
combo.connect('changed', callback) # self._comboChanged) combo.connect('changed', callback) # self._comboChanged)
def _currentComboChanged(self, w): def _currentComboChanged(self, w):
gi = self.games[w.get_active()] gi = self.games[w.get_active()]
self.gameid = gi.id self.gameid = gi.id
@ -250,17 +252,16 @@ class Game_StatsDialog:
drawing = self.widgets_tree.get_widget('session_drawingarea') drawing = self.widgets_tree.get_widget('session_drawingarea')
self._createChart(drawing, 'session') self._createChart(drawing, 'session')
def _top10ComboChanged(self, w): def _top10ComboChanged(self, w):
gi = self.games[w.get_active()] gi = self.games[w.get_active()]
self._updateTop(gi.id) self._updateTop(gi.id)
def _createText(self, name): def _createText(self, name):
if name == 'total': if name == 'total':
won, lost = self.app.stats.getStats(self.player, self.gameid) won, lost = self.app.stats.getStats(self.player, self.gameid)
else: else:
won, lost = self.app.stats.getSessionStats(self.player, self.gameid) won, lost = self.app.stats.getSessionStats(
self.player, self.gameid)
pwon, plost = self._getPwon(won, lost) pwon, plost = self._getPwon(won, lost)
label = self.widgets_tree.get_widget(name+'_num_won_label') label = self.widgets_tree.get_widget(name+'_num_won_label')
label.set_text(str(won)) label.set_text(str(won))
@ -273,16 +274,15 @@ class Game_StatsDialog:
label = self.widgets_tree.get_widget(name+'_num_total_label') label = self.widgets_tree.get_widget(name+'_num_total_label')
label.set_text(str(won+lost)) label.set_text(str(won+lost))
def _drawingExposeEvent(self, drawing, e, frame): def _drawingExposeEvent(self, drawing, e, frame):
self._createChart(drawing, frame) self._createChart(drawing, frame)
def _createChart(self, drawing, frame): def _createChart(self, drawing, frame):
if frame == 'total': if frame == 'total':
won, lost = self.app.stats.getStats(self.player, self.gameid) won, lost = self.app.stats.getStats(self.player, self.gameid)
else: else:
won, lost = self.app.stats.getSessionStats(self.player, self.gameid) won, lost = self.app.stats.getSessionStats(
self.player, self.gameid)
pwon, plost = self._getPwon(won, lost) pwon, plost = self._getPwon(won, lost)
s, ewon, elost = 0, int(360.0*pwon), int(360.0*plost) s, ewon, elost = 0, int(360.0*pwon), int(360.0*plost)
@ -294,7 +294,7 @@ class Game_StatsDialog:
alloc = drawing.allocation alloc = drawing.allocation
width, height = alloc.width, alloc.height width, height = alloc.width, alloc.height
w, h = 90, 50 w, h = 90, 50
##x, y = 10, 10 # x, y = 10, 10
x, y = (width-w)/2, (height-h)/2 x, y = (width-w)/2, (height-h)/2
dy = 9 dy = 9
y = y-dy/2 y = y-dy/2
@ -331,21 +331,21 @@ class Game_StatsDialog:
tw, th = ext[1][2]/pango.SCALE, ext[1][3]/pango.SCALE tw, th = ext[1][2]/pango.SCALE, ext[1][3]/pango.SCALE
win.draw_layout(gc, x+w/2-tw/2, y+h/2-th/2, pangolayout) win.draw_layout(gc, x+w/2-tw/2, y+h/2-th/2, pangolayout)
def _createTop(self): def _createTop(self):
for n in ('top_10_time_treeview', for n in ('top_10_time_treeview',
'top_10_moves_treeview', 'top_10_moves_treeview',
'top_10_total_moves_treeview'): 'top_10_total_moves_treeview'):
self._createTopList(n) self._createTopList(n)
def _updateTop(self, gameid): def _updateTop(self, gameid):
if (self.player not in self.app.stats.games_stats or s = self.app.stats.games_stats
gameid not in self.app.stats.games_stats[self.player] or cond = (self.player not in s or
not self.app.stats.games_stats[self.player][gameid].time_result.top): gameid not in s[self.player] or
not s[self.player][gameid].time_result.top)
if cond:
return return
s = self.app.stats.games_stats[self.player][gameid] s = s[self.player][gameid]
label = self.widgets_tree.get_widget('playing_time_minimum_label') label = self.widgets_tree.get_widget('playing_time_minimum_label')
label.set_text(format_time(s.time_result.min)) label.set_text(format_time(s.time_result.min))
@ -371,10 +371,10 @@ class Game_StatsDialog:
for n, ss in ( for n, ss in (
('top_10_time_treeview', s.time_result.top), ('top_10_time_treeview', s.time_result.top),
('top_10_moves_treeview', s.moves_result.top), ('top_10_moves_treeview', s.moves_result.top),
('top_10_total_moves_treeview', s.total_moves_result.top)): ('top_10_total_moves_treeview', s.total_moves_result.top)
):
self._updateTopList(n, ss) self._updateTopList(n, ss)
def _createTopList(self, tv_name): def _createTopList(self, tv_name):
treeview = self.widgets_tree.get_widget(tv_name) treeview = self.widgets_tree.get_widget(tv_name)
store = gtk.ListStore(gobject.TYPE_INT, # N store = gtk.ListStore(gobject.TYPE_INT, # N
@ -393,11 +393,10 @@ class Game_StatsDialog:
): ):
column = gtk.TreeViewColumn(label, gtk.CellRendererText(), text=n) column = gtk.TreeViewColumn(label, gtk.CellRendererText(), text=n)
column.set_resizable(True) column.set_resizable(True)
##column.set_sort_column_id(n) # column.set_sort_column_id(n)
treeview.append_column(column) treeview.append_column(column)
n += 1 n += 1
def _updateTopList(self, tv_name, top): def _updateTopList(self, tv_name, top):
treeview = self.widgets_tree.get_widget(tv_name) treeview = self.widgets_tree.get_widget(tv_name)
store = treeview.get_model() store = treeview.get_model()
@ -416,7 +415,6 @@ class Game_StatsDialog:
store.set(iter, 0, row, 1, i.game_number, 2, t, 3, r) store.set(iter, 0, row, 1, i.game_number, 2, t, 3, r)
row += 1 row += 1
def _createStatsList(self): def _createStatsList(self):
treeview = self.widgets_tree.get_widget('all_games_treeview') treeview = self.widgets_tree.get_widget('all_games_treeview')
n = 0 n = 0
@ -453,7 +451,6 @@ class Game_StatsDialog:
treeview.set_rules_hint(True) treeview.set_rules_hint(True)
return store return store
def _createLogList(self, name): def _createLogList(self, name):
# #
treeview = self.widgets_tree.get_widget(name) treeview = self.widgets_tree.get_widget(name)
@ -481,7 +478,6 @@ class Game_StatsDialog:
treeview.set_rules_hint(True) treeview.set_rules_hint(True)
return store return store
def _getPwon(self, won, lost): def _getPwon(self, won, lost):
pwon, plost = 0.0, 0.0 pwon, plost = 0.0, 0.0
if won + lost > 0: if won + lost > 0:
@ -490,7 +486,6 @@ class Game_StatsDialog:
plost = 1.0 - pwon plost = 1.0 - pwon
return pwon, plost return pwon, plost
def _cmpPlayingTime(self, store, iter1, iter2): def _cmpPlayingTime(self, store, iter1, iter2):
val1 = store.get_value(iter1, 4) val1 = store.get_value(iter1, 4)
val2 = store.get_value(iter2, 4) val2 = store.get_value(iter2, 4)
@ -533,7 +528,8 @@ class Status_StatsDialog(MfxMessageDialog): #MfxDialog
n = n + len(s.cards) n = n + len(s.cards)
w1 = (_('Highlight piles: ') + str(stats.highlight_piles) + '\n' + w1 = (_('Highlight piles: ') + str(stats.highlight_piles) + '\n' +
_('Highlight cards: ') + str(stats.highlight_cards) + '\n' + _('Highlight cards: ') + str(stats.highlight_cards) + '\n' +
_('Highlight same rank: ') + str(stats.highlight_samerank) + '\n') _('Highlight same rank: ') +
str(stats.highlight_samerank) + '\n')
if game.s.talon: if game.s.talon:
if game.gameinfo.redeals != 0: if game.gameinfo.redeals != 0:
w2 = w2 + _('\nRedeals: ') + str(game.s.talon.round - 1) w2 = w2 + _('\nRedeals: ') + str(game.s.talon.round - 1)
@ -571,6 +567,3 @@ class Status_StatsDialog(MfxMessageDialog): #MfxDialog
class ProgressionDialog: class ProgressionDialog:
# FIXME # FIXME
pass pass

View file

@ -10,7 +10,7 @@ use String::ShellQuote qw/ shell_quote /;
# my $cmd = shell_quote( 'flake8', '.' ); # my $cmd = shell_quote( 'flake8', '.' );
my $cmd = shell_quote( 'flake8', my $cmd = shell_quote( 'flake8',
grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/*.py ./pysollib/[cm]*/*.py ./pysollib/pysolgtk/{[a-s]*,t[a-i]*,tk[a-h]*}.py') ); grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/*.py ./pysollib/[cm]*/*.py ./pysollib/pysolgtk/{[a-s]*,t[a-i]*,tk[a-s]*}.py') );
# TEST # TEST
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." ); eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );