Ejemplo n.º 1
0
class Generator(plugin.Plugin):
    """Plugin Interface Extension Point for Generator
    type plugin objects. Generator objects are used
    to generate a document/code from one type to another.

    """
    observers = plugin.ExtensionPoint(GeneratorI)

    def InstallMenu(self, menu):
        """Appends the menu of available Generators onto
        the given menu.
        @param menu: menu to install entries into
        @type menu: wx.Menu

        """
        # Fetch all the menu items for each generator object
        menu_items = list()
        for observer in self.observers:
            try:
                menu_i = observer.GetMenuEntry(menu)
                if menu_i:
                    menu_items.append((menu_i.GetItemLabel(), menu_i))
            except Exception, msg:
                util.Log("[generator][err] %s" % str(msg))

        # Construct the menu
        menu_items.sort()
        genmenu = ed_menu.EdMenu()
        for item in menu_items:
            genmenu.AppendItem(item[1])
        menu.AppendMenu(ed_glob.ID_GENERATOR, _("Generator"), genmenu,
                        _("Generate Code and Documents"))
Ejemplo n.º 2
0
class MainWindowAddOn(plugin.Plugin):
    """Plugin that Extends the L{MainWindowI}"""
    observers = plugin.ExtensionPoint(iface.MainWindowI)
    def Init(self, window):
        """Call all observers once to initialize
        @param window: window that observers become children of

        """
        for observer in self.observers:
            try:
                observer.PlugIt(window)
            except Exception, msg:
                util.Log("[ed_main][err] MainWindowAddOn.Init: %s" % str(msg))
Ejemplo n.º 3
0
class BitmapProvider(plugin.Plugin):
    """Plugin that fetches requested icons from the current active theme.

    """
    observers = plugin.ExtensionPoint(ThemeI)

    def __GetCurrentProvider(self):
        """Gets the provider of the current theme resources
        @return: ThemeI object

        """
        theme = Profile_Get('ICONS', 'str', u'')
        for prov in self.observers:
            if theme == prov.GetName():
                return prov

        # Case if a theme was deleted while it was the active theme
        if theme.lower() != u'default':
            Profile_Set('ICONS', u'Default')

        return None

    def GetThemes(self):
        """Gets a list of the installed and activated themes
        @return: list of strings

        """
        return [name.GetName() for name in self.observers]

    def GetBitmap(self, bmp_id, client):
        """Gets a 16x16 or 32x32 pixel bitmap depending on client value.
        May return a NullBitmap if no suitable bitmap can be
        found.

        @param bmp_id: id of bitmap to lookup
        @param client: wxART_MENU, ART_MIME, wxART_TOOLBAR
        @see: L{ed_glob.py}

        """
        prov = self.__GetCurrentProvider()
        if prov is not None:
            if client == wx.ART_MENU:
                bmp = prov.GetMenuBitmap(bmp_id)
            else:
                bmp = prov.GetToolbarBitmap(bmp_id)

            if bmp.IsOk():
                return bmp
        return wx.NullBitmap
Ejemplo n.º 4
0
class Shelf(plugin.Plugin):
    """Plugin that creates a notebook for holding the various Shelf items
    implemented by L{ShelfI}.

    """
    SHELF_NAME = u'Shelf'
    observers = plugin.ExtensionPoint(ShelfI)

    def __init__(self, pmgr):
        """Create the Shelf
        @param pmgr: This plugins manager

        """
        self._log = wx.GetApp().GetLog()
        self._shelf = None
        self._parent = None
        self._open = dict()
        self._imgidx = dict()
        self._imglst = wx.ImageList(16, 16)

    def _GetMenu(self):
        """Return the menu of this object
        @return: ed_menu.EdMenu()

        """
        menu = ed_menu.EdMenu()
        menu.Append(ed_glob.ID_SHOW_SHELF, _("Show Shelf") + \
                    ed_menu.EdMenuBar.keybinder.GetBinding(ed_glob.ID_SHOW_SHELF),
                    _("Show the Shelf"))
        menu.AppendSeparator()
        menu_items = list()
        for observer in self.observers:
            # Register Observers
            self._open[observer.GetName()] = 0
            try:
                menu_i = observer.GetMenuEntry(menu)
                if menu_i is not None:
                    menu_items.append((menu_i.GetItemLabel(), menu_i))
            except Exception, msg:
                self._log("[shelf][err] %s" % str(msg))
        menu_items.sort()

        combo = 0
        for item in menu_items:
            combo += 1
            item[1].SetText(item[1].GetText() + "\tCtrl+Alt+" + str(combo))
            menu.AppendItem(item[1])
        return menu
