~launchpad-p-s/sofastatistics/main

« back to all changes in this revision

Viewing changes to dataselect.py

  • Committer: Grant Paton-Simpson
  • Date: 2009-05-19 04:21:43 UTC
  • Revision ID: g@ubuntu-20090519042143-p561mbokz3inefvd
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
import wx
 
3
import sys
 
4
import pprint
 
5
 
 
6
import getdata
 
7
import projects
 
8
import table_edit
 
9
 
 
10
 
 
11
class DataSelectDlg(wx.Dialog):
 
12
    def __init__(self, parent, proj_name):
 
13
        """
 
14
        NB self.dbe etc are all set during getdata.setupDataDropdowns
 
15
            because it calls getDbDetsObj to get the bits it needs
 
16
            and gets all the rest at the same time.
 
17
        No point getting them again in a more explicit way.
 
18
        """
 
19
        title = "Data in \"%s\" Project" % proj_name
 
20
        wx.Dialog.__init__(self, parent=parent, title=title,
 
21
                           size=(500, 300), 
 
22
                           style=wx.CAPTION|wx.CLOSE_BOX|
 
23
                           wx.SYSTEM_MENU, pos=(100, 100))
 
24
        self.parent = parent
 
25
        self.panel = wx.Panel(self)
 
26
        lblfont = wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD)
 
27
        self.szrMain = wx.BoxSizer(wx.VERTICAL)
 
28
        lblChoose = wx.StaticText(self.panel, -1, 
 
29
                                  "Choose an existing data table ...")
 
30
        proj_dic = projects.GetProjSettingsDic(proj_name=proj_name)
 
31
        self.var_labels, self.var_notes, self.val_dics = \
 
32
            projects.GetLabels(proj_dic["fil_labels"])
 
33
        getdata.setupDataDropdowns(self, self.panel, proj_dic["default_dbe"], 
 
34
                             proj_dic["conn_dets"], proj_dic["default_dbs"], 
 
35
                             proj_dic["default_tbls"])
 
36
        self.dropDatabases.Bind(wx.EVT_CHOICE, self.OnDatabaseSel)
 
37
        self.dropTables.Bind(wx.EVT_CHOICE, self.OnTableSel)
 
38
        self.chkReadOnly = wx.CheckBox(self.panel, -1, "Read Only")
 
39
        self.chkReadOnly.SetValue(True)
 
40
        self.btnOpen = wx.Button(self.panel, wx.ID_OPEN)
 
41
        self.btnOpen.Bind(wx.EVT_BUTTON, self.OnOpen)
 
42
        szrExistingTop = wx.BoxSizer(wx.HORIZONTAL)
 
43
        lblDbs = wx.StaticText(self.panel, -1, "Databases:")
 
44
        lblDbs.SetFont(lblfont)
 
45
        szrExistingTop.Add(lblDbs, 0, wx.RIGHT, 5)
 
46
        szrExistingTop.Add(self.dropDatabases, 0)
 
47
        self.dropDatabases.Bind(wx.EVT_CHOICE, self.OnDatabaseSel)
 
48
        szrExistingBottom = wx.BoxSizer(wx.HORIZONTAL)
 
49
        lblTbls = wx.StaticText(self.panel, -1, "Data tables:")
 
50
        lblTbls.SetFont(lblfont)
 
51
        szrExistingBottom.Add(lblTbls, 0, wx.RIGHT, 5)
 
52
        szrExistingBottom.Add(self.dropTables, 1, wx.GROW|wx.RIGHT, 10)
 
53
        szrExistingBottom.Add(self.chkReadOnly, 0, wx.TOP|wx.LEFT, 5)
 
54
        szrExistingBottom.Add(self.btnOpen, 0)
 
55
        bxExisting = wx.StaticBox(self.panel, -1, "Existing data tables")
 
56
        szrExisting = wx.StaticBoxSizer(bxExisting, wx.VERTICAL)
 
57
        szrExisting.Add(szrExistingTop, 0, wx.GROW|wx.ALL, 10)
 
