| 1 |
#!/usr/bin/env python |
|---|
| 2 |
# -*- coding: utf-8 -*- |
|---|
| 3 |
import os |
|---|
| 4 |
import inspect |
|---|
| 5 |
import dabo |
|---|
| 6 |
dabo.ui.loadUI("wx") |
|---|
| 7 |
from dabo.dLocalize import _ |
|---|
| 8 |
from dabo.ui.dialogs.PreferenceDialog import PreferenceDialog |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
class PrefEditorPrefDialog(PreferenceDialog): |
|---|
| 12 |
def addPages(self): |
|---|
| 13 |
dayMins = 24*60 |
|---|
| 14 |
pm = self.PreferenceManager |
|---|
| 15 |
updKey = pm.web_update |
|---|
| 16 |
self.preferenceKeys.append(updKey) |
|---|
| 17 |
upPage = self.addCategory(_("Web Updates")) |
|---|
| 18 |
|
|---|
| 19 |
sz = upPage.Sizer = dabo.ui.dSizer("v") |
|---|
| 20 |
hsz = dabo.ui.dSizer("h") |
|---|
| 21 |
chkUpdateCheck = dabo.ui.dCheckBox(upPage, OnHit=self.onChkUpdate, |
|---|
| 22 |
Caption=_("Check for Preference Editor updates"), RegID="chkForPrefManUpdates", |
|---|
| 23 |
DataSource=updKey, DataField="web_update", |
|---|
| 24 |
ToolTipText="Should we check for updates to the Preference Editor?") |
|---|
| 25 |
btnCheckNow = dabo.ui.dButton(upPage, Caption=_("Check now..."), |
|---|
| 26 |
OnHit=self.onCheckNow, ToolTipText="Check the Dabo server for updates") |
|---|
| 27 |
hsz.append(chkUpdateCheck, valign="middle") |
|---|
| 28 |
hsz.appendSpacer(8) |
|---|
| 29 |
hsz.append(btnCheckNow, valign="middle") |
|---|
| 30 |
sz.append(hsz, halign="center", border=20) |
|---|
| 31 |
|
|---|
| 32 |
radFrequency = dabo.ui.dRadioList(upPage, Orientation="Vertical", |
|---|
| 33 |
Caption=_("Check every..."), RegID="radWebUpdateFrequency", |
|---|
| 34 |
Choices=[_("Every time an app is run"), _("Once a day"), _("Once a week"), _("Once a month")], |
|---|
| 35 |
Keys = [0, dayMins, dayMins*7,dayMins*30], |
|---|
| 36 |
ValueMode="Keys", DataSource=updKey, DataField="update_interval", |
|---|
| 37 |
ToolTipText=_("How often should we check for updates?"), |
|---|
| 38 |
DynamicEnabled = lambda: self.chkForPrefManUpdates.Value) |
|---|
| 39 |
sz.append(radFrequency, halign="center") |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
def onChkUpdate(self, evt): |
|---|
| 43 |
self.update() |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
def onCheckNow(self, evt): |
|---|
| 47 |
ret = self.Application.checkForUpdates(project="prf") |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
def main(): |
|---|
| 53 |
app = dabo.dApp(BasePrefKey="PrefEditor", MainFormClass="PrefEditor.cdxml", |
|---|
| 54 |
PreferenceDialogClass=PrefEditorPrefDialog) |
|---|
| 55 |
curdir = os.getcwd() |
|---|
| 56 |
# Get the current location's path |
|---|
| 57 |
fname = os.path.abspath(inspect.getfile(main)) |
|---|
| 58 |
pth = os.path.dirname(fname) |
|---|
| 59 |
# Switch to that path |
|---|
| 60 |
os.chdir(pth) |
|---|
| 61 |
app.start() |
|---|
| 62 |
|
|---|
| 63 |
# Return to the original location |
|---|
| 64 |
os.chdir(curdir) |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
if __name__ == "__main__": |
|---|
| 69 |
main() |
|---|