Beispiel #1
0
 def mEditGameComment(self, *args):
     if self._cancelDrag(break_pause=False):
         return
     game, gi = self.game, self.game.gameinfo
     kw = {'game': gi.name, 'id': game.getGameNumber(format=1)}
     cc = _("Comments for %(game)s %(id)s:\n\n") % kw
     c = game.gsaveinfo.comment or cc
     d = EditTextDialog(game.top, _("Comments for %(id)s") % kw, text=c)
     if d.status == 0 and d.button == 0:
         text = d.text
         if text.strip() == cc.strip():
             game.gsaveinfo.comment = ""
         else:
             game.gsaveinfo.comment = d.text
             # save to file
             fn = os.path.join(self.app.dn.config, "comments.txt")
             fn = os.path.normpath(fn)
             if not text.endswith(os.linesep):
                 text += os.linesep
             enc = locale.getpreferredencoding()
             try:
                 open(fn, 'a').write(text.encode(enc, 'replace'))
             except Exception as err:
                 d = MfxExceptionDialog(
                     self.top, err, text=_("Error while writing to file"))
             else:
                 d = MfxMessageDialog(
                     self.top,
                     title=_("%s Info") % TITLE,
                     bitmap="info",
                     text=_("Comments were appended to\n\n%(filename)s") %
                     {'filename': fn})
     self._setCommentMenu(bool(game.gsaveinfo.comment))
Beispiel #2
0
 def _mStatsSave(self, player, filename, write_method):
     file = None
     if player is None:
         text = _("Demo statistics")
         filename = filename + "_demo"
     else:
         text = _("Your statistics")
     filename = os.path.join(self.app.dn.config, filename + ".txt")
     filename = os.path.normpath(filename)
     try:
         file = open(filename, "a")
         a = FileStatsFormatter(self.app, file)
         write_method(a, player)
     except EnvironmentError as ex:
         if file:
             file.close()
         MfxExceptionDialog(self.top,
                            ex,
                            text=_("Error while writing to file"))
     else:
         if file:
             file.close()
         MfxMessageDialog(self.top,
                          title=TITLE + _(" Info"),
                          bitmap="info",
                          text=text + _(" were appended to\n\n") + filename)
Beispiel #3
0
 def mEditGameComment(self, *args):
     if self._cancelDrag(break_pause=False): return
     game, gi = self.game, self.game.gameinfo
     t = " " + game.getGameNumber(format=1)
     cc = _("Comments for %s:\n\n") % (gi.name + t)
     c = game.gsaveinfo.comment or cc
     d = EditTextDialog(game.top, _("Comments for ") + t, text=c)
     if d.status == 0 and d.button == 0:
         text = d.text
         if text.strip() == cc.strip():
             game.gsaveinfo.comment = ""
         else:
             game.gsaveinfo.comment = d.text
             # save to file
             fn = os.path.join(self.app.dn.config, "comments.txt")
             fn = os.path.normpath(fn)
             if not text.endswith(os.linesep):
                 text += os.linesep
             enc = locale.getpreferredencoding()
             try:
                 fd = open(fn, 'a')
                 fd.write(text.encode(enc, 'replace'))
             except Exception, err:
                 d = MfxExceptionDialog(
                     self.top, err, text=_("Error while writing to file"))
             else:
                 if fd: fd.close()
                 d = MfxMessageDialog(
                     self.top,
                     title=TITLE + _(" Info"),
                     bitmap="info",
                     text=_("Comments were appended to\n\n") + fn)
Beispiel #4
0
 def _mStatsSave(self, player, filename, write_method):
     file = None
     if player is None:
         text = _("Demo statistics")
         filename = filename + "_demo"
     else:
         text = _("Your statistics")
     filename = os.path.join(self.app.dn.config, filename + ".txt")
     filename = os.path.normpath(filename)
     try:
         file = open(filename, "a")
         a = FileStatsFormatter(self.app, file)
         write_method(a, player)
     except EnvironmentError, ex:
         if file: file.close()
         d = MfxExceptionDialog(self.top,
                                ex,
                                text=_("Error while writing to file"))
Beispiel #5
0
 def _mStatsSave(self, player, filename, write_method):
     if player is None:
         text = _("Demo statistics were appended to\n\n%(filename)s")
         filename = filename + "_demo"
     else:
         text = _("Your statistics were appended to\n\n%(filename)s")
     filename = os.path.join(self.app.dn.config, filename + ".txt")
     filename = os.path.normpath(filename)
     try:
         a = FileStatsFormatter(self.app, open(filename, "a"))
         write_method(a, player)
     except EnvironmentError as ex:
         MfxExceptionDialog(self.top, ex,
                            text=_("Error while writing to file"))
     else:
         MfxMessageDialog(
             self.top, title=_("%s Info") % TITLE, bitmap="info",
             text=text % {'filename': filename})
