/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/labeldialog.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/UI/labeldialog.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (hide annotations)
Tue Aug 28 15:41:52 2001 UTC (23 years, 6 months ago) by bh
Original Path: trunk/thuban/Thuban/UI/labeldialog.py
File MIME type: text/x-python
File size: 3129 byte(s)
import all the source files

1 bh 6 # Copyright (c) 2001 by Intevation GmbH
2     # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     __version__ = "$Revision$"
9    
10     from wxPython.wx import *
11    
12    
13     class LabelListCtrl(wxListCtrl):
14    
15     def __init__(self, parent, id, table, shape_index):
16     wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT)
17    
18     self.InsertColumn(0, "Field")
19     self.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
20     self.InsertColumn(1, "Value")
21     self.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER)
22    
23     self.fill_list(table, shape_index)
24    
25     self.selected = -1
26    
27     EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected)
28    
29     def fill_list(self, table, shape):
30     num_cols = table.field_count()
31     num_rows = table.record_count()
32    
33     names = []
34     values = {}
35     for i in range(num_cols):
36     type, name, length, decc = table.field_info(i)
37     names.append(name)
38     record = table.read_record(shape)
39    
40     for i in range(len(names)):
41     name = names[i]
42     value = record[name]
43     self.InsertStringItem(i, name)
44     self.SetStringItem(i, 1, str(value))
45     values[i] = value
46     self.values = values
47    
48     def OnItemSelected(self, event):
49     self.selected = event.m_itemIndex
50    
51     def GetValue(self):
52     if self.selected >= 0:
53     return self.values[self.selected]
54     else:
55     return ""
56    
57    
58     class LabelDialog(wxDialog):
59    
60     def __init__(self, parent, table, shape_index):
61     wxDialog.__init__(self, parent, -1, "Label Values", wxDefaultPosition,
62     style = wxRESIZE_BORDER|wxCAPTION|wxDIALOG_MODAL)
63    
64     self.parent = parent
65     self.dialog_layout(table, shape_index)
66    
67     def dialog_layout(self, table, shape_index):
68     top_box = wxBoxSizer(wxVERTICAL)
69    
70     self.list = LabelListCtrl(self, -1, table, shape_index)
71     top_box.Add(self.list, 1, wxEXPAND|wxALL, 4)
72    
73     box = wxBoxSizer(wxHORIZONTAL)
74     box.Add(wxButton(self, wxID_OK, "OK"), 0, wxALL, 4)
75     box.Add(wxButton(self, wxID_CANCEL, "Cancel"), 0, wxALL, 4)
76     top_box.Add(box, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
77    
78     EVT_BUTTON(self, wxID_OK, self.OnOK)
79     EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
80    
81     self.SetAutoLayout(true)
82     self.SetSizer(top_box)
83     top_box.Fit(self)
84     top_box.SetSizeHints(self)
85    
86     def OnOK(self, event):
87     result = self.list.GetValue()
88     if result:
89     self.end_dialog(wxID_OK, str(result))
90     else:
91     self.end_dialog(wxID_CANCEL, None)
92    
93     def OnCancel(self, event):
94     self.end_dialog(wxID_CANCEL, None)
95    
96     def end_dialog(self, wx_result, result):
97     self.result = result
98     self.EndModal(wx_result)
99    
100     def run_label_dialog(parent, table, shape_index):
101     dialog = LabelDialog(parent, table, shape_index)
102     if dialog.ShowModal() == wxID_OK:
103     return dialog.result
104     else:
105     return None
106    

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26