Example #1
0
 def on_save_workspace(self, evt):
     if not self.confirm_properties():
         return
     p = Properties()
     dlg = wx.FileDialog(
         self,
         message="Save workspace as...",
         defaultDir=os.getcwd(),
         defaultFile='%s_%s.workspace' % (os.path.splitext(
             os.path.split(p._filename)[1])[0], p.image_table),
         style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT | wx.FD_CHANGE_DIR)
     if dlg.ShowModal() == wx.ID_OK:
         wx.GetApp().save_workspace(dlg.GetPath())
Example #2
0
 def on_save_properties(self, evt):
     if not self.confirm_properties():
         return
     p = Properties()
     dirname, filename = os.path.split(p._filename)
     ext = os.path.splitext(p._filename)[-1]
     dlg = wx.FileDialog(self,
                         message="Save properties as...",
                         defaultDir=dirname,
                         defaultFile=filename,
                         wildcard=ext,
                         style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
                         | wx.FD_CHANGE_DIR)
     if dlg.ShowModal() == wx.ID_OK:
         p.save_file(dlg.GetPath())
Example #3
0
    def Start(self):
        '''Initialize CPA
        '''
        if hasattr(sys, "frozen") and sys.platform == "darwin":
            # Some versions of Macos like to put CPA in a sandbox. If we're frozen Java should be packed in,
            # so let's just figure out the directory on run time.
            os.environ["CP_JAVA_HOME"] = os.path.abspath(
                os.path.join(sys.prefix, "..", "Resources/Home"))
        '''List of tables created by the user during this session'''
        self.user_tables = []

        p = Properties()
        self.frame = MainGUI(p, None, size=(1000, -1))
        self.frame.Show()  # Show frame
        if not p.is_initialized():
            from cpa.guiutils import show_load_dialog
            try:
                if not show_load_dialog():
                    example_link_address = 'cellprofileranalyst.org'
                    dlg = wx.MessageDialog(
                        None,
                        'CellProfiler Analyst requires a properties file. Download an example at %s'
                        % (example_link_address), 'Properties file required',
                        wx.OK)
                    response = dlg.ShowModal()
                    logging.error(
                        'CellProfiler Analyst requires a properties file.')
                    return False
                else:
                    db = DBConnect()
                    db.connect()
                    db.register_gui_parent(self.frame)
            except Exception as e:
                p._initialized = False
                # Fully raising the exception during this startup sequence will crash CPA.
                # So we'll display it manually.
                show_exception_as_dialog(type(e),
                                         e,
                                         e.__traceback__,
                                         raisefurther=False)
                logging.critical(e)

        try:
            from cpa.updatechecker import check_update
            check_update(self.frame, event=False)
        except:
            logging.warn("CPA was unable to check for updates.")
        return True
Example #4
0
 def clear_link_tables(self, evt=None):
     if not self.confirm_properties():
         return
     p = Properties()
     dlg = wx.MessageDialog(
         self, 'This will delete the tables '
         '"%s" and "%s" from your database. '
         'CPA will automatically recreate these tables as it '
         'discovers how your database is linked. Are you sure you '
         'want to proceed?' % (p.link_tables_table, p.link_columns_table),
         'Clear table linking information?',
         wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
     response = dlg.ShowModal()
     if response != wx.ID_YES:
         return
     db = DBConnect()
     db.execute('DROP TABLE IF EXISTS %s' % (p.link_tables_table))
     db.execute('DROP TABLE IF EXISTS %s' % (p.link_columns_table))
     db.Commit()
Example #5
0
    def on_load_properties(self, evt):
        # Show confirmation dialog.
        if self.properties.is_initialized():
            dlg = wx.MessageDialog(
                None,
                "Loading a new file will close all windows and clear unsaved data. Proceed?",
                'Load properties file', wx.OK | wx.CANCEL)
            response = dlg.ShowModal()
            if response != wx.ID_OK:
                return

        # Close all subwindows
        for window in self.GetChildren():
            if isinstance(window, wx.Frame):
                window.Destroy()

        # Shut down existing connections and wipe properties.
        db = DBConnect()
        db.Disconnect()
        p = Properties()
        p.clear()
        self.console.Clear()

        if not p.is_initialized():
            from cpa.guiutils import show_load_dialog
            if not show_load_dialog():
                example_link_address = 'cellprofileranalyst.org'
                dlg = wx.MessageDialog(
                    None,
                    'CellProfiler Analyst requires a properties file. Download an example at %s'
                    % (example_link_address), 'Properties file required',
                    wx.OK)
                response = dlg.ShowModal()
                logging.error(
                    'CellProfiler Analyst requires a properties file.')
            else:
                db.connect()
                db.register_gui_parent(self)
Example #6
0
import unittest
from cpa.imagereader import ImageReader
from cpa.properties import Properties

p = Properties()

# fake-up some props
p._filename = '../../CPAnalyst_test_data/test_images/'
p.image_channel_colors = ['red', 'green', 'blue', 'none', 'none', 'none']
p.object_name = ['cell', 'cells']
p.image_names = ['', '', '']
p.image_id = 'ImageNumber'

ir = ImageReader()


class TestImageReader(unittest.TestCase):
    def test_tif1(self):
        # TIF RGB, 8-bit, PackBits encoding
        fds = ['color.tif']
        images = ir.ReadImages(fds)
        assert len(images) == 3
        for im in images:
            assert 0. <= im.min() <= im.max() <= 1.
            assert im.shape == (512, 512)

    def test_tif2(self):
        # 2 RGB TIFS
        fds = ['color.tif', 'color.tif']
        images = ir.ReadImages(fds)
        assert len(images) == 6
Example #7
0
 def setup_mysql(self):
     self.p = Properties()
     self.db = DBConnect()
     self.db.Disconnect()
     self.p.LoadFile('../../CPAnalyst_test_data/nirht_test.properties')
Example #8
0
 def setup_sqlite2(self):
     self.p = Properties()
     self.db = DBConnect()
     self.db.Disconnect()
     self.p.LoadFile(
         '../../CPAnalyst_test_data/export_to_db_test.properties')