Ejemplo n.º 5
0
class AutoCompExtension(plugin.Plugin):
    """Plugin that Extends the autocomp feature"""
    observers = plugin.ExtensionPoint(iface.AutoCompI)
    def GetCompleter(self, buff):
        """Get the completer for the specified file type id
        @param buff: EditraStc instance

        """
        ftypeid = buff.GetLangId()
        for observer in self.observers:
            try:
                if observer.GetFileTypeId() == ftypeid:
                    return observer.GetCompleter(buff)
            except Exception, msg:
                util.Log("[ed_basestc][err] GetCompleter Extension: %s" % str(msg))
        else:
Ejemplo n.º 6
0
class ScriptProcessor(plugin.Plugin):
    """Processes script/macro data and executes the scripted actions
    @note: implements the ScriptProcessorI

    """
    observers = plugin.ExtensionPoint(ScriptProcessorI)
    def RunScript(self, script, script_type):
        """Runs the given script
        @param script: script to run
        @param script_type: the scripts type

        """
        res = False
        for ob in observers:
            stype = ob.GetType()
            if stype == script_type:
                res = ob.ExecuteScript(script)
                break
        return res
Ejemplo n.º 7
0
class Shelf(plugin.Plugin):
    """Plugin that creates a notebook for holding the various Shelf items
    implemented by L{ShelfI}.

    """
    SHELF_NAME = u'Shelf'
    observers = plugin.ExtensionPoint(iface.ShelfI)
    delegate = None

    def GetUiHandlers(self):
        """Gets the update ui handlers for the shelf's menu
        @return: [(ID, handler),]

        """
        handlers = [(item.GetId(), Shelf.delegate.UpdateShelfMenuUI)
                    for item in self.observers]
        return handlers

    def Init(self, parent):
        """Mixes the shelf into the parent window
        @param parent: Reference to MainWindow

        """
        # First check if the parent has an instance already
        parent = parent
        mgr = parent.GetFrameManager()
        if mgr.GetPane(Shelf.SHELF_NAME).IsOk():
            return

        shelf = EdShelfBook(parent)
        mgr.AddPane(shelf,
                    wx.aui.AuiPaneInfo().Name(Shelf.SHELF_NAME).\
                            Caption("Shelf").Bottom().Layer(0).\
                            CloseButton(True).MaximizeButton(False).\
                            BestSize(wx.Size(500,250)))

        # Hide the pane and let the perspective manager take care of it
        mgr.GetPane(Shelf.SHELF_NAME).Hide()
        mgr.Update()

        # Create the delegate
        # Parent MUST take ownership and clear the class variable before
        # another call to Init is made.
        delegate = EdShelfDelegate(shelf, self)
        assert Shelf.delegate is None, "Delegate not cleared!"
        Shelf.delegate = delegate

        # Install Shelf menu under View and bind event handlers
        view = parent.GetMenuBar().GetMenuByName("view")
        menu = delegate.GetMenu()
        pos = 0
        for pos in xrange(view.GetMenuItemCount()):
            mitem = view.FindItemByPosition(pos)
            if mitem.GetId() == ed_glob.ID_PERSPECTIVES:
                break

        view.InsertMenu(pos + 1, ed_glob.ID_SHELF, _("Shelf"), menu,
                        _("Put an item on the Shelf"))

        for item in menu.GetMenuItems():
            if item.IsSeparator():
                continue
            parent.Bind(wx.EVT_MENU, delegate.OnGetShelfItem, item)

        if menu.GetMenuItemCount() < 3:
            view.Enable(ed_glob.ID_SHELF, False)

        # Check for any other plugin specific install needs
        for observer in self.observers:
            if not observer.IsInstalled() and \
               hasattr(observer, 'InstallComponents'):
                observer.InstallComponents(parent)

        delegate.StockShelf(Profile_Get('SHELF_ITEMS', 'list', []))
