Exemplo n.º 1
0
    def testPriority_01(self):
        items = []
        event = Event()
        event.bind(self.eventAdd_1, 0)
        event(items)

        self.assertEqual(items, [1])
Exemplo n.º 2
0
    def testPriority_01(self):
        items = []
        event = Event()
        event.bind(self.eventAdd_1, 0)
        event(items)

        self.assertEqual(items, [1])
Exemplo n.º 3
0
    def testPriority_07(self):
        items = []
        event = Event()
        event.bind(self.eventAdd_1, 10)
        event.bind(self.eventAdd_2, 10)
        event.bind(self.eventAdd_3, 20)
        event(items)

        self.assertEqual(items, [3, 1, 2])
Exemplo n.º 4
0
    def testClear2(self):
        event = Event()
        event += self.event1
        event += self.event2

        event.clear()
        self.assertEqual(len(event), 0)

        event(111)

        self.assertEqual(self.value1, 0)
        self.assertEqual(self.value2, 0)
Exemplo n.º 5
0
    def testClear2(self):
        event = Event()
        event += self.event1
        event += self.event2

        event.clear()
        self.assertEqual(len(event), 0)

        event(111)

        self.assertEqual(self.value1, 0)
        self.assertEqual(self.value2, 0)
Exemplo n.º 6
0
    def __init__(self, application):
        self._application = application

        self.onFinishDialogEvent = Event()
        self._parser = None
        self._selectedText = u''
        self._config = SnippetsConfig(self._application.config)
        self._recentSnippetPath = None

        self._dialog = VariablesDialog(self._application.mainWindow)
        self._dialog.ok_button.Bind(wx.EVT_BUTTON, handler=self._onOk)
        self._dialog.Bind(EVT_VAR_CHANGE, handler=self._onVarChange)
        self._dialog.SetClientSize((self._config.variablesDialogWidth,
                                    self._config.variablesDialogHeight))
Exemplo n.º 7
0
    def _createEvents(self):
        # Выбор новой страницы
        # Параметры: новая выбранная страница
        self.onPageSelect = Event()

        # Обновление дерева
        # Параметры: sender - из-за кого обновляется дерево
        self.onTreeUpdate = Event()

        # Начало сложного обновления дерева
        # Параметры: root - корень дерева
        self.onStartTreeUpdate = Event()

        # Конец сложного обновления дерева
        # Параметры: root - корень дерева
        self.onEndTreeUpdate = Event()

        # Обновление страницы
        # Параметры:
        #     sender
        #     **kwargs
        # kwargs содержит значение 'change', хранящее флаги того,
        #     что изменилось
        self.onPageUpdate = Event()

        # Изменение порядка страниц
        # Параметры: page - страница, положение которой изменили
        self.onPageOrderChange = Event()

        # Переименование страницы.
        # Параметры:
        #   page - переименованная страница,
        #   oldSubpath - старый относительный путь до страницы
        self.onPageRename = Event()

        # Создание страницы
        # Параметры: sender
        self.onPageCreate = Event()

        # Удаленеи страницы
        # Параметр - удаленная страница
        self.onPageRemove = Event()

        # Event occurs after change attached file list.
        # Parameters:
        #     page - current (selected) page
        #     params - instance if the AttachListChangedParams class
        self.onAttachListChanged = Event()
Exemplo n.º 8
0
    def __init__(self, application):
        self._application = application

        self.onFinishDialog = Event()
        self._dialog = None
        self._parser = None
        self._selectedText = u''
Exemplo n.º 9
0
    def testRemove1(self):
        event = Event()
        event += self.event1
        event -= self.event1

        event()

        self.assertEqual(self.value1, 0)
Exemplo n.º 10
0
    def testAdd1(self):
        event = Event()
        event += self.event1

        event()

        self.assertEqual(self.value1, 1)
        self.assertEqual(self.value2, 0)
Exemplo n.º 11
0
    def testAdd2(self):
        event = Event()
        event += self.event2

        event(111)

        self.assertEqual(self.value1, 0)
        self.assertEqual(self.value2, 2)
Exemplo n.º 12
0
    def testAdd3(self):
        event = Event()
        event += self.event2
        event += self.event3

        event(111)

        self.assertEqual(self.value2, 2)
        self.assertEqual(self.value3, 3)
