/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/bboxdump/bboxdump.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Extensions/bboxdump/bboxdump.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/thuban/Extensions/bboxdump/bboxdump.py revision 2356 by jan, Tue Sep 28 19:31:05 2004 UTC branches/WIP-pyshapelib-bramz/Extensions/bboxdump/bboxdump.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 1  Line 1 
1  # Copyright (C) 2003-2004 by Intevation GmbH  # Copyright (C) 2004 by Intevation GmbH
2  # Authors:  # Authors:
3  # Frank Koormann <[email protected]>  # Frank Koormann <[email protected]> (2004)
4  #  #
5  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
6  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 20  __version__ = '$Revision$' Line 20  __version__ = '$Revision$'
20  import os, sys  import os, sys
21  import string  import string
22    
23  from wxPython.wx import *  import wx
24  from wxPython.lib.dialogs import wxScrolledMessageDialog  from wx.lib.dialogs import ScrolledMessageDialog
25    
26  from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor  from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
27  from Thuban.UI.command import registry, Command  from Thuban.UI.command import registry, Command
28  from Thuban.UI.mainwindow import main_menu, _has_selected_shape_layer  from Thuban.UI.mainwindow import main_menu, _has_selected_shape_layer
 from Thuban.UI.extensionregistry import ExtensionDesc, ext_registry  
29  from Thuban import _  from Thuban import _
30    
31  import shapelib  import shapelib
32  import dbflib  import dbflib
33    
 ext_registry.add(ExtensionDesc(  
     name = 'bboxdump',  
     version = '1.0.0',  
     authors= [ 'Frank Koormann' ],  
     copyright = '2003-2004 Intevation GmbH',  
     desc = _("Dumps the bounding boxes of all\n" \  
              "shapes of the selected layer.")))  
   
