From: Harishankar Date: Mon, 6 Dec 2010 16:30:51 +0000 (+0530) Subject: Implemented drawing the grid in player application X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=4faccf7bc1bf7591ae83feafcd7039bb36cf9d54;p=getaclue.git Implemented drawing the grid in player application Implemented the drawing functionality in gtk player application --- diff --git a/player_mainwindow.py b/player_mainwindow.py index 58de825..00be083 100644 --- a/player_mainwindow.py +++ b/player_mainwindow.py @@ -4,14 +4,76 @@ # Main window class for GetAClue player +import cPickle import pygtk pygtk.require20 () import gtk +import pango +import crosswordpuzzle class MainWindow: def gtk_main_quit (self, *args): gtk.main_quit () + # drawing for puzzle grid + def on_puzzlegrid_expose_event (self, drawarea, event): + # if puzzle is loaded + if self.puzzle: + # size the area + drawarea.set_size_request (self.puzzle.cols*30+2, self.puzzle.rows*30+2) + + # set background color to white + col = drawarea.window.get_colormap ().alloc_color (gtk.gdk.Color ("white")) + drawarea.window.set_background (col) + + #numlayout = gtk.PrintContext().create_pango_layout () + #numlayout.set_font_description (pango.FontDescription ("Sans 8")) + ctx = drawarea.window.cairo_create () + ctx.set_line_width (1.5) + + for row in range (self.puzzle.rows): + for col in range (self.puzzle.cols): + # if the area is not occupied + if (self.puzzle.data[row][col].occupied_across is False and + self.puzzle.data[row][col].occupied_down is False): + ctx.rectangle (col*30, row*30, 30, 30) + ctx.fill () + else: + ctx.rectangle (col*30, row*30, 30, 30) + ctx.stroke () + # if numbered + if self.puzzle.data[row][col].numbered <> 0: + ctx.select_font_face ("Sans 7") + ctx.move_to (col*30+2, row*30+10) + ctx.show_text (str(self.puzzle.data[row][col].numbered)) + + return False + + def load_clues (self): + # get the clues list store objects + across = self.ui.get_object ("clues_across") + down = self.ui.get_object ("clues_down") + across.clear () + down.clear () + + # if puzzle is loaded + if self.puzzle: + clues_across = self.puzzle.get_clues_across () + clues_down = self.puzzle.get_clues_down () + # insert the numbers and the clues for across + for word, clue in clues_across: + across.append ([str(self.puzzle.data[word[1]][word[2]].numbered), + clue]) + # insert the numbers and the clues for down + for word, clue in clues_down: + down.append ([ str(self.puzzle.data[word[1]][word[2]].numbered), + clue]) + + def open_file (self, file): + self.puzzle = cPickle.load (open (file, "rb")) + self.window.set_title ("GetAClue player - " + file) + self.load_clues () + def __init__ (self, file_to_play = None): # load the user interface self.ui = gtk.Builder () @@ -41,9 +103,12 @@ class MainWindow: # connect the signals self.ui.connect_signals (self) - # set the window title + # set the puzzle to None + self.puzzle = None + + # open the file if it is set if file_to_play: - self.window.set_title ("GetAClue player - " + file_to_play) + self.open_file (file_to_play) gtk.main () diff --git a/playerwindow.glade b/playerwindow.glade index a52e5ef..9441946 100644 --- a/playerwindow.glade +++ b/playerwindow.glade @@ -23,6 +23,8 @@ 360 True GetAClue player + 640 + 480 @@ -127,10 +129,25 @@ True - - 120 - 120 + True + True + automatic + automatic + + + True + queue + + + 120 + 120 + True + + + + + 0 @@ -140,21 +157,32 @@ True True + 180 - - 80 - 150 + True True - clues_across + automatic + automatic - - Number - - - - - Clue Across + + 80 + 150 + True + True + clues_across + False + 0 + + + Number + + + + + Clue Across + + @@ -164,20 +192,30 @@ - - 80 - 150 + True True - clues_down + automatic + automatic - - Number - - - - - Clue Down + + 80 + 150 + True + True + clues_down + False + 0 + + + Number + + + + + Clue Down + +