Esempio n. 1
0
 def load_data(self):
     """Loads the data set and plots"""
     exception_queue = Queue.Queue()
     data_thd = workerthread.WorkerThread(exception_queue=exception_queue,
                                          target=self.controller.load_data)
     data_thd.start()
     while True:
         data_thd.join(0.125)
         if not data_thd.is_alive():
             try:
                 exc_type, exc = exception_queue.get(block=False)
                 module_logger.error("Unable to load data: {0}".format(exc))
                 err_msg = "An error occurred while loading data:\n{0}".format(
                     exc)
                 if len(err_msg) > 150:
                     # Truncate lengthy error messages
                     err_msg = ''.join([err_msg[:150], "\n(continued)"])
                 err_dlg = wx.MessageDialog(self.parent,
                                            message=err_msg,
                                            caption="Unable To Load Data",
                                            style=wx.ICON_ERROR)
                 err_dlg.ShowModal()
             except Queue.Empty:
                 pass
             break
         wx.GetApp().Yield(True)
     self.title = 'Plot - {0}'.format(os.path.basename(self.data_file))
     wx.Frame.__init__(self,
                       id=wx.ID_ANY,
                       parent=self.parent,
                       title=self.title)
     self.init_menu()
     self.init_ui()
     self.controller.check_data_dims()
     self.controller.plot(self.controller.data)
Esempio n. 2
0
 def fetch_plugin(self):
     """Downloads the plugin"""
     url_dict = self.get_configured_url()
     busy_dlg = dialogs.progressDialog(dlg_title="Retrieving Archive",
                                       dlg_msg="Please wait, retrieving archive...")
     exception_queue = Queue.Queue()
     fetch_plugin_thd = workerthread.WorkerThread(exception_queue=exception_queue,
                                                  target=self.model.get_plugin,
                                                  args=(url_dict,))
     fetch_plugin_thd.start()
     while True:
         fetch_plugin_thd.join(0.125)
         busy_dlg.update()
         if not fetch_plugin_thd.is_alive():
             busy_dlg.close()
             try:
                 exc_type, exc = exception_queue.get(block=False)
                 err_str = str(exc)
                 if len(err_str) == 0:
                     err_str = exc_type.__name__
                 module_logger.error("Unable to read archive: {0}".format(err_str))
                 err_msg = "An error occurred while reading the archive:\n{0}".format(err_str)
                 err_dlg = wx.MessageDialog(self.view, message=err_msg,
                                            caption="Unable To Read Archive",
                                            style=wx.ICON_ERROR)
                 err_dlg.ShowModal()
             except Queue.Empty:
                 pass
             break
         wx.GetApp().Yield()
Esempio n. 3
0
 def import_data(self, import_fn, *args, **kwargs):
     """Imports data using the specified function"""
     exception_queue = Queue.Queue()
     import_thd = workerthread.WorkerThread(exception_queue=exception_queue,
                                            target=import_fn,
                                            *args,
                                            **kwargs)
     import_thd.start()
     while True:
         import_thd.join(0.125)
         if not import_thd.is_alive():
             try:
                 exc_type, exc = exception_queue.get(block=False)
                 err_str = str(exc)
                 if len(err_str) == 0:
                     err_str = exc_type.__name__
                 module_logger.error(
                     "Error importing text file: {0}".format(err_str))
                 err_msg = "An error occurred during import:\n{0}".format(
                     err_str)
                 err_dlg = wx.MessageDialog(self.view,
                                            message=err_msg,
                                            caption="Unable To Import File",
                                            style=wx.ICON_ERROR)
                 err_dlg.ShowModal()
             except Queue.Empty:
                 pass
             gc.collect()
             break
         wx.GetApp().Yield()
