Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/canvas.py
blob: 46b8e38d0f7ee56a66826a5203a20fad5cf51a88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2012 S. Daniel Francis <francis@sugarlabs.org>
#
# 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_bg_color('#FFFFFF')

    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