summaryrefslogtreecommitdiff
path: root/src/emc/usr_intf/gmoccapy/dialogs.py
blob: 8014a27f5c0e4e590c68a1c2f2a256889256df95 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python

'''
    This class is used to handle the dialogs from gmoccapy,
    it is just a coppy of a class from gscreen and has been slighly modified

    Copyright 2014 Norbert Schechner
    nieson@web.de

    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

'''

import gtk
import gladevcp
import pango

# This dialog is for unlocking the system tab
# The unlock code number is defined at the top of the page
def system_dialog(self):
    dialog = gtk.Dialog(_("Enter System Unlock Code"),
               self.widgets.window1,
               gtk.DIALOG_DESTROY_WITH_PARENT,
               (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
    label = gtk.Label(_("Enter System Unlock Code"))
    label.modify_font(pango.FontDescription("sans 20"))
    calc = gladevcp.Calculator()
    dialog.vbox.pack_start(label)
    dialog.vbox.add(calc)
    calc.set_value("")
    calc.set_property("font", "sans 20")
    calc.set_editable(True)
    calc.entry.connect("activate", lambda w : dialog.emit("response", gtk.RESPONSE_ACCEPT))
    dialog.parse_geometry("400x400")
    dialog.set_decorated(True)
    dialog.show_all()
    response = dialog.run()
    code = calc.get_value()
    dialog.destroy()
    if response == gtk.RESPONSE_ACCEPT:
        if code == int(self.unlock_code):
            return True
    return False


def entry_dialog(self, data = None, header = _("Enter value") , label = _("Enter the value to set"), integer = False):
    dialog = gtk.Dialog(header,
               self.widgets.window1,
               gtk.DIALOG_DESTROY_WITH_PARENT,
               (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
    label = gtk.Label(label)
    label.modify_font(pango.FontDescription("sans 20"))
    calc = gladevcp.Calculator()
    dialog.vbox.pack_start(label)
    dialog.vbox.add(calc)
    if data != None:
        calc.set_value(data)
    else:
        calc.set_value("")
    calc.set_property("font", "sans 20")
    calc.set_editable(True)
    calc.entry.connect("activate", lambda w : dialog.emit("response", gtk.RESPONSE_ACCEPT))
    dialog.parse_geometry("400x400")
    dialog.set_decorated(True)
    dialog.show_all()
    if integer: # The user is only allowed to enter integer values, we hide some button
        calc.num_pad_only(True)
        calc.integer_entry_only(True)
    response = dialog.run()
    value = calc.get_value()
    dialog.destroy()
    if response == gtk.RESPONSE_ACCEPT:
        if value != None:
            return float(value)
        else:
            return "ERROR"
    return "CANCEL"

# display warning dialog
def warning_dialog(self, message, secondary = None, title = "Operator Message"):
    dialog = gtk.MessageDialog(self.widgets.window1,
        gtk.DIALOG_DESTROY_WITH_PARENT,
        gtk.MESSAGE_INFO, gtk.BUTTONS_OK, message)
    # if there is a secondary message then the first message text is bold
    if secondary:
        dialog.format_secondary_text(secondary)
    dialog.show_all()
    dialog.set_title(title)
    result = dialog.run()
    dialog.destroy()
    if result == gtk.RESPONSE_OK:
        result = True
    else:
        result = False
    return result

def yesno_dialog(self, header = _("Question") , label = _("Please decide:")):
    dialog = gtk.MessageDialog(self.widgets.window1,
             gtk.DIALOG_DESTROY_WITH_PARENT,
             gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, header)
    label = gtk.Label(label)
    dialog.vbox.pack_start(label)
    dialog.set_decorated(True)
    dialog.show_all()
    response = dialog.run()
    dialog.destroy()
    if response == gtk.RESPONSE_YES:
        return True
    return False

# dialog for run from line
def restart_dialog(self):

    # highlight the gcode down one line lower
    # used for run-at-line restart
    def restart_down(widget, obj, calc):
        obj.widgets.gcode_view.line_down()
        line = int(obj.widgets.gcode_view.get_line_number())
        calc.set_value(line)

    # highlight the gcode down one line higher
    # used for run-at-line restart
    def restart_up(widget, obj, calc):
        obj.widgets.gcode_view.line_up()
        line = int(obj.widgets.gcode_view.get_line_number())
        calc.set_value(line)

    # highlight the gcode of the entered line
    # used for run-at-line restart
    def enter_button(widget, obj, calc):
        line = int(calc.get_value())
        obj.start_line = line
        obj.widgets.gcode_view.set_line_number(line)

    restart_dialog = gtk.Dialog(_("Restart Entry"),
               self.widgets.window1, gtk.DIALOG_DESTROY_WITH_PARENT,
               (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                 gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
    label = gtk.Label(_("Restart Entry"))
    label.modify_font(pango.FontDescription("sans 20"))
    restart_dialog.vbox.pack_start(label)
    calc = gladevcp.Calculator()
    restart_dialog.vbox.add(calc)
    calc.set_value("%d" % self.widgets.gcode_view.get_line_number())
    calc.set_property("font", "sans 20")
    calc.set_editable(True)
    calc.num_pad_only(True)
    calc.integer_entry_only(True)
    calc.entry.connect("activate", enter_button, self, calc)
    box = gtk.HButtonBox()
    upbutton = gtk.Button(label = _("Up"))
    box.add(upbutton)
    enterbutton = gtk.Button(label = _("Enter"))
    box.add(enterbutton)
    downbutton = gtk.Button(label = _("Down"))
    box.add(downbutton)
    calc.calc_box.pack_end(box, expand = False, fill = False, padding = 0)
    upbutton.connect("clicked", restart_up, self, calc)
    downbutton.connect("clicked", restart_down, self, calc)
    enterbutton.connect("clicked", enter_button, self, calc)
    restart_dialog.parse_geometry("400x400+0+0")
    restart_dialog.show_all()
    result = restart_dialog.run()
    restart_dialog.destroy()
    if result == gtk.RESPONSE_REJECT:
        line = 0
    else:
        line = int(calc.get_value())
        if line == None:
            line = 0
    self.widgets.gcode_view.set_line_number(line)
    self.start_line = line
    self._add_alarm_entry(_("Ready to Restart program from line %d" % line))