summaryrefslogtreecommitdiff
path: root/plugins/python/welcome/panel.py
blob: a577c8c6acd2678ba10d4656324f02dd11204c65 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/python
# -*- coding: utf-8 -*-

from welcome.binary import NewBinary
from welcome.version import VersionChecker
from welcome.website import WebInvitation
from welcome.board import SmallBoard
from welcome.tip import TipOfTheDay
from gi.repository import GObject, Gtk, Gdk
from pychrysalide.gui.panels import PanelItem


class WelcomePanel(PanelItem):
    """Display a welcome panel if nothing is open in the main part of the editor."""


    def __init__(self):
        """Initialize the Python instance of the panel."""

        content = self._build_panel_content()

        super(WelcomePanel, self).__init__(PanelItem.PIP_SINGLETON, 'Welcome', 'First commands', \
                                           content, False, 'N')


    def _build_panel_content(self):
        """Build content for the welcome panel."""

        self._area = None

        # Constitution du support principal

        support = Gtk.Grid()

        support.props.halign = Gtk.Align.CENTER
        support.props.valign = Gtk.Align.CENTER
        support.props.margin = 20

        support.set_column_homogeneous(True)
        support.set_row_homogeneous(True)
        support.set_column_spacing(20)
        support.set_row_spacing(20)

        # Mise en place des différentes tuiles

        cells = { }

        for x in range(4):
            for y in range(3):
                cells[(x, y)] = False

        tiles = [

            NewBinary(),
            VersionChecker(),
            WebInvitation(),
            TipOfTheDay()

        ]

        for t in tiles:

            x, y, w, h = t.get_location()

            for i in range(x, x + w):
                for j in range(y, y + h):
                    assert(cells[(i, j)] == False)
                    cells[(i, j)] = True

            t.attach(self)
            support.attach(t, x, y, w, h)

        for x in range(4):
            for y in range(3):
                if not cells[(x, y)]:
                    tile = SmallBoard()
                    tile.attach(self)
                    support.attach(tile, x, y, 1, 1)

        # Charge les styles propres aux panneaux

        style_provider = Gtk.CssProvider()

        style_provider.load_from_data(SmallBoard.css.encode())

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), 
            style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )


        support.show_all()
        return support


    def define_selected_area(self, area):

        self._area = area

        ####
        #self.queue_draw()


    def draw_selected_area(self, widget, cr):


        alloc = widget.get_allocation()




        def draw_rounded2(cr, area, radius):
            """ draws rectangles with rounded (circular arc) corners """
            from math import pi
            a,b,c,d=area
            cr.arc(a + radius, c + radius, radius, 2*(pi/2), 3*(pi/2))
            cr.arc(b - radius, c + radius, radius, 3*(pi/2), 4*(pi/2))
            cr.arc(b - radius, d - radius, radius, 0*(pi/2), 1*(pi/2))  # ;o)
            cr.arc(a + radius, d - radius, radius, 1*(pi/2), 2*(pi/2))
            cr.rectangle(self._area.x, self._area.y, self._area.width, self._area.height)
            cr.close_path()
            cr.fill()


        if self._area != None:
            cr.set_source_rgba(0, 0, 0, 0.15)

            border = 4

            pts = ( self._area.x - border, self._area.x + self._area.width + border,
                    self._area.y - border, self._area.y + self._area.height + border )

            #cr.save()

            draw_rounded2(cr, pts, 16)

            ctx = self.get_style_context()


            Gtk.render_background(ctx, cr, 0, 20, 100, 100)
            Gtk.render_background(ctx, cr, self._area.x, self._area.y, self._area.width, self._area.height)


            #cr.restore()


        return False