Exemple #1
0
    def __init__(self, pattern):
        self._workingfile = None
        self.view = PatternEditorWidget(pattern)
        self.title = TITLE
        self.update_title()
        self._undo_manager = UndoManager(pattern, deepcopy)

        self.view.menu.newPatternRequested.connect(self.new)
        self.view.menu.openPatternRequested.connect(self.open)
        self.view.menu.savePatternRequested.connect(self.save)
        self.view.menu.undoRequested.connect(self.undo)
        self.view.menu.redoRequested.connect(self.redo)
        self.view.menu.deleteRequested.connect(self.delete_selected_indexes)
        self.view.menu.themesRequested.connect(self.set_theme)
        self.view.menu.verifyRequested.connect(self.verify_pattern)

        self.view.graph.figureClicked.connect(self.edit_figure)
        self.view.graph.behaviorClicked.connect(self.edit_behaviors)
        self.view.graph.connectionClicked.connect(self.edit_connection)
        self.view.graph.rowClicked.connect(self.append_index_at_row)

        set_shortcut("Ctrl+Z", self.view, self.undo)
        set_shortcut("Ctrl+Y", self.view, self.redo)
        set_shortcut("Ctrl+N", self.view, self.new)
        set_shortcut("Ctrl+S", self.view, self.save)
        set_shortcut("Ctrl+O", self.view, self.open)
        set_shortcut("del", self.view, self.delete_selected_indexes)
Exemple #2
0
    def __init__(self, chords):
        self._workingfile = None
        self.title = TITLE
        self.view = ChordGridView(chords)
        self.update_title()
        self._undo_manager = UndoManager(chords, deepcopy)
        self._copy_manager = CopyManager(chords, self.is_index_selected)

        self.view.menu.newRequested.connect(self.new)
        self.view.menu.openRequested.connect(self.open)
        self.view.menu.saveRequested.connect(self.save)
        self.view.menu.addRequested.connect(self.add)
        self.view.menu.deleteRequested.connect(self.delete)
        self.view.menu.cutRequested.connect(self.cut)
        self.view.menu.copyRequested.connect(self.copy)
        self.view.menu.pasteRequested.connect(self.paste)
        self.view.menu.undoRequested.connect(self.undo)
        self.view.menu.redoRequested.connect(self.redo)

        self.view.chordgrid_editor.gridModified.connect(self.modified)
        self.view.chordgrid_editor.lastIndexModified.connect(
            self._copy_manager.set_index)

        set_shortcut("Ctrl+Z", self.view, self.undo)
        set_shortcut("Ctrl+Y", self.view, self.redo)
        set_shortcut("Ctrl+N", self.view, self.new)
        set_shortcut("Ctrl+S", self.view, self.save)
        set_shortcut("Ctrl+O", self.view, self.open)
        set_shortcut("Ctrl+X", self.view, self.cut)
        set_shortcut("Ctrl+C", self.view, self.copy)
        set_shortcut("Ctrl+V", self.view, self.paste)
        set_shortcut("del", self.view, self.delete)
Exemple #3
0
 def new(self):
     result = NewMenu(sorted(list(PATTERNS.keys()))).exec_()
     if self.check_save() is not True:
         return
     pattern = PATTERNS[result] if result else get_new_pattern()
     self._workingfile = None
     self._undo_manager = UndoManager(pattern, deepcopy)
     self.view.graph.set_pattern(pattern)
     self.update_title()
Exemple #4
0
    def new(self):
        if self.check_save() is not True:
            return

        chordgrid = get_new_chordgrid()
        self._workingfile = None
        self.view.chordgrid_editor.set_chordgrid(chordgrid)
        self._undo_manager = UndoManager(chordgrid, deepcopy)
        self._copy_manager.set_array(self._undo_manager.data)
        self.update_title()
Exemple #5
0
    def open(self):
        if not self.check_save():
            return

        filename = open_dialog(filter_="mmc")
        if not filename:
            return

        with open(filename, 'r') as f:
            chordgrid = json.load(f)
        self._workingfile = filename
        self.view.chordgrid_editor.set_chordgrid(chordgrid)
        self._undo_manager = UndoManager(chordgrid, deepcopy)
        self._copy_manager.set_array(self._undo_manager.data)
        self.update_title()
Exemple #6
0
 def open(self):
     if not self.check_save():
         return
     filename = open_dialog(filter_="mmp")
     if not filename:
         return
     with open(filename, 'r') as f:
         try:
             pattern = json.load(f)
             pattern = json_to_pattern(pattern)
         except:
             invalid_file_dialog(filename)
             return
     if not is_valid_pattern(pattern):
         invalid_file_dialog(filename)
         return
     self._workingfile = filename
     self.modified(pattern)
     self._undo_manager = UndoManager(pattern, deepcopy)
     self.update_title()
