def populate_central_widget(self): self.vertical_widgets = collections.OrderedDict() self.horizontal_splitter = QSplitter( Qt.Horizontal, self.vertical_splitter) self.horizontal_widgets = collections.OrderedDict() self.vertical_widgets["horizontal_splitter"] = self.horizontal_splitter Alter.invoke_all( 'main_window_add_vertical_widget', self.vertical_widgets, self ) for widget in self.vertical_widgets.values(): self.vertical_splitter.addWidget(widget) Alter.invoke_all( 'main_window_add_horizontal_widget', self.horizontal_widgets, self.vertical_splitter ) for widget in self.horizontal_widgets.values(): self.horizontal_splitter.addWidget(widget) #restore horizontal splitter state state = ModuleManager.core['settings'].Settings.value( self.KEY_H_SPLITTER_STATE, None ) if state: self.horizontal_splitter.restoreState(state)
def __init__(self, parent=None): super(TabWidget, self).__init__(parent) self.tabBar().installEventFilter(self) self.setTabsClosable(True) self.setMovable(True) self.setFocusPolicy(Qt.NoFocus) self.icon_modified = QIcon('images/is-modified.png') self.icon_not_modified = QIcon('images/is-not-modified.png') self.tabCloseRequested.connect(self.on_tab_closed) nav_icon = QIcon('images/navigation-menu.png') self.menu_button = QPushButton('', self) self.menu_button.setIcon(nav_icon) self.menu_button.setFlat(True) self.menu_button.clicked.connect(self.on_menu_button_clicked) self.menu_button.setObjectName('TabWidgetMenuButton') self.menu_button.setToolTip('Menu with useful actions') self.setCornerWidget(self.menu_button, Qt.TopRightCorner) self.menu = QMenu(self) self.add_action('Remove current tab', 'ctrl+w', TabWidgetHelper.remove) self.add_action('Remove all tab', 'ctrl+shift+w', TabWidgetHelper.remove_all) self.add_separator() self.add_action('Next Tab', QKeySequence.NextChild, TabWidgetHelper.next_tab) self.add_action('Previous Tab', QKeySequence.PreviousChild, TabWidgetHelper.previous_tab) Alter.invoke_all('tab_widget_add_action', self) self.currentChanged[int].connect(self.on_current_changed)
def __init__(self, parent=None): super(TabWidget, self).__init__(parent) self.tabBar().installEventFilter(self) self.setTabsClosable(True) self.setMovable(True) self.setFocusPolicy(Qt.NoFocus) self.icon_modified = QIcon('images/is-modified.png') self.icon_not_modified = QIcon('images/is-not-modified.png') self.tabCloseRequested.connect(self.on_tab_closed) nav_icon = QIcon('images/navigation-menu.png') self.menu_button = QPushButton('', self) self.menu_button.setIcon(nav_icon) self.menu_button.setFlat(True) self.menu_button.clicked.connect(self.on_menu_button_clicked) self.menu_button.setObjectName('TabWidgetMenuButton') self.menu_button.setToolTip('Menu with useful actions') self.setCornerWidget(self.menu_button, Qt.TopRightCorner) self.menu = QMenu(self) self.add_action('Remove current tab', 'ctrl+w', TabWidgetHelper.remove) self.add_action( 'Remove all tab', 'ctrl+shift+w', TabWidgetHelper.remove_all) self.add_separator() self.add_action('Next Tab', QKeySequence.NextChild, TabWidgetHelper.next_tab) self.add_action('Previous Tab', QKeySequence.PreviousChild, TabWidgetHelper.previous_tab) self.add_separator() self.add_action('Open file', QKeySequence.Open, TabWidgetHelper.open_file) Alter.invoke_all('tab_widget_add_action', self) self.currentChanged[int].connect(self.on_current_changed)
def keyPressEvent(self, event): line, index = self.getCursorPosition() events = [event] self.auto_close_event(events, line, index) #invoke other modules Alter.invoke_all('editor_key_presse_event', self, events, line, index) for evt in events: super(Editor, self).keyPressEvent(evt)
def __init__(self, argv): super(Mojuru, self).__init__(argv) ModuleManager.add_module_directory('core', self.core_path) ModuleManager.add_module_directory('custom', self.custom_path) ModuleManager.load_all('core') ModuleManager.load_all('custom') Alter.invoke_all('mojuru_init', self)
def save(self, parent, action=None): Alter.invoke_all('editor_presave', self) if self.modified: with open(self.file_info.absoluteFilePath(), 'w') as f: f.write(self.get_value()) self.original_to_current_doc() self.modificationChanged.emit(False) parent.status_bar.showMessage(self.tr("Saved file.")) Alter.invoke_all('editor_save', self) else : parent.status_bar.showMessage(self.tr("Nothing to save."))
def reload_central_widget(self): self.save_state() for index in range(self.vertical_splitter.count()): widget = self.vertical_splitter.widget(index) widget.hide() widget.setParent(None) del widget Alter.clear() ModuleManager.reload_all_modules('core') ModuleManager.reload_all_modules('custom') self.load_central_widget()
def save(self, parent, action=None): Alter.invoke_all('editor_presave', self) if self.modified: with open(self.file_info.absoluteFilePath(), 'w') as f: f.write(self.get_value()) self.original_to_current_doc() self.modificationChanged.emit(False) parent.status_bar.showMessage(self.tr("Saved file.")) Alter.invoke_all('editor_save', self) else: parent.status_bar.showMessage(self.tr("Nothing to save."))
def save(self, parent, action=None): Alter.invoke_all('editor_presave', self) if self.isModified(): with open(self.file_info.absoluteFilePath(), 'w') as f: #I don't understand encoding >< but it works b_text = self.text().encode('utf-8') f.write(str(b_text, 'utf-8')) self.setModified(False) parent.status_bar.showMessage(self.tr("Saved file.")) Alter.invoke_all('editor_save', self) else: parent.status_bar.showMessage(self.tr("Nothing to save."))
def save(self, parent, action=None): Alter.invoke_all('editor_presave', self) if self.isModified(): with open(self.file_info.absoluteFilePath(), 'w') as f: #I don't understand encoding >< but it works b_text = self.text().encode('utf-8') f.write(str(b_text, 'utf-8')) self.setModified(False) parent.status_bar.showMessage(self.tr("Saved file.")) Alter.invoke_all('editor_save', self) else : parent.status_bar.showMessage(self.tr("Nothing to save."))
def __init__(self, file_info, parent=None): super(Editor, self).__init__(parent) self.file_info = file_info self.lang = EditorHelper.lang_from_file_info(file_info) self.setUtf8(True) with open(file_info.absoluteFilePath(), 'r') as f: text = f.read() self.setText(text) self.setModified(False) self.modificationChanged[bool].connect(self.on_modification_changed) Alter.invoke_all('editor_init', self) self.configure()
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle('Mojuru') app_icon = QIcon('images/mojuru_logo.png') self.setWindowIcon(app_icon) reload_modules_action = QAction('Reload MainWindow', self) reload_modules_action.setShortcut('ctrl+shift+alt+r') reload_modules_action.triggered.connect(self.reload_central_widget) self.addAction(reload_modules_action) quit_action = QAction('Quit', self) quit_action.setShortcut('ctrl+q') quit_action.triggered.connect(self.on_quit) self.addAction(quit_action) self.vertical_splitter = QSplitter(Qt.Vertical, self) self.setCentralWidget(self.vertical_splitter) self.load_central_widget() self.file_menu = self.menuBar().addMenu(self.tr('&File')) self.file_menu.addAction(quit_action) self.file_menu.addSeparator() self.module_menu = self.menuBar().addMenu(self.tr('&Modules')) self.module_menu.addAction(reload_modules_action) self.module_menu.addSeparator() Alter.invoke_all('main_window_init', self) #restore main window state size = ModuleManager.core['settings'].Settings.value( self.KEY_WINDOW_SIZE, QSize(600, 400)) maximized = ModuleManager.core['settings'].Settings.value( self.KEY_WINDOW_MAXIMIZED, False) position = ModuleManager.core['settings'].Settings.value( self.KEY_WINDOW_POSITION, QPoint(0, 0)) if maximized == 'true': self.showMaximized() else: self.resize(size) self.move(position)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle('Mojuru') app_icon = QIcon('images/mojuru_logo.png') self.setWindowIcon(app_icon) reload_modules_action = QAction('Reload MainWindow', self) reload_modules_action.setShortcut('ctrl+shift+alt+r') reload_modules_action.triggered.connect(self.reload_central_widget) self.addAction(reload_modules_action) quit_action = QAction('Quit', self) quit_action.setShortcut('ctrl+q') quit_action.triggered.connect(self.on_quit) self.addAction(quit_action) self.vertical_splitter = QSplitter(Qt.Vertical, self) self.setCentralWidget(self.vertical_splitter) self.load_central_widget() self.file_menu = self.menuBar().addMenu(self.tr('&File')) self.file_menu.addAction(quit_action) self.file_menu.addSeparator() self.module_menu = self.menuBar().addMenu(self.tr('&Modules')) self.module_menu.addAction(reload_modules_action) self.module_menu.addSeparator() Alter.invoke_all('main_window_init', self) #restore main window state size = ModuleManager.core['settings'].Settings.value( self.KEY_WINDOW_SIZE, QSize(600, 400)) maximized = ModuleManager.core['settings'].Settings.value( self.KEY_WINDOW_MAXIMIZED, False) position = ModuleManager.core['settings'].Settings.value( self.KEY_WINDOW_POSITION, QPoint(0,0)) if maximized == 'true': self.showMaximized() else: self.resize(size) self.move(position)
def __init__(self, file_info, parent=None): super(AceEditor, self).__init__(parent) self.parent = parent self.file_info = file_info self.editor_actions = {} self.language = EditorHelper.lang_from_file_info(file_info) self.editor = Ace(self.file_info, self) self.status_bar = StatusBar(self) self.editor.modificationChanged.connect( self.modification_changed) self.editor.cursorPositionChanged.connect(self.on_cursor_changed) self.v_box = QVBoxLayout(self) self.v_box.setSpacing(0) self.v_box.setContentsMargins(0, 0, 0, 0) self.v_box.addWidget(self.editor, 1) self.v_box.addWidget(self.status_bar, 0) self.setLayout(self.v_box) self.status_bar.menu_button.clicked.connect( self.on_menu_button_clicked) self.menu = QMenu(self) self.add_action('Save', 'ctrl+s', self.editor.save) self.add_separator() self.add_action( 'Show hidden', 'ctrl+i', self.editor.toggle_hidden,checkable=True ) self.add_action( 'Use soft tabs', 'ctrl+shift+alt+s', self.editor.toggle_soft_tabs, checkable=True ) self.setFocusPolicy(Qt.NoFocus) self.setFocusProxy(self.editor) Alter.invoke_all('editor_widget_init', self)
def configure(self): font = QFont() font.setFamily('ubuntu mono') font.setFixedPitch(True) font.setPointSize(12) self.setFont(font) lexer_class = EditorHelper.language_lexer(self.file_info) if lexer_class: base_lexer = lexer_class() self.lang_lexer = type( self.lang, (lexer_class, ), { 'keys_ens': [base_lexer.keywords(i) for i in range(10)], 'keywords': lambda self, ens: self.keys_ens[ens] })() #self.lang_lexer = lexer_class() if lexer_class else None #ModuleManager.core['theme_manager'].ThemeManager.set_editor_theme( # self, self.lang_lexer) if hasattr(self, 'lang_lexer'): self.lang_lexer.setFont(font) self.setLexer(self.lang_lexer) fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginLineNumbers(1, True) self.setMarginWidth(1, fontmetrics.width("00000")) self.setCaretLineVisible(True) self.setIndentationGuides(True) self.setIndentationsUseTabs(False) self.setIndentationWidth(4) self.setTabWidth(4) self.setAutoIndent(True) self.setBackspaceUnindents(True) self.setFolding(QsciScintilla.BoxedTreeFoldStyle) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.setEdgeColumn(79) self.setEdgeColor(QColor('#424242')) self.setEdgeMode(QsciScintilla.EdgeLine) Alter.invoke_all('editor_configure', self)
def configure(self): font = QFont() font.setFamily('ubuntu mono') font.setFixedPitch(True) font.setPointSize(12) self.setFont(font) lexer_class = EditorHelper.language_lexer(self.file_info) if lexer_class: base_lexer = lexer_class() self.lang_lexer = type(self.lang, (lexer_class,), { 'keys_ens': [base_lexer.keywords(i) for i in range(10)], 'keywords': lambda self, ens: self.keys_ens[ens] })() #self.lang_lexer = lexer_class() if lexer_class else None #ModuleManager.core['theme_manager'].ThemeManager.set_editor_theme( # self, self.lang_lexer) if hasattr(self, 'lang_lexer'): self.lang_lexer.setFont(font) self.setLexer(self.lang_lexer) fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginLineNumbers(1, True) self.setMarginWidth(1, fontmetrics.width("00000")) self.setCaretLineVisible(True) self.setIndentationGuides(True) self.setIndentationsUseTabs(False) self.setIndentationWidth(4) self.setTabWidth(4) self.setAutoIndent(True) self.setBackspaceUnindents(True) self.setFolding(QsciScintilla.BoxedTreeFoldStyle) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.setEdgeColumn(79) self.setEdgeColor(QColor('#424242')) self.setEdgeMode(QsciScintilla.EdgeLine) Alter.invoke_all('editor_configure', self)
def populate_central_widget(self): self.vertical_widgets = collections.OrderedDict() self.horizontal_splitter = QSplitter(Qt.Horizontal, self.vertical_splitter) self.horizontal_widgets = collections.OrderedDict() self.vertical_widgets["horizontal_splitter"] = self.horizontal_splitter Alter.invoke_all('main_window_add_vertical_widget', self.vertical_widgets, self) for widget in self.vertical_widgets.values(): self.vertical_splitter.addWidget(widget) Alter.invoke_all('main_window_add_horizontal_widget', self.horizontal_widgets, self.vertical_splitter) for widget in self.horizontal_widgets.values(): self.horizontal_splitter.addWidget(widget) #restore horizontal splitter state state = ModuleManager.core['settings'].Settings.value( self.KEY_H_SPLITTER_STATE, None) if state: self.horizontal_splitter.restoreState(state)
def connect_widgets(self): Alter.invoke_all('main_window_connect_widgets', self.vertical_widgets, self.horizontal_widgets)
def onFileItemActivated(self, file_info): Alter.invoke_all('tab_widget_add_tab', self, file_info)
from os import listdir from os.path import isfile, join, dirname, realpath from random import randint import sys path = dirname(realpath(__file__)) + "/../" sys.path.insert(0, path) from alter import Alter if __name__ == "__main__": src = "./data/img/" out = "./output/" files = [f for f in listdir(src) if isfile(join(src, f))] for f in files: altr = Alter(join(src, f)) altr.salt().write(directory=out) altr = Alter(join(src, f)) altr.pepper().write(directory=out) altr = Alter(join(src, f)) altr.salt().pepper().write(directory=out)
def connect_widgets(self): Alter.invoke_all( 'main_window_connect_widgets', self.vertical_widgets, self.horizontal_widgets )
def run(self): Alter.invoke_all('mojuru_set_main_window', self) self.exec_()
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ Mojuru Main """ import sys import os.path from PyQt5.QtCore import QFileInfo from PyQt5.QtWidgets import QApplication from alter import Alter, ModuleManager Alter.register('mojuru_init') Alter.register('mojuru_set_main_window') class Mojuru(QApplication): app_path = QFileInfo(__file__).absoluteDir().absolutePath() core_path = os.path.join(app_path, 'modules', 'core') custom_path = os.path.join(app_path, 'modules', 'custom') def __init__(self, argv): super(Mojuru, self).__init__(argv) ModuleManager.add_module_directory('core', self.core_path) ModuleManager.add_module_directory('custom', self.custom_path) ModuleManager.load_all('core')
def __init__(self, file_info, parent=None): super(EditorWidget, self).__init__(parent) self.parent = parent self.file_info = file_info self.v_box = QVBoxLayout(self) self.v_box.setSpacing(0) self.v_box.setContentsMargins(0, 0, 0, 0) self.status_bar = StatusBar(self) self.editor = Editor(self.file_info, self) self.editor.modificationChanged[bool].connect( self.on_modification_changed) self.editor.cursorPositionChanged.connect(self.on_cursor_changed) self.v_box.addWidget(self.editor) self.v_box.addWidget(self.status_bar) self.setLayout(self.v_box) self.status_bar.menu_button.clicked.connect( self.on_menu_button_clicked) self.menu = QMenu(self) self.add_action(self.tr('Save'), 'ctrl+s', self.editor.save) self.add_separator() self.add_action( self.tr('Zoom in'), QKeySequence.ZoomIn, self.editor.zoomIn, wrapped=False ) self.add_action( self.tr('Zoom out'), QKeySequence.ZoomOut, self.editor.zoomOut, wrapped=False ) self.add_action( self.tr('Zoom reset'), 'ctrl+0', self.editor.zoom_reset ) self.add_action( self.tr('Indent current line'), 'ctrl+i', self.editor.indent_current_line ) self.add_action( self.tr('Unindent current line'), 'ctrl+shift+i', self.editor.unindent_current_line ) self.add_separator() self.add_action( self.tr('Auto close brackets and quotes'), 'ctrl+alt+a', EditorHelper.auto_close_brackets_quotes, checkable=True, checked=ModuleManager.core['settings'].Settings.value( EditorHelper.SETTINGS_AUTO_CLOSE_BRACKETS, 'true' ) ) self.add_action( self.tr('Use tabs to indent/unindent'), 'ctrl+shift+alt+&', EditorHelper.use_tabs_to_indent, checkable=True, checked=ModuleManager.core['settings'].Settings.value( EditorHelper.SETTINGS_USE_TABS_TO_INDENT, 'true' ) ) self.add_action( self.tr('Comment/Uncomment line(s)'), 'ctrl+e', self.editor.comment_lines ) self.setFocusPolicy(Qt.NoFocus) self.setFocusProxy(self.editor) Alter.invoke_all('editor_widget_init', self)