34  # Widget IDs  # Widget IDs
35  ID_FILENAME = 4001  ID_FILENAME = 4001
36  ID_ATTRIBUTES = 4002  ID_ATTRIBUTES = 4002
37  ID_SELFN = 4003  ID_SELFN = 4003
38    
39  class BBoxDumpDialog(wxDialog):  class BBoxDumpDialog(wx.Dialog):
40      """Bounding Box Dump Dialog      """Bounding Box Dump Dialog
41    
42      Specify a filename for the dump and optionally a layer's column      Specify a filename for the dump and optionally a layer's column
# Line 53  class BBoxDumpDialog(wxDialog): Line 44  class BBoxDumpDialog(wxDialog):
44      """      """
45    
46      def __init__(self, parent, title, layer = None):      def __init__(self, parent, title, layer = None):
47          wxDialog.__init__(self, parent, -1, title,          wx.Dialog.__init__(self, parent, -1, title,
48                            style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)                            style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
49    
50          if layer is None:          if layer is None:
51              return wxID_CANCEL              return wx.ID_CANCEL
52    
53          # Store the layer          # Store the layer
54          self.layer = layer          self.layer = layer
55    
56          # Filename selection elements          # Filename selection elements
57          self.filename = wxTextCtrl(self, ID_FILENAME, "")          self.filename = wx.TextCtrl(self, ID_FILENAME, "")
58          self.button_selectfile = wxButton(self, ID_SELFN, _('Select...'))          self.button_selectfile = wx.Button(self, ID_SELFN, _('Select...'))
59          EVT_BUTTON(self, ID_SELFN, self.OnSelectFilename)          wx.EVT_BUTTON(self, ID_SELFN, self.OnSelectFilename)
60    
61          # Column choice elements          # Column choice elements
62          self.choice_column = wxChoice(self, ID_ATTRIBUTES)          self.choice_column = wx.Choice(self, ID_ATTRIBUTES)
63          self.choice_column.Append(_('Select...'), None)          self.choice_column.Append(_('Select...'), None)
64          for col in self.layer.ShapeStore().Table().Columns():          for col in self.layer.ShapeStore().Table().Columns():
65                  self.choice_column.Append(col.name, col)                  self.choice_column.Append(col.name, col)
66          self.choice_column.SetSelection(0)          self.choice_column.SetSelection(0)
67    
68          # Dialog button elements          # Dialog button elements
69          self.button_dump = wxButton(self, wxID_OK, _("OK"))          self.button_dump = wx.Button(self, wx.ID_OK, _("OK"))
70          EVT_BUTTON(self, wxID_OK, self.OnDump)          wx.EVT_BUTTON(self, wx.ID_OK, self.OnDump)
71          self.button_dump.SetDefault()          self.button_dump.SetDefault()
72          # TODO: Disable the OK button until a filename is entered ...          # TODO: Disable the OK button until a filename is entered ...
73          # self.button_dump.Enable(False)          # self.button_dump.Enable(False)
74          self.button_cancel = wxButton(self, wxID_CANCEL, _("Cancel"))          self.button_cancel = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
75    
76    
77          # Dialog Layout: three horizontal box sizers.          # Dialog Layout: three horizontal box sizers.
78          topbox = wxBoxSizer(wxVERTICAL)          topbox = wx.BoxSizer(wx.VERTICAL)
79    
80          hbox = wxBoxSizer(wxHORIZONTAL)          hbox = wx.BoxSizer(wx.HORIZONTAL)
81          topbox.Add(hbox, 0, wxALL|wxEXPAND)          topbox.Add(hbox, 0, wx.ALL|wx.EXPAND)
82          hbox.Add(wxStaticText(self, -1, _("File:")),          hbox.Add(wx.StaticText(self, -1, _("File:")),
83                   0, wxALL|wxALIGN_CENTER_VERTICAL, 4)                   0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
84          hbox.Add(self.filename, 1, wxALL|wxEXPAND, 4)          hbox.Add(self.filename, 1, wx.ALL|wx.EXPAND, 4)
85          hbox.Add(self.button_selectfile, 0, wxALL, 4)          hbox.Add(self.button_selectfile, 0, wx.ALL, 4)
86    
87          hbox = wxBoxSizer(wxHORIZONTAL)          hbox = wx.BoxSizer(wx.HORIZONTAL)
88          topbox.Add(hbox, 0, wxALL|wxEXPAND)          topbox.Add(hbox, 0, wx.ALL|wx.EXPAND)
89          hbox.Add(wxStaticText(self, -1, _("Group by:")),          hbox.Add(wx.StaticText(self, -1, _("Group by:")),
90                   0, wxALL|wxALIGN_CENTER_VERTICAL, 4)                   0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
91          hbox.Add(self.choice_column, 1, wxALL|wxEXPAND, 4)          hbox.Add(self.choice_column, 1, wx.ALL|wx.EXPAND, 4)
92    
93          hbox = wxBoxSizer(wxHORIZONTAL)          hbox = wx.BoxSizer(wx.HORIZONTAL)
94          topbox.Add(hbox, 0, wxALL|wxEXPAND)          topbox.Add(hbox, 0, wx.ALL|wx.EXPAND)
95          hbox.Add(self.button_dump, 0, wxALL|wxALIGN_CENTER,          hbox.Add(self.button_dump, 0, wx.ALL|wx.ALIGN_CENTER,
96                    10)                    10)
97          hbox.Add(self.button_cancel, 0, wxALL|wxALIGN_CENTER,          hbox.Add(self.button_cancel, 0, wx.ALL|wx.ALIGN_CENTER,
98                    10)                    10)
99    
100          # Finalize ...          # Finalize ...
# Line 131  class BBoxDumpDialog(wxDialog): Line 122  class BBoxDumpDialog(wxDialog):
122              ThubanEndBusyCursor()              ThubanEndBusyCursor()
123    
124          if bboxmessage:          if bboxmessage:
125              dlg = wxScrolledMessageDialog(              dlg = ScrolledMessageDialog(
126                                  self.parent, bboxmessage,                                  self.parent, bboxmessage,
127                                  _("Bounding Box Dump %s") % self.layer.Title())                                  _("Bounding Box Dump %s") % self.layer.Title())
128              dlg.ShowModal()              dlg.ShowModal()
# Line 141  class BBoxDumpDialog(wxDialog): Line 132  class BBoxDumpDialog(wxDialog):
132    
133          Opens a file dialog to specify a file to dump into.          Opens a file dialog to specify a file to dump into.
134          """          """
135          dlg = wxFileDialog(self, _("Dump Bounding Boxes To"),          dlg = wx.FileDialog(self, _("Dump Bounding Boxes To"),
136                         os.path.dirname(self.filename.GetValue()),                         os.path.dirname(self.filename.GetValue()),
137                         os.path.basename(self.filename.GetValue()),                         os.path.basename(self.filename.GetValue()),
138                         _("CSV Files (*.csv)|*.csv|") +                         _("CSV Files (*.csv)|*.csv|") +
139                         _("All Files (*.*)|*.*"),                         _("All Files (*.*)|*.*"),
140                         wxSAVE|wxOVERWRITE_PROMPT)                         wx.SAVE|wx.OVERWRITE_PROMPT)
141          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wx.ID_OK:
142              self.filename.SetValue(dlg.GetPath())              self.filename.SetValue(dlg.GetPath())
143              dlg.Destroy()              dlg.Destroy()
144          else:          else:
# Line 166  def bboxdump(layer, column, filename): Line 157  def bboxdump(layer, column, filename):
157      shapelist = {}      shapelist = {}
158      bboxmessage = []      bboxmessage = []
159    
160      dlg= wxProgressDialog(_("Bounding Box Dump"),      dlg= wx.ProgressDialog(_("Bounding Box Dump"),
161                            _("Collecting shapes ..."),                            _("Collecting shapes ..."),
162                            layer.ShapeStore().NumShapes(),                            layer.ShapeStore().NumShapes(),
163                            None)                            None)
# Line 199  def bboxdump(layer, column, filename): Line 190  def bboxdump(layer, column, filename):
190              cnt = cnt + 1              cnt = cnt + 1
191    
192      dlg.Destroy()      dlg.Destroy()
193      dlg= wxProgressDialog(_("Bounding Box Dump"),      dlg= wx.ProgressDialog(_("Bounding Box Dump"),
194                            _("Dump bounding boxes of selected shapes ..."),                            _("Dump bounding boxes of selected shapes ..."),
195                            len(shapelist),                            len(shapelist),
196                            None)                            None)

Legend:
Removed from v.2356  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26