def __init__(self, gamelist): self.gamelist = gamelist self.filtered = False self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) selection = self.gamelist.get_selection() self.conid = selection.connect_after('changed', self.on_selection_changed) self.gamelist.preview_cid = self.conid # buttons toolbar = Gtk.Toolbar() firstButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_PREVIOUS) toolbar.insert(firstButton, -1) prevButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_REWIND) toolbar.insert(prevButton, -1) nextButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_FORWARD) toolbar.insert(nextButton, -1) lastButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_NEXT) toolbar.insert(lastButton, -1) filterButton = Gtk.ToggleToolButton(Gtk.STOCK_FIND) toolbar.insert(filterButton, -1) firstButton.connect("clicked", self.on_first_clicked) prevButton.connect("clicked", self.on_prev_clicked) nextButton.connect("clicked", self.on_next_clicked) lastButton.connect("clicked", self.on_last_clicked) filterButton.connect("clicked", self.on_filter_clicked) tool_box = Gtk.Box() tool_box.pack_start(toolbar, False, False, 0) # board self.boardview = BoardView(preview=True) self.boardview.set_size_request(170, 170) self.gamemodel = self.boardview.model self.boardview.got_started = True self.boardview.auto_update_shown = False self.box.pack_start(self.boardview, True, True, 0) self.box.pack_start(tool_box, False, True, 0) self.box.show_all() # force first game to show self.gamelist.set_cursor(0)
def __init__ (self, widgets, fcbutton, opendialog, enddir): self.position = 0 self.gameno = 0 self.filename = None self.chessfile = None self.widgets = widgets self.fcbutton = fcbutton self.enddir = enddir # Treeview self.list = self.widgets["gamesTree"] self.list.set_model(gtk.ListStore(str, str,str,str)) # GTK_SELECTION_BROWSE - exactly one item is always selected self.list.get_selection().set_mode(gtk.SELECTION_BROWSE) self.list.get_selection().connect_after( 'changed', self.on_selection_changed) # Add columns renderer = gtk.CellRendererText() renderer.set_property("xalign",0) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=0)) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=1)) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=2)) renderer = gtk.CellRendererText() renderer.set_property("xalign",1) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=3)) # Connect buttons self.widgets["first_button"].connect("clicked", self.on_first_button) self.widgets["back_button"].connect("clicked", self.on_back_button) self.widgets["forward_button"].connect("clicked", self.on_forward_button) self.widgets["last_button"].connect("clicked", self.on_last_button) # Add the board self.boardview = BoardView(preview=True) self.boardview.set_size_request(170,170) self.widgets["boardPreviewDock"].add(self.boardview) self.boardview.show() self.gamemodel = self.boardview.model self.boardview.gotStarted = True # Connect label showing possition self.boardview.connect('shown_changed', self.shown_changed) self.boardview.autoUpdateShown = False # Add the filechooserbutton self.widgets["fileChooserDock"].add(fcbutton) # Connect doubleclicking a file to on_file_activated fcbutton.connect("file-activated", self.on_file_activated) # Connect the openbutton in the dialog to on_file_activated openbut = opendialog.get_children()[0].get_children()[1].get_children()[0] openbut.connect("clicked", self.on_file_activated) # The first time the button is opened, the player has just opened # his/her file, before we connected the dialog. if self._retrieve_filename(): self.on_file_activated(fcbutton)
def save(file, model, position=None): """Export the current position into a .png file""" boardview = BoardView(model) padding = int(SQUARE / 4) if boardview.show_cords else 0 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, SQUARE * 8 + padding * 2, SQUARE * 8 + padding * 2) context = cairo.Context(surface) boardview.shown = position boardview.square = 0 + padding, 0 + padding, SQUARE * 8, SQUARE boardview.drawBoard(context, None) boardview.drawPieces(context, None) if boardview.show_cords: boardview.drawCords(context, None) surface.write_to_png(file.name)
def __init__(self): GObject.GObject.__init__(self) self.view = BoardView() self.add(self.view) self.view.showEnpassant = True self.connect("button_press_event", self.button_press) self.connect("button_release_event", self.button_release) self.add_events(Gdk.EventMask.LEAVE_NOTIFY_MASK | Gdk.EventMask.POINTER_MOTION_MASK) self.connect("motion_notify_event", self.motion_notify) self.connect("leave_notify_event", self.leave_notify) self.brush = None
def __init__(self, widgets, fcbutton, opendialog, enddir): self.position = 0 self.gameno = 0 self.filename = None self.chessfile = None self.widgets = widgets self.fcbutton = fcbutton self.opendialog = opendialog self.enddir = enddir # Treeview self.list = self.widgets["gamesTree"] self.list.set_model(Gtk.ListStore(str, str, str, str)) # GTK_SELECTION_BROWSE - exactly one item is always selected self.list.get_selection().set_mode(Gtk.SelectionMode.BROWSE) self.list.get_selection().connect_after('changed', self.onSelectionChanged) # Add columns renderer = Gtk.CellRendererText() renderer.set_property("xalign", 0) self.list.append_column(Gtk.TreeViewColumn(None, renderer, text=0)) self.list.append_column(Gtk.TreeViewColumn(None, renderer, text=1)) self.list.append_column(Gtk.TreeViewColumn(None, renderer, text=2)) renderer = Gtk.CellRendererText() renderer.set_property("xalign", 1) self.list.append_column(Gtk.TreeViewColumn(None, renderer, text=3)) # Connect buttons self.widgets["first_button"].connect("clicked", self.onFirstButton) self.widgets["back_button"].connect("clicked", self.onBackButton) self.widgets["forward_button"].connect("clicked", self.onForwardButton) self.widgets["last_button"].connect("clicked", self.onLastButton) # Add the board self.boardview = BoardView(preview=True) self.boardview.set_size_request(170, 170) self.widgets["boardPreviewDock"].add(self.boardview) self.boardview.show() self.gamemodel = self.boardview.model self.boardview.got_started = True # Connect label showing possition self.boardview.connect('shownChanged', self.shownChanged) self.boardview.auto_update_shown = False # Add the filechooserbutton self.widgets["fileChooserDock"].add(fcbutton) def onFileSet(*args): fcbutton = args[0] self.onFileActivated(fcbutton.get_filename()) fcbutton.connect("file-set", onFileSet) # This is needed for game files specified on the command line to work fcbutton.connect("file-activated", onFileSet) def onResponse(fcdialog, resp): if resp == Gtk.ResponseType.ACCEPT: self.onFileActivated(opendialog.get_filename()) opendialog.connect("response", onResponse)
class BoardPreview: def __init__(self, widgets, fcbutton, opendialog, enddir): self.position = 0 self.gameno = 0 self.filename = None self.chessfile = None self.widgets = widgets self.fcbutton = fcbutton self.opendialog = opendialog self.enddir = enddir # Treeview self.list = self.widgets["gamesTree"] self.list.set_model(Gtk.ListStore(str, str, str, str)) # GTK_SELECTION_BROWSE - exactly one item is always selected self.list.get_selection().set_mode(Gtk.SelectionMode.BROWSE) self.list.get_selection().connect_after('changed', self.onSelectionChanged) # Add columns renderer = Gtk.CellRendererText() renderer.set_property("xalign", 0) self.list.append_column(Gtk.TreeViewColumn(None, renderer, text=0)) self.list.append_column(Gtk.TreeViewColumn(None, renderer, text=1)) self.list.append_column(Gtk.TreeViewColumn(None, renderer, text=2)) renderer = Gtk.CellRendererText() renderer.set_property("xalign", 1) self.list.append_column(Gtk.TreeViewColumn(None, renderer, text=3)) # Connect buttons self.widgets["first_button"].connect("clicked", self.onFirstButton) self.widgets["back_button"].connect("clicked", self.onBackButton) self.widgets["forward_button"].connect("clicked", self.onForwardButton) self.widgets["last_button"].connect("clicked", self.onLastButton) # Add the board self.boardview = BoardView(preview=True) self.boardview.set_size_request(170, 170) self.widgets["boardPreviewDock"].add(self.boardview) self.boardview.show() self.gamemodel = self.boardview.model self.boardview.got_started = True # Connect label showing possition self.boardview.connect('shownChanged', self.shownChanged) self.boardview.auto_update_shown = False # Add the filechooserbutton self.widgets["fileChooserDock"].add(fcbutton) def onFileSet(*args): fcbutton = args[0] self.onFileActivated(fcbutton.get_filename()) fcbutton.connect("file-set", onFileSet) # This is needed for game files specified on the command line to work fcbutton.connect("file-activated", onFileSet) def onResponse(fcdialog, resp): if resp == Gtk.ResponseType.ACCEPT: self.onFileActivated(opendialog.get_filename()) opendialog.connect("response", onResponse) def onFileActivated(self, filename): # filename is None if a non-existent file is passed as command line argument if filename is None: return self.set_filename(filename) if os.path.isdir(filename): return ending = filename[filename.rfind(".") + 1:] loader = self.enddir[ending] self.chessfile = chessfile = loader.load(protoopen(filename)) self.list.get_model().clear() for gameno in range(len(chessfile)): names = chessfile.get_player_names(gameno) names = [ellipsize(name, 9) for name in names] result = reprResult[chessfile.get_result(gameno)] result = result.replace("1/2", "½") self.list.get_model().append(["%s." % (gameno + 1)] + names + [result]) self.last_sel = -1 # The row that was last selected self.list.set_cursor((0, )) self.widgets["whitePlayerCombobox"].set_active(0) self.widgets["blackPlayerCombobox"].set_active(0) def onSelectionChanged(self, selection): iter = selection.get_selected()[1] if iter == None: self.gamemodel.boards = [Board(FEN_EMPTY)] del self.gamemodel.moves[:] self.boardview.shown = 0 self.boardview.redrawCanvas() return path = self.list.get_model().get_path(iter) indices = path.get_indices() sel = indices[0] if sel == self.last_sel: return self.last_sel = sel self.boardview.animation_lock.acquire() try: try: self.chessfile.loadToModel(sel, -1, self.gamemodel) except LoadingError as err: dialogue = Gtk.MessageDialog(type=Gtk.MessageType.WARNING, \ buttons=Gtk.ButtonsType.OK, \ message_format=err.args[0]) dialogue.format_secondary_text(err.args[1]) dialogue.connect("response", lambda dialogue, a: dialogue.hide()) dialogue.show() if self.gamemodel.variant.variant == NORMALCHESS: radiobutton = self.widgets["playNormalRadio"] radiobutton.set_active(True) else: radiobutton = self.widgets["playVariant1Radio"] radiobutton.set_active(True) conf.set("ngvariant1", self.gamemodel.variant.variant) radiobutton.set_label("%s" % self.gamemodel.variant.name) if self.gamemodel.tags.get("TimeControl"): radiobutton = self.widgets["blitzRadio"] radiobutton.set_active(True) conf.set("ngblitz min", self.gamemodel.timemodel.minutes) conf.set("ngblitz gain", self.gamemodel.timemodel.gain) else: radiobutton = self.widgets["notimeRadio"] radiobutton.set_active(True) self.boardview.lastMove = None self.boardview._shown = self.gamemodel.lowply last = self.gamemodel.ply finally: self.boardview.animation_lock.release() self.boardview.redrawCanvas() self.boardview.shown = last self.shownChanged(self.boardview, last) def onFirstButton(self, button): self.boardview.showFirst() def onBackButton(self, button): self.boardview.showPrev() def onForwardButton(self, button): self.boardview.showNext() def onLastButton(self, button): self.boardview.showLast() def shownChanged(self, board_view, shown): pos = "%d." % (shown / 2 + 1) if shown & 1: pos += ".." self.widgets["posLabel"].set_text(pos) def set_filename(self, filename): as_path = splitUri(filename)[-1] if os.path.isfile(as_path): self.fcbutton.show() #if filename != self._retrieve_filename(): # self.fcbutton.set_filename(os.path.abspath(as_path)) self.fcbutton.set_filename(os.path.abspath(as_path)) else: self.fcbutton.set_uri("") self.fcbutton.hide() self.filename = filename def get_filename(self): return self.filename def isEmpty(self): return not self.chessfile or not len(self.chessfile) def getPosition(self): return self.boardview.shown def getGameno(self): iter = self.list.get_selection().get_selected()[1] if iter == None: return -1 path = self.list.get_model().get_path(iter) indices = path.get_indices() return indices[0]
class BoardPreview: def __init__ (self, widgets, fcbutton, opendialog, enddir): self.position = 0 self.gameno = 0 self.filename = None self.chessfile = None self.widgets = widgets self.fcbutton = fcbutton self.enddir = enddir # Treeview self.list = self.widgets["gamesTree"] self.list.set_model(gtk.ListStore(str,str,str)) # GTK_SELECTION_BROWSE - exactly one item is always selected self.list.get_selection().set_mode(gtk.SELECTION_BROWSE) self.list.get_selection().connect_after( 'changed', self.on_selection_changed) # Add columns renderer = gtk.CellRendererText() renderer.set_property("xalign",0) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=0)) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=1)) renderer = gtk.CellRendererText() renderer.set_property("xalign",1) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=2)) # Connect buttons self.widgets["first_button"].connect("clicked", self.on_first_button) self.widgets["back_button"].connect("clicked", self.on_back_button) self.widgets["forward_button"].connect("clicked", self.on_forward_button) self.widgets["last_button"].connect("clicked", self.on_last_button) # Add the board self.boardview = BoardView() self.boardview.set_size_request(170,170) self.widgets["boardPreviewDock"].add(self.boardview) self.boardview.show() self.gamemodel = self.boardview.model self.boardview.gotStarted = True # Connect label showing possition self.boardview.connect('shown_changed', self.shown_changed) self.boardview.autoUpdateShown = False # Add the filechooserbutton self.widgets["fileChooserDock"].add(fcbutton) # Connect doubleclicking a file to on_file_activated fcbutton.connect("file-activated", self.on_file_activated) # Connect the openbutton in the dialog to on_file_activated openbut = opendialog.get_children()[0].get_children()[1].get_children()[0] openbut.connect("clicked", self.on_file_activated) # The first time the button is opened, the player has just opened # his/her file, before we connected the dialog. if self._retrieve_filename(): self.on_file_activated(fcbutton) def on_file_activated (self, *args): filename = self._retrieve_filename() if filename: if filename == self.get_filename(): return self.set_filename(filename) elif self.get_filename(): filename = self.get_filename() else: return if os.path.isdir(filename): return ending = filename[filename.rfind(".")+1:] loader = self.enddir[ending] self.chessfile = chessfile = loader.load(protoopen(filename)) self.list.get_model().clear() for gameno in range(len(chessfile)): names = chessfile.get_player_names (gameno) names = [ellipsize (name, 9) for name in names] result = reprResult[chessfile.get_result (gameno)] result = result.replace("1/2","½") self.list.get_model().append (names+[result]) self.lastSel = -1 # The row that was last selected self.list.set_cursor((0,)) def on_selection_changed (self, selection): iter = selection.get_selected()[1] if iter == None: self.gamemodel.boards = [Board(FEN_EMPTY)] del self.gamemodel.moves[:] self.boardview.shown = 0 self.boardview.redraw_canvas() return sel = self.list.get_model().get_path(iter)[0] if sel == self.lastSel: return self.lastSel = sel self.boardview.animationLock.acquire() try: try: self.chessfile.loadToModel(sel, -1, self.gamemodel) except LoadingError, e: #TODO: Pressent this a little nicer print e self.boardview.lastMove = None self.boardview._shown = self.gamemodel.lowply last = self.gamemodel.ply finally:
def save(file, model, position=None, flip=False): """Export the current position into a .png file""" show_cords = conf.get("showCords") boardview = BoardView(model) padding = int(SQUARE / 4) if show_cords else 0 width = SQUARE * 8 + padding * 2 height = SQUARE * 8 + padding * 2 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) context = cairo.Context(surface) boardview.shown = position boardview.square = 0 + padding, 0 + padding, SQUARE * 8, SQUARE if flip: boardview._rotation = math.pi boardview.matrix = cairo.Matrix.init_rotate(math.pi) boardview.matrix, boardview.invmatrix = matrixAround( boardview.matrix, width / 2.0, height / 2.0) context.transform(boardview.matrix) boardview.drawBoard(context, None) boardview.drawPieces(context, None) if show_cords: boardview.drawCords(context, None) surface.write_to_png(file.name)
class PreviewPanel: def __init__(self, gamelist): self.gamelist = gamelist self.filtered = False self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) selection = self.gamelist.get_selection() self.conid = selection.connect_after('changed', self.on_selection_changed) self.gamelist.preview_cid = self.conid # buttons toolbar = Gtk.Toolbar() firstButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_PREVIOUS) toolbar.insert(firstButton, -1) prevButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_REWIND) toolbar.insert(prevButton, -1) nextButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_FORWARD) toolbar.insert(nextButton, -1) lastButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_NEXT) toolbar.insert(lastButton, -1) filterButton = Gtk.ToggleToolButton(Gtk.STOCK_FIND) toolbar.insert(filterButton, -1) firstButton.connect("clicked", self.on_first_clicked) prevButton.connect("clicked", self.on_prev_clicked) nextButton.connect("clicked", self.on_next_clicked) lastButton.connect("clicked", self.on_last_clicked) filterButton.connect("clicked", self.on_filter_clicked) tool_box = Gtk.Box() tool_box.pack_start(toolbar, False, False, 0) # board self.boardview = BoardView(preview=True) self.boardview.set_size_request(170, 170) self.gamemodel = self.boardview.model self.boardview.got_started = True self.boardview.auto_update_shown = False self.box.pack_start(self.boardview, True, True, 0) self.box.pack_start(tool_box, False, True, 0) self.box.show_all() # force first game to show self.gamelist.set_cursor(0) def on_selection_changed(self, selection): model, iter = selection.get_selected() if iter is None: self.gamemodel.boards = [Board(FEN_EMPTY)] del self.gamemodel.moves[:] self.boardview.shown = 0 self.boardview.redrawCanvas() return path = self.gamelist.get_model().get_path(iter) gameno = self.gamelist.get_gameno(path) self.boardview.animation_lock.acquire() try: try: self.gamelist.chessfile.loadToModel(gameno, -1, self.gamemodel) except LoadingError as err: dialogue = Gtk.MessageDialog(type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK, message_format=err.args[0]) if len(err.args) > 1: dialogue.format_secondary_text(err.args[1]) dialogue.connect("response", lambda dialogue, a: dialogue.hide()) dialogue.show() self.boardview.lastMove = None self.boardview._shown = self.gamemodel.lowply finally: self.boardview.animation_lock.release() self.boardview.redrawCanvas() self.boardview.shown = self.gamelist.ply def on_first_clicked(self, button): self.boardview.showFirst() self.update_gamelist() def on_prev_clicked(self, button): self.boardview.showPrev() self.update_gamelist() def on_next_clicked(self, button): self.boardview.showNext() self.update_gamelist() def on_last_clicked(self, button): self.boardview.showLast() self.update_gamelist() def on_filter_clicked(self, button): self.filtered = button.get_active() self.update_gamelist() def update_gamelist(self): if not self.filtered: return self.board = self.gamemodel.boards[self.boardview.shown].board bb = self.board.friends[0] | self.board.friends[1] self.gamelist.ply = self.board.plyCount self.gamelist.chessfile.build_where_bitboards(self.board.plyCount, bb) self.gamelist.offset = 0 self.gamelist.chessfile.build_query() self.gamelist.load_games()
def __init__(self, widgets, fcbutton, opendialog, enddir): self.position = 0 self.gameno = 0 self.filename = None self.chessfile = None self.widgets = widgets self.fcbutton = fcbutton self.enddir = enddir # Treeview self.list = self.widgets["gamesTree"] self.list.set_model(gtk.ListStore(str, str, str)) # GTK_SELECTION_BROWSE - exactly one item is always selected self.list.get_selection().set_mode(gtk.SELECTION_BROWSE) self.list.get_selection().connect_after('changed', self.on_selection_changed) # Add columns renderer = gtk.CellRendererText() renderer.set_property("xalign", 0) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=0)) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=1)) renderer = gtk.CellRendererText() renderer.set_property("xalign", 1) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=2)) # Connect buttons self.widgets["first_button"].connect("clicked", self.on_first_button) self.widgets["back_button"].connect("clicked", self.on_back_button) self.widgets["forward_button"].connect("clicked", self.on_forward_button) self.widgets["last_button"].connect("clicked", self.on_last_button) # Add the board self.boardview = BoardView() self.boardview.set_size_request(170, 170) self.widgets["boardPreviewDock"].add(self.boardview) self.boardview.show() self.gamemodel = self.boardview.model self.boardview.gotStarted = True # Connect label showing possition self.boardview.connect('shown_changed', self.shown_changed) self.boardview.autoUpdateShown = False # Add the filechooserbutton self.widgets["fileChooserDock"].add(fcbutton) # Connect doubleclicking a file to on_file_activated fcbutton.connect("file-activated", self.on_file_activated) # Connect the openbutton in the dialog to on_file_activated openbut = opendialog.get_children()[0].get_children()[1].get_children( )[0] openbut.connect("clicked", self.on_file_activated) # The first time the button is opened, the player has just opened # his/her file, before we connected the dialog. if self._retrieve_filename(): self.on_file_activated(fcbutton)
class BoardPreview: def __init__(self, widgets, fcbutton, opendialog, enddir): self.position = 0 self.gameno = 0 self.filename = None self.chessfile = None self.widgets = widgets self.fcbutton = fcbutton self.enddir = enddir # Treeview self.list = self.widgets["gamesTree"] self.list.set_model(gtk.ListStore(str, str, str)) # GTK_SELECTION_BROWSE - exactly one item is always selected self.list.get_selection().set_mode(gtk.SELECTION_BROWSE) self.list.get_selection().connect_after('changed', self.on_selection_changed) # Add columns renderer = gtk.CellRendererText() renderer.set_property("xalign", 0) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=0)) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=1)) renderer = gtk.CellRendererText() renderer.set_property("xalign", 1) self.list.append_column(gtk.TreeViewColumn(None, renderer, text=2)) # Connect buttons self.widgets["first_button"].connect("clicked", self.on_first_button) self.widgets["back_button"].connect("clicked", self.on_back_button) self.widgets["forward_button"].connect("clicked", self.on_forward_button) self.widgets["last_button"].connect("clicked", self.on_last_button) # Add the board self.boardview = BoardView() self.boardview.set_size_request(170, 170) self.widgets["boardPreviewDock"].add(self.boardview) self.boardview.show() self.gamemodel = self.boardview.model self.boardview.gotStarted = True # Connect label showing possition self.boardview.connect('shown_changed', self.shown_changed) self.boardview.autoUpdateShown = False # Add the filechooserbutton self.widgets["fileChooserDock"].add(fcbutton) # Connect doubleclicking a file to on_file_activated fcbutton.connect("file-activated", self.on_file_activated) # Connect the openbutton in the dialog to on_file_activated openbut = opendialog.get_children()[0].get_children()[1].get_children( )[0] openbut.connect("clicked", self.on_file_activated) # The first time the button is opened, the player has just opened # his/her file, before we connected the dialog. if self._retrieve_filename(): self.on_file_activated(fcbutton) def on_file_activated(self, *args): filename = self._retrieve_filename() if filename: if filename == self.get_filename(): return self.set_filename(filename) elif self.get_filename(): filename = self.get_filename() else: return if os.path.isdir(filename): return ending = filename[filename.rfind(".") + 1:] loader = self.enddir[ending] self.chessfile = chessfile = loader.load(protoopen(filename)) self.list.get_model().clear() for gameno in range(len(chessfile)): names = chessfile.get_player_names(gameno) names = [ellipsize(name, 9) for name in names] result = reprResult[chessfile.get_result(gameno)] result = result.replace("1/2", "½") self.list.get_model().append(names + [result]) self.lastSel = -1 # The row that was last selected self.list.set_cursor((0, )) def on_selection_changed(self, selection): iter = selection.get_selected()[1] if iter == None: self.gamemodel.boards = [Board(FEN_EMPTY)] del self.gamemodel.moves[:] self.boardview.shown = 0 self.boardview.redraw_canvas() return sel = self.list.get_model().get_path(iter)[0] if sel == self.lastSel: return self.lastSel = sel self.boardview.animationLock.acquire() try: try: self.chessfile.loadToModel(sel, -1, self.gamemodel) except LoadingError, e: #TODO: Pressent this a little nicer print e self.boardview.lastMove = None self.boardview._shown = self.gamemodel.lowply last = self.gamemodel.ply finally: