Exemplo n.º 1
0
   def __init__(self, *args, **kwargs):
      self.update = None
      wx.py.shell.Shell.__init__(self, *args, **kwargs)
      self.push("from gamera.gui import gui")
      self.push("from gamera.gui.matplotlib_support import *")
      self.push("from gamera.core import *")
      self.push("init_gamera()")
      self.locals = self.interp.locals
      self.autoCallTip = False

      style = wx.py.editwindow.FACES.copy()
      style['mono'] = config.get("shell_font_face")
      style['size'] = config.get("shell_font_size")
      self.setStyles(style)
      self.ScrollToLine(1)
      compat_wx.configure_shell_auto_completion(self)
Exemplo n.º 2
0
   def import_command_line_modules(self):
      sys.argv = config.get_free_args()
      if len(sys.argv):
         file = sys.argv[0]
         try:
            name = os.path.basename(file)[:-3]
            module = imp.load_source(name, file)
            self.shell.locals[name] = module
            self.shell.push(name)
            imported = True
         except Exception as e:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            gui_util.message("Error importing file '%s':\n%s" %
                             (file, "".join(
               traceback.format_exception(exc_type, exc_value, exc_traceback))))

      execfiles = config.get("execfile")
      if execfiles is not None:
         for file in execfiles:
            try:
               self.shell.run("execfile(%s)" % repr(file))
            except Exception as e:
               exc_type, exc_value, exc_traceback = sys.exc_info()
               gui_util.message("Error importing file '%s':\n%s" %
                                (file, "".join(traceback.format_exception(
                  exc_type, exc_value, exc_traceback))))
Exemplo n.º 3
0
def ProgressFactory(message, length=1, numsteps=0):
   if has_gui.gui != None:
      return has_gui.gui.ProgressBox(message, length, numsteps)
   elif config.get("progress_bar"):
      return ProgressText(message, length)
   else:
      return ProgressNothing(message, length)
Exemplo n.º 4
0
def ProgressFactory(message, length=1, numsteps=0):
    if has_gui.gui != None:
        return has_gui.gui.ProgressBox(message, length, numsteps)
    elif config.get("progress_bar"):
        return ProgressText(message, length)
    else:
        return ProgressNothing(message, length)
Exemplo n.º 5
0
   def __init__(self, *args, **kwargs):
      self.update = None
      wx.py.shell.Shell.__init__(self, *args, **kwargs)
      self.push("from gamera.gui import gui")
      self.push("from gamera.gui.matplotlib_support import *")
      self.push("from gamera.core import *")
      self.push("init_gamera()")
      self.locals = self.interp.locals
      self.autoCallTip = False

      style = wx.py.editwindow.FACES.copy()
      style['mono'] = config.get("shell_font_face")
      style['size'] = config.get("shell_font_size")
      self.setStyles(style)
      self.ScrollToLine(1)
      compat_wx.configure_shell_auto_completion(self)
Exemplo n.º 6
0
def directory_dialog(parent, create=1):
    last_directory = config.get("default_dir")
    if create:
        style = wx.DD_NEW_DIR_BUTTON
    else:
        style = 0
    dlg = wx.DirDialog(parent, "Choose a directory", last_directory, style)
    if dlg.ShowModal() == wx.ID_OK:
        filename = dlg.GetPath()
        dlg.Destroy()
        return filename
    return None
Exemplo n.º 7
0
def directory_dialog(parent, create=1):
   last_directory = config.get("default_dir")
   if create:
      style = wx.DD_NEW_DIR_BUTTON
   else:
      style = 0
   dlg = wx.DirDialog(parent, "Choose a directory", last_directory, style)
   if dlg.ShowModal() == wx.ID_OK:
      filename = dlg.GetPath()
      dlg.Destroy()
      return filename
   return None