Ejemplo n.º 8
0
class BitmapProvider(plugin.Plugin):
    """Plugin that fetches requested icons from the current active theme.

    """
    observers = plugin.ExtensionPoint(ThemeI)

    def __GetCurrentProvider(self):
        """Gets the provider of the current theme resources
        @return: ThemeI object

        """
        theme = Profile_Get('ICONS', 'str', u'')
        for prov in self.observers:
            if theme == prov.GetName():
                return prov

        # Case if a theme was deleted while it was the active theme
        if theme.lower() != u'default':
            Profile_Set('ICONS', u'Default')

        return None

    def _GetTango(self, bmp_id, client):
        """Try to get the icon from the default tango theme"""
        theme = None
        bmp = wx.NullBitmap
        for prov in self.observers:
            if prov.GetName() == TangoTheme.name:
                theme = prov
                break
        else:
            return bmp

        if client == wx.ART_TOOLBAR:
            bmp = theme.GetToolbarBitmap(bmp_id)
        elif client == wx.ART_MENU:
            bmp = theme.GetMenuBitmap(bmp_id)
        elif client == wx.ART_OTHER:
            bmp = theme.GetOtherBitmap(bmp_id)
        else:
            pass

        return bmp

    def GetThemes(self):
        """Gets a list of the installed and activated themes
        @return: list of strings

        """
        return [name.GetName() for name in self.observers]

    def GetBitmap(self, bmp_id, client):
        """Gets a 16x16 or 32x32 pixel bitmap depending on client value.
        May return a NullBitmap if no suitable bitmap can be
        found.

        @param bmp_id: id of bitmap to lookup
        @param client: wxART_MENU, wxART_TOOLBAR
        @see: L{ed_glob}

        """
        prov = self.__GetCurrentProvider()
        if prov is not None:
            if client == wx.ART_MENU:
                bmp = prov.GetMenuBitmap(bmp_id)
            elif client == wx.ART_OTHER:
                # Backwards compatibility for older interface
                if hasattr(prov, 'GetOtherBitmap'):
                    bmp = prov.GetOtherBitmap(bmp_id)
                else:
                    bmp = wx.NullBitmap
            else:
                bmp = prov.GetToolbarBitmap(bmp_id)

            if bmp.IsOk():
                return bmp

        # Try to fallback to tango theme when icon lookup fails
        bmp = self._GetTango(bmp_id, client)
        if bmp.IsOk():
            return bmp

        return wx.NullBitmap
Ejemplo n.º 9
0
class Shelf(plugin.Plugin):
    """Plugin that creates a notebook for holding the various Shelf items
    implemented by L{ShelfI}.

    """
    SHELF_NAME = u'Shelf'
    observers = plugin.ExtensionPoint(iface.ShelfI)

    def GetUiHandlers(self, delegate):
        """Gets the update ui handlers for the shelf's menu
        @param delegate: L{EdShelfDelegate} instance
        @return: [(ID, handler),]

        """
        handlers = [(item.GetId(), delegate.UpdateShelfMenuUI)
                    for item in self.observers]
        return handlers

    def Init(self, parent):
        """Mixes the shelf into the parent window
        @param parent: Reference to MainWindow
        @return: L{EdShelfDelegate}

        """
        # First check if the parent has an instance already
        mgr = parent.GetFrameManager()
        if mgr.GetPane(Shelf.SHELF_NAME).IsOk():
            return

        # HACK - fixes mouse event issues that result in wrong
        #        tab indexes being reported in the notebook.
        wrapper = ShelfWrapper(parent)
        shelf = wrapper.GetShelf()
        mgr.AddPane(wrapper,
                    ed_fmgr.EdPaneInfo().Name(Shelf.SHELF_NAME).\
                            Caption(_("Shelf")).Bottom().Layer(0).\
                            CloseButton(True).MaximizeButton(True).\
                            BestSize(wx.Size(500,250)))

        # Hide the pane and let the perspective manager take care of it
        mgr.GetPane(Shelf.SHELF_NAME).Hide()
        mgr.Update()

        # Create the delegate
        delegate = EdShelfDelegate(shelf, self)

        # Install Shelf menu under View and bind event handlers
        view = parent.GetMenuBar().GetMenuByName("view")
        menu = delegate.GetMenu()
        pos = 0
        for pos in range(view.GetMenuItemCount()):
            mitem = view.FindItemByPosition(pos)
            if mitem.GetId() == ed_glob.ID_PERSPECTIVES:
                break

        view.InsertMenu(pos + 1, ed_glob.ID_SHELF, _("Shelf"), menu,
                        _("Put an item on the Shelf"))

        for item in menu.GetMenuItems():
            if item.IsSeparator():
                continue
            parent.Bind(wx.EVT_MENU, delegate.OnGetShelfItem, item)

        if menu.GetMenuItemCount() < 3:
            view.Enable(ed_glob.ID_SHELF, False)

        # Check for any other plugin specific install needs
        for observer in self.observers:
            if not observer.IsInstalled() and \
               hasattr(observer, 'InstallComponents'):
                observer.InstallComponents(parent)

        # Only Load Perspective if all items are loaded
        if delegate.StockShelf(Profile_Get('SHELF_ITEMS', 'list', [])):
            delegate.SetPerspective(Profile_Get('SHELF_LAYOUT', 'str', u""))
            delegate.SetSelection(Profile_Get('SHELF_SELECTION', 'int', -1))
        return delegate