Ejemplo n.º 1
0
Archivo: ui.py Proyecto: joaomdsc/mapv
    def on_open_file(self, _):
        d = wx.FileDialog(self, 'Open a DLG-3 file', get_dir(), '',
                          '*.*', wx.FD_OPEN)
        if d.ShowModal() == wx.ID_OK:
            dir = d.GetDirectory()
            self.category = os.path.split(dir)[1]
            set_dir(dir)
            file = d.GetFilename()

            # The 'ui' module shouldn't deal in details of the model such as
            # mapname, category, etc. The role of the 'on_open_file' method is
            # just to get a filepath from the user and pass it onto the
            # controller.
            if self.win.model is None or self.win.model.kind != 'Dlg3':
                self.win.model = Dlg3Model()
            filepath = os.path.join(dir, file)
            try:
                mapname, category, filename = self.win.model.open(filepath)
            # FIXME define an application-specific exception
            except ValueError:
                s = f"Can't open '{filepath}'"
                self.GetStatusBar().PushStatusText(s)
                d.Destroy()
            # A file has been opened
            s = f'Opened {mapname}, {category}, {filename}'
            self.GetStatusBar().PushStatusText(s)
            self.panel.pnl.set_check(category, True)
            # End of scope of previous remark on the role of the 'ui' module.
            self.win.update_view()
        d.Destroy()
Ejemplo n.º 2
0
 def test02_single_file(self):
     model = Dlg3Model()
     filename = '453066.HY.opt.gz'
     model.open(build_filepath('brunswick-e_GA', 'hydrography', filename))
     x = list(model.get_all_files())
     self.assertEqual(1, len(x))
     self.assertEqual(filename, x[0].filename)
Ejemplo n.º 3
0
Archivo: ui.py Proyecto: joaomdsc/mapv
 def on_open_place(self, e):
     obj = e.GetEventObject()
     id = e.GetId()
     mapname = obj.GetLabel(id)
     s = f'Opening {mapname}'
     self.GetStatusBar().PushStatusText(s)
     if self.win.model is None or self.win.model.kind == 'Usgs':
         self.win.model = Dlg3Model()
     self.win.model.open_mapname(mapname)
     self.win.update_view()
Ejemplo n.º 4
0
 def test03_two_files(self):
     model = Dlg3Model()
     filename1 = '453066.HY.opt.gz'
     model.open(build_filepath('brunswick-e_GA', 'hydrography', filename1))
     filename2 = '453067.HY.opt.gz'
     model.open(build_filepath('brunswick-e_GA', 'hydrography', filename2))
     x = list(model.get_all_files())
     self.assertEqual(2, len(x))
     names = [y.filename for y in x]
     self.assertIn(filename1, names)
     self.assertIn(filename2, names)
Ejemplo n.º 5
0
 def test04_two_mapnames(self):
     model = Dlg3Model()
     filename1 = '525694.HY.opt.gz'
     model.open(build_filepath('los_angeles-e_CA', 'hydrography',
                               filename1))
     filename2 = '525802.HY.opt.gz'
     model.open(build_filepath('long_beach-e_CA', 'hydrography', filename2))
     x = list(model.get_all_files())
     self.assertEqual(2, len(x))
     names = [y.filename for y in x]
     self.assertIn(filename1, names)
     self.assertIn(filename2, names)
Ejemplo n.º 6
0
Archivo: ui.py Proyecto: joaomdsc/mapv
    def __init__(self, filepath=None, mapname=None):
        """mapname is the mapname-e_STATE identifier described in DLG 00README.
        """
        super().__init__(None, -1, title='Mapv', size=(900, 600))

        self.SetTitle('Mapv')
        self.CreateStatusBar()

        # Horizontal sizer
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        
        # Controls panel
        self.panel = MainPanel(self)
        hbox.Add(self.panel, 0, wx.EXPAND, 0)

        # Drawing area
        self.win = DrawingArea(self, size=(600,800))
        hbox.Add(self.win, 1, wx.EXPAND, 0)
        
        hbox.SetSizeHints(self)
        self.SetSizer(hbox)

        # Menus
        self.places_submenu = None  # for adding/removing items
        self.places_menuitem = None  # for enabling/disabling the submenu
        self.SetMenuBar(self.create_menus())
        self.Show(True)

        # Initially open file
        if filepath is not None:
            set_dir(os.path.dirname(filepath))
            self.win.model = Dlg3Model()
            self.win.model.open(filepath)
            
        if mapname is not None:
            self.win.model = Dlg3Model()
            self.win.model.open_mapname(mapname)

        # Reflect the current state 
        self.win.update_view()
Ejemplo n.º 7
0
    def setUpClass(cls):
        """Called once before the tests are run.

        This loads one file into the model."""
        cls.model = Dlg3Model()
        cls.mapname = 'boston-e_MA'
        cls.category = 'hydrography'

        # Build a file path
        cls.filepath = build_filepath(cls.mapname, cls.category,
                                      '444595.HY.opt.gz')

        # Open file in the model
        cls.model.open(cls.filepath)
Ejemplo n.º 8
0
    def test00_empty_model(self):
        model = Dlg3Model()
        category = 'hydrography'
        self.assertEqual(0, len(model.get_local_mapnames()))
        self.assertIsNone(model.get_first_file())
        self.assertIsNone(model.bounding_box())

        # Test the 'get_files_by_category' method
        g = model.get_files_by_category(category)
        with self.assertRaises(StopIteration):
            next(g)

        # Test open_files_category. Should add nothing, no new files, because
        # there is no open mapname yet.
        model.open_files_category(category)

        # Check that there are no files in this category
        g = model.get_files_by_category(category)
        with self.assertRaises(StopIteration):
            next(g)
Ejemplo n.º 9
0
 def test01_empty_model(self):
     model = Dlg3Model()
     g = model.get_all_files()
     # Check that there are no files
     with self.assertRaises(StopIteration):
         next(g)