def show(self, parent=None, locals={}, function=None, wizard=0, docstring=""): docstring = util.dedent(docstring) self.wizard = wizard if function != None: self.function = function self.setup(parent, locals, docstring, function) while 1: result = wx.Dialog.ShowModal(self.window) try: if result == wx.ID_CANCEL: return None elif self.function is None: if function is None: return tuple(self.get_args()) else: return function + self.get_args_string() else: ret = self.function + self.get_args_string() self.window.Destroy() return ret except ArgInvalidException, e: gui_util.message(str(e)) #except Exception: # throw else: break
def create_help_display(parent, docstring): """ Creates a help window that contains the information specified by the *docstring*. :param parent: Window which should be the parent of the help window :param docstring: Content of the help window :return: help window """ import wx if wx.VERSION >= (2, 5): import wx.html from gamera import util from gamera.gui.gui_util import docstring_to_html try: docstring = util.dedent(docstring) html = docstring_to_html(docstring) window = wx.html.HtmlWindow(parent, -1, size=wx.Size(50, 100)) if "gtk2" in wx.PlatformInfo: window.SetStandardFonts() window.SetPage(html) window.SetBackgroundColour(wx.Colour(255, 255, 232)) if wx.VERSION < (2, 8): window.SetBestFittingSize(wx.Size(50, 150)) else: window.SetInitialSize(wx.Size(50, 150)) return window except Exception, e: print e
def _create_help_display(self, docstring): docstring = util.dedent(docstring) style = (wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2) window = wx.TextCtrl(self.window, -1, style=style, size=wx.Size(50, 100)) window.SetValue(docstring) window.SetBackgroundColour(wx.Colour(255, 255, 232)) return window
def register(cls): # add_to_image = add_to_image and cls.add_to_image if cls.return_type != None: if cls.return_type.name == None: cls.return_type = copy.copy(cls.return_type) cls.return_type.name = cls.__name__ if not hasattr(cls, "__call__"): # This loads the actual C++ function if it is not directly # linked in the Python PluginFunction class parts = cls.__module__.split('.') file = inspect.getfile(cls) cpp_module_name = '_' + parts[-1] directory = os.path.split(file)[0] sys.path.append(directory) found = imp.find_module(cpp_module_name) del sys.path[-1] if found: module = imp.load_module(cpp_module_name, *found) if module == None: return func = getattr(module, cls.__name__) elif cls.__call__ is None: func = None else: func = cls.__call__ if type(cls.__call__) == new.instancemethod: func = cls.__call__.im_func func.func_doc = ("%s\n\n%s" % (cls.get_formatted_argument_list(), util.dedent(cls.__doc__))) cls.__call__ = staticmethod(func) if cls.category == None: category = cls.module.category else: category = cls.category if not category is None and not func is None: image_type = isinstance(cls.self_type, ImageType) if image_type: pixel_types = cls.self_type.pixel_types else: pixel_types = [NONIMAGE] for pixel_type in pixel_types: if not plugin_methods.has_key(pixel_type): plugin_methods[pixel_type] = {} start = plugin_methods[pixel_type] for subcategory in category.split('/'): if not start.has_key(subcategory): start[subcategory] = {} start = start[subcategory] start[cls.__name__] = cls if not func is None and not cls.self_type is None: cls.self_type.register(cls, func)
def create_help_display(parent, docstring): """ Creates a help window that contains the information specified by the *docstring*. :param parent: Window which should be the parent of the help window :param docstring: Content of the help window :return: help window """ import wx if wx.VERSION >= (2, 5): import wx.html from gamera import util from gamera.gui.gui_util import docstring_to_html try: docstring = util.dedent(docstring) html = docstring_to_html(docstring) window = wx.html.HtmlWindow(parent, -1, size=wx.Size(50, 100)) if "gtk2" in wx.PlatformInfo: window.SetStandardFonts() window.SetPage(html) window.SetBackgroundColour(wx.Colour(255, 255, 232)) if wx.VERSION < (2, 8): window.SetBestFittingSize(wx.Size(50, 150)) else: window.SetInitialSize(wx.Size(50, 150)) return window except Exception as e: print(e) else: from gamera import util docstring = util.dedent(docstring) style = (wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2) window = wx.TextCtrl(parent, -1, style=style, size=wx.Size(50, 100)) window.SetValue(docstring) window.SetBackgroundColour(wx.Colour(255, 255, 232)) return window
def _create_help_display(self, docstring): try: docstring = util.dedent(docstring) html = gui_util.docstring_to_html(docstring) window = wx.html.HtmlWindow(self.window, -1, size=wx.Size(50, 100)) if wx.VERSION >= (2, 5) and "gtk2" in wx.PlatformInfo: window.SetStandardFonts() window.SetPage(html) window.SetBackgroundColour(wx.Colour(255, 255, 232)) if wx.VERSION < (2, 8): window.SetBestFittingSize(wx.Size(50, 150)) else: window.SetInitialSize(wx.Size(50, 150)) return window except Exception, e: print e
def method_doc(self, func, level, images, s): s.write("``%s``\n" % func.__name__) s.write(underline(level, func.__name__, 4)) s.write("\n\n") if func.return_type is not None: s.write(func.return_type.rest_repr() + " ") header = "**%s** (%s)\n" % (func.__name__, ', '.join( [x.rest_repr(True) for x in func.args.list])) s.write(header) s.write("\n\n") if func.self_type is not None: s.write(":Operates on: %s\n" % func.self_type.rest_repr(False)) if func.return_type is not None: s.write(":Returns: %s\n" % (func.return_type.rest_repr(False))) if func.category is None: category = func.module.category else: category = func.category if category is not None: s.write(":Category: %s\n" % category) file = os.path.split(inspect.getsourcefile(func))[1] if file == 'plugin.py': file = 'core.py' s.write(":Defined in: %s\n" % os.path.split(inspect.getsourcefile(func))[1]) if func.author is None: author = func.module.author else: author = func.author if author is not None: if func.module.url is not None and 0: s.write(":Author: `%s`__\n.. __: %s\n" % (author, func.module.url)) else: s.write(":Author: %s\n" % (author, )) if func.image_types_must_match: s.write( "\n*All images passed in (including self) must have the same pixel type.*\n\n" ) doc = func.__doc__ if doc is None or doc == "": s.write("\n.. warning:: No documentation written.\n\n") else: doc = util.dedent(doc) s.write("\n\n%s\n" % doc) self.method_example(func, level, images, s)
def PluginFactory(name, category=None, return_type=None, self_type=ImageType(ALL), args=None): from gamera import core cls = new.classobj(name, (PluginFunction,), {}) if not category is None: cls.category = category cls.return_type = return_type cls.self_type = self_type if args is None: cls.args = Args([]) else: cls.args = args func = getattr(core.ImageBase, name) cls.__call__ = func cls.__doc__ = util.dedent(func.__doc__) cls.module = Builtin return cls
def method_doc(self, func, level, images, s): s.write(u"``%s``\n" % func.__name__) s.write(underline(level, func.__name__, 4)) s.write("\n\n") if func.return_type != None: s.write(func.return_type.rest_repr() + " ") header = u"**%s** (%s)\n" % (func.__name__, ', '.join( [x.rest_repr(True) for x in func.args.list])) s.write(header) s.write("\n\n") if func.self_type != None: s.write(u":Operates on: %s\n" % func.self_type.rest_repr(False)) if func.return_type != None: s.write(u":Returns: %s\n" % (func.return_type.rest_repr(False))) if func.category == None: category = func.module.category else: category = func.category if category != None: s.write(u":Category: %s\n" % category) file = os.path.split(inspect.getsourcefile(func))[1] if file == 'plugin.py': file = 'core.py' s.write(":Defined in: %s\n" % os.path.split(inspect.getsourcefile(func))[1]) if func.author is None: author = func.module.author else: author = func.author if author != None: if func.module.url != None and 0: s.write(u":Author: `%s`__\n.. __: %s\n" % (author, func.module.url)) else: s.write(u":Author: %s\n" % (author,)) if func.image_types_must_match: s.write("\n*All images passed in (including self) must have the same pixel type.*\n\n") doc = func.__doc__ if doc is None or doc == "": s.write("\n.. warning:: No documentation written.\n\n") else: doc = util.dedent(doc) s.write(u"\n\n%s\n" % doc) self.method_example(func, level, images, s)
def escape_docstring(cls): if cls.__doc__ is None: doc = '' doc = util.dedent(cls.__doc__) doc = doc.replace("\n", r"\n").replace('"', r'\"') return r'"%s\n\n%s"' % (cls.get_formatted_argument_list(), doc)
window = wx.html.HtmlWindow(parent, -1, size=wx.Size(50, 100)) if "gtk2" in wx.PlatformInfo: window.SetStandardFonts() window.SetPage(html) window.SetBackgroundColour(wx.Colour(255, 255, 232)) if wx.VERSION < (2, 8): window.SetBestFittingSize(wx.Size(50, 150)) else: window.SetInitialSize(wx.Size(50, 150)) return window except Exception, e: print e else: from gamera import util docstring = util.dedent(docstring) style = (wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2) window = wx.TextCtrl(parent, -1, style=style, size=wx.Size(50, 100)) window.SetValue(docstring) window.SetBackgroundColour(wx.Colour(255, 255, 232)) return window def configure_size_small_height(grid_sizer, window, min_width, client_area): if wx.VERSION < (2, 8): grid_sizer.SetBestFittingSize(wx.Size(0, 0)) window.SetBestFittingSize(wx.Size(min_width, client_area.height/2)) else: grid_sizer.SetInitialSize(wx.Size(0, 0)) window.SetInitialSize(wx.Size(min_width, client_area.height/2)) def configure_size_normal_height(grid_sizer, window, min_width, min_height):