Esempio n. 4
0
 def on_export_text(self, evt):
     """Handles request to export selected data to delimited ASCII"""
     file_dlg = wx.FileDialog(parent=self.view, message="Please specify an output filename.",
                              style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
     if file_dlg.ShowModal() == wx.ID_OK:
         exportfmt_dlg = dlg.ExportTextDialog(parent=self.view)
         if exportfmt_dlg.ShowModal() == wx.ID_OK:
             wx.BeginBusyCursor()
             export_params = exportfmt_dlg.get_export_parameters()
             exception_queue = Queue.Queue()
             export_text_thd = workerthread.WorkerThread(exception_queue=exception_queue,
                                                         target=dataio.export_txt,
                                                         args=(file_dlg.GetPath(), self.view.data_panel.data),
                                                         kwargs=export_params)
             export_text_thd.start()
             while True:
                 export_text_thd.join(0.125)
                 if not export_text_thd.is_alive():
                     try:
                         exc_type, exc = exception_queue.get(block=False)
                         err_str = str(exc)
                         if len(err_str) == 0:
                             err_str = exc_type.__name__
                         module_logger.error("Error exporting to text file: {0}".format(err_str))
                         err_msg = "An error occurred during export:\n{0}".format(err_str)
                         err_dlg = wx.MessageDialog(self.view, message=err_msg,
                                                    caption="Unable To Export File", style=wx.ICON_ERROR)
                         err_dlg.ShowModal()
                     except Queue.Empty:
                         pass
                     break
                 wx.GetApp().Yield()
             wx.EndBusyCursor()
         exportfmt_dlg.Destroy()
Esempio n. 5
0
 def test_execution(self):
     """Verify execution without Exceptions"""
     a_thread = workerthread.WorkerThread(exception_queue=self.exception_queue,
                                          return_queue=self.message_queue,
                                          target=self.sample_function, args=(1, 2))
     a_thread.start()
     a_thread.join()
     self.assertEqual(self.sample_function(1, 2), self.message_queue.get())
Esempio n. 6
0
 def test_exception_execution(self):
     """Verify Exceptions are passed back through the Exception Queue"""
     a_thread = workerthread.WorkerThread(exception_queue=self.exception_queue,
                                          return_queue=self.message_queue,
                                          target=self.sample_exception_function, args=(1, 2))
     a_thread.start()
     a_thread.join()
     exc_type, exc = self.exception_queue.get()
     self.assertTrue(isinstance(exc, Exception))
Esempio n. 7
0
 def run_model(self, model_instance):
     """Runs the specified POD Model instance in a separate thread."""
     exception_queue = Queue.Queue()
     model_thd = workerthread.WorkerThread(exception_queue=exception_queue,
                                           target=model_instance.run)
     model_thd.start()
     progress_dlg = dialogs.progressDialog(dlg_title="Running POD Model",
                                           dlg_msg="Please wait, running POD Model...")
     while True:
         model_thd.join(0.125)
         progress_dlg.update()
         if not model_thd.is_alive():
             try:
                 exc_type, exc = exception_queue.get(block=False)
                 err_str = str(exc)
                 if len(err_str) == 0:
                     err_str = exc_type.__name__
                 module_logger.error("Unable to run POD Model: {0}".format(err_str))
                 err_msg = "An error occurred while running the POD Model:\n{0}".format(err_str)
                 err_dlg = wx.MessageDialog(self.view.parent, message=err_msg,
                                            caption="Error In POD Model Execution",
                                            style=wx.ICON_ERROR)
                 err_dlg.ShowModal()
                 err_dlg.Destroy()
                 return
             except Queue.Empty:
                 # No errors occurred, continue processing
                 model_instance.plot1(self.view.axes1)
                 model_instance.plot2(self.view.axes2)
                 if model_instance.data is not None: # Model returned data to display
                     try:
                         self.populate_spreadsheet(self.view.output_grid, model_instance.data)
                         self.view.spreadsheet_nb.ChangeSelection(self.view.output_sheet_page)
                     except MemoryError: # File too large to load
                         module_logger.error("Unable to preview data, file too large to fit in memory.")
                         err_msg = "The file is too large to load."
                         err_dlg = wx.MessageDialog(self.view, message=err_msg,
                                                    caption="Unable To Preview Data",
                                                    style=wx.ICON_ERROR)
                         err_dlg.ShowModal()
                         err_dlg.Destroy()
                 if model_instance.results is not None: # Model return output text to display
                     self.view.txtoutput_tc.WriteText(model_instance.results)
                 self.refresh_plots()
                 break
             finally:
                 progress_dlg.close()
         wx.GetApp().Yield(True)
Esempio n. 8
0
 def load_data(self):
     exception_queue = Queue.Queue()
     data_thd = workerthread.WorkerThread(exception_queue=exception_queue,
                                          target=self.controller.load_data)
     data_thd.start()
     while True:
         data_thd.join(0.125)
         if not data_thd.is_alive():
             try:
                 exc_type, exc = exception_queue.get(block=False)
                 err_str = str(exc)
                 if len(err_str) == 0:
                     err_str = exc_type.__name__
                 module_logger.error(
                     "Unable to load data: {0}".format(err_str))
                 err_msg = "An error occurred while loading data:\n{0}".format(
                     err_str)
                 if len(err_msg) > 150:
                     # Truncate lengthy error messages
                     err_msg = ''.join([err_msg[:150], "\n(continued)"])
                 err_dlg = wx.MessageDialog(self.parent,
                                            message=err_msg,
                                            caption="Unable To Load Data",
                                            style=wx.ICON_ERROR)
                 err_dlg.ShowModal()
             except Queue.Empty:
                 pass
             break
         wx.GetApp().Yield(True)
     if self.has_data():
         if self.controller.data.ndim == 3:
             module_logger.info("Data are 3D, requesting planar slice.")
             slice_dlg = dialogs.PlanarSliceDialog(
                 parent=self,
                 data_shape=self.controller.data.shape,
                 title="Specify 2D Plane")
             if slice_dlg.ShowModal() == wx.ID_OK:
                 self.controller.load_data(slice_dlg.get_data_slice())
             module_logger.info("User cancelled planar slice operation.")
             slice_dlg.Destroy()
         self.controller.populate_spreadsheet()