Exemplo n.º 8
0
 def __init__(self, parent, extensions="*.*", multiple=0):
    cls = self.__class__
    if cls.last_directory is None:
       cls.last_directory = path.abspath(config.get("default_dir"))
    if multiple:
       self._flags |= wx.FD_MULTIPLE
       self._multiple = True
    else:
       self._multiple = False
    wx.FileDialog.__init__(
       self, parent, "Choose a file",
       cls.last_directory, "", str(extensions), style=self._flags)
    self.extensions = extensions
Exemplo n.º 9
0
 def __init__(self, parent, extensions="*.*", multiple=0):
    cls = self.__class__
    if cls.last_directory is None:
       cls.last_directory = path.abspath(config.get("default_dir"))
    if multiple:
       self._flags |= wx.FD_MULTIPLE
       self._multiple = True
    else:
       self._multiple = False
    wx.FileDialog.__init__(
       self, parent, "Choose a file",
       cls.last_directory, "", str(extensions), style=self._flags)
    self.extensions = extensions
Exemplo n.º 10
0
def _init_gamera():
    global _gamera_initialised
    if _gamera_initialised:
        return
    _gamera_initialised = True
   # Create the default functions for the menupl
    for method in (
        plugin.PluginFactory(
            "load_image", "File", plugin.ImageType(ALL, "image"),
            plugin.ImageType(ALL), plugin.Args([plugin.FileOpen("filename", extension=util.load_image_file_extension_finder)])),
        plugin.PluginFactory(
            "save_image", "File", None,
            plugin.ImageType(ALL), plugin.Args([plugin.FileSave("filename", extension=util.save_image_file_extension_finder)])),
        plugin.PluginFactory(
            "display", "Displaying", None, plugin.ImageType(ALL), None),
        plugin.PluginFactory(
            "display_ccs", "Displaying", None, plugin.ImageType([ONEBIT]),
            None),
        plugin.PluginFactory(
            "display_false_color", "Displaying", None,
            plugin.ImageType([GREYSCALE, FLOAT]),
            None),
        plugin.PluginFactory(
            "classify_manual", "Classification", None,
            plugin.ImageType([ONEBIT]), plugin.Args([plugin.String("id")])),
        plugin.PluginFactory(
            "classify_heuristic", "Classification", None,
            plugin.ImageType([ONEBIT]), plugin.Args([plugin.String("id")])),
        plugin.PluginFactory(
            "classify_automatic", "Classification", None,
            plugin.ImageType([ONEBIT]), plugin.Args([plugin.String("id")])),
        plugin.PluginFactory(
            "unclassify", "Classification", None,
            plugin.ImageType([ONEBIT]), None),
        plugin.PluginFactory(
            "get_main_id", "Classification", plugin.String("id"),
            plugin.ImageType([ONEBIT]), None),
        plugin.PluginFactory(
            "get_confidence", "Classification", plugin.Float("confidence"),
            plugin.ImageType([ONEBIT]), plugin.Args([plugin.Choice("confidence_type", default=NoneDefault)])),
        plugin.PluginFactory(
            "has_id_name", "Classification", plugin.Check("result"),
            plugin.ImageType([ONEBIT]), plugin.Args([plugin.String("id")])),
        plugin.PluginFactory(
            #"subimage", "Utility", plugin.Check("result"),
            "subimage", "Utility", plugin.ImageType(ALL),
            plugin.ImageType(ALL), plugin.Args([plugin.Point("upper_left"),
                                             plugin.Point("lower_right")])),
        plugin.PluginFactory(
            "to_xml", "XML", plugin.String('xml'),
            plugin.ImageType([ONEBIT]), None),
        plugin.PluginFactory(
            "to_xml_filename", "XML", None, plugin.ImageType([ONEBIT]),
            plugin.Args([
        plugin.FileSave("filename", extension=gamera_xml.extensions)]))
      ):
        method.register()
    try:
        verbose = config.get("verbosity_level")
    except:
        verbose = 0
    paths.import_directory(paths.plugins, globals(), locals(), verbose)
    sys.path.append(".")
Exemplo n.º 11
0
class ShellFrame(wx.Frame):
    def __init__(self, parent, id, title):
        global shell
        wx.Frame.__init__(
            self,
            parent,
            id,
            title,
            (100, 100),
            # Win32 change
            [600, 550],
            style=wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN
            | wx.NO_FULL_REPAINT_ON_RESIZE)
        wx.EVT_CLOSE(self, self._OnCloseWindow)

        self.known_modules = {}
        self.menu = self.make_menu()
        self.SetMenuBar(self.menu)

        if aui:
            self._aui = aui.AuiManager(self)
            nb_style = (aui.AUI_NB_TAB_SPLIT | aui.AUI_NB_TAB_MOVE
                        | aui.AUI_NB_TAB_EXTERNAL_MOVE
                        | aui.AUI_NB_SCROLL_BUTTONS)
            nb = aui.AuiNotebook(self, style=nb_style)
            control_parent = self
        else:
            splitter = wx.SplitterWindow(self,
                                         -1,
                                         style=wx.SP_3DSASH | wx.CLIP_CHILDREN
                                         | wx.NO_FULL_REPAINT_ON_RESIZE
                                         | wx.SP_LIVE_UPDATE)
            control_parent = splitter

        self.icon_display = icon_display.IconDisplay(control_parent, self)
        if aui:
            self.shell = PyShellGameraShell(parent=self)
            rootObject = self.shell.interp.locals
            self.filling = wx.py.filling.Filling(parent=nb,
                                                 rootObject=rootObject,
                                                 rootIsNamespace=True)
            # Add 'filling' to the interpreter's locals.
            self.calltip = Calltip(parent=nb)
            self.sessionlisting = wx.py.crust.SessionListing(parent=nb)
        else:
            crust = PyCrustGameraShell(control_parent, -1)
            self.shell = crust.shell
        self.shell.main_win = self
        self.shell.update = self.Update
        image_menu.set_shell(self.shell)
        image_menu.set_shell_frame(self)
        self.shell.push("from gamera.gui import gui")
        self.shell.push("from gamera.gui.matplotlib_support import *")
        self.shell.push("from gamera.core import *")
        self.shell.push("init_gamera()")

        self.shell.update = self.Update
        self.icon_display.shell = self.shell
        self.icon_display.main = self
        self.Update()
        self.shell.SetFocus()

        if aui:
            self._aui.AddPane(
                self.icon_display,
                aui.AuiPaneInfo().Name("icon_display").CenterPane().MinSize(
                    wx.Size(96, 96)).CloseButton(False).CaptionVisible(
                        True).Caption("Objects").Dockable(True))
            self._aui.AddPane(
                self.shell,
                aui.AuiPaneInfo().Name("shell").CenterPane().MinSize(
                    wx.Size(200, 200)).CloseButton(False).CaptionVisible(
                        True).MaximizeButton(True).Caption(
                            "Interactive Python Shell").Dockable(True))
            nb.AddPage(self.calltip, "Documentation")
            nb.AddPage(self.filling, "Namespace")
            nb.AddPage(self.sessionlisting, "History")
            self._aui.AddPane(
                nb,
                aui.AuiPaneInfo().Name("notebook").CenterPane().MinSize(
                    wx.Size(200, 100)).MaximizeButton(True))

            self._aui.GetPane("notebook").Show().Bottom()
            self._aui.GetPane("icon_display").Show().Left()
            self._aui.Update()
        else:
            splitter.SetMinimumPaneSize(20)
            splitter.SplitVertically(self.icon_display, crust, 120)
            splitter.SetSashPosition(120)

        self.status = StatusBar(self)
        self.SetStatusBar(self.status)
        from gamera.gui import gamera_icons
        icon = wx.IconFromBitmap(gamera_icons.getIconBitmap())
        self.SetIcon(icon)
        self.Move(wx.Point(int(30), int(30)))
        wx.Yield()

    def import_command_line_modules(self):
        sys.argv = config.get_free_args()
        if len(sys.argv):
            file = sys.argv[0]
            try:
                name = os.path.basename(file)[:-3]
                module = imp.load_source(name, file)
                self.shell.locals[name] = module
                self.shell.push(name)
                imported = True
            except Exception, e:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                gui_util.message("Error importing file '%s':\n%s" %
                                 (file, "".join(
                                     traceback.format_exception(
                                         exc_type, exc_value, exc_traceback))))

        execfiles = config.get("execfile")
        if execfiles is not None:
            for file in execfiles:
                try:
                    self.shell.run("execfile(%s)" % repr(file))
                except Exception, e:
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    gui_util.message(
                        "Error importing file '%s':\n%s" % (file, "".join(
                            traceback.format_exception(exc_type, exc_value,
                                                       exc_traceback))))
