X-Git-Url: https://harishankar.org/repos/?p=getaclue.git;a=blobdiff_plain;f=player_mainwindow.py;h=6ba91371cef65dd14317a6e0c9543f94ef87fe01;hp=8234893d0a6923de42a5e4cf55bb6ba377286cbf;hb=ed2b699c63f1dd0005366ce7fb84f9c39a7bd27a;hpb=8e96d1e907d35e47615ff1fe610bca7c88f392cd diff --git a/player_mainwindow.py b/player_mainwindow.py index 8234893..6ba9137 100644 --- a/player_mainwindow.py +++ b/player_mainwindow.py @@ -4,6 +4,8 @@ # Main window class for GetAClue player +import sys +import os.path import cPickle import pygtk pygtk.require20 () @@ -16,6 +18,19 @@ class MainWindow: # typing mode constants ACROSS = 1 DOWN = 2 + # license text to be displayed in the about dialog + LICENSE_TEXT = """GetAClue is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +GetAClue is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GetAClue. If not, see .""" # quit verification def verify_quit (self): @@ -161,6 +176,10 @@ class MainWindow: puzgrid.queue_draw () dlg.destroy () + # callback for menu help about activated event + def on_about_activate (self, menu_item): + # display the about dialog + self.about () # function to set the selected row/col based on the number clicked # on the clues list and also set the typing mode @@ -180,9 +199,6 @@ class MainWindow: # update the puzzle grid puzgrid = self.ui.get_object ("puzzlegrid") - # set focus to the puzzle grid - self.window.set_focus (puzgrid) - puzgrid.queue_draw () # callback for tree view "across" being activated @@ -195,6 +211,10 @@ class MainWindow: self.set_selection_of_num (anum) + # focus on the drawing area + puzgrid = self.ui.get_object ("puzzlegrid") + self.window.set_focus (puzgrid) + return False # callback for tree view "down" being activated @@ -207,6 +227,10 @@ class MainWindow: self.set_selection_of_num (dnum, False) + # focus on the drawing area + puzgrid = self.ui.get_object ("puzzlegrid") + self.window.set_focus (puzgrid) + # moving the current selection in grid by one up or down def move_selection_updown (self, step): # increase or reduce the row by step until an occupied grid is found @@ -243,7 +267,7 @@ class MainWindow: if self.puzzle: # set a guess only if not revealed if self.puzzle.data[self.selected_row][self.selected_col].revealed is False: - self.puzzle.data[self.selected_row][self.selected_col].guess = guess_char.upper () + self.puzzle.data[self.selected_row][self.selected_col].guess = guess_char # across mode typing if self.typing_mode == self.ACROSS: # move by one character across but only if there is no block @@ -305,52 +329,65 @@ class MainWindow: return False - # callback for puzzle grid key release event + # callback for main window key release event def on_puzzlegrid_key_press_event (self, drawarea, event): if self.puzzle: key = gtk.gdk.keyval_name (event.keyval).lower () - if event.state == gtk.gdk.SHIFT_MASK and key == "up": + if key == "up": # reduce the row by 1 until you find an occupied grid and not a # black block self.move_selection_updown (-1) self.typing_mode = self.DOWN drawarea.queue_draw () - elif event.state == gtk.gdk.SHIFT_MASK and key == "down": + return True + elif key == "down": # increase the row by 1 until you find an occupied grid and not a # black block self.move_selection_updown (1) self.typing_mode = self.DOWN drawarea.queue_draw () - elif event.state == gtk.gdk.SHIFT_MASK and key == "right": + return True + elif key == "right": # increase the column by 1 until you find an occupied grid and not # a black block self.move_selection_across (1) self.typing_mode = self.ACROSS drawarea.queue_draw () - elif event.state == gtk.gdk.SHIFT_MASK and key == "left": + return True + elif key == "left": # decrease the column by 1 until you find an occupied grid and not # a black block self.move_selection_across (-1) self.typing_mode = self.ACROSS drawarea.queue_draw () + return True # if it is A-Z or a-z then elif len (key) == 1 and key.isalpha (): - self.set_guess (key) + guess_char = key.upper () + self.set_guess (guess_char) drawarea.queue_draw () + return True # if it is the delete key then delete character at selected row/col - elif key == "delete" or key == "space": + elif key == "delete": self.puzzle.data[self.selected_row][self.selected_col].guess = None drawarea.queue_draw () + return True + # if the key is space key then delete character and move across or + # down one step depending on the mode + elif key == "space": + self.set_guess (None) + drawarea.queue_draw () + return True # if it is backspace key then delete character at previous row/col # depending on the input mode. If across editing mode, then delete # at previous column else at previous row elif key == "backspace": self.delete_prev_guess () drawarea.queue_draw () + return True return False - # puzzle grid focus in event def on_puzzlegrid_focus_out_event (self, drawarea, event): if self.puzzle: @@ -508,10 +545,28 @@ class MainWindow: dlg.run () dlg.destroy () + # about dialog + def about (self): + dlg = gtk.AboutDialog () + dlg.set_name ("GetAClue Player") + dlg.set_copyright ("Copyright 2010 V.Harishankar") + dlg.set_website ("http://harishankar.org/software") + dlg.set_authors (("Harishankar",)) + dlg.set_logo (self.window.get_icon()) + dlg.set_license (self.LICENSE_TEXT) + dlg.set_comments ("Create and play Crossword puzzles") + dlg.run () + dlg.destroy () + def __init__ (self, file_to_play = None): # load the user interface self.ui = gtk.Builder () - self.ui.add_from_file ("playerwindow.glade") + + # Path for the interface file - change this if you are distributing + # the application and put the icon, interface file in a different + # location!! + gladepath = os.path.join (sys.path[0], "playerwindow.glade") + self.ui.add_from_file (gladepath) # window object self.window = self.ui.get_object ("mainwindow")