Beispiel #6
0
 def loadCardset(self,
                 cs,
                 id=0,
                 update=7,
                 progress=None,
                 tocache=False,
                 noprogress=False):
     # print 'loadCardset', cs.ident
     r = 0
     if cs is None or cs.error:
         return 0
     if cs is self.cardset:
         if not tocache:
             self.updateCardset(id, update=update)
         return 1
     # cache carsets
     # self.cardsets_cache:
     #   key: Cardset.type
     #   value: (Cardset.ident, Images, SubsampledImages)
     c = self.cardsets_cache.get(cs.type)
     if c and c[0] == cs.ident:
         # print 'load from cache', c
         self.images, self.subsampled_images = c[1], c[2]
         if not tocache:
             self.updateCardset(id, update=update)
             if self.menubar is not None:
                 self.menubar.updateBackgroundImagesMenu()
         return 1
     #
     if progress is None and not noprogress:
         self.wm_save_state()
         self.wm_withdraw()
         title = _("Loading cardset %s...") % cs.name
         color = self.opt.colors['table']
         if self.tabletile_index > 0:
             color = "#008200"
         progress = PysolProgressBar(self,
                                     self.top,
                                     title=title,
                                     color=color,
                                     images=self.progress_images)
     images = Images(self.dataloader, cs)
     try:
         if not images.load(app=self, progress=progress):
             raise Exception("Invalid or damaged cardset")
         simages = SubsampledImages(images)
         if tocache:
             simages.setNegative(self.opt.negative_bottom)
         # The save cardsets option is deprecated, and its existence
         # directly conflicts with the ability to allow previews of
         # other cardset types.
         # if self.opt.save_cardsets:
         c = self.cardsets_cache.get(cs.type)
         if c:
             # c[1].destruct()
             destruct(c[1])
         self.cardsets_cache[cs.type] = (cs.ident, images, simages)
         if not tocache:
             # elif self.images is not None:
             #    # self.images.destruct()
             #    destruct(self.images)
             #
             if self.cardset:
                 if self.cardset.ident != cs.ident:
                     if self.cardset.type == cs.type:
                         # clear saved games geometry
                         self.opt.games_geometry = {}
             # update
             self.images = images
             self.subsampled_images = simages
             self.updateCardset(id, update=update)
         r = 1
     except (Exception, TclError, UnpicklingError) as ex:
         traceback.print_exc()
         cs.error = 1
         # restore settings
         self.nextgame.cardset = self.cardset
         if self.cardset:
             self.cardset_manager.setSelected(self.cardset.index)
         # images.destruct()
         destruct(images)
         MfxExceptionDialog(self.top,
                            ex,
                            title=_("Cardset load error"),
                            text=_("Error while loading cardset"))
     self.intro.progress = progress
     if r and not tocache and self.menubar is not None:
         self.menubar.updateBackgroundImagesMenu()
     return r
Beispiel #7
0
 def loadCardset(self, cs, id=0, update=7, progress=None):
     # print 'loadCardset', cs.ident
     r = 0
     if cs is None or cs.error:
         return 0
     if cs is self.cardset:
         self.updateCardset(id, update=update)
         return 1
     # cache carsets
     # self.cardsets_cache:
     #   key: Cardset.type
     #   value: (Cardset.ident, Images, SubsampledImages)
     c = self.cardsets_cache.get(cs.type)
     if c and c[0] == cs.ident:
         # print 'load from cache', c
         self.images, self.subsampled_images = c[1], c[2]
         self.updateCardset(id, update=update)
         if self.menubar is not None:
             self.menubar.updateBackgroundImagesMenu()
         return 1
     #
     if progress is None:
         self.wm_save_state()
         self.wm_withdraw()
         title = _("Loading %s %s...") % (CARDSET, cs.name)
         color = self.opt.colors['table']
         if self.tabletile_index > 0:
             color = "#008200"
         progress = PysolProgressBar(self,
                                     self.top,
                                     title=title,
                                     color=color,
                                     images=self.progress_images)
     images = Images(self.dataloader, cs)
     try:
         if not images.load(app=self, progress=progress):
             raise Exception("Invalid or damaged " + CARDSET)
         simages = SubsampledImages(images)
         if self.opt.save_cardsets:
             c = self.cardsets_cache.get(cs.type)
             if c:
                 # c[1].destruct()
                 destruct(c[1])
             self.cardsets_cache[cs.type] = (cs.ident, images, simages)
         elif self.images is not None:
             # self.images.destruct()
             destruct(self.images)
         #
         if self.cardset:
             if self.cardset.ident != cs.ident:
                 if self.cardset.type == cs.type:
                     # clear saved games geometry
                     self.opt.games_geometry = {}
         # update
         self.images = images
         self.subsampled_images = simages
         self.updateCardset(id, update=update)
         r = 1
     except (Exception, TclError, UnpicklingError) as ex:
         traceback.print_exc()
         cs.error = 1
         # restore settings
         self.nextgame.cardset = self.cardset
         if self.cardset:
             self.cardset_manager.setSelected(self.cardset.index)
         # images.destruct()
         destruct(images)
         MfxExceptionDialog(self.top,
                            ex,
                            title=CARDSET + _(" load error"),
                            text=_("Error while loading ") + CARDSET)
     self.intro.progress = progress
     if r and self.menubar is not None:
         self.menubar.updateBackgroundImagesMenu()
     return r