Code Duplication    Length = 64-66 lines in 2 locations

client/osci/dialog/ChangeQtyDlg.py 1 location

@@ 24-89 (lines=66) @@
21
import pygameui as ui
22
from osci import client, gdata, res
23
24
class ChangeQtyDlg:
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

client/osci/dialog/PasswordDlg.py 1 location

@@ 24-87 (lines=64) @@
21
import pygameui as ui
22
from osci import gdata
23
24
class PasswordDlg:
25
26
    def __init__(self, app, hide):
27
        self.app = app
28
        self.createUI()
29
        if hide:
30
            self.win.vPassword.showChar = '*'
31
32
    def display(self, confirmAction):
33
        self.confirmAction = confirmAction
34
        self.win.show()
35
        self.app.setFocus(self.win.vPassword)
36
        # register for updates
37
        if self not in gdata.updateDlgs:
38
            gdata.updateDlgs.append(self)
39
40
    def hide(self):
41
        self.win.setStatus(_("Ready."))
42
        self.win.hide()
43
        # unregister updates
44
        if self in gdata.updateDlgs:
45
            gdata.updateDlgs.remove(self)
46
47
    def update(self):
48
        self.show()
49
50
    def onOK(self, widget, action, data):
51
        self.password = self.win.vPassword.text
52
        if not self.password:
53
            self.win.setStatus(_("Please enter password."))
54
            return
55
        self.hide()
56
        self.confirmAction(self.password)
57
58
    def onCancel(self, widget, action, data):
59
        self.password = ''
60
        self.hide()
61
62
    def createUI(self):
63
        w, h = gdata.scrnSize
64
        self.win = ui.Window(self.app,
65
            modal = 1,
66
            escKeyClose = 1,
67
            movable = 0,
68
            title = _('Enter password'),
69
            rect = ui.Rect((w - 264) / 2, (h - 104) / 2, 264, 104),
70
            layoutManager = ui.SimpleGridLM(),
71
        )
72
        # creating dialog window
73
        self.win.subscribeAction('*', self)
74
75
        ui.Label(self.win,
76
            text = _("Password:"),
77
            align = ui.ALIGN_E,
78
            layout = (0, 1, 5, 1)
79
        )
80
        ui.Entry(self.win, id = 'vPassword',
81
            align = ui.ALIGN_W,
82
            layout = (5, 1, 5, 1),
83
        )
84
        ui.Title(self.win, layout = (0, 3, 3, 1))
85
        ui.TitleButton(self.win, layout = (3, 3, 5, 1), text = _("Cancel"), action = "onCancel")
86
        okBtn = ui.TitleButton(self.win, layout = (8, 3, 5, 1), text = _("OK"), action = 'onOK')
87
        self.win.acceptButton = okBtn
88