コード例 #1
0
    def __init__(self, drawer):
        """Initialization commands class."""
        self.drawer = drawer
        self.phrases = self.drawer.phrases
        self.message = Message(self.drawer)
        self.notes = Notes(self.message, self.phrases)
        self.config = self.drawer.config
        self.config.checker(self.message, self.phrases)
        self.tree = Tree()
        self.actions = Actions(self.tree, self.notes)

        self.set_window()
コード例 #2
0
ファイル: commands.py プロジェクト: DollaR84/HotSound
    def __init__(self, drawer):
        """Initialization commands class."""
        self.drawer = drawer
        self.phrases = self.drawer.phrases
        self.message = Message(self.drawer)
        self.linker = Linker()
        self.player = Player()

        self.config = self.drawer.config
        self.config.get_outputs = self.player.get_outputs
        self.player.config = self.config

        self.wildcard = 'Wave files (*.wav)|*.wav|' \
                        'All files (*.*)|*.*'

        self.__mods = [
            wx.WXK_CONTROL,
            wx.WXK_SHIFT,
            wx.WXK_ALT,
            wx.WXK_WINDOWS_LEFT,
            wx.WXK_WINDOWS_RIGHT,
            wx.WXK_WINDOWS_MENU,
        ]

        self.set_window()
コード例 #3
0
ファイル: insert.py プロジェクト: DollaR84/dumper
    def __init__(self, parent):
        """Initialize interface."""
        super().__init__(parent, wx.ID_ANY, 'Вставка записи')
        self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)
        self.command = parent.command
        self.message = Message(self)
        index = parent.tables.GetSelection()
        self.table = self.command.dumper.get_tables_names()[index]
        self.params = self.command.dumper.get_table_params(self.table)
        self.values = [param[3] for param in self.params]
        self.names = [param[0] for param in self.params]

        box_columns = wx.StaticBox(self, wx.ID_ANY, 'Столбцы')
        self.columns = wx.ListBox(self, wx.ID_ANY, choices=self.names,
                                  style=wx.LB_SINGLE | wx.LB_HSCROLL,
                                  validator=NotNullValidator())
        self.value = wx.TextCtrl(self, wx.ID_ANY,
                                 style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER,
                                 validator=NumberValidator())
        label = 'Заменить && на html код'
        self.fix_amp = wx.CheckBox(self, wx.ID_ANY, label)
        label = 'Заменить символы (&&, <, >, ", \\n) на html коды'
        self.fix_html = wx.CheckBox(self, wx.ID_ANY, label)
        but_set = wx.Button(self, wx.ID_ANY, 'Задать')
        but_save = wx.Button(self, wx.ID_OK, 'Сохранить')
        but_cancel = wx.Button(self, wx.ID_CANCEL, 'Отмена')

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_panels = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)
        sizer_left = wx.StaticBoxSizer(box_columns, wx.VERTICAL)
        sizer_left.Add(self.columns, 1, wx.EXPAND | wx.ALL, 5)
        sizer_panels.Add(sizer_left, 1, wx.EXPAND | wx.ALL)
        sizer_right = wx.BoxSizer(wx.VERTICAL)
        sizer_right.Add(self.value, 1, wx.EXPAND | wx.ALL, 5)
        sizer_right.Add(self.fix_amp, 0, wx.EXPAND | wx.ALL, 5)
        sizer_right.Add(self.fix_html, 0, wx.EXPAND | wx.ALL, 5)
        sizer_right.Add(but_set, 0, wx.ALIGN_CENTER, 5)
        sizer_panels.Add(sizer_right, 1, wx.EXPAND | wx.ALL)
        sizer.Add(sizer_panels, 1, wx.EXPAND | wx.ALL)
        sizer_but = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)
        sizer_but.Add(but_save, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        sizer_but.Add(but_cancel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        sizer.Add(sizer_but, 0, wx.EXPAND | wx.ALL)
        self.SetSizer(sizer)

        self.Bind(wx.EVT_LISTBOX, self.select_column, self.columns)
        self.Bind(wx.EVT_BUTTON, self.set_column, but_set)

        self.fix_amp.SetValue(False)
        self.fix_html.SetValue(False)
        but_save.SetDefault()
        self.Layout()
コード例 #4
0
 def __init__(self, drawer, dumper):
     """Initilizing commands class."""
     self.drawer = drawer
     self.dumper = dumper
     self.message = Message(self.drawer)
コード例 #5
0
class Commands:
    """Helper class, contains command for bind events, menu and buttons."""
    def __init__(self, drawer, dumper):
        """Initilizing commands class."""
        self.drawer = drawer
        self.dumper = dumper
        self.message = Message(self.drawer)

    def db_browse(self, event):
        """Change file database sqlite."""
        self.drawer.path = self.drawer.db_ctrl.GetPath()

    def sql_browse(self, event):
        """Change file dump file for save."""
        self.drawer.path_sql = self.drawer.sql_ctrl.GetPath()

    def connect(self, event):
        """Connect sqlite database."""
        if self.drawer.but_connect.GetValue():
            self.dumper.start(self.drawer.path)
            self.drawer.tables.Set(self.dumper.get_tables_names())
            self.drawer.but_add_table.Enable()
            self.drawer.but_insert.Enable()
            self.drawer.but_update.Enable()
            self.drawer.but_delete.Enable()
            self.drawer.but_save.Enable()
            self.drawer.but_connect.SetLabel('Отключить')
        else:
            self.dumper.finish()
            self.drawer.tables.Set([])
            self.drawer.but_add_table.Disable()
            self.drawer.but_insert.Disable()
            self.drawer.but_update.Disable()
            self.drawer.but_delete.Disable()
            self.drawer.but_save.Disable()
            self.drawer.but_connect.SetLabel('Подключить')
        self.drawer.Layout()

    def save(self, event):
        """Save dump sql database in file."""
        if '' == self.drawer.path_sql:
            self.message.error('Ошибка', 'Имя файла дампа не указано')
            return
        self.dumper.dump(self.drawer.path_sql)
        if self.drawer.mysql.GetValue():
            self.dumper.fix_mysql(self.drawer.path_sql)
        if self.drawer.drop_table.GetValue():
            self.dumper.add_drop_tables(self.drawer.path_sql)
        if self.drawer.del_quotes.GetValue():
            self.dumper.del_quotes_around_table_name(self.drawer.path_sql)
        if self.drawer.use_db.GetValue():
            self.dumper.use_database_name(self.drawer.path_sql)
        elif self.drawer.add_db.GetValue():
            self.dumper.add_database_name(self.drawer.path_sql)
        self.message.information('Сохранение', 'Файл дампа успешно сохранен')

    def about(self, event):
        """Run about dialog."""
        About(self.drawer, 'О программе...', 'Конструктор дампов базы данных',
              '1.0', 'Руслан Долованюк').ShowModal()

    def close(self, event):
        """Close event for button close."""
        self.drawer.Close(True)

    def close_window(self, event):
        """Close window event."""
        self.drawer.Destroy()
コード例 #6
0
ファイル: add_table.py プロジェクト: DollaR84/dumper
    def __init__(self, parent):
        """Initialize interface."""
        super().__init__(parent, wx.ID_ANY, 'Добавление таблицы')
        self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)
        self.command = parent.command
        self.message = Message(self)
        self.params = []
        self.param_names = []

        box_table = wx.StaticBox(self, wx.ID_ANY, 'Наименование таблицы')
        self.table = wx.TextCtrl(self, wx.ID_ANY, validator=TableValidator())
        box_columns = wx.StaticBox(self, wx.ID_ANY, 'Столбцы')
        box_name = wx.StaticBox(box_columns, wx.ID_ANY, 'Имя')
        self.name = wx.TextCtrl(box_name, wx.ID_ANY)
        box_type = wx.StaticBox(box_columns, wx.ID_ANY, 'Тип')
        self.type = wx.Choice(box_type,
                              wx.ID_ANY,
                              choices=parent.command.dumper.get_param_types())
        self.not_null = wx.CheckBox(box_columns, wx.ID_ANY, 'NOT NULL')
        but_add = wx.Button(box_columns, wx.ID_ANY, 'Добавить')
        self.columns = wx.ListBox(self,
                                  wx.ID_ANY,
                                  choices=self.param_names,
                                  style=wx.LB_SINGLE | wx.LB_HSCROLL)
        self.but_del = wx.Button(self, wx.ID_ANY, 'Удалить')
        but_save = wx.Button(self, wx.ID_OK, 'Сохранить')
        but_cancel = wx.Button(self, wx.ID_CANCEL, 'Отмена')

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_panels = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)
        sizer_left = wx.BoxSizer(wx.VERTICAL)
        sizer_table = wx.StaticBoxSizer(box_table, wx.HORIZONTAL)
        sizer_table.Add(self.table, 1, wx.EXPAND | wx.ALL, 5)
        sizer_left.Add(sizer_table, 0, wx.EXPAND | wx.ALL)
        sizer_columns = wx.StaticBoxSizer(box_columns, wx.VERTICAL)
        sizer_name = wx.StaticBoxSizer(box_name, wx.HORIZONTAL)
        sizer_name.Add(self.name, 1, wx.EXPAND | wx.ALL, 5)
        sizer_columns.Add(sizer_name, 0, wx.EXPAND | wx.ALL)
        sizer_type = wx.StaticBoxSizer(box_type, wx.HORIZONTAL)
        sizer_type.Add(self.type, 1, wx.EXPAND | wx.ALL, 5)
        sizer_columns.Add(sizer_type, 0, wx.EXPAND | wx.ALL)
        sizer_columns.Add(self.not_null, 0, wx.EXPAND | wx.ALL, 5)
        sizer_columns.Add(but_add, 0, wx.ALIGN_CENTER, 5)
        sizer_left.Add(sizer_columns, 1, wx.EXPAND | wx.ALL)
        sizer_panels.Add(sizer_left, 1, wx.EXPAND | wx.ALL)
        sizer_right = wx.BoxSizer(wx.VERTICAL)
        sizer_right.Add(self.columns, 1, wx.EXPAND | wx.ALL, 5)
        sizer_right.Add(self.but_del, 0, wx.ALIGN_CENTER, 5)
        sizer_panels.Add(sizer_right, 1, wx.EXPAND | wx.ALL)
        sizer.Add(sizer_panels, 1, wx.EXPAND | wx.ALL)
        sizer_but = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)
        sizer_but.Add(but_save, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        sizer_but.Add(but_cancel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        sizer.Add(sizer_but, 0, wx.EXPAND | wx.ALL)
        self.SetSizer(sizer)

        self.Bind(wx.EVT_BUTTON, self.add_column, but_add)
        self.Bind(wx.EVT_BUTTON, self.del_column, self.but_del)
        self.Bind(wx.EVT_LISTBOX, self.sel_column, self.columns)

        but_save.SetDefault()
        self.not_null.SetValue(True)
        self.type.SetSelection(0)
        self.but_del.Disable()
        self.Layout()
コード例 #7
0
ファイル: add_table.py プロジェクト: DollaR84/dumper
class AddTableDialog(wx.Dialog):
    """Create interface dialog add table."""
    def __init__(self, parent):
        """Initialize interface."""
        super().__init__(parent, wx.ID_ANY, 'Добавление таблицы')
        self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)
        self.command = parent.command
        self.message = Message(self)
        self.params = []
        self.param_names = []

        box_table = wx.StaticBox(self, wx.ID_ANY, 'Наименование таблицы')
        self.table = wx.TextCtrl(self, wx.ID_ANY, validator=TableValidator())
        box_columns = wx.StaticBox(self, wx.ID_ANY, 'Столбцы')
        box_name = wx.StaticBox(box_columns, wx.ID_ANY, 'Имя')
        self.name = wx.TextCtrl(box_name, wx.ID_ANY)
        box_type = wx.StaticBox(box_columns, wx.ID_ANY, 'Тип')
        self.type = wx.Choice(box_type,
                              wx.ID_ANY,
                              choices=parent.command.dumper.get_param_types())
        self.not_null = wx.CheckBox(box_columns, wx.ID_ANY, 'NOT NULL')
        but_add = wx.Button(box_columns, wx.ID_ANY, 'Добавить')
        self.columns = wx.ListBox(self,
                                  wx.ID_ANY,
                                  choices=self.param_names,
                                  style=wx.LB_SINGLE | wx.LB_HSCROLL)
        self.but_del = wx.Button(self, wx.ID_ANY, 'Удалить')
        but_save = wx.Button(self, wx.ID_OK, 'Сохранить')
        but_cancel = wx.Button(self, wx.ID_CANCEL, 'Отмена')

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_panels = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)
        sizer_left = wx.BoxSizer(wx.VERTICAL)
        sizer_table = wx.StaticBoxSizer(box_table, wx.HORIZONTAL)
        sizer_table.Add(self.table, 1, wx.EXPAND | wx.ALL, 5)
        sizer_left.Add(sizer_table, 0, wx.EXPAND | wx.ALL)
        sizer_columns = wx.StaticBoxSizer(box_columns, wx.VERTICAL)
        sizer_name = wx.StaticBoxSizer(box_name, wx.HORIZONTAL)
        sizer_name.Add(self.name, 1, wx.EXPAND | wx.ALL, 5)
        sizer_columns.Add(sizer_name, 0, wx.EXPAND | wx.ALL)
        sizer_type = wx.StaticBoxSizer(box_type, wx.HORIZONTAL)
        sizer_type.Add(self.type, 1, wx.EXPAND | wx.ALL, 5)
        sizer_columns.Add(sizer_type, 0, wx.EXPAND | wx.ALL)
        sizer_columns.Add(self.not_null, 0, wx.EXPAND | wx.ALL, 5)
        sizer_columns.Add(but_add, 0, wx.ALIGN_CENTER, 5)
        sizer_left.Add(sizer_columns, 1, wx.EXPAND | wx.ALL)
        sizer_panels.Add(sizer_left, 1, wx.EXPAND | wx.ALL)
        sizer_right = wx.BoxSizer(wx.VERTICAL)
        sizer_right.Add(self.columns, 1, wx.EXPAND | wx.ALL, 5)
        sizer_right.Add(self.but_del, 0, wx.ALIGN_CENTER, 5)
        sizer_panels.Add(sizer_right, 1, wx.EXPAND | wx.ALL)
        sizer.Add(sizer_panels, 1, wx.EXPAND | wx.ALL)
        sizer_but = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)
        sizer_but.Add(but_save, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        sizer_but.Add(but_cancel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        sizer.Add(sizer_but, 0, wx.EXPAND | wx.ALL)
        self.SetSizer(sizer)

        self.Bind(wx.EVT_BUTTON, self.add_column, but_add)
        self.Bind(wx.EVT_BUTTON, self.del_column, self.but_del)
        self.Bind(wx.EVT_LISTBOX, self.sel_column, self.columns)

        but_save.SetDefault()
        self.not_null.SetValue(True)
        self.type.SetSelection(0)
        self.but_del.Disable()
        self.Layout()

    def add_column(self, event):
        """Add column in list params."""
        typ = self.command.dumper.get_param_types()[self.type.GetSelection()]
        name = self.name.GetValue()
        if '' == name:
            self.message.error('Ошибка имени столбца',
                               'Имя столбца не указано')
        elif name in self.param_names:
            self.message.error('Ошибка имени столбца',
                               'Данное имя уже существует')
        elif 'id' == name:
            self.message.error('Ошибка имени столбца',
                               'Данное имя зарезервировано')
        else:
            not_null = ' NOT NULL' if self.not_null.GetValue() else ''
            param = name + ' ' + typ + not_null
            self.params.append(param)
            self.param_names.append(name)
            self.columns.Set(self.param_names)
            self.name.SetValue('')
            self.type.SetSelection(0)
            self.not_null.SetValue(True)
            self.Layout()

    def sel_column(self, event):
        """Change selection in columns list."""
        self.but_del.Enable()

    def del_column(self, event):
        """Delete column from list."""
        index = self.columns.GetSelection()
        self.param_names.pop(index)
        self.columns.Set(self.param_names)
        self.but_del.Disable()
        self.Layout()
コード例 #8
0
class Commands:
    """Helper class, contains command for bind events, menu and buttons."""

    def __init__(self, drawer):
        """Initialization commands class."""
        self.drawer = drawer
        self.phrases = self.drawer.phrases
        self.message = Message(self.drawer)
        self.notes = Notes(self.message, self.phrases)
        self.config = self.drawer.config
        self.config.checker(self.message, self.phrases)
        self.tree = Tree()
        self.actions = Actions(self.tree, self.notes)

        self.set_window()

    def set_window(self):
        """Set size and position window from saving data."""
        self.drawer.SetPosition(self.config.get_pos())
        self.drawer.SetSize(self.config.get_size())
        self.drawer.Layout()

    def donate(self, event):
        """Run donate hyperlink in browser."""
        webbrowser.open(self.config.donate_url)

    def home(self, event):
        """Run home page hyperlink in browser."""
        webbrowser.open(self.phrases.about.url)

    def about(self, event):
        """Run about dialog."""
        About(
              self.drawer,
              self.phrases.about.title,
              self.phrases.about.name,
              version.VERSION,
              self.phrases.about.author
             ).ShowModal()

    def close(self, event):
        """Close event for button close."""
        self.drawer.Close(True)

    def close_window(self, event):
        """Close window event."""
        if self.config.general_expand == 'true':
            self.expand_tree_save()
        self.notes.close()

        self.config.set_pos(self.drawer.GetScreenPosition())
        self.config.set_size(self.drawer.GetSize())
        self.config.close()

        self.drawer.Destroy()

    def __sort(self, titles, parents):
        """Sort titles and parents dictionaries by order_sort field."""
        sort_notes = OrderedDict()
        parents_list = [0]
        childs = []
        while parents:
            for parent in parents_list:
                order_dict = self.notes.get_order(parent)
                if order_dict:
                    order_id = [item[0] for item in sorted(list(order_dict.items()), key=lambda i: i[1])]
                    for index in order_id:
                        sort_notes[index] = (parent, titles[index])
                        parents.pop(index)
                    childs.append(copy.copy(order_id))
            parents_list = childs.pop(0)
        return sort_notes

    def init_tree(self):
        """Initialization tree widget."""
        titles = self.notes.get_titles()
        parents = self.notes.get_parents()
        sort_notes = self.__sort(titles, parents)
        wx_tree_id = self.drawer.tree.AddRoot(self.phrases.widgets.tree.root)
        self.tree.add(0, -1, wx_tree_id)
        for index, note in sort_notes.items():
            parent_wx_tree_id = self.tree.id2wx_tree_id(note[0])
            wx_tree_id = self.drawer.tree.AppendItem(parent_wx_tree_id, note[1])
            self.tree.add(index, note[0], wx_tree_id)
        if self.config.general_expand == 'true':
            self.expand_tree_init()

    def expand_tree_init(self):
        """Init expand tree if set config settings."""
        expands = self.notes.get_expands()
        wx_tree_id = self.tree.id2wx_tree_id(0)
        self.drawer.tree.Expand(wx_tree_id)
        for index in range(1, self.tree.get_count()):
            wx_tree_id = self.tree.id2wx_tree_id(index)
            if expands.get(index, 0) == 1:
                self.drawer.tree.Expand(wx_tree_id)
            else:
                self.drawer.tree.Collapse(wx_tree_id)

    def expand_tree_save(self):
        """Save expand tree if set config settings."""
        expands = {}
        for index in range(1, self.tree.get_count()):
            wx_tree_id = self.tree.id2wx_tree_id(index)
            if self.drawer.tree.IsExpanded(wx_tree_id):
                expands[index] = 1
            else:
                expands[index] = 0
        self.notes.set_expands(expands)

    def __set_state_order_menuitem(self, state):
        """Set state menu items order."""
        self.drawer.order_up.Enable(state)
        self.drawer.order_down.Enable(state)
        self.drawer.order_parent_up.Enable(state)
        self.drawer.order_parent_down.Enable(state)

    def __set_state_sort_menuitem(self, state):
        """Set state menu items sort."""
        self.drawer.sort_titles.Enable(state)
        self.drawer.sort_childcount_up.Enable(state)
        self.drawer.sort_childcount_down.Enable(state)
        self.drawer.sort_state_up.Enable(state)
        self.drawer.sort_state_down.Enable(state)

    def __set_state_undo_menuitem(self):
        """Set menu items undo and redo."""
        if self.actions.isUndo():
            self.drawer.undo.Enable(True)
        else:
            self.drawer.undo.Enable(False)
        if self.actions.isRedo():
            self.drawer.redo.Enable(True)
        else:
            self.drawer.redo.Enable(False)

    def __set_state_del(self, state):
        """Set state to delete button and delete menu item."""
        self.drawer.but_del.Enable(state)
        self.drawer.del_note.Enable(state)

    def __disable_widgets(self):
        """Disable state for all widgets."""
        self.__set_state_del(False)
        self.drawer.data.SetValue('')
        self.drawer.data.Disable()
        self.drawer.readonly.Enable(False)
        self.drawer.state_check.Enable(False)
        self.drawer.states.Enable(False)

    def __tree_select(self):
        """Change select item in tree with program select."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        if index is None:
            self.__set_state_order_menuitem(False)
            self.__set_state_sort_menuitem(False)
            self.__disable_widgets()
            self.drawer.but_create.Disable()
            self.drawer.create_child.Enable(False)
            self.drawer.info_date.Enable(False)
        elif index == 0:
            self.__set_state_order_menuitem(False)
            self.__set_state_sort_menuitem(True)
            self.__disable_widgets()
            self.drawer.but_create.Enable(True)
            self.drawer.create_child.Enable(True)
            self.drawer.info_date.Enable(False)
        else:
            self.__set_state_order_menuitem(True)
            self.__set_state_sort_menuitem(True)
            self.drawer.info_date.Enable(True)
            self.drawer.data.Enable()
            data = self.notes.get_note(index)
            self.drawer.data.SetValue(data)
            self.drawer.readonly.Enable(True)
            readonly = self.notes.get_readonly(index)
            self.drawer.readonly.SetValue(readonly)
            self.__set_state_text_note(not readonly)
            self.__set_state_del(not readonly)
            self.drawer.state_check.Enable(True)
            state_check = self.notes.get_state_check(index)
            self.drawer.state_check.SetValue(state_check)
            self.drawer.states.Enable(state_check)
            self.__set_state(index)
            self.drawer.but_create.Enable(True)
            self.drawer.create_child.Enable(True)
        self.drawer.but_save.Disable()
        self.drawer.save_note.Enable(False)

    def tree_select(self, event):
        """Change select item in tree."""
        self.__tree_select()

    def tree_activated(self, event):
        """Activated edit label on tree item."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        readonly = self.drawer.readonly.GetValue()
        if readonly:
            if (self.config.readonly_password_check == "true") and self.__check_password():
                readonly = False
        if (index != 0) and (not readonly):
            self.drawer.tree.EditLabel(event.GetItem())

    def tree_end_edit(self, event):
        """Finish edit label item tree."""
        wx_tree_id = self.drawer.tree.GetSelection()
        index = self.tree.wx_tree_id2id(wx_tree_id)
        title = event.GetLabel()
        if title != '':
            self.actions.run(SaveTitle(index, title))
            self.__set_state_undo_menuitem()

    def text_change(self, event):
        """Change text controls note."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        if index != 0:
            self.drawer.but_save.Enable()
            self.drawer.save_note.Enable(True)

    def __set_state_text_note(self, state):
        """Set data text control note readonly state."""
        self.drawer.data.SetEditable(state)

    def __check_password(self):
        """Check state readonly password."""
        result = False
        dlg = PasswordEntryDialog(self.drawer, self.drawer.phrases.titles.password)
        if RetCode.OK == dlg.ShowModal():
            hashpass= hashlib.sha1(dlg.GetValue().encode("utf-8"))
            if hashpass.hexdigest() == self.config.readonly_password:
                result = True
        dlg.Destroy()
        return result

    def __change_readonly(self, index, readonly):
        """Change readonly attribute for widgets."""
        self.actions.run(SetReadonly(index, readonly))
        self.__set_state_text_note(not readonly)
        self.__set_state_del(not readonly)

    def change_readonly(self, event):
        """Change readonly attribute for note."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        readonly = self.drawer.readonly.GetValue()
        if readonly:
            self.__change_readonly(index, readonly)
        elif self.config.readonly_password_check != "true":
            self.__change_readonly(index, readonly)
        elif self.__check_password():
            self.__change_readonly(index, readonly)
        else:
            self.drawer.readonly.SetValue(True)
        self.__set_state_undo_menuitem()

    def change_state(self, event):
        """Change state attribute for note."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        state_check = self.drawer.state_check.GetValue()
        self.actions.run(SetStateCheck(index, state_check))
        self.drawer.states.Enable(state_check)
        self.__set_state_undo_menuitem()

    def choice_state(self, event):
        """Set state for note."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        state = self.drawer.states.GetString(self.drawer.states.GetSelection())
        self.actions.run(SetState(index, state))
        self.__set_state_undo_menuitem()

    def __set_state(self, index):
        """Set string in choice states."""
        state = self.notes.get_state(index)
        select = self.drawer.states.FindString(state)
        if select == self.drawer.get_not_found():
            select = 0
        self.drawer.states.SetSelection(select)

    def save(self, event):
        """Save data note in database."""
        wx_tree_id = self.drawer.tree.GetSelection()
        index = self.tree.wx_tree_id2id(wx_tree_id)
        data = self.drawer.data.GetValue()
        self.actions.run(SaveNote(index, data))
        self.__set_state_undo_menuitem()
        self.drawer.but_save.Disable()
        self.drawer.save_note.Enable(False)

    def delete(self, event):
        """Delete note from database."""
        if self.message.question(self.phrases.titles.warning, self.phrases.questions.del_note):
            index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
            parent_id = self.tree.get_parent_id(index)
            self.drawer.tree.DeleteAllItems()
            self.actions.run(DelNote(index))
            self.__set_state_undo_menuitem()
            self.tree.clear()
            self.init_tree()
            self.drawer.tree.SelectItem(self.tree.id2wx_tree_id(parent_id))
            self.__tree_select()

    def create(self, event):
        """Create new note."""
        if event.GetId() == self.drawer.create_root.GetId():
            parent_id = 0
        else:
            parent_id = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        index = self.tree.get_count()
        parent_wx_tree_id = self.tree.id2wx_tree_id(parent_id)
        wx_tree_id = self.drawer.tree.AppendItem(parent_wx_tree_id, self.phrases.widgets.tree.new_note)
        self.drawer.tree.Expand(parent_wx_tree_id)
        self.drawer.tree.SelectItem(wx_tree_id)
        self.tree.add(index, parent_id, wx_tree_id)
        self.actions.run(CreateNote(index, self.drawer.tree.GetItemText(wx_tree_id)))
        self.__set_state_undo_menuitem()
        self.__tree_select()

    def insert(self, event):
        """Insert new note."""
        before_item = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        if before_item != 0:
            parent_id = self.tree.get_parent_id(before_item)
            index = self.tree.get_count()
            parent_wx_tree_id = self.tree.id2wx_tree_id(parent_id)
            wx_tree_id = self.drawer.tree.AppendItem(parent_wx_tree_id, self.phrases.widgets.tree.new_note)
            self.actions.run(InsertNote(index, before_item, self.drawer.tree.GetItemText(wx_tree_id)))
            self.__set_state_undo_menuitem()
            self.expand_tree_save()
            self.tree.clear()
            self.drawer.tree.DeleteAllItems()
            self.init_tree()
            parent_wx_tree_id = self.tree.id2wx_tree_id(parent_id)
            self.drawer.tree.Expand(parent_wx_tree_id)
            self.drawer.tree.SelectItem(self.tree.id2wx_tree_id(index))
            self.__tree_select()

    def rollback(self, event):
        """Process menu commands undo and redo."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        parent = self.tree.get_parent_id(index)
        if event.GetId() == self.drawer.undo.GetId():
            self.actions.undo()
        elif event.GetId() == self.drawer.redo.GetId():
            self.actions.redo()
        self.__set_state_undo_menuitem()
        self.expand_tree_save()
        self.tree.clear()
        self.drawer.tree.DeleteAllItems()
        self.init_tree()
        select = self.tree.id2wx_tree_id(index)
        if select is None:
            select = self.tree.id2wx_tree_id(parent)
        self.drawer.tree.SelectItem(select)
        self.__tree_select()

    def order(self, event):
        """Order items."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        if event.GetId() == self.drawer.order_up.GetId():
            self.actions.run(OrderUp(index))
        elif event.GetId() == self.drawer.order_down.GetId():
            self.actions.run(OrderDown(index))
        elif event.GetId() == self.drawer.order_parent_up.GetId():
            self.actions.run(OrderParentUp(index))
        elif event.GetId() == self.drawer.order_parent_down.GetId():
            self.actions.run(OrderParentDown(index))
        self.__set_state_undo_menuitem()
        self.expand_tree_save()
        self.tree.clear()
        self.drawer.tree.DeleteAllItems()
        self.init_tree()
        self.drawer.tree.SelectItem(self.tree.id2wx_tree_id(index))
        self.__tree_select()

    def sort(self, event):
        """Sort items."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        if event.GetId() == self.drawer.sort_titles.GetId():
            self.actions.run(SortTitle(index))
        elif event.GetId() == self.drawer.sort_childcount_up.GetId():
            self.actions.run(SortChildCountUp(index))
        elif event.GetId() == self.drawer.sort_childcount_down.GetId():
            self.actions.run(SortChildCountDown(index))
        elif event.GetId() == self.drawer.sort_state_up.GetId():
            self.actions.run(SortStateUp(index))
        elif event.GetId() == self.drawer.sort_state_down.GetId():
            self.actions.run(SortStateDown(index))
        self.__set_state_undo_menuitem()
        self.expand_tree_save()
        self.tree.clear()
        self.drawer.tree.DeleteAllItems()
        self.init_tree()
        self.drawer.tree.SelectItem(self.tree.id2wx_tree_id(index))
        self.__tree_select()

    def count(self, event):
        """Show information of count notes."""
        if event.GetId() == self.drawer.count_root.GetId():
            self.message.information(self.phrases.titles.info, self.phrases.info.count.root % self.tree.get_count_childs(0))
        elif event.GetId() == self.drawer.count_child.GetId():
            index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
            self.message.information(self.phrases.titles.info, self.phrases.info.count.child % self.tree.get_count_childs(index))
        else:
            self.message.information(self.phrases.titles.info, self.phrases.info.count.total % (self.tree.get_count() - 1))

    def info_date(self, event):
        """Show info of date create and date update note."""
        index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
        date_create, date_update = self.notes.get_date(index)
        create = self.phrases.info.date.create.format(date_create)
        update = self.phrases.info.date.update.format(date_update)
        self.message.information(self.phrases.titles.info, '\n'.join([create, update]))

    def options(self, event):
        """Run settings dialog."""
        if self.config.open_settings(self.drawer):
            self.drawer.states.Set(self.config.get_states(self.phrases.widgets.states))
            index = self.tree.wx_tree_id2id(self.drawer.tree.GetSelection())
            self.drawer.Layout()
            state = self.notes.get_state(index)
            self.drawer.states.SetSelection(self.drawer.states.FindString(state))
            self.message.information(self.phrases.titles.info, self.phrases.info.need_restart)