Exemplo n.º 13
0
    def testRemove2(self):
        event = Event()
        event += self.event2
        event += self.event3
        event -= self.event2

        event(111)

        self.assertEqual(self.value2, 0)
        self.assertEqual(self.value3, 3)
Exemplo n.º 14
0
    def testAdd4(self):
        event = Event()
        event += self.event4
        event += self.event4

        event(111)

        self.assertEqual(self.value4, 1)

        event -= self.event4
        event -= self.event4
        event -= self.event4
Exemplo n.º 15
0
    def testPriority_07(self):
        items = []
        event = Event()
        event.bind(self.eventAdd_1, 10)
        event.bind(self.eventAdd_2, 10)
        event.bind(self.eventAdd_3, 20)
        event(items)

        self.assertEqual(items, [3, 1, 2])
Exemplo n.º 16
0
    def __init__(self, parent, application):
        super().__init__(parent, style=wx.TAB_TRAVERSAL)

        self._currentpage = None
        self._application = application
        self.mainWindow = self._application.mainWindow

        # Событие, срабатывающее, когда устанавливается новая страница
        # Параметр: новая страница
        self._onSetPage = Event()

        # Словарь, хранящий информацию о созданных инструментах
        # Ключ - строка, описывающая инструмент
        # Значение - экземпляр класса ToolsInfo
        self._tools = {}
