Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/MenuActions.py
blob: 9ef6ae97377149bd987da9cc8dd5179dd2d3c26e (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
# MenuActions.py    Stores the actions for the MenuItems
#
# Copyright (C) 2011 Laurent BERNABE
#
# 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 2 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
# St, Fifth Floor, Boston, MA 02110-1301  USA

from gettext import gettext as _
from InputDialog import InputDialog
    
import pygtk
pygtk.require('2.0')
import gtk

class MenuActions(object):
    '''
    Wraps codes for the menu actions in both
    pure pygtk mode and in sugar mode
    '''

    def __init__(self, wrappedDrawingArea):
        '''
        Constructor
        => wrappedDrawingArea argument : the instance of 
        TheDrawingAreaEventBox to act upon
        => MenuActions(wrappedDrawingArea)
        '''
        self.__wrappedDrawingArea = wrappedDrawingArea
        
    def manageDrawingWrite(self):
        '''
        manageDrawingWrite()
        Wraps code for menu Drawing->Write
        '''
        dialog = InputDialog(_("Line thickness value ?"),text="5")
        user_value = dialog.run()
        if user_value != None :
            try:
                line_thickness = int(user_value)
                assert line_thickness > 0
            except (ValueError, AssertionError) :
                message = _("As you did not give an correct integer value,\n5 will be taken")
                message_dialog = gtk.MessageDialog(None,
                                                   gtk.DIALOG_MODAL,
                                                   gtk.MESSAGE_ERROR,
                                                   gtk.BUTTONS_OK,
                                                   message)
                message_dialog.run()
                message_dialog.destroy()
                line_thickness = 5
            self.__wrappedDrawingArea.setRecordingMode(line_thickness)
        
    def manageDrawingRead(self):
        '''
        manageDrawingRead()
        Wraps code for menu Drawing->Read
        '''
        dialog = InputDialog(_("Steps drawing delays (milliseconds) ?"),text="10")
        user_value = dialog.run()
        if user_value != None :
            try:
                delay_milliseconds = int(user_value)
                assert delay_milliseconds > 0
            except (ValueError, AssertionError) :
                message = _("As you did not give an correct integer value,\n10 will be taken")
                message_dialog = gtk.MessageDialog(None,
                                                   gtk.DIALOG_MODAL,
                                                   gtk.MESSAGE_ERROR,
                                                   gtk.BUTTONS_OK,
                                                   message)
                message_dialog.run()
                message_dialog.destroy()
                delay_milliseconds = 10
            self.__wrappedDrawingArea.setReadingMode(delay_milliseconds)