Exemplo n.º 12
0
def _init_gamera():
    global _gamera_initialised
    if _gamera_initialised:
        return
    _gamera_initialised = True
    # Create the default functions for the menupl
    for method in (
            plugin.PluginFactory(
                "load_image", "File", plugin.ImageType(ALL, "image"),
                plugin.ImageType(ALL),
                plugin.Args([
                    plugin.FileOpen(
                        "filename",
                        extension=util.load_image_file_extension_finder)
                ])),
            plugin.PluginFactory(
                "save_image", "File", None, plugin.ImageType(ALL),
                plugin.Args([
                    plugin.FileSave(
                        "filename",
                        extension=util.save_image_file_extension_finder)
                ])),
            plugin.PluginFactory("display", "Displaying", None,
                                 plugin.ImageType(ALL), None),
            plugin.PluginFactory("display_ccs", "Displaying", None,
                                 plugin.ImageType([ONEBIT]), None),
            plugin.PluginFactory("display_false_color", "Displaying", None,
                                 plugin.ImageType([GREYSCALE, FLOAT]), None),
            plugin.PluginFactory("classify_manual", "Classification", None,
                                 plugin.ImageType([ONEBIT]),
                                 plugin.Args([plugin.String("id")])),
            plugin.PluginFactory("classify_heuristic", "Classification", None,
                                 plugin.ImageType([ONEBIT]),
                                 plugin.Args([plugin.String("id")])),
            plugin.PluginFactory("classify_automatic", "Classification", None,
                                 plugin.ImageType([ONEBIT]),
                                 plugin.Args([plugin.String("id")])),
            plugin.PluginFactory("unclassify", "Classification", None,
                                 plugin.ImageType([ONEBIT]), None),
            plugin.PluginFactory("get_main_id", "Classification",
                                 plugin.String("id"),
                                 plugin.ImageType([ONEBIT]), None),
            plugin.PluginFactory(
                "get_confidence", "Classification", plugin.Float("confidence"),
                plugin.ImageType([ONEBIT]),
                plugin.Args(
                    [plugin.Choice("confidence_type", default=NoneDefault)])),
            plugin.PluginFactory("has_id_name", "Classification",
                                 plugin.Check("result"),
                                 plugin.ImageType([ONEBIT]),
                                 plugin.Args([plugin.String("id")])),
            plugin.PluginFactory(
                #"subimage", "Utility", plugin.Check("result"),
                "subimage",
                "Utility",
                plugin.ImageType(ALL),
                plugin.ImageType(ALL),
                plugin.Args(
                    [plugin.Point("upper_left"),
                     plugin.Point("lower_right")])),
            plugin.PluginFactory("to_xml", "XML", plugin.String('xml'),
                                 plugin.ImageType([ONEBIT]), None),
            plugin.PluginFactory(
                "to_xml_filename", "XML", None, plugin.ImageType([ONEBIT]),
                plugin.Args([
                    plugin.FileSave("filename",
                                    extension=gamera_xml.extensions)
                ]))):
        method.register()
    try:
        verbose = config.get("verbosity_level")
    except:
        verbose = 0
    paths.import_directory(paths.plugins, globals(), locals(), verbose)
    sys.path.append(".")