58
        szrExisting.Add(szrExistingBottom, 0, wx.GROW|wx.ALL, 10)
 
59
        bxNew = wx.StaticBox(self.panel, -1, "")
 
60
        szrNew = wx.StaticBoxSizer(bxNew, wx.HORIZONTAL)
 
61
        lblMakeNew = wx.StaticText(self.panel, -1, "... or make a new data table")
 
62
        btnMakeNew = wx.Button(self.panel, wx.ID_NEW)
 
63
        #btnMakeNew.Bind(wx.EVT_BUTTON, self.OnNewClick)
 
64
        szrNew.Add(lblMakeNew, 1, wx.GROW|wx.ALL, 10)
 
65
        szrNew.Add(btnMakeNew, 0, wx.ALL, 10)
 
66
        self.SetupButtons()
 
67
        self.lblFeedback = wx.StaticText(self.panel, -1, "")
 
68
        self.szrButtons.Add(self.lblFeedback, 0, wx.LEFT|wx.TOP, 10)
 
69
        self.szrMain.Add(lblChoose, 0, wx.ALL, 10)
 
70
        self.szrMain.Add(szrExisting, 1, wx.LEFT|wx.BOTTOM|wx.RIGHT|wx.GROW, 10)
 
71
        self.szrMain.Add(szrNew, 0, wx.GROW|wx.LEFT|wx.BOTTOM|wx.RIGHT, 10)
 
72
        self.szrMain.Add(self.szrButtons, 0, wx.ALL, 10)
 
73
        self.panel.SetSizer(self.szrMain)
 
74
        self.szrMain.SetSizeHints(self)
 
75
        self.Layout()
 
76
        
 
77
    def SetupButtons(self):
 
78
        """
 
79
        Must have ID of wx.ID_... to trigger validators (no event binding 
 
80
            needed) and for std dialog button layout.
 
81
        """
 
82
        btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
 
83
        btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
 
84
        btnOK = wx.Button(self.panel, wx.ID_OK)
 
85
        btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
 
86
        btnOK.SetDefault()
 
87
        self.szrButtons = wx.StdDialogButtonSizer()
 
88
        self.szrButtons.AddButton(btnCancel)
 
89
        self.szrButtons.AddButton(btnOK)
 
90
        self.szrButtons.Realize()
 
91
 
 
92
    def AddFeedback(self, feedback):
 
93
        self.lblFeedback.SetLabel(feedback)
 
94
        wx.Yield()
 
95
        
 
96
    def OnDatabaseSel(self, event):
 
97
        getdata.ResetDataAfterDbSel(self)
 
98
    
 
99
    def OnTableSel(self, event):
 
100
        getdata.ResetDataAfterTblSel(self)
 
101
    
 
102
    def OnOpen(self, event):
 
103
        ""
 
104
        if not self.has_unique:
 
105
            wx.MessageBox("Table \"%s\" cannot be opened because it " % \
 
106
              self.tbl_name + \
 
107
              "lacks a unique index") # needed for caching even if read only
 
108
        else:
 
109
            read_only = self.chkReadOnly.IsChecked()
 
110
            dlg = table_edit.TblEditor(self, self.dbe, self.conn, 
 
111
                                       self.cur, self.db, self.tbl_name, 
 
112
                                       self.flds, self.var_labels, self.idxs,
 
113
                                       read_only)
 
114
            dlg.ShowModal()
 
115
        event.Skip()
 
116
    
 
117
    def OnCancel(self, event):
 
118
        self.Destroy()
 
119
    
 
120
    def OnOK(self, event):
 
121
        self.Destroy()
 
122
        
 
123
 
 
124
if __name__ == "__main__":
 
125
    app = wx.PySimpleApp()
 
126
    myframe = DataSelectDlg(None, "MOH.proj")
 
127
    myframe.Show()
 
128
    app.MainLoop()
 
129
    
 
 
b'\\ No newline at end of file'