| 1 |
# -*- coding: utf-8 -*- |
|---|
| 2 |
import wx |
|---|
| 3 |
import dabo |
|---|
| 4 |
import dabo.ui |
|---|
| 5 |
import dabo.icons |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
if dabo.ui.getUIType() is None: |
|---|
| 9 |
dabo.ui.loadUI("wx") |
|---|
| 10 |
|
|---|
| 11 |
from dabo.dLocalize import _ |
|---|
| 12 |
import dabo.dEvents as dEvents |
|---|
| 13 |
dKeys = dabo.ui.dKeys |
|---|
| 14 |
|
|---|
| 15 |
class lbl(dabo.ui.dLabel): |
|---|
| 16 |
def initProperties(self): |
|---|
| 17 |
self.Alignment = "Right" |
|---|
| 18 |
self.AutoResize = False |
|---|
| 19 |
self.Width = 100 |
|---|
| 20 |
|
|---|
| 21 |
class lblMessage(dabo.ui.dLabel): |
|---|
| 22 |
def initProperties(self): |
|---|
| 23 |
self.Alignment = "Center" |
|---|
| 24 |
self.AutoResize = False |
|---|
| 25 |
self.Caption = _("Please enter your login information.") |
|---|
| 26 |
self.FontBold = True |
|---|
| 27 |
self.FontItalic = True |
|---|
| 28 |
self.ForeColor = "Blue" |
|---|
| 29 |
self.FontSize = 10 |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
class txt(dabo.ui.dTextBox): |
|---|
| 33 |
pass |
|---|
| 34 |
|
|---|
| 35 |
class txtPass(txt): |
|---|
| 36 |
def initProperties(self): |
|---|
| 37 |
self.PasswordEntry = True |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
class Login(dabo.ui.dOkCancelDialog): |
|---|
| 41 |
def initProperties(self): |
|---|
| 42 |
self.AutoSize = True |
|---|
| 43 |
self.BorderResizable = True |
|---|
| 44 |
if self.Application: |
|---|
| 45 |
appName = self.Application.getAppInfo("appName") |
|---|
| 46 |
else: |
|---|
| 47 |
appName = '' |
|---|
| 48 |
if len(appName) > 0: |
|---|
| 49 |
self.Caption = _("Login to %s" % appName) |
|---|
| 50 |
else: |
|---|
| 51 |
self.Caption = _("Please Login") |
|---|
| 52 |
self.ShowCaption = False |
|---|
| 53 |
self.ShowCloseButton = True |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
def addControls(self): |
|---|
| 57 |
super(Login, self).afterInit() |
|---|
| 58 |
|
|---|
| 59 |
self.addObject(lbl, 'lblUserName') |
|---|
| 60 |
self.addObject(txt, 'txtUserName') |
|---|
| 61 |
self.lblUserName.Caption = _("User:") |
|---|
| 62 |
self.txtUserName.Value = "" |
|---|
| 63 |
|
|---|
| 64 |
self.addObject(lbl, 'lblPassword') |
|---|
| 65 |
self.addObject(txtPass, 'txtPassword') |
|---|
| 66 |
self.lblPassword.Caption = _("Password:") |
|---|
| 67 |
self.txtPassword.Value = "" |
|---|
| 68 |
|
|---|
| 69 |
self.addObject(lblMessage, 'lblMessage') |
|---|
| 70 |
|
|---|
| 71 |
self.user, self.password = None, None |
|---|
| 72 |
|
|---|
| 73 |
# Icon disabled: not configurable, problem with py2app/py2exe |
|---|
| 74 |
#self.bm = dabo.ui.dImage(self, Picture=dabo.icons.getIconFileName("daboIcon048.png")) |
|---|
| 75 |
|
|---|
| 76 |
mainSizer = self.Sizer |
|---|
| 77 |
mainSizer.append((0,5)) |
|---|
| 78 |
|
|---|
| 79 |
bs1 = dabo.ui.dSizer("horizontal") |
|---|
| 80 |
#bs1.append(self.bm) |
|---|
| 81 |
|
|---|
| 82 |
bs1.append((23,0)) |
|---|
| 83 |
|
|---|
| 84 |
vs = dabo.ui.dSizer("vertical") |
|---|
| 85 |
bs = dabo.ui.dSizer("horizontal") |
|---|
| 86 |
|
|---|
| 87 |
bs.append(self.lblUserName) |
|---|
| 88 |
bs.append((5,0)) |
|---|
| 89 |
bs.append(self.txtUserName, proportion=1) |
|---|
| 90 |
vs.append(bs, "expand", 1) |
|---|
| 91 |
|
|---|
| 92 |
bs = dabo.ui.dSizer("horizontal") |
|---|
| 93 |
bs.append(self.lblPassword) |
|---|
| 94 |
bs.append((5,0)) |
|---|
| 95 |
bs.append(self.txtPassword, proportion=1) |
|---|
| 96 |
vs.append(bs, "expand", 1) |
|---|
| 97 |
|
|---|
| 98 |
bs1.append(vs, proportion=1) |
|---|
| 99 |
mainSizer.append(bs1, "expand", 1) |
|---|
| 100 |
|
|---|
| 101 |
mainSizer.append((0,15)) |
|---|
| 102 |
|
|---|
| 103 |
mainSizer.append(self.lblMessage, "expand", 1) |
|---|
| 104 |
|
|---|
| 105 |
mainSizer.layout() |
|---|
| 106 |
|
|---|
| 107 |
# Map enter key to accept button (because DefaultButton doesn't work): |
|---|
| 108 |
self.bindKey("enter", self.onOK) |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
def setMessage(self, message): |
|---|
| 112 |
self.lblMessage.Caption = message |
|---|
| 113 |
self.Sizer.layout() |
|---|
| 114 |
|
|---|
| 115 |
def onCancel(self, evt): |
|---|
| 116 |
self.user, self.password = None, None |
|---|
| 117 |
self.super(evt) |
|---|
| 118 |
|
|---|
| 119 |
def onOK(self, evt): |
|---|
| 120 |
self.user, self.password = self.txtUserName.Value, self.txtPassword.Value |
|---|
| 121 |
self.super(evt) |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
if __name__ == '__main__': |
|---|
| 125 |
app = wx.PySimpleApp() |
|---|
| 126 |
form = Login(None) |
|---|
| 127 |
form.show() |
|---|
| 128 |
print form.user, form.password |
|---|