Issues (229)

client/osci/dialog/ChangeQtyDlg.py (1 issue)

1
#
2
#  Copyright 2001 - 2016 Ludek Smid [http://www.ospace.net/]
3
#
4
#  This file is part of Outer Space.
5
#
6
#  Outer Space is free software; you can redistribute it and/or modify
7
#  it under the terms of the GNU General Public License as published by
8
#  the Free Software Foundation; either version 2 of the License, or
9
#  (at your option) any later version.
10
#
11
#  Outer Space is distributed in the hope that it will be useful,
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
#  GNU General Public License for more details.
15
#
16
#  You should have received a copy of the GNU General Public License
17
#  along with Outer Space; if not, write to the Free Software
18
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
#
20
21
import pygameui as ui
22
from osci import client, gdata, res
23
24 View Code Duplication
class ChangeQtyDlg:
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
25
26
    def __init__(self, app):
27
        self.app = app
28
        self.createUI()
29
30
    def display(self, quantity, confirmAction = None):
31
        self.confirmAction = confirmAction
32
        self.win.vQuantity.text = str(quantity)
33
        self.win.show()
34
        self.app.setFocus(self.win.vQuantity)
35
        # register for updates
36
        if self not in gdata.updateDlgs:
37
            gdata.updateDlgs.append(self)
38
39
    def hide(self):
40
        self.win.setStatus(_("Ready."))
41
        self.win.hide()
42
        # unregister updates
43
        if self in gdata.updateDlgs:
44
            gdata.updateDlgs.remove(self)
45
46
    def update(self):
47
        self.show()
48
49
    def onOK(self, widget, action, data):
50
        try:
51
            self.quantity = int(self.win.vQuantity.text)
52
        except ValueError:
53
            self.win.setStatus(_("Specify quantity (1, 2, 3, ...)."))
54
            return
55
        self.hide()
56
        if self.confirmAction:
57
            self.confirmAction()
58
59
    def onCancel(self, widget, action, data):
60
        self.quantity = None
61
        self.hide()
62
63
    def createUI(self):
64
        w, h = gdata.scrnSize
65
        self.win = ui.Window(self.app,
66
            modal = 1,
67
            escKeyClose = 1,
68
            movable = 0,
69
            title = _('Change quantity'),
70
            rect = ui.Rect((w - 264) / 2, (h - 104) / 2, 264, 104),
71
            layoutManager = ui.SimpleGridLM(),
72
        )
73
        # creating dialog window
74
        self.win.subscribeAction('*', self)
75
76
        ui.Label(self.win,
77
            text = _("New quantity:"),
78
            align = ui.ALIGN_E,
79
            layout = (0, 1, 6, 1)
80
        )
81
        ui.Entry(self.win, id = 'vQuantity',
82
            align = ui.ALIGN_W,
83
            layout = (6, 1, 3, 1),
84
            #text = self.quantity,
85
        )
86
        ui.Title(self.win, layout = (0, 3, 3, 1))
87
        ui.TitleButton(self.win, layout = (3, 3, 5, 1), text = _("Cancel"), action = "onCancel")
88
        okBtn = ui.TitleButton(self.win, layout = (8, 3, 5, 1), text = _("OK"), action = 'onOK')
89
        self.win.acceptButton = okBtn
90