class __CentralWidget(QWidget): ############################################################################### # CentralWidget SIGNALS ############################################################################### """ splitterCentralRotated() """ ############################################################################### def __init__(self, parent=None): QWidget.__init__(self, parent) self.parent = parent #This variables are used to save the splitter sizes before hide self._splitterMainSizes = None self._splitterAreaSizes = None self.lateralPanel = None hbox = QHBoxLayout(self) hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(0) #Create Splitters to divide the UI in: MainPanel, Explorer, Misc self._splitterArea = QSplitter(Qt.Horizontal) self._splitterMain = QSplitter(Qt.Vertical) #Create scrollbar for follow mode self.scrollBar = QScrollBar(Qt.Vertical, self) self.scrollBar.setFixedWidth(20) self.scrollBar.setToolTip('Follow Mode: Scroll the Editors together') self.scrollBar.hide() self.connect(self.scrollBar, SIGNAL("valueChanged(int)"), self.move_follow_scrolls) #Add to Main Layout hbox.addWidget(self.scrollBar) hbox.addWidget(self._splitterArea) def insert_central_container(self, container): self.mainContainer = container self._splitterMain.insertWidget(0, container) def insert_lateral_container(self, container): self.lateralPanel = LateralPanel(container) self._splitterArea.insertWidget(0, self.lateralPanel) def insert_bottom_container(self, container): self.misc = container self._splitterMain.insertWidget(1, container) def showEvent(self, event): #Show Event QWidget.showEvent(self, event) #Avoid recalculate the panel sizes if they are already loaded if self._splitterArea.count() == 2: return #Rearrange widgets on Window self._splitterArea.insertWidget(0, self._splitterMain) qsettings = QSettings() #Lists of sizes as list of QVariant- heightList = [QVariant, QVariant] heightList = list( qsettings.value("window/central/mainSize", [(self.height() / 3) * 2, self.height() / 3])) widthList = list( qsettings.value("window/central/areaSize", [(self.width() / 6) * 5, self.width() / 6])) self._splitterMainSizes = [int(heightList[0]), int(heightList[1])] self._splitterAreaSizes = [int(widthList[0]), int(widthList[1])] if not event.spontaneous(): self.change_misc_visibility() if bin(settings.UI_LAYOUT)[-1] == '1': self.splitter_central_rotate() if bin(settings.UI_LAYOUT >> 1)[-1] == '1': self.splitter_misc_rotate() if bin(settings.UI_LAYOUT >> 2)[-1] == '1': self.splitter_central_orientation() #Set the sizes to splitters self._splitterMain.setSizes(self._splitterMainSizes) self._splitterArea.setSizes(self._splitterAreaSizes) self.misc.setVisible( qsettings.value("window/show_misc", False, type=bool)) def change_misc_visibility(self): if self.misc.isVisible(): self._splitterMainSizes = self._splitterMain.sizes() self.misc.hide() widget = self.mainContainer.get_actual_widget() if widget: widget.setFocus() else: self.misc.show() self.misc.gain_focus() def change_main_visibility(self): if self.mainContainer.isVisible(): self.mainContainer.hide() else: self.mainContainer.show() def change_explorer_visibility(self, force_hide=False): if self.lateralPanel.isVisible() or force_hide: self._splitterAreaSizes = self._splitterArea.sizes() self.lateralPanel.hide() else: self.lateralPanel.show() def splitter_central_rotate(self): w1, w2 = self._splitterArea.widget(0), self._splitterArea.widget(1) self._splitterArea.insertWidget(0, w2) self._splitterArea.insertWidget(1, w1) self.emit(SIGNAL("splitterCentralRotated()")) def splitter_central_orientation(self): if self._splitterArea.orientation() == Qt.Horizontal: self._splitterArea.setOrientation(Qt.Vertical) else: self._splitterArea.setOrientation(Qt.Horizontal) def splitter_misc_rotate(self): w1, w2 = self._splitterMain.widget(0), self._splitterMain.widget(1) self._splitterMain.insertWidget(0, w2) self._splitterMain.insertWidget(1, w1) def splitter_misc_orientation(self): if self._splitterMain.orientation() == Qt.Horizontal: self._splitterMain.setOrientation(Qt.Vertical) else: self._splitterMain.setOrientation(Qt.Horizontal) def get_area_sizes(self): if self.lateralPanel.isVisible(): self._splitterAreaSizes = self._splitterArea.sizes() return self._splitterAreaSizes def get_main_sizes(self): if self.misc.isVisible(): self._splitterMainSizes = self._splitterMain.sizes() return self._splitterMainSizes def enable_follow_mode_scrollbar(self, val): if val: editorWidget = self.mainContainer.get_actual_editor() maxScroll = editorWidget.verticalScrollBar().maximum() position = editorWidget.verticalScrollBar().value() self.scrollBar.setMaximum(maxScroll) self.scrollBar.setValue(position) self.scrollBar.setVisible(val) def move_follow_scrolls(self, val): widget = self.mainContainer._tabMain.currentWidget() diff = widget._sidebarWidget.highest_line - val s1 = self.mainContainer._tabMain.currentWidget().verticalScrollBar() s2 = self.mainContainer._tabSecondary.\ currentWidget().verticalScrollBar() s1.setValue(val) s2.setValue(val + diff)
class __CentralWidget(QWidget): ############################################################################### # CentralWidget SIGNALS ############################################################################### """ splitterCentralRotated() """ ############################################################################### def __init__(self, parent=None): QWidget.__init__(self, parent) self.parent = parent # This variables are used to save the splitter sizes before hide self._splitterMainSizes = None self._splitterAreaSizes = None self.lateralPanel = None hbox = QHBoxLayout(self) hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(0) # Create Splitters to divide the UI in: MainPanel, Explorer, Misc self._splitterArea = QSplitter(Qt.Horizontal) self._splitterMain = QSplitter(Qt.Vertical) # Create scrollbar for follow mode self.scrollBar = QScrollBar(Qt.Vertical, self) self.scrollBar.setFixedWidth(20) self.scrollBar.setToolTip("Follow Mode: Scroll the Editors together") self.scrollBar.hide() self.connect(self.scrollBar, SIGNAL("valueChanged(int)"), self.move_follow_scrolls) # Add to Main Layout hbox.addWidget(self.scrollBar) hbox.addWidget(self._splitterArea) def insert_central_container(self, container): self.mainContainer = container self._splitterMain.insertWidget(0, container) def insert_lateral_container(self, container): self.lateralPanel = LateralPanel(container) self._splitterArea.insertWidget(0, self.lateralPanel) def insert_bottom_container(self, container): self.misc = container self._splitterMain.insertWidget(1, container) def showEvent(self, event): # Show Event QWidget.showEvent(self, event) # Avoid recalculate the panel sizes if they are already loaded if self._splitterArea.count() == 2: return # Rearrange widgets on Window self._splitterArea.insertWidget(0, self._splitterMain) qsettings = QSettings() # Lists of sizes as list of QVariant- heightList = [QVariant, QVariant] heightList = list(qsettings.value("window/central/mainSize", [(self.height() / 3) * 2, self.height() / 3])) widthList = list(qsettings.value("window/central/areaSize", [(self.width() / 6) * 5, self.width() / 6])) self._splitterMainSizes = [int(heightList[0]), int(heightList[1])] self._splitterAreaSizes = [int(widthList[0]), int(widthList[1])] if not event.spontaneous(): self.change_misc_visibility() if bin(settings.UI_LAYOUT)[-1] == "1": self.splitter_central_rotate() if bin(settings.UI_LAYOUT >> 1)[-1] == "1": self.splitter_misc_rotate() if bin(settings.UI_LAYOUT >> 2)[-1] == "1": self.splitter_central_orientation() # Set the sizes to splitters self._splitterMain.setSizes(self._splitterMainSizes) self._splitterArea.setSizes(self._splitterAreaSizes) def change_misc_visibility(self): if self.misc.isVisible(): self._splitterMainSizes = self._splitterMain.sizes() self.misc.hide() widget = self.mainContainer.get_actual_widget() if widget: widget.setFocus() else: self.misc.show() self.misc.gain_focus() def change_main_visibility(self): if self.mainContainer.isVisible(): self.mainContainer.hide() else: self.mainContainer.show() def change_explorer_visibility(self, force_hide=False): if self.lateralPanel.isVisible() or force_hide: self._splitterAreaSizes = self._splitterArea.sizes() self.lateralPanel.hide() else: self.lateralPanel.show() def splitter_central_rotate(self): w1, w2 = self._splitterArea.widget(0), self._splitterArea.widget(1) self._splitterArea.insertWidget(0, w2) self._splitterArea.insertWidget(1, w1) self.emit(SIGNAL("splitterCentralRotated()")) def splitter_central_orientation(self): if self._splitterArea.orientation() == Qt.Horizontal: self._splitterArea.setOrientation(Qt.Vertical) else: self._splitterArea.setOrientation(Qt.Horizontal) def splitter_misc_rotate(self): w1, w2 = self._splitterMain.widget(0), self._splitterMain.widget(1) self._splitterMain.insertWidget(0, w2) self._splitterMain.insertWidget(1, w1) def splitter_misc_orientation(self): if self._splitterMain.orientation() == Qt.Horizontal: self._splitterMain.setOrientation(Qt.Vertical) else: self._splitterMain.setOrientation(Qt.Horizontal) def get_area_sizes(self): if self.lateralPanel.isVisible(): self._splitterAreaSizes = self._splitterArea.sizes() return self._splitterAreaSizes def get_main_sizes(self): if self.misc.isVisible(): self._splitterMainSizes = self._splitterMain.sizes() return self._splitterMainSizes def enable_follow_mode_scrollbar(self, val): if val: editorWidget = self.mainContainer.get_actual_editor() maxScroll = editorWidget.verticalScrollBar().maximum() position = editorWidget.verticalScrollBar().value() self.scrollBar.setMaximum(maxScroll) self.scrollBar.setValue(position) self.scrollBar.setVisible(val) def move_follow_scrolls(self, val): widget = self.mainContainer._tabMain.currentWidget() diff = widget._sidebarWidget.highest_line - val s1 = self.mainContainer._tabMain.currentWidget().verticalScrollBar() s2 = self.mainContainer._tabSecondary.currentWidget().verticalScrollBar() s1.setValue(val) s2.setValue(val + diff)
class MainWindow(QWidget, MainWindowGeneric): def __init__(self, parent): QWidget.__init__(self) MainWindowGeneric.__init__(self) self._parent = parent self.settings = QSettings('NINJA-IDE', 'Kunai') self.settings.beginGroup('Preferences') self.settings.beginGroup('Interface') self._vbox = QVBoxLayout(self) #Splitters self.splitterMain = QSplitter() self.splitterCentral = QSplitter(Qt.Vertical) #Properties Panel self._properties = PropertiesWidget(self) #Central self._central = CentralWidget(self) self.show_start_page() self.splitterCentral.insertWidget( self.settings.value('central_tab_position', 0).toInt()[0], self._central) #Display Container self.container = DisplayContainer(self) self._hide_container() self.splitterCentral.insertWidget( self.settings.value('container_tab_position', 1).toInt()[0], self.container) height = [(self.height() / 3) * 2, self.height() / 3] self.splitterCentral.setSizes([height[self.settings.value('central_tab_position', 0).toInt()[0]], height[self\ .settings.value('container_tab_position', 1).toInt()[0]]]) #Size Central Splitter self.splitterMain.insertWidget( self.settings.value('main_tab_position', 0).toInt()[0], self.splitterCentral) self.splitterMain.insertWidget( self.settings.value('properties_tab_position', 1).toInt()[0], self._properties) width = [(self.width() / 6) * 5, self.width() / 6] self.splitterMain.setSizes([width[self.settings.value('main_tab_position', 0).toInt()[0]],\ width[self.settings.value('properties_tab_position', 1).toInt()[0]]]) self._vbox.addWidget(self.splitterMain) self.settings.endGroup() #End General Preferences self.settings.endGroup() #flag for reload_file self._reloading = False #Shortcuts shortCloseTab = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_W), self) shortNew = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_N), self) shortNewProject = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_J), self) shortOpen = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_O), self) shortOpenProject = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_P), self) shortSave = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), self) shortSaveAll = QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S), self) shortRedo = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Y), self) shortComment = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_D), self) shortHorizontalLine = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_R), self) shortIndentLess = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_Tab), self) shortHideContainer = QShortcut(QKeySequence(Qt.Key_F4), self) shortHideEditor = QShortcut(QKeySequence(Qt.Key_F3), self) shortHideExplorer = QShortcut(QKeySequence(Qt.Key_F2), self) shortRunFile = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F6), self) shortRunProgram = QShortcut(QKeySequence(Qt.Key_F6), self) shortHideAll = QShortcut(QKeySequence(Qt.Key_F11), self) shortFind = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self) shortFindReplace = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_H), self) shortHelp = QShortcut(QKeySequence(Qt.Key_F1), self) shortSplitHorizontal = QShortcut(QKeySequence(Qt.Key_F10), self) shortSplitVertical = QShortcut(QKeySequence(Qt.Key_F9), self) shortReloadFile = QShortcut(QKeySequence(Qt.Key_F5), self) #Signal -> Slot self.connect(shortCloseTab, SIGNAL("activated()"), self.close_actual_tab) self.connect(shortNew, SIGNAL("activated()"), self.new_editor) self.connect(shortNewProject, SIGNAL("activated()"), self.new_project) self.connect(shortOpen, SIGNAL("activated()"), self.open_file) self.connect(shortOpenProject, SIGNAL("activated()"), self.open_project_folder) self.connect(shortSave, SIGNAL("activated()"), self.save) self.connect(shortSaveAll, SIGNAL("activated()"), self.save_project) self.connect(shortComment, SIGNAL("activated()"), lambda: self._central.obtain_editor().comment()) self.connect(shortIndentLess, SIGNAL("activated()"), lambda: self._central.obtain_editor().indent_less()) self.connect( shortHorizontalLine, SIGNAL("activated()"), lambda: self._central.obtain_editor().insert_horizontal_line()) self.connect(shortRedo, SIGNAL("activated()"), lambda: self._central.obtain_editor().redo()) self.connect(shortHideContainer, SIGNAL("activated()"), self._hide_container) self.connect(shortHideEditor, SIGNAL("activated()"), self._hide_editor) self.connect(shortHideExplorer, SIGNAL("activated()"), self._hide_explorer) self.connect(shortRunFile, SIGNAL("activated()"), self._run_code) self.connect(shortRunProgram, SIGNAL("activated()"), self._run_program) self.connect(shortHideAll, SIGNAL("activated()"), self._hide_all) self.connect(shortFind, SIGNAL("activated()"), self._open_find) self.connect(shortFindReplace, SIGNAL("activated()"), self._open_find_replace) self.connect(shortHelp, SIGNAL("activated()"), self._show_python_doc) self.connect(shortSplitHorizontal, SIGNAL("activated()"), lambda: self.split_tab(True)) self.connect(shortSplitVertical, SIGNAL("activated()"), lambda: self.split_tab(False)) self.connect(shortReloadFile, SIGNAL("activated()"), lambda: self.reload_file()) def change_window_title(self, title): self._parent.setWindowTitle('NINJA-IDE - ' + title) def _open_find(self): if not self._parent._status.isVisible(): self._parent._status.show() self._parent._status.focus_find(self._central.obtain_editor()) def _open_find_replace(self): if not self._parent._status.isVisible(): self._parent._status.show() self._parent._status.replace_visibility(True) self._parent._status.focus_find(self._central.obtain_editor()) def _hide_container(self): if self.containerIsVisible: self.container.hide() self.containerIsVisible = False self._central.obtain_editor().setFocus() else: self.container.show() self.containerIsVisible = True self.container.gain_focus() def _hide_editor(self): if self._central.isVisible(): self._central.hide() else: self._central.show() def _hide_explorer(self): if self._properties.isVisible(): self._properties.hide() else: self._properties.show() def _splitter_central_orientation(self): if self.splitterCentral.orientation() == Qt.Horizontal: self.splitterCentral.setOrientation(Qt.Vertical) else: self.splitterCentral.setOrientation(Qt.Horizontal) def get_splitter_central_orientation(self): return self.splitterCentral.orientation() def _splitter_main_orientation(self): if self.splitterMain.orientation() == Qt.Horizontal: self.splitterMain.setOrientation(Qt.Vertical) else: self.splitterMain.setOrientation(Qt.Horizontal) def get_splitter_main_orientation(self): return self.splitterMain.orientation() def _splitter_main_rotate(self): w = self.splitterMain.widget(0) w1 = self.splitterMain.widget(1) self.splitterMain.insertWidget(0, w1) self.splitterMain.insertWidget(1, w) def get_splitter_main_position(self): w = self.splitterMain.widget(0) return w.__class__ def _splitter_central_rotate(self): w = self.splitterCentral.widget(0) w1 = self.splitterCentral.widget(1) self.splitterCentral.insertWidget(0, w1) self.splitterCentral.insertWidget(1, w) def get_splitter_central_position(self): w = self.splitterCentral.widget(0) return w.__class__ def get_splitter_position_0(self): return type(self.splitterCentral.widget(0)) def get_splitter_main_position_0(self): return type(self.splitterMain.widget(0)) def reload_panels_position(self): self.settings = QSettings('NINJA-IDE', 'Kunai') self.settings.beginGroup('Preferences') self.settings.beginGroup('Interface') #first with the splitterCentral c = self.splitterCentral.widget(0) c1 = self.splitterCentral.widget(1) if (type(c) == CentralWidget): self.splitterCentral.insertWidget( self.settings.value('central_tab_position', 0).toInt()[0], c) self.splitterCentral.insertWidget( self.settings.value('container_tab_position', 1).toInt()[0], c1) else: self.splitterCentral.insertWidget( self.settings.value('central_tab_position', 0).toInt()[0], c1) self.splitterCentral.insertWidget( self.settings.value('container_tab_position', 1).toInt()[0], c) #now with the splitterMain m = self.splitterMain.widget(0) m1 = self.splitterMain.widget(1) if (type(m) == QSplitter): self.splitterMain.insertWidget( self.settings.value('central_tab_position', 0).toInt()[0], m) self.splitterMain.insertWidget( self.settings.value('container_tab_position', 1).toInt()[0], m1) else: self.splitterMain.insertWidget( self.settings.value('central_tab_position', 0).toInt()[0], m1) self.splitterMain.insertWidget( self.settings.value('container_tab_position', 1).toInt()[0], m) def get_open_projects(self): return self._properties._treeProjects.get_open_projects() def _run_code(self): if self.save(): self.container.show() self.containerIsVisible = True editor = self._central.obtain_editor() ext = self.get_file_extension(editor.path) if ext == 'html': height = self.height() / 3 self.splitterCentral.setSizes([height, height * 2]) self.container.render_web_page(editor.path) elif ext == 'py': height = self.height() / 3 self.splitterCentral.setSizes([height * 2, height]) self.container.run_application(editor.path) else: self.execute_file(editor.path, ext) def _run_program(self, actual=None): self.container.show() self.containerIsVisible = True if actual is None: actual = self._properties._treeProjects.actualProject if actual is None: return mainFile = actual.mainFile if mainFile == '': self._properties._treeProjects.open_project_properties() self.containerIsVisible = False self.container.hide() return path = manage_files.create_abs_path(actual.path, mainFile) self._central.save_project_files(actual.path) lang = actual.lang() type_ = actual.projectType if lang == 'html': height = self.height() / 3 self.splitterCentral.setSizes([height, height * 2]) self.container.render_web_page(path) elif lang == 'py': height = self.height() / 3 self.splitterCentral.setSizes([height * 2, height]) self.container.run_application(path) else: self.execute_program(path, lang, type_) def _stop_program(self): self.container.kill_application() def _hide_all(self): if self._properties.isVisible(): self._properties.hide() self.container.hide() self._parent._toolbar.hide() else: if self.containerIsVisible: self.container.show() self._properties.show() self._parent._toolbar.show() def show_start_page(self): startPage = Browser(resources.start_page_url) self.add_tab(startPage, 'Start Page') def show_report_bugs(self): bugsPage = Browser(resources.bugs_page) self.add_tab(bugsPage, 'Report Bugs!') def _show_python_doc(self): process = runner.start_pydoc() docPage = Browser(process[1], process[0]) self.add_tab(docPage, 'Python Documentation') def new_editor(self, lang='py'): if not self._reloading: editor = factory_editor(lang, self._central.actual_tab()) self.add_tab(editor, 'New Document') def add_tab(self, component, title): self._central.actual_tab().add_tab(component, title) def split_tab(self, option): if option: self._central.show_split(Qt.Horizontal) else: self._central.show_split(Qt.Vertical) def new_project(self): project = WizardNewProject(self) project.show() def show_preferences(self): prefs = PreferencesWindow(self) prefs.show() def open_document(self, fileName, project=None): try: if not self._central.actual_tab().is_open(fileName): self._central.actual_tab().notOpening = False editor = factory_editor(fileName, self._central.actual_tab(), project) content = self.read_file_content(fileName) editor.setPlainText(content) editor.path = fileName editor.ask_if_externally_modified = True #self.add_tab(editor, self.get_file_name(fileName)) if not editor.has_write_permission(): fileName += ' (Read-Only)' self.add_tab(editor, self.get_file_name(fileName)) self.change_window_title(fileName) else: self._central.actual_tab().move_to_open(fileName) except Exception, reason: print reason QMessageBox.information(self, 'Incorrect File', 'The file couldn\'t be open') self._central.actual_tab().notOpening = True
class MainWindow(QWidget, MainWindowGeneric): def __init__(self, parent): QWidget.__init__(self) MainWindowGeneric.__init__(self) self._parent = parent self.settings = QSettings("NINJA-IDE", "Kunai") self.settings.beginGroup("Preferences") self.settings.beginGroup("Interface") self._vbox = QVBoxLayout(self) # Splitters self.splitterMain = QSplitter() self.splitterCentral = QSplitter(Qt.Vertical) # Properties Panel self._properties = PropertiesWidget(self) # Central self._central = CentralWidget(self) self.show_start_page() self.splitterCentral.insertWidget(self.settings.value("central_tab_position", 0).toInt()[0], self._central) # Display Container self.container = DisplayContainer(self) self._hide_container() self.splitterCentral.insertWidget(self.settings.value("container_tab_position", 1).toInt()[0], self.container) height = [(self.height() / 3) * 2, self.height() / 3] self.splitterCentral.setSizes( [ height[self.settings.value("central_tab_position", 0).toInt()[0]], height[self.settings.value("container_tab_position", 1).toInt()[0]], ] ) # Size Central Splitter self.splitterMain.insertWidget(self.settings.value("main_tab_position", 0).toInt()[0], self.splitterCentral) self.splitterMain.insertWidget(self.settings.value("properties_tab_position", 1).toInt()[0], self._properties) width = [(self.width() / 6) * 5, self.width() / 6] self.splitterMain.setSizes( [ width[self.settings.value("main_tab_position", 0).toInt()[0]], width[self.settings.value("properties_tab_position", 1).toInt()[0]], ] ) self._vbox.addWidget(self.splitterMain) self.settings.endGroup() # End General Preferences self.settings.endGroup() # flag for reload_file self._reloading = False # Shortcuts shortCloseTab = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_W), self) shortNew = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_N), self) shortNewProject = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_J), self) shortOpen = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_O), self) shortOpenProject = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_P), self) shortSave = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), self) shortSaveAll = QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S), self) shortRedo = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Y), self) shortComment = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_D), self) shortHorizontalLine = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_R), self) shortIndentLess = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_Tab), self) shortHideContainer = QShortcut(QKeySequence(Qt.Key_F4), self) shortHideEditor = QShortcut(QKeySequence(Qt.Key_F3), self) shortHideExplorer = QShortcut(QKeySequence(Qt.Key_F2), self) shortRunFile = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F6), self) shortRunProgram = QShortcut(QKeySequence(Qt.Key_F6), self) shortHideAll = QShortcut(QKeySequence(Qt.Key_F11), self) shortFind = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self) shortFindReplace = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_H), self) shortHelp = QShortcut(QKeySequence(Qt.Key_F1), self) shortSplitHorizontal = QShortcut(QKeySequence(Qt.Key_F10), self) shortSplitVertical = QShortcut(QKeySequence(Qt.Key_F9), self) shortReloadFile = QShortcut(QKeySequence(Qt.Key_F5), self) # Signal -> Slot self.connect(shortCloseTab, SIGNAL("activated()"), self.close_actual_tab) self.connect(shortNew, SIGNAL("activated()"), self.new_editor) self.connect(shortNewProject, SIGNAL("activated()"), self.new_project) self.connect(shortOpen, SIGNAL("activated()"), self.open_file) self.connect(shortOpenProject, SIGNAL("activated()"), self.open_project_folder) self.connect(shortSave, SIGNAL("activated()"), self.save) self.connect(shortSaveAll, SIGNAL("activated()"), self.save_project) self.connect(shortComment, SIGNAL("activated()"), lambda: self._central.obtain_editor().comment()) self.connect(shortIndentLess, SIGNAL("activated()"), lambda: self._central.obtain_editor().indent_less()) self.connect( shortHorizontalLine, SIGNAL("activated()"), lambda: self._central.obtain_editor().insert_horizontal_line() ) self.connect(shortRedo, SIGNAL("activated()"), lambda: self._central.obtain_editor().redo()) self.connect(shortHideContainer, SIGNAL("activated()"), self._hide_container) self.connect(shortHideEditor, SIGNAL("activated()"), self._hide_editor) self.connect(shortHideExplorer, SIGNAL("activated()"), self._hide_explorer) self.connect(shortRunFile, SIGNAL("activated()"), self._run_code) self.connect(shortRunProgram, SIGNAL("activated()"), self._run_program) self.connect(shortHideAll, SIGNAL("activated()"), self._hide_all) self.connect(shortFind, SIGNAL("activated()"), self._open_find) self.connect(shortFindReplace, SIGNAL("activated()"), self._open_find_replace) self.connect(shortHelp, SIGNAL("activated()"), self._show_python_doc) self.connect(shortSplitHorizontal, SIGNAL("activated()"), lambda: self.split_tab(True)) self.connect(shortSplitVertical, SIGNAL("activated()"), lambda: self.split_tab(False)) self.connect(shortReloadFile, SIGNAL("activated()"), lambda: self.reload_file()) def change_window_title(self, title): self._parent.setWindowTitle("NINJA-IDE - " + title) def _open_find(self): if not self._parent._status.isVisible(): self._parent._status.show() self._parent._status.focus_find(self._central.obtain_editor()) def _open_find_replace(self): if not self._parent._status.isVisible(): self._parent._status.show() self._parent._status.replace_visibility(True) self._parent._status.focus_find(self._central.obtain_editor()) def _hide_container(self): if self.containerIsVisible: self.container.hide() self.containerIsVisible = False self._central.obtain_editor().setFocus() else: self.container.show() self.containerIsVisible = True self.container.gain_focus() def _hide_editor(self): if self._central.isVisible(): self._central.hide() else: self._central.show() def _hide_explorer(self): if self._properties.isVisible(): self._properties.hide() else: self._properties.show() def _splitter_central_orientation(self): if self.splitterCentral.orientation() == Qt.Horizontal: self.splitterCentral.setOrientation(Qt.Vertical) else: self.splitterCentral.setOrientation(Qt.Horizontal) def get_splitter_central_orientation(self): return self.splitterCentral.orientation() def _splitter_main_orientation(self): if self.splitterMain.orientation() == Qt.Horizontal: self.splitterMain.setOrientation(Qt.Vertical) else: self.splitterMain.setOrientation(Qt.Horizontal) def get_splitter_main_orientation(self): return self.splitterMain.orientation() def _splitter_main_rotate(self): w = self.splitterMain.widget(0) w1 = self.splitterMain.widget(1) self.splitterMain.insertWidget(0, w1) self.splitterMain.insertWidget(1, w) def get_splitter_main_position(self): w = self.splitterMain.widget(0) return w.__class__ def _splitter_central_rotate(self): w = self.splitterCentral.widget(0) w1 = self.splitterCentral.widget(1) self.splitterCentral.insertWidget(0, w1) self.splitterCentral.insertWidget(1, w) def get_splitter_central_position(self): w = self.splitterCentral.widget(0) return w.__class__ def get_splitter_position_0(self): return type(self.splitterCentral.widget(0)) def get_splitter_main_position_0(self): return type(self.splitterMain.widget(0)) def reload_panels_position(self): self.settings = QSettings("NINJA-IDE", "Kunai") self.settings.beginGroup("Preferences") self.settings.beginGroup("Interface") # first with the splitterCentral c = self.splitterCentral.widget(0) c1 = self.splitterCentral.widget(1) if type(c) == CentralWidget: self.splitterCentral.insertWidget(self.settings.value("central_tab_position", 0).toInt()[0], c) self.splitterCentral.insertWidget(self.settings.value("container_tab_position", 1).toInt()[0], c1) else: self.splitterCentral.insertWidget(self.settings.value("central_tab_position", 0).toInt()[0], c1) self.splitterCentral.insertWidget(self.settings.value("container_tab_position", 1).toInt()[0], c) # now with the splitterMain m = self.splitterMain.widget(0) m1 = self.splitterMain.widget(1) if type(m) == QSplitter: self.splitterMain.insertWidget(self.settings.value("central_tab_position", 0).toInt()[0], m) self.splitterMain.insertWidget(self.settings.value("container_tab_position", 1).toInt()[0], m1) else: self.splitterMain.insertWidget(self.settings.value("central_tab_position", 0).toInt()[0], m1) self.splitterMain.insertWidget(self.settings.value("container_tab_position", 1).toInt()[0], m) def get_open_projects(self): return self._properties._treeProjects.get_open_projects() def _run_code(self): if self.save(): self.container.show() self.containerIsVisible = True editor = self._central.obtain_editor() ext = self.get_file_extension(editor.path) if ext == "html": height = self.height() / 3 self.splitterCentral.setSizes([height, height * 2]) self.container.render_web_page(editor.path) elif ext == "py": height = self.height() / 3 self.splitterCentral.setSizes([height * 2, height]) self.container.run_application(editor.path) else: self.execute_file(editor.path, ext) def _run_program(self, actual=None): self.container.show() self.containerIsVisible = True if actual is None: actual = self._properties._treeProjects.actualProject if actual is None: return mainFile = actual.mainFile if mainFile == "": self._properties._treeProjects.open_project_properties() self.containerIsVisible = False self.container.hide() return path = manage_files.create_abs_path(actual.path, mainFile) self._central.save_project_files(actual.path) lang = actual.lang() type_ = actual.projectType if lang == "html": height = self.height() / 3 self.splitterCentral.setSizes([height, height * 2]) self.container.render_web_page(path) elif lang == "py": height = self.height() / 3 self.splitterCentral.setSizes([height * 2, height]) self.container.run_application(path) else: self.execute_program(path, lang, type_) def _stop_program(self): self.container.kill_application() def _hide_all(self): if self._properties.isVisible(): self._properties.hide() self.container.hide() self._parent._toolbar.hide() else: if self.containerIsVisible: self.container.show() self._properties.show() self._parent._toolbar.show() def show_start_page(self): startPage = Browser(resources.start_page_url) self.add_tab(startPage, "Start Page") def show_report_bugs(self): bugsPage = Browser(resources.bugs_page) self.add_tab(bugsPage, "Report Bugs!") def _show_python_doc(self): process = runner.start_pydoc() docPage = Browser(process[1], process[0]) self.add_tab(docPage, "Python Documentation") def new_editor(self, lang="py"): if not self._reloading: editor = factory_editor(lang, self._central.actual_tab()) self.add_tab(editor, "New Document") def add_tab(self, component, title): self._central.actual_tab().add_tab(component, title) def split_tab(self, option): if option: self._central.show_split(Qt.Horizontal) else: self._central.show_split(Qt.Vertical) def new_project(self): project = WizardNewProject(self) project.show() def show_preferences(self): prefs = PreferencesWindow(self) prefs.show() def open_document(self, fileName, project=None): try: if not self._central.actual_tab().is_open(fileName): self._central.actual_tab().notOpening = False editor = factory_editor(fileName, self._central.actual_tab(), project) content = self.read_file_content(fileName) editor.setPlainText(content) editor.path = fileName editor.ask_if_externally_modified = True # self.add_tab(editor, self.get_file_name(fileName)) if not editor.has_write_permission(): fileName += " (Read-Only)" self.add_tab(editor, self.get_file_name(fileName)) self.change_window_title(fileName) else: self._central.actual_tab().move_to_open(fileName) except Exception, reason: print reason QMessageBox.information(self, "Incorrect File", "The file couldn't be open") self._central.actual_tab().notOpening = True
class MainWindow(QWidget, MainWindowGeneric): def __init__(self, parent): QWidget.__init__(self) MainWindowGeneric.__init__(self) self._parent = parent self._vbox = QVBoxLayout(self) #Splitters self.splitterMain = QSplitter() self.splitterCentral = QSplitter(Qt.Vertical) #Properties Panel self._properties = PropertiesWidget(self) #Central self._central = CentralWidget(self) self.show_start_page() self.splitterCentral.addWidget(self._central) #Display Container self.container = DisplayContainer(self) self._hide_container() self.splitterCentral.addWidget(self.container) height = [(self.height() / 3) * 2, self.height() / 3] self.splitterCentral.setSizes([height[0], height[1]]) #Size Central Splitter self.splitterMain.addWidget(self.splitterCentral) self.splitterMain.addWidget(self._properties) width = [(self.width() / 6) * 5, self.width() / 6] self.splitterMain.setSizes([width[0], width[1]]) self._vbox.addWidget(self.splitterMain) #flag for reload_file self._reloading = False #Shortcuts shortCloseTab = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_W), self) shortNew = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_N), self) shortNewProject = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_J), self) shortOpen = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_O), self) shortOpenProject = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_P), self) shortSave = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), self) shortSaveAll = QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S), self) shortPrint = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_I), self) shortRedo = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Y), self) shortComment = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_D), self) shortHorizontalLine = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_R), self) shortTitleComment = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_T), self) shortIndentLess = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_Tab), self) shortHideContainer = QShortcut(QKeySequence(Qt.Key_F4), self) shortHideEditor = QShortcut(QKeySequence(Qt.Key_F3), self) shortHideExplorer = QShortcut(QKeySequence(Qt.Key_F2), self) shortRunFile = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F6), self) shortRunProgram = QShortcut(QKeySequence(Qt.Key_F6), self) shortHideAll = QShortcut(QKeySequence(Qt.Key_F11), self) shortFind = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self) shortFindReplace = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_H), self) shortHelp = QShortcut(QKeySequence(Qt.Key_F1), self) shortSplitHorizontal = QShortcut(QKeySequence(Qt.Key_F10), self) shortSplitVertical = QShortcut(QKeySequence(Qt.Key_F9), self) shortFollowMode = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F10), self) shortReloadFile = QShortcut(QKeySequence(Qt.Key_F5), self) shortShowProjectsTree = QShortcut(QKeySequence(Qt.ALT + Qt.Key_1), self) shortShowSymbolsTree = QShortcut(QKeySequence(Qt.ALT + Qt.Key_2), self) #Signal -> Slot self.connect(shortCloseTab, SIGNAL("activated()"), self.close_actual_tab) self.connect(shortNew, SIGNAL("activated()"), self.new_editor) self.connect(shortNewProject, SIGNAL("activated()"), self.new_project) self.connect(shortOpen, SIGNAL("activated()"), self.open_file) self.connect(shortOpenProject, SIGNAL("activated()"), self.open_project_folder) self.connect(shortSave, SIGNAL("activated()"), self.save) self.connect(shortSaveAll, SIGNAL("activated()"), self.save_project) self.connect(shortPrint, SIGNAL("activated()"), self._print_file) self.connect(shortComment, SIGNAL("activated()"), lambda: self._central.obtain_editor().comment()) self.connect(shortIndentLess, SIGNAL("activated()"), lambda: self._central.obtain_editor().indent_less()) self.connect(shortHorizontalLine, SIGNAL("activated()"), lambda: self._central.obtain_editor().insert_horizontal_line()) self.connect(shortTitleComment, SIGNAL("activated()"), lambda: self._central.obtain_editor().insert_title_comment()) self.connect(shortRedo, SIGNAL("activated()"), lambda: self._central.obtain_editor().redo()) self.connect(shortHideContainer, SIGNAL("activated()"), self._hide_container) self.connect(shortHideEditor, SIGNAL("activated()"), self._hide_editor) self.connect(shortHideExplorer, SIGNAL("activated()"), self._hide_explorer) self.connect(shortRunFile, SIGNAL("activated()"), self._run_code) self.connect(shortRunProgram, SIGNAL("activated()"), self._run_program) self.connect(shortHideAll, SIGNAL("activated()"), self._hide_all) self.connect(shortFind, SIGNAL("activated()"), self._open_find) self.connect(shortFindReplace, SIGNAL("activated()"), self._open_find_replace) self.connect(shortHelp, SIGNAL("activated()"), self._show_python_doc) self.connect(shortSplitHorizontal, SIGNAL("activated()"), lambda: self.split_tab(True)) self.connect(shortSplitVertical, SIGNAL("activated()"), lambda: self.split_tab(False)) self.connect(shortFollowMode, SIGNAL("activated()"), self._view_follow_mode) self.connect(shortReloadFile, SIGNAL("activated()"), lambda: self.reload_file()) self.connect(shortShowProjectsTree, SIGNAL("activated()"), self.show_projects_tree) self.connect(shortShowSymbolsTree, SIGNAL("activated()"), self.show_symbols_tree) def change_window_title(self, title): self._parent.setWindowTitle('NINJA-IDE - ' + title) def _open_find(self): if not self._parent._status.isVisible(): self._parent._status.show() self._parent._status.focus_find(self._central.obtain_editor()) def _open_find_replace(self): if not self._parent._status.isVisible(): self._parent._status.show() self._parent._status.replace_visibility(True) self._parent._status.focus_find(self._central.obtain_editor()) def _print_file(self): self.printer = QPrinter(QPrinter.HighResolution) self.printer.setPageSize(QPrinter.A4) if self._central.obtain_editor().path: fileName = manage_files.get_basename(self._central.obtain_editor().path) fileName = fileName[:fileName.rfind('.')] + '.pdf' else: fileName = 'newDocument.pdf' self.printer.setOutputFileName(fileName) dialog = QPrintDialog(self.printer, self) if dialog.exec_(): self.printer.setDocName(manage_files.get_basename(self._central.obtain_editor().path)) self._central.obtain_editor().document().print_(self.printer) def _hide_container(self): if self.containerIsVisible: self.container.hide() self.containerIsVisible = False self._central.obtain_editor().setFocus() else: self.container.show() self.containerIsVisible = True self.container.gain_focus() def _hide_editor(self): if self._central.isVisible(): self._central.hide() else: self._central.show() def _hide_explorer(self): if self._properties.isVisible(): self._properties.hide() else: self._properties.show() def _splitter_central_orientation(self): if self.splitterCentral.orientation() == Qt.Horizontal: self.splitterCentral.setOrientation(Qt.Vertical) else: self.splitterCentral.setOrientation(Qt.Horizontal) def get_splitter_central_orientation(self): return self.splitterCentral.orientation() def _splitter_main_orientation(self): if self.splitterMain.orientation() == Qt.Horizontal: self.splitterMain.setOrientation(Qt.Vertical) else: self.splitterMain.setOrientation(Qt.Horizontal) def get_splitter_main_orientation(self): return self.splitterMain.orientation() def _splitter_main_rotate(self): w = self.splitterMain.widget(0) w1 = self.splitterMain.widget(1) if type(w) is PropertiesWidget: w.setTabPosition(QTabWidget.East) else: w1.setTabPosition(QTabWidget.West) self.splitterMain.insertWidget(0, w1) self.splitterMain.insertWidget(1, w) def get_splitter_main_position(self): w = self.splitterMain.widget(0) return w.__class__ def _splitter_central_rotate(self): w = self.splitterCentral.widget(0) w1 = self.splitterCentral.widget(1) self.splitterCentral.insertWidget(0, w1) self.splitterCentral.insertWidget(1, w) def get_splitter_central_position(self): w = self.splitterCentral.widget(0) return w.__class__ def get_splitter_position_0(self): return type(self.splitterCentral.widget(0)) def get_splitter_main_position_0(self): return type(self.splitterMain.widget(0)) def reload_panels_position(self): self.settings = QSettings('NINJA-IDE', 'Kunai') self.settings.beginGroup('Preferences') self.settings.beginGroup('Interface') #first with the splitterCentral c = self.splitterCentral.widget(0) c1 = self.splitterCentral.widget(1) if (type(c) == CentralWidget): self.splitterCentral.insertWidget(self.settings.value('central_tab_position', 0).toInt()[0], c) self.splitterCentral.insertWidget(self.settings.value('container_tab_position', 1).toInt()[0], c1) else: self.splitterCentral.insertWidget(self.settings.value('central_tab_position', 0).toInt()[0], c1) self.splitterCentral.insertWidget(self.settings.value('container_tab_position', 1).toInt()[0], c) #now with the splitterMain m = self.splitterMain.widget(0) m1 = self.splitterMain.widget(1) if (type(m) == QSplitter): self.splitterMain.insertWidget(self.settings.value('central_tab_position', 0).toInt()[0], m) self.splitterMain.insertWidget(self.settings.value('container_tab_position', 1).toInt()[0], m1) else: self.splitterMain.insertWidget(self.settings.value('central_tab_position', 0).toInt()[0], m1) self.splitterMain.insertWidget(self.settings.value('container_tab_position', 1).toInt()[0], m) def get_open_projects(self): return self._properties._treeProjects.get_open_projects() def _run_code(self): if self.save(): self.container.show() self.containerIsVisible = True editor = self._central.obtain_editor() ext = self.get_file_extension(editor.path) if ext == 'html': height = self.height() / 3 self.splitterCentral.setSizes([height, height * 2]) self.container.render_web_page(editor.path) elif ext == 'py': height = self.height() / 3 self.splitterCentral.setSizes([height * 2, height]) self.container.run_application(editor.path) else: self.execute_file(editor.path, ext) def _run_program(self, actual=None): self.container.show() self.containerIsVisible = True if actual is None: actual = self._properties._treeProjects.actualProject if actual is None: return mainFile = actual.mainFile if mainFile == '': self._properties._treeProjects.open_project_properties() self.containerIsVisible = False self.container.hide() return path = manage_files.create_abs_path(actual.path, mainFile) self._central.save_project_files(actual.path) lang = actual.lang() type_ = actual.projectType if lang == 'html': height = self.height() / 3 self.splitterCentral.setSizes([height, height * 2]) self.container.render_web_page(path) elif lang == 'py': height = self.height() / 3 self.splitterCentral.setSizes([height * 2, height]) self.container.run_application(path, actual.pythonPath) else: self.execute_program(path, lang, type_) def _stop_program(self): self.container.kill_application() def _hide_all(self): if self._properties.isVisible(): self._properties.hide() self.container.hide() self._parent._toolbar.hide() else: if self.containerIsVisible: self.container.show() self._properties.show() self._parent._toolbar.show() def show_start_page(self): startPage = Browser(resources.start_page_url, None, self) self.add_tab(startPage, 'Start Page') def show_report_bugs(self): bugsPage = Browser(resources.bugs_page) self.add_tab(bugsPage, 'Report Bugs!') def show_plugins_doc(self): bugsPage = Browser(resources.plugins_doc) self.add_tab(bugsPage, 'How to Write NINJA-IDE plugins') def _show_python_doc(self): process = runner.start_pydoc() docPage = Browser(process[1], process[0]) self.add_tab(docPage, 'Python Documentation') def new_editor(self, lang='py'): if not self._reloading: editor = factory_editor(lang, self._central.actual_tab()) self.add_tab(editor, 'New Document') def add_tab(self, component, title): self._central.actual_tab().add_tab(component, title) def split_tab(self, option): if option: self._central.show_split(Qt.Horizontal) else: self._central.show_split(Qt.Vertical) def _view_follow_mode(self): self._central._show_follow_mode() def new_project(self): project = WizardNewProject(self) project.show() def show_preferences(self): prefs = PreferencesWindow(self) prefs.show() def open_document(self, fileName, project=None): try: if not self._central.actual_tab().is_open(fileName): self._central.actual_tab().notOpening = False editor = factory_editor(fileName, self._central.actual_tab(), project) content = self.read_file_content(fileName) editor.setPlainText(content) editor.path = fileName editor.ask_if_externally_modified = True #self.add_tab(editor, self.get_file_name(fileName)) if not editor.has_write_permission(): fileName += ' (Read-Only)' self.add_tab(editor, self.get_file_name(fileName)) self.change_window_title(fileName) editor.find_errors_and_check_style() else: self._central.actual_tab().move_to_open(fileName) except Exception, reason: print reason QMessageBox.information(self, 'Incorrect File', 'The file couldn\'t be open') self._central.actual_tab().notOpening = True