Exemple #7
0
class PatternEditor():

    def __init__(self, pattern):
        self._workingfile = None
        self.view = PatternEditorWidget(pattern)
        self.title = TITLE
        self.update_title()
        self._undo_manager = UndoManager(pattern, deepcopy)

        self.view.menu.newPatternRequested.connect(self.new)
        self.view.menu.openPatternRequested.connect(self.open)
        self.view.menu.savePatternRequested.connect(self.save)
        self.view.menu.undoRequested.connect(self.undo)
        self.view.menu.redoRequested.connect(self.redo)
        self.view.menu.deleteRequested.connect(self.delete_selected_indexes)
        self.view.menu.themesRequested.connect(self.set_theme)
        self.view.menu.verifyRequested.connect(self.verify_pattern)

        self.view.graph.figureClicked.connect(self.edit_figure)
        self.view.graph.behaviorClicked.connect(self.edit_behaviors)
        self.view.graph.connectionClicked.connect(self.edit_connection)
        self.view.graph.rowClicked.connect(self.append_index_at_row)

        set_shortcut("Ctrl+Z", self.view, self.undo)
        set_shortcut("Ctrl+Y", self.view, self.redo)
        set_shortcut("Ctrl+N", self.view, self.new)
        set_shortcut("Ctrl+S", self.view, self.save)
        set_shortcut("Ctrl+O", self.view, self.open)
        set_shortcut("del", self.view, self.delete_selected_indexes)

    @property
    def pattern(self):
        return self._undo_manager.data

    def set_title(self, title):
        self.title = title
        self.update_title()

    def update_title(self):
        title = self.title + (" - " + self._workingfile if self._workingfile else "")
        self.view.setWindowTitle(title)

    def append_index_at_row(self, row):
        pattern = self._undo_manager.data
        figure = (0, 0, 0, 0)
        append_figure_at_row(pattern, figure, row)
        self.modified(pattern)

    def edit_figure(self, index, point):
        pattern = self._undo_manager.data
        figure = get_figure_at(pattern, index)
        balloon = FigureBalloon(figure, parent=self.view)
        result = balloon.exec_(point)
        if result is True:
            set_figure_at(pattern, index, balloon.figure)
            self.modified(pattern)

    def edit_behaviors(self, index, point):
        pattern = self._undo_manager.data
        behaviors = get_behaviors_at(pattern, index)
        balloon = BehaviorsBalloon(behaviors, parent=self.view)
        result = balloon.exec_(point)
        if result is True:
            set_behaviors_at(pattern, index, balloon.behaviors)
            self.modified(pattern)

    def edit_connection(self, in_index, out_index, point):
        pattern = self._undo_manager.data
        relationship = get_relationship(pattern, in_index, out_index)
        balloon = ConnectionBalloon(relationship, parent=self.view)
        result = balloon.exec_(point)
        if result is True:
            set_relationship(pattern, in_index, out_index, balloon.value)
            self.modified(pattern)

    def show(self):
        self.view.show()

    def modified(self, pattern):
        self._undo_manager.set_data_modified(pattern)
        self.view.graph.set_pattern(pattern)

    def new(self):
        result = NewMenu(sorted(list(PATTERNS.keys()))).exec_()
        if self.check_save() is not True:
            return
        pattern = PATTERNS[result] if result else get_new_pattern()
        self._workingfile = None
        self._undo_manager = UndoManager(pattern, deepcopy)
        self.view.graph.set_pattern(pattern)
        self.update_title()

    def open(self):
        if not self.check_save():
            return
        filename = open_dialog(filter_="mmp")
        if not filename:
            return
        with open(filename, 'r') as f:
            try:
                pattern = json.load(f)
                pattern = json_to_pattern(pattern)
            except:
                invalid_file_dialog(filename)
                return
        if not is_valid_pattern(pattern):
            invalid_file_dialog(filename)
            return
        self._workingfile = filename
        self.modified(pattern)
        self._undo_manager = UndoManager(pattern, deepcopy)
        self.update_title()

    def save(self):
        if self._workingfile is None:
            filename = save_dialog(filter_="mmp")
            if not filename:
                return
            self._workingfile = filename
        with open(self._workingfile, 'w') as f:
            p = pattern_to_json(self._undo_manager.data)
            json.dump(p, f, indent=2)
        self._undo_manager.set_data_saved()
        self.update_title()

    def undo(self):
        self._undo_manager.undo()
        self.view.graph.set_pattern(self._undo_manager.data)

    def redo(self):
        self._undo_manager.redo()
        self.view.graph.set_pattern(self._undo_manager.data)

    def check_save(self):
        if self._undo_manager.data_saved is False:
            result = data_lost_question()
            if result is True:
                self.save()
                return True
            elif result is None:
                return False
        return True

    def delete_selected_indexes(self):
        indexes = [
            i.index for i in self.view.graph.pattern.selected_indexes()]
        # delete by the last index to avoid reindexing durange the procedure
        # and avoid crashes with multi selected indexes delete
        indexes = [i for i in reversed(sorted(indexes))]
        if not indexes:
            return
        pattern = self._undo_manager.data
        for index in indexes:
            delete_figure_at(pattern, index)
        self._undo_manager.set_data_modified(pattern)
        self.view.graph.set_pattern(pattern)

    def verify_pattern(self):
        pattern = self._undo_manager.data
        result, details = is_iterable_pattern(pattern)
        check_pattern_dialog(result, details)

    def set_theme(self, theme):
        # theme = ThemesMenu(sorted(list(THEMES.keys()))).exec_()
        if theme:
            self.view.set_theme(theme)
