Package application :: Package dialogs :: Module autosyncprefs
[hide private]
[frames] | no frames]

Source Code for Module application.dialogs.autosyncprefs

  1  #   Copyright (c) 2003-2007 Open Source Applications Foundation 
  2  # 
  3  #   Licensed under the Apache License, Version 2.0 (the "License"); 
  4  #   you may not use this file except in compliance with the License. 
  5  #   You may obtain a copy of the License at 
  6  # 
  7  #       http://www.apache.org/licenses/LICENSE-2.0 
  8  # 
  9  #   Unless required by applicable law or agreed to in writing, software 
 10  #   distributed under the License is distributed on an "AS IS" BASIS, 
 11  #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 12  #   See the License for the specific language governing permissions and 
 13  #   limitations under the License. 
 14   
 15   
 16  import wx 
 17  from i18n import ChandlerMessageFactory as _ 
 18  from osaf import sharing 
 19   
 20  """ 
 21  Note: need to migrate translation logic to a base wx dialog class that can handle all the work for sub classes 
 22  """ 
 23   
24 -def Show(view):
25 26 win = AutoSyncPrefs(_(u"Sync Preferences"), view) 27 win.CenterOnScreen() 28 val = win.ShowModal() 29 30 if val == wx.ID_OK: 31 # Assign the new values 32 win.AssignNewValues() 33 34 win.Destroy() 35 return val == wx.ID_OK
36 37
38 -class AutoSyncPrefs(wx.Dialog):
39 - def __init__(self, title, view, size=wx.DefaultSize, 40 pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE):
41 42 # Instead of calling wx.Dialog.__init__ we precreate the dialog 43 # so we can set an extra style that must be set before 44 # creation, and then we create the GUI dialog using the Create 45 # method. 46 pre = wx.PreDialog() 47 pre.Create(None, -1, title, pos, size, style) 48 49 # This next step is the most important, it turns this Python 50 # object into the real wrapper of the dialog (instead of pre) 51 # as far as the wxPython extension is concerned. 52 self.this = pre.this 53 54 # Now continue with the normal construction of the dialog 55 # contents 56 sizer = wx.BoxSizer(wx.VERTICAL) 57 58 box = wx.BoxSizer(wx.HORIZONTAL) 59 label = wx.StaticText(self, -1, _(u"&Synchronize")) 60 box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) 61 choice = wx.Choice(self, -1, choices=[]) 62 63 interval = sharing.getAutoSyncInterval(view) 64 65 choices = [ 66 (_(u"Manually"), None), 67 (_(u"Every 30 minutes"), 30), 68 (_(u"Every hour"), 60), 69 (_(u"Every 2 hours"), 120), 70 (_(u"Every 6 hours"), 360), 71 (_(u"Every day"), 1440), 72 ] 73 for (text, minutes) in choices: 74 newIndex = choice.Append(text) 75 choice.SetClientData(newIndex, minutes) 76 if interval == minutes: 77 choice.SetSelection(newIndex) 78 79 box.Add(choice, 0, wx.ALIGN_CENTRE|wx.ALL, 5) 80 81 sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) 82 83 line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) 84 sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) 85 86 box = wx.BoxSizer(wx.HORIZONTAL) 87 88 btn = wx.Button(self, wx.ID_OK) 89 btn.SetDefault() 90 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) 91 92 btn = wx.Button(self, wx.ID_CANCEL) 93 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) 94 95 sizer.Add(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) 96 97 self.SetSizer(sizer) 98 self.SetAutoLayout(True) 99 sizer.Fit(self) 100 101 # Store these, using attribute names that hopefully wont collide with 102 # any wx attributes 103 self.view = view 104 self.choice = choice
105
106 - def AssignNewValues(self):
107 index = self.choice.GetSelection() 108 minutes = self.choice.GetClientData(index) 109 sharing.setAutoSyncInterval(self.view, minutes) 110 self.view.commit()
111