Exemplo n.º 17
0
    def __init__(self):
        # Opened wiki
        self.__wikiroot = None

        # Application's main window
        self.__mainWindow = None

        # Application's global config
        self.config = None
        self.recentWiki = None
        self.actionController = None
        self.plugins = PluginsLoader(self)
        self.pageUidDepot = PageUidDepot()

        # Values for shared purpose
        self.sharedData = {}

        self.customEvents = CustomEvents()

        # Events

        # Opening wiki event
        # Parameters:
        #     root - opened wiki root (it may be None)
        self.onWikiOpen = Event()

        # Closing wiki event
        # Parameters:
        #     root - closed wiki root (it may be None)
        self.onWikiClose = Event()

        # Updating page wiki event
        # Parameters:
        #     sender - updated page
        #     **kwargs
        # kwargs contain 'change' key, which contain changing flags
        self.onPageUpdate = Event()

        # Creating new wiki page
        # Parameters:
        #     sender - new page
        self.onPageCreate = Event()

        # Tree updating event
        # Parameters:
        #     sender - Page, because of which the tree is updated.
        self.onTreeUpdate = Event()

        # Other page selection event
        # Parameters:
        #     sender - selected page
        self.onPageSelect = Event()

        # User want insert link to selected attached files to page
        # Parameters:
        #     fnames - selected file names (names only, without full paths)
        self.onAttachmentPaste = Event()

        # Changings in the bookmarks list event
        # Parameters:
        #     bookmark - Bookmarks class instance
        self.onBookmarksChanged = Event()

        # Removing the page event
        # Parameters:
        #     page - page is removed
        self.onPageRemove = Event()

        # Renaming page event
        # Parameters:
        #     page - page is renamed,
        #     oldSubpath - previous relative path to page
        self.onPageRename = Event()

        # Beginning complex tree updating (updating of several steps) event
        # Parameters:
        #     root - wiki tree root
        self.onStartTreeUpdate = Event()

        # Finishing complex tree updating (updating of several steps) event
        # Parameters:
        #     root - wiki tree root
        self.onEndTreeUpdate = Event()

        # Beginning HTML rendering event
        # Parameters:
        #   page - rendered page
        #   htmlView - window for HTML view
        self.onHtmlRenderingBegin = Event()

        # Finishing HTML rendering event
        # Parameters:
        #   page - rendered page
        #   htmlView - window for HTML view
        self.onHtmlRenderingEnd = Event()

        # Changing page order event
        # Parameters:
        #     page - page with changed order
        self.onPageOrderChange = Event()

        # Evont for forced saving page state
        # (e.g. by the loss the focus or by timer)
        # Parameters:
        #     --
        self.onForceSave = Event()

        # The event occurs after wiki parser (Parser class) creation,
        # but before it using
        # Parameter:
        #     parser - Parser class instance
        self.onWikiParserPrepare = Event()

        # Event occurs during preferences dialog creation
        # Parameters:
        #     dialog - outwiker.gui.preferences.prefdialog.PrefDialog
        #              class instance
        self.onPreferencesDialogCreate = Event()

        # Event occurs after preferences dialog closing.
        # Parameters:
        #     dialog - outwiker.gui.preferences.prefdialog.PrefDialog
        #              class instance
        self.onPreferencesDialogClose = Event()

        # Event occurs after (!) the page view creation
        # (inside CurrentPagePanel instance)
        # Parameters:
        #     page - new selected page
        self.onPageViewCreate = Event()

        # Event occurs before(!) the page view removing
        # (inside CurrentPagePanel instance)
        # Parameters:
        #     page - Current selected page
        self.onPageViewDestroy = Event()

        # Event occurs after the popup menu creation by right mouse click
        # on the notes tree
        # Parameters:
        #     menu - created popup menu,
        #     page - the page on which was right clicked in the notes tree
        self.onTreePopupMenu = Event()

        # Event occurs before HTML generation (for wiki and HTML pages)
        # Order of the calling preprocessing events is not regulated
        # Parameters:
        #    page - page for which HTML is generated
        #    params - instance of the outwiker.core.events.PreprocessingParams
        #             class
        self.onPreprocessing = Event()

        # Event occurs after HTML generation (for wiki and HTML pages)
        # Order of the calling preprocessing events is not regulated
        # Parameters:
        #    page - page for which HTML is generated
        #    params - instance of the outwiker.core.events.PostprocessingParams
        #             class
        self.onPostprocessing = Event()

        # Event occurs after wiki parsing but before HTML improving
        # Parameters:
        #     page - page for which HTML is generated
        #     params - instance of the
        #              outwiker.core.events.PreHtmlImprovingParams class
        self.onPreHtmlImproving = Event()

        # Event occurs during HtmlImproverFactory instance creation
        # Parameters:
        #     factory - HtmlImproverFactory instance in which can add
        #     the new HtmlImprover instances by add() method
        self.onPrepareHtmlImprovers = Event()

        # Event occurs when cursor hovers under link on preview tab
        # Parameters:
        #     page - current page
        #     params - instance of the outwiker.core.events.HoverLinkParams
        #              class
        self.onHoverLink = Event()

        # Event occurs when user click to link on a page
        # Parameters:
        #     page - current page
        #     params - instance of the outwiker.core.events.LinkClickParams
        #              class
        self.onLinkClick = Event()

        # Event occurs when user click with right button in text editor
        # Parameters:
        #     page - current page
        #     params - instance of the the
        #              outwiker.core.events.EditorPopupMenuParams class
        self.onEditorPopupMenu = Event()

        # Event occurs after page dialog creation
        # Parameters:
        #     page - current(selected) page
        #     params - instance of the PageDialogInitParams class
        self.onPageDialogInit = Event()

        # Event occurs before page dialog will be destroyed
        # Parameters:
        #     page - current (selected) page
        #     params - instance of the PageDialogDestroyParams class
        self.onPageDialogDestroy = Event()

        # Event occurs after page type changing
        # Parameters:
        #     page - current (selected) page
        #     params - instance of the PageDialogPageTypeChangedParams class
        self.onPageDialogPageTypeChanged = Event()

        # Event occurs after page type changing
        # Parameters:
        #     page - current(selected) page
        #     params - instance of the PageDialogPageTitleChangedParams class
        self.onPageDialogPageTitleChanged = Event()

        # Event occurs after page style changing
        # Parameters:
        #     page - current (selected) page
        #     params - instance of the PageDialogPageStyleChangedParams class
        self.onPageDialogPageStyleChanged = Event()

        # Event occurs after page icon changing
        # Parameters:
        #     page - current (selected) page
        #     params - instance of the PageDialogPageIconChangedParams class
        self.onPageDialogPageIconChanged = Event()

        # Event occurs after page tag list changing
        # Parameters:
        #     page - current(selected) page
        #     params - instance of the PageDialogPageTagsChangedParams class
        self.onPageDialogPageTagsChanged = Event()

        # Event occurs during page dialog initialization,
        # during general panel creation. Evens sender expect what event
        # handlers will fill the page factories list with addPageFactory method
        # Parameters:
        #     page - current (selected) page
        #     params - instance of the PageDialogPageFactoriesNeededParams
        #              class
        self.onPageDialogPageFactoriesNeeded = Event()

        # Event occurs by TextEditor when it needs styles
        # Parameters:
        #     page - current (selected) page
        #     params - instance of the EditorStyleNeededParams class
        self.onEditorStyleNeeded = Event()

        # Event forces update and render current page
        # Parameters:
        #     page - current (selected) page
        #     params - instance of the PageUpdateNeededParams class
        self.onPageUpdateNeeded = Event()

        # Event occurs before wiki opening
        # Parameters:D:\0enter\jenyay\projects\outwiker\plugins\statistics\statistics\locale\sv\LC_MESSAGES\
        #    page - current (selected) page
        #    params - instance of the PreWikiOpenParams class
        self.onPreWikiOpen = Event()

        # Event occurs after wiki opening
        # Parameters:
        #    page - current (selected) page
        #    params - instance of the PostWikiOpenParams class
        self.onPostWikiOpen = Event()

        # Event occurs in the IconsPanel after generation list of
        # the icons groups.
        # Parameters:
        #     page - current (selected) page
        #     params - instance of the IconsGroupsListInitParams class
        self.onIconsGroupsListInit = Event()

        # Event occurs after switch mode of a page: text / preview / HTML / ...
        # Parameters:
        #     page - current (selected) page
        #     params - instance if the PageModeChangeParams class
        self.onPageModeChange = Event()

        # Event occurs after change attached file list.
        # Parameters:
        #     page - current (selected) page
        #     params - instance if the AttachListChangedParams class
        self.onAttachListChanged = Event()
Exemplo n.º 18
0
    def testClear1(self):
        event = Event()
        self.assertEqual(len(event), 0)

        event.clear()
        self.assertEqual(len(event), 0)
Exemplo n.º 19
0
class VariablesDialogController(object):
    '''
    Controller to manage VariablesDialog.
    '''
    def __init__(self, application):
        self._application = application

        self.onFinishDialogEvent = Event()
        self._parser = None
        self._selectedText = u''
        self._config = SnippetsConfig(self._application.config)
        self._recentSnippetPath = None

        self._dialog = VariablesDialog(self._application.mainWindow)
        self._dialog.ok_button.Bind(wx.EVT_BUTTON, handler=self._onOk)
        self._dialog.Bind(EVT_VAR_CHANGE, handler=self._onVarChange)
        self._dialog.SetClientSize((self._config.variablesDialogWidth,
                                    self._config.variablesDialogHeight))

    @property
    def dialog(self):
        return self._dialog

    def ShowDialog(self, selectedText, template, template_path):
        self._recentSnippetPath = template_path
        dirname = os.path.dirname(template_path)
        self._selectedText = selectedText
        self._parser = SnippetParser(template, dirname, self._application)
        variables_list = self._parser.getVariables()

        # Get non builtin variables
        variables = sorted([var for var
                            in variables_list
                            if not var.startswith('__')])

        self.dialog.hideVarPanel()
        self.dialog.setSnippetText(template)
        [*map(lambda var: self.dialog.addStringVariable(var), variables)]

        shortTemplateName = self._getShortTemplateName(template_path)
        self.dialog.templateFileName = shortTemplateName
        self.dialog.wikiCommandChecked = False

        # Show dialog if user must enter variable's values
        self._updateResult()
        if (self._application.selectedPage is not None and
                self._application.selectedPage.getTypeString() == u'wiki'):
            self.dialog.setWikiCommandSetVisible(True)
        else:
            self.dialog.setWikiCommandSetVisible(False)

        self.dialog.setFocusToFirstVariable()
        self.dialog.Show()

    def _getShortTemplateName(self, template_fname):
        '''
        Convert full template path to short path
        '''
        snippets_dir = getSnippetsDir()
        shortTemplateName = template_fname

        if shortTemplateName.startswith(snippets_dir):
            shortTemplateName = shortTemplateName[len(snippets_dir) + 1:]

        shortTemplateName = shortTemplateName.replace(u'\\', u'/')
        return shortTemplateName

    def destroy(self):
        self.onFinishDialogEvent.clear()
        self.dialog.ok_button.Unbind(wx.EVT_BUTTON, handler=self._onOk)
        self.dialog.Unbind(EVT_VAR_CHANGE, handler=self._onVarChange)
        self.dialog.Close()
        self.dialog.Destroy()

    def FinishDialog(self):
        try:
            w, h = self._dialog.GetClientSize()
            self._config.variablesDialogWidth = w
            self._config.variablesDialogHeight = h
            self._config.recentSnippet = self._recentSnippetPath
        except EnvironmentError:
            pass

        text = self.GetResult()
        self.onFinishDialogEvent(FinishDialogParams(text))
        self.dialog.Close()

    def CloseDialog(self):
        self.dialog.Close()

    def GetResult(self):
        if not self.dialog.wikiCommandChecked:
            return self.dialog.getResult()
        else:
            return self._makeWikiCommand(self.dialog.getVarDict(),
                                         self.dialog.templateFileName)

    def _makeWikiCommand(self, vardict, template_name):
        vars_str = u''

        for varname in sorted(vardict.keys()):
            value = vardict[varname]
            if u'"' not in value:
                vars_str += u' {name}="{value}"'.format(name=varname,
                                                        value=vardict[varname])
            else:
                vars_str += u" {name}='{value}'".format(name=varname,
                                                        value=vardict[varname])

        result = u'(:snip file="{template}"{vars}:)(:snipend:)'.format(
            template=template_name,
            vars=vars_str)
        return result

    def _onOk(self, event):
        self.FinishDialog()

    def _onVarChange(self, event):
        self._updateResult()

    def _updateResult(self):
        variables = self.dialog.getVarDict()
        text = self._parser.process(self._selectedText,
                                    self._application.selectedPage,
                                    **variables)
        self.dialog.setResult(text)
Exemplo n.º 20
0
    def testClear1(self):
        event = Event()
        self.assertEqual(len(event), 0)

        event.clear()
        self.assertEqual(len(event), 0)
Exemplo n.º 21
0
 def testRemove3(self):
     event = Event()
     event -= self.event1
Exemplo n.º 22
0
class VariablesDialogController(object):
    '''
    Controller to manage VariablesDialog.
    '''
    def __init__(self, application):
        self._application = application

        self.onFinishDialog = Event()
        self._dialog = None
        self._parser = None
        self._selectedText = u''

    def ShowDialog(self, selectedText, template):
        if self._application.selectedPage is None:
            return

        if self._dialog is None:
            self._dialog = VariablesDialog(self._application.mainWindow,
                                           self._application)
            self._dialog.ok_button.Bind(wx.EVT_BUTTON, handler=self._onOk)
            self._dialog.Bind(EVT_VAR_CHANGE, handler=self._onVarChange)

        self._selectedText = selectedText
        self._parser = SnippetParser(template, self._application)

        # Get non builtin variables
        variables = sorted([var for var
                            in self._parser.getVariables()
                            if not var.startswith('__')])

        self._dialog.setSnippetText(template)
        map(lambda var: self._dialog.addStringVariable(var), variables)

        # Show dialog if user must enter variable's values
        if variables:
            self._updateResult()
            self._dialog.Show()
        else:
            self._finishDialog()

    def destroy(self):
        self.onFinishDialog.clear()
        if self._dialog is not None:
            self._dialog.ok_button.Unbind(wx.EVT_BUTTON, handler=self._onOk)
            self._dialog.Unbind(EVT_VAR_CHANGE, handle=self._onVarChange)
            self._dialog.Close()
            self._dialog = None

    def _finishDialog(self):
        if self._application.selectedPage is not None:
            text = self._dialog.getResult()
            self.onFinishDialog(FinishDialogParams(text))
        self._dialog.Close()
        self._dialog = None

    def _onOk(self, event):
        self._finishDialog()

    def _onVarChange(self, event):
        self._updateResult()

    def _updateResult(self):
        variables = self._dialog.getVarDict()
        text = self._parser.process(self._selectedText,
                                    self._application.selectedPage,
                                    **variables)
        self._dialog.setResult(text)