Exemple #8
0
class ChordGridEditor():
    def __init__(self, chords):
        self._workingfile = None
        self.title = TITLE
        self.view = ChordGridView(chords)
        self.update_title()
        self._undo_manager = UndoManager(chords, deepcopy)
        self._copy_manager = CopyManager(chords, self.is_index_selected)

        self.view.menu.newRequested.connect(self.new)
        self.view.menu.openRequested.connect(self.open)
        self.view.menu.saveRequested.connect(self.save)
        self.view.menu.addRequested.connect(self.add)
        self.view.menu.deleteRequested.connect(self.delete)
        self.view.menu.cutRequested.connect(self.cut)
        self.view.menu.copyRequested.connect(self.copy)
        self.view.menu.pasteRequested.connect(self.paste)
        self.view.menu.undoRequested.connect(self.undo)
        self.view.menu.redoRequested.connect(self.redo)

        self.view.chordgrid_editor.gridModified.connect(self.modified)
        self.view.chordgrid_editor.lastIndexModified.connect(
            self._copy_manager.set_index)

        set_shortcut("Ctrl+Z", self.view, self.undo)
        set_shortcut("Ctrl+Y", self.view, self.redo)
        set_shortcut("Ctrl+N", self.view, self.new)
        set_shortcut("Ctrl+S", self.view, self.save)
        set_shortcut("Ctrl+O", self.view, self.open)
        set_shortcut("Ctrl+X", self.view, self.cut)
        set_shortcut("Ctrl+C", self.view, self.copy)
        set_shortcut("Ctrl+V", self.view, self.paste)
        set_shortcut("del", self.view, self.delete)

    @property
    def chordgrid(self):
        return self._undo_manager.data

    def set_title(self, title):
        self.title = title
        self.update_title()

    def update_title(self):
        title = self.title + (" - " +
                              self._workingfile if self._workingfile else "")
        self.view.setWindowTitle(title)

    def set_parentview(self, parent=None):
        self.view.setParent(parent)

    def show(self):
        self.view.show()

    def new(self):
        if self.check_save() is not True:
            return

        chordgrid = get_new_chordgrid()
        self._workingfile = None
        self.view.chordgrid_editor.set_chordgrid(chordgrid)
        self._undo_manager = UndoManager(chordgrid, deepcopy)
        self._copy_manager.set_array(self._undo_manager.data)
        self.update_title()

    def open(self):
        if not self.check_save():
            return

        filename = open_dialog(filter_="mmc")
        if not filename:
            return

        with open(filename, 'r') as f:
            chordgrid = json.load(f)
        self._workingfile = filename
        self.view.chordgrid_editor.set_chordgrid(chordgrid)
        self._undo_manager = UndoManager(chordgrid, deepcopy)
        self._copy_manager.set_array(self._undo_manager.data)
        self.update_title()

    def save(self):
        if self._workingfile is None:
            filename = save_dialog(filter_="mmc")
            if not filename:
                return
            self._workingfile = filename

        with open(self._workingfile, 'w') as f:
            chordgrid = self._undo_manager.data
            json.dump(chordgrid, f, indent=2)

        self._undo_manager.set_data_saved()
        self.update_title()

    def add(self):
        chordgrid = self._undo_manager.data
        chordgrid.extend([None] * 32)
        self.view.chordgrid_editor.set_chordgrid(chordgrid)
        self.modified()

    def delete(self):
        self.view.chordgrid_editor.delete_selection()

    def cut(self):
        chordgrid = self._copy_manager.cut()
        self.view.chordgrid_editor.set_chordgrid(chordgrid)
        self.modified()

    def copy(self):
        self._copy_manager.copy()

    def paste(self):
        data = self._copy_manager.paste()
        if data is not None:
            self.view.chordgrid_editor.set_chordgrid(data)
            self.modified()

    def undo(self):
        self._undo_manager.undo()
        data = self._undo_manager.data
        self.view.chordgrid_editor.set_chordgrid(data)
        self._copy_manager.set_array(data)

    def redo(self):
        self._undo_manager.redo()
        data = self._undo_manager.data
        self.view.chordgrid_editor.set_chordgrid(data)
        self._copy_manager.set_array(data)

    def modified(self):
        data = self.view.chordgrid_editor.chordgrid
        self._undo_manager.set_data_modified(data)
        self._copy_manager.set_array(data)

    def check_save(self):
        if self._undo_manager.data_saved is False:
            result = data_lost_question()
            if result is True:
                self.save()
                return True
            elif result is None:
                return False
        return True

    def is_index_selected(self, index):
        return self.view.chordgrid_editor.is_index_selected(index)