Logo Search packages:      
Sourcecode: uligo version File versions  Download package

def uligo::App::__init__ (   self,
  master 
)

Initialize the GUI, some variables, etc. 

Definition at line 1526 of file uligo.py.

01526                               :
        """ Initialize the GUI, some variables, etc. """

        # The main window
        
        self.master = master
        self.frame = Frame(master)
        self.frame.pack(expand=YES, fill=BOTH)

        leftFrame = Frame(self.frame)
        rightFrame = Frame(self.frame)
        middleFrame = Frame(self.frame, width=10)
        leftFrame.pack(side=LEFT)
        middleFrame.pack(side=LEFT)
        rightFrame.pack(side=RIGHT, expand=YES, fill=BOTH)

        # The board and the clock

        self.board = Board(rightFrame, 19, (30,25))
        self.clockFrame = Frame(leftFrame)
        self.clock = clock.Clock(self.clockFrame, 150, self.timeover)

        self.options = BunchTkVar()
        self.options.maxTime = self.clock.maxTime
        self.options.use3Dstones = self.board.use3Dstones
        self.options.problemModeVar = IntVar()
        self.options.problemModeVar.set(1)

        # ---- 'guess next move' mode stuff --------------------------------------------------------

        self.gameInfoCanv = Canvas(self.clockFrame, width=100, height=100, highlightthickness=0)

        self.guessModeButtonFrame = Frame(self.clockFrame)
        self.guessModeCanvas = Canvas(self.clockFrame, height=80, width=150)
        self.options.modeVarGM = StringVar()
        self.options.modeVarGM.set('BW')
        Label(self.guessModeButtonFrame, text='Guess ').pack(side=LEFT, expand=NO)
        self.BbuttonGM = Radiobutton(self.guessModeButtonFrame, text='B', variable=self.options.modeVarGM,
                                     indicatoron=0,
                                     command=self.changeModeGM, value='B')
        self.WbuttonGM = Radiobutton(self.guessModeButtonFrame, text='W', variable=self.options.modeVarGM,
                                     indicatoron=0,
                                     command=self.changeModeGM, value='W')
        self.BWbuttonGM= Radiobutton(self.guessModeButtonFrame, text='BW', variable=self.options.modeVarGM,
                                     indicatoron=0,
                                     command=self.changeModeGM, value='BW')
        for b in [self.BbuttonGM, self.WbuttonGM, self.BWbuttonGM]: b.pack(side=LEFT, expand=NO)
        
        # ------------------------------------------------------------------------------------------
        # The menus

        menu = Menu(master)
        master.config(menu=menu)

        filemenu = Menu(menu)
        menu.add_cascade(label='File', underline=0, menu=filemenu)
        filemenu.add_command(label='Open problem collection ...', underline=0, command=self.readProblemColl)
        filemenu.add_command(label='Replay game', underline=0, command=self.replayGame)
        filemenu.add_separator()
        filemenu.add_command(label='Clear Statistics', underline=0, command=self.clearStatistics)
        filemenu.add_command(label='Statistics', underline=0, command=self.printStatistics)
        filemenu.add_separator()
        filemenu.add_command(label='Exit', underline =1, command=self.quit)
        self.optionsmenu = Menu(menu)
        menu.add_cascade(label='Options', underline=0, menu=self.optionsmenu)

        self.options.fuzzy = self.board.fuzzy    # make 'save options' easy
        self.optionsmenu.add_checkbutton(label='Fuzzy stone placement', underline = 0, 
                                         variable=self.options.fuzzy, command=self.board.fuzzyStones)

        self.options.shadedStoneVar = self.board.shadedStoneVar
        self.options.shadedStoneVar.set(1)
        self.optionsmenu.add_checkbutton(label='Shaded stone mouse pointer', underline = 0, 
                                         variable=self.options.shadedStoneVar)

        self.options.allowInvertColorVar = IntVar()
        self.options.allowInvertColorVar.set(1)
        self.optionsmenu.add_checkbutton(label='Allow color switch', underline = 7, 
                                         variable=self.options.allowInvertColorVar)

        self.options.allowRotatingVar = IntVar()
        self.options.allowRotatingVar.set(1)
        self.optionsmenu.add_checkbutton(label='Allow mirroring/rotating', underline = 6,
                                         variable=self.options.allowRotatingVar)

        self.options.animateSolVar = IntVar()
        self.options.animateSolVar.set(1)
        animSolMenu = Menu(self.optionsmenu)
        self.optionsmenu.add_cascade(label='Show solution mode', underline = 7, menu=animSolMenu)
        animSolMenu.add_radiobutton(label='animate', variable = self.options.animateSolVar, value = 1)
        animSolMenu.add_radiobutton(label='navigate', variable = self.options.animateSolVar, value = 0)

        self.options.replaySpeedVar = IntVar()
        self.options.replaySpeedVar.set(2)
        replaySp = Menu(self.optionsmenu)
        self.optionsmenu.add_cascade(label='Replay speed', underline = 0, menu=replaySp)
        replaySp.add_radiobutton(label='very fast', variable=self.options.replaySpeedVar, value=0)
        replaySp.add_radiobutton(label='fast', variable=self.options.replaySpeedVar, value=1)
        replaySp.add_radiobutton(label='medium', variable=self.options.replaySpeedVar, value=2)
        replaySp.add_radiobutton(label='slow', variable=self.options.replaySpeedVar, value=4)

        self.optionsmenu.add_command(label='Change clock settings', underline=7, 
                                     command=self.clock.changeMaxtime)

        wrongmenu = Menu(self.optionsmenu)
        self.optionsmenu.add_cascade(label='Wrong variations', menu=wrongmenu)
        self.options.wrongVar = IntVar()
        self.options.wrongVar.set(1)
        wrongmenu.add_radiobutton(label='Show WRONG at the end of variation',
                                         variable=self.options.wrongVar, value=0)
        wrongmenu.add_radiobutton(label='Show WRONG when entering variation',
                                         variable=self.options.wrongVar, value=1)
        wrongmenu.add_radiobutton(label='Do not descend into wrong variations',
                                         variable=self.options.wrongVar, value=2)

        self.optionsmenu.add_command(label='Random/sequential order mode', underline=2,
                                     state=DISABLED)
        self.options.modeVar = IntVar()
        self.options.modeVar.set(0)

        self.optionsmenu.add_checkbutton(label='Use 3D stones', variable=self.options.use3Dstones,
                                         command=self.board.resize)

        self.helpmenu = Menu(menu, name='help')
        menu.add_cascade(label='Help', underline=0, menu=self.helpmenu)

        self.helpmenu.add_command(label='About ...', underline=0, command=self.helpAbout)
        self.helpmenu.add_command(label='Documentation', underline=0, command=self.helpDoc)
        self.helpmenu.add_command(label='License', underline=0, command=self.helpLicense)

        # The buttons

        bframe = Frame(leftFrame)
        bframe.pack(side=TOP)

        self.backButton = Button(bframe, text='Back', fg='blue', command=self.backProblem,
                                 underline=0)
        self.restartButton = Button(bframe, text='Re', fg='blue', command=self.restartProblem,
                                 underline=0)
        self.nextButton = Button(bframe, text='Next', fg='blue', command=self.nextProblem,
                                 underline = 0)
        self.frame.bind('<n>', lambda e, s=self.nextButton: s.invoke())
        self.frame.bind('<q>', lambda e, self=self: self.quit())
        
        self.whoseTurnCanv = Canvas(leftFrame, height = 180, width = 130, highlightthickness=0)
        self.whoseTurnID = 0

        self.statusbar = StatusBar(leftFrame)

        b1frame = Frame(leftFrame)
        b1frame.pack(side=TOP)

        self.showSolVar = IntVar()
        self.showSolutionButton = Checkbutton(b1frame, text='Show solution', fg='blue',
                                              underline=0,
                                              indicatoron=0, variable=self.showSolVar, command=self.showSolution)
        self.frame.bind('<s>', lambda e, s=self.showSolutionButton: s.invoke())

        self.hintButton = Button(b1frame, text='Hint', command=self.giveHint)

        b2frame = Frame(leftFrame)
        b2frame.pack(side=TOP)

        self.undoButton = Button(b2frame, text='Undo', fg='blue', command=self.undo2,
                                 underline=0)
        self.frame.bind('<u>', lambda e, s=self.undoButton: s.invoke())

        self.tryVarVar = IntVar()
        self.tryVarButton = Checkbutton(b2frame, text='Try variation', fg='blue', 
                                        indicatoron=0, variable=self.tryVarVar, command=self.tryVariation)
        self.frame.bind('<t>', lambda e, s=self.tryVarButton: s.invoke())

        self.pbmName = StringVar()
        self.pbmNameLabel = Label(leftFrame, height=1, width=15, relief=SUNKEN, justify=LEFT,
                                  textvariable=self.pbmName)

        self.comments = ScrolledText(rightFrame, height = 5, width = 70, wrap=WORD, 
                              relief=SUNKEN, state = DISABLED)

        self.uligopath = sys.path[0]     # the path where uligo.py, board.py, clock.py, Sgflib,
                                         # uligo.doc and uligo.def reside (if uligo is installed
                                         # system-wide under Unix, each user may additionally
                                         # have his own uligo.def in $HOME/.uligo

        self.sgfpath = os.path.join(self.uligopath,'sgf') # default path for sgf files, may be overridden
                                                          # in uligo.def
        self.datpath = ''                  # default prefix to get the path for .dat files from sgfpath
                                           # (if sgf's and dat's are in the same directory, this is '',
                                           # if dat's are in  $HOME/.uligo (under Unix), this should
                                           # be '/home/username/.uligo'
        self.optionspath = self.uligopath  # default path for .opt and (individual) .def files
        self.currentFile = ''              # default sgf file


        # try to load button images

        self.tkImages = []
        try:
            for button, imageFile in [(self.backButton, 'left'), (self.restartButton, 'reload'),
                                      (self.nextButton, 'right'), (self.hintButton, 'hint'),
                                      (self.showSolutionButton, 'showsol'),
                                      (self.tryVarButton, 'tryvar'), (self.undoButton, 'undo'),
                                      (self.BbuttonGM, 'b'), (self.WbuttonGM, 'w'), (self.BWbuttonGM, 'bw')]:
                im = PhotoImage(file = os.path.join(self.uligopath, 'gifs', imageFile+'.gif'))
                button.config(image=im)
                self.tkImages.append(im)
        except (TclError, IOError): pass

        try:
            im = PhotoImage(file = os.path.join(self.uligopath, 'gifs', 'bgd.gif'))
            self.guessModeCanvas.create_image(75,40, image=im)
            self.tkImages.append(im)
        except (TclError, IOError): pass

        try:
            self.BsTurn = PhotoImage(file = os.path.join(self.uligopath, 'gifs', 'BsTurn.gif'))
            self.WsTurn = PhotoImage(file = os.path.join(self.uligopath, 'gifs', 'WsTurn.gif'))
        except (TclError, IOError):
            self.BsTurn = None
            self.WsTurn = None

        # pack everything

        self.backButton.pack(side=LEFT, expand=YES, fill=BOTH)
        self.restartButton.pack(side=LEFT, expand=YES, fill=BOTH)                         
        self.nextButton.pack(side=LEFT, expand=YES, fill=BOTH)
        self.hintButton.pack(side=LEFT, expand=YES, fill=BOTH)
        self.showSolutionButton.pack(expand=YES, fill=BOTH)
        self.undoButton.pack(side=LEFT, expand=YES, fill=BOTH)
        self.tryVarButton.pack(expand=YES, fill=BOTH)

        emptySpace = Frame(leftFrame, height=40)
        emptySpace.pack(expand=YES, fill=BOTH, side=BOTTOM)

        self.statusbar.pack(expand=YES, fill=BOTH, side=BOTTOM)
        self.pbmNameLabel.pack(expand=NO, fill=X, side=BOTTOM)

        emptySpace = Frame(leftFrame, height=10)
        emptySpace.pack(expand=YES, fill=BOTH, side=BOTTOM)

        self.clockFrame.pack(expand=YES, fill=X, side=BOTTOM)
        self.clock.pack(expand=NO, side=BOTTOM)
        self.whoseTurnCanv.pack(expand=YES, fill=BOTH)
        self.comments.pack(expand=YES, fill=BOTH, side=BOTTOM)
        self.board.pack(expand=YES, fill=BOTH)

        # The statistics window (initially withdrawn)

        self.statisticsWindow = Toplevel()
        self.statisticsWindow.withdraw()
        self.statisticsWindow.title('Statistics')
        self.statisticsText = StringVar()
        Label(self.statisticsWindow, height=10, width=50, justify=LEFT, font = ('Courier', 11),
               textvariable=self.statisticsText).pack()
        self.statisticsWindow.protocol('WM_DELETE_WINDOW', self.statisticsWindow.withdraw)        

        # load options, and some initialization
 
        self.pbms = []
        self.pbmRec = None

        self.disableButtons()
        self.board.update_idletasks()

        # read the uligo.def file (default problem collection)

        try:
            f = open(os.path.join(self.uligopath,'uligo.def'))
            s = split(f.read(),'\n')
            f.close()
        except IOError:
            pass
        else:
            if s[0]=='uligo03':      # otherwise this is an old .def file which should be ignored
                counter = 1
                while 1:
                    line = s[counter]
                    counter = counter + 1
                    if line and line[0] == 'i':            # refer to individual def-file
                        l = line[2:]
                        self.optionspath = os.path.join(os.getenv('HOME',l),'.uligo')
                        self.datpath = self.optionspath
                        
                        if not os.path.exists(self.optionspath):
                            os.mkdir(self.optionspath)
                        try:
                            f1 = open(os.path.join(self.optionspath, 'uligo.def'))
                            s1 = split(f1.read(),'\n')
                            for l1 in s1: s.append(l1)
                        except IOError:
                            pass
                    elif line and line[0] == 'd':          # new datpath
                        s1 = split(line)
                        if len(s1)>1: self.datpath = line[2:]
                        else: self.datpath = ''
                    elif line and line[0] == 's':          # new sgfpath
                        self.sgfpath = line[2:]
                    elif line and line[0] == 'f':          # default sgf file
                        self.currentFile = line[2:]
                    if counter >= len(s): break
                    
        self.loadOptions()
        master.deiconify()
        self.cursor = None

        # display the logo
        
        currentTime = time.time()
        self.board.update()
        
        try:
            self.logo = PhotoImage(file=os.path.join(self.uligopath,'gifs/logo.gif'))
            s = 2 * self.board.canvasSize[0] + 18 * self.board.canvasSize[1]  # size of canvas in pixel
            im = self.board.create_image(max(0,(s-400)/2),max(0,(s-190)/2),
                                         image=self.logo, tags='logo', anchor=NW)
            self.board.tkraise(im)
            self.board.update_idletasks()
        except TclError:
            pass
                
        
        if self.options.problemModeVar.get():
            if self.currentFile: self.readProblemColl(self.sgfpath, self.currentFile)
        else:
            if self.currentFile: self.replayGame(self.sgfpath, self.currentFile, 1)

        # and remove the logo ...
        
        if time.time()-currentTime < 1:
            time.sleep(1 - time.time() + currentTime) # show logo for at least 1 second
        self.board.delete('logo')

# ---------------------------------------------------------------------------------------

root = Tk()


Generated by  Doxygen 1.6.0   Back to index