#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2012 S. Daniel Francis # # This program 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. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import logging logger = logging.getLogger('canvas') logger.debug('start canvas') import math from gi.repository import Gtk from gi.repository import Gdk from number_box import SudokuNumberBox logger.debug('Import all') class Canvas(Gtk.AspectFrame): def __init__(self, toolbar_box, activity): Gtk.AspectFrame.__init__(self) self.group_size = 9 self.set_shadow_type(Gtk.ShadowType.NONE) self.activity = activity self.table = Gtk.Table(rows = self.group_size, columns = self.group_size, homogeneous = True) self.__entries__ = {} for x in range(self.group_size): for y in range(self.group_size): e = SudokuNumberBox(upper = self.group_size) e.x = x e.y = y self.table.attach(e, x, x+1, y, y+1, ) self.__entries__[(x, y)] = e self.eb = Gtk.EventBox() self.eb.add(self.table) self.add(self.eb) self.table.set_row_spacings(1) self.table.set_col_spacings(1) box_side = int(math.sqrt(self.group_size)) for n in range(1, box_side): self.table.set_row_spacing(box_side*n-1, 2) self.table.set_col_spacing(box_side*n-1, 2) self.table.set_border_width(2) self.eb.show_all() for e in self.__entries__.values(): e.show() self.set_parent_for(activity) self.set_bg_color('black') def set_parent_for(self, parent): for entry in self.__entries__.values(): entry.set_parent_win(parent) def set_bg_color (self, color): try: if type(color) == str: color = Gdk.color_parse(color) color = Gdk.RGBA(color.red/65535.0, color.green/65535.0, color.blue/65535.0) else: color = Gdk.RGBA(*color) except: logging.critical("set_bg_color handed Bad color: %s" % color, exc_info=True) return self.eb.override_color(Gtk.StateFlags.NORMAL, color) self.eb.override_background_color(Gtk.StateFlags.NORMAL, color) self.table.override_color(Gtk.StateFlags.NORMAL, color) self.table.override_background_color(Gtk.StateFlags.NORMAL, color) for e in self.__entries__.values(): e.override_background_color(Gtk.StateFlags.NORMAL, color) def write_file(self, path): pass def read_file(self, path): pass def new(self): pass