def createPageWithDialog(parentwnd, parentpage): """ Показать диалог настроек и создать страницу """ assert parentpage is not None if parentpage.readonly: raise outwiker.core.exceptions.ReadonlyException page = None with CreatePageDialog(parentwnd, parentpage, Application) as dlg: if dlg.ShowModal() == wx.ID_OK: factory = dlg.selectedFactory alias = dlg.pageTitle siblings = [child_page.title for child_page in parentpage.children] title = getAlternativeTitle(alias, siblings) try: page = factory.create(parentpage, title, []) if title != alias: page.alias = alias except EnvironmentError: MessageBox(_(u"Can't create page"), "Error", wx.ICON_ERROR | wx.OK) return None assert page is not None if not dlg.setPageProperties(page): return None page.root.selectedPage = page return page
def createPageWithDialog(parentwnd, parentpage): """ Показать диалог настроек и создать страницу """ assert parentpage is not None if parentpage.readonly: raise outwiker.core.exceptions.ReadonlyException page = None with CreatePageDialog(parentwnd, parentpage, Application) as dlg: if dlg.ShowModal() == wx.ID_OK: factory = dlg.selectedFactory alias = dlg.pageTitle siblings = [child_page.title for child_page in parentpage.children] title = getAlternativeTitle(alias, siblings) try: page = factory.create(parentpage, title, []) if title != alias: page.alias = alias except EnvironmentError: showError(Application.mainWindow, _(u"Can't create page")) return None assert page is not None if not dlg.setPageProperties(page): return None page.root.selectedPage = page return page
def test_title_strip(self): title = ' Проверка тест ' siblings = [] newtitle = getAlternativeTitle(title, siblings) self.assertEqual(newtitle, 'Проверка тест')
def test_title_siblings_07(self): title = 'Проверка' siblings = ['Test', 'проверка'] newtitle = getAlternativeTitle(title, siblings) self.assertEqual(newtitle, 'Проверка (1)')
def test_title_ok_01(self): title = 'Проверка' siblings = [] newtitle = getAlternativeTitle(title, siblings) self.assertEqual(newtitle, title)
def test_empty_03(self): title = '' siblings = ['(1)'] newtitle = getAlternativeTitle(title, siblings) self.assertEqual(newtitle, '(2)')
def test_title_replace_03(self): title = 'Проверка ><|?*:"\\/#% test' siblings = [] newtitle = getAlternativeTitle(title, siblings) self.assertEqual(newtitle, 'Проверка ___________ test')
def test_title_replace_01(self): title = 'Проверка:' siblings = [] newtitle = getAlternativeTitle(title, siblings) self.assertEqual(newtitle, 'Проверка_')
def test_title_replace_siblings_02(self): title = 'Проверка:' siblings = ['Проверка_', 'Проверка_ (1)'] newtitle = getAlternativeTitle(title, siblings) self.assertEqual(newtitle, 'Проверка_ (2)')