class MainWindow(QMainWindow): """ We are modifying some of the attributes of a QMainWindow class Create an instance of CentralWidget class Variables: centralWidget <CentralWidget> Methods: Inherited from QMainWindow: setCentralWidget setWindowTitle """ def __init__(self): super().__init__() self.centralWidget = CentralWidget() newPalette = self.centralWidget.palette() newPalette.setColor(self.centralWidget.backgroundRole(), QColor(105, 105, 105)) self.centralWidget.setAutoFillBackground(True) self.centralWidget.setPalette(newPalette) self.centralWidget.setFixedWidth(325) self.centralWidget.setFixedHeight(500) self.setCentralWidget(self.centralWidget) self.setWindowTitle("The Game") """
def __init__(self): super().__init__() self.centralWidget = CentralWidget() self.centralWidget.setObjectName("centralWidget") self.centralWidget.setStyleSheet( "#centralWidget {background-color: blue ; color : #f8f8f8}") self.setCentralWidget(self.centralWidget) self.setWindowTitle("Character Select") """
def __init__(self): super().__init__() self.centralWidget = CentralWidget() newPalette = self.centralWidget.palette() newPalette.setColor(self.centralWidget.backgroundRole(), QColor(105, 105, 105)) self.centralWidget.setAutoFillBackground(True) self.centralWidget.setPalette(newPalette) self.centralWidget.setFixedWidth(325) self.centralWidget.setFixedHeight(500) self.setCentralWidget(self.centralWidget) self.setWindowTitle("The Game") """
def __init__(self): super().__init__() self.centralWidget = CentralWidget() newPalette = self.centralWidget.palette() newPalette.setColor(self.centralWidget.backgroundRole(), QColor(0, 105, 105)) self.centralWidget.setAutoFillBackground(True) self.centralWidget.setPalette(newPalette) self.centralWidget.setFixedWidth(355) self.centralWidget.setFixedHeight(580) # self.setGeometry(self.left, self.top, self.width, self.height) self.setCentralWidget(self.centralWidget) self.setWindowTitle("The Game") self.mainMenuBar = self.menuBar() fileMenu = self.mainMenuBar.addMenu('File') characterMenu = self.mainMenuBar.addMenu('Character') helpMenu = self.mainMenuBar.addMenu('Help') saveAction = QAction('Save', self) exitAction = QAction('Exit', self) exitAction.triggered.connect(qApp.quit) characterAction = QAction('Character Info', self) inventoryAction = QAction('Inventory', self) roomDescAction = QAction('Description', self) actionAvailAction = QAction('Actions', self) fileMenu.addAction(saveAction) fileMenu.addAction(exitAction) characterMenu.addAction(characterAction) characterMenu.addAction(inventoryAction) helpMenu.addAction(roomDescAction) helpMenu.addAction(actionAvailAction) self.mainMenuBar.setVisible(False) self.centralWidget.procShowMenu.connect(self.showMenuBar)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # --------------------------------------------------------------------- # Setup Window # --------------------------------------------------------------------- self.setWindowTitle("Developer Dashboard") self.setWindowIcon(QIcon('logo.png')) # --------------------------------------------------------------------- # Menus/ Widgets # --------------------------------------------------------------------- # Create an instance of an Actions object. This contains all the QActions # to be used in this application. self.actions = Actions() # Create a MainWidget object. Note the Actions are being passed in. self.mainWidget = CentralWidget(self.actions) # Set the central widget self.setCentralWidget(self.mainWidget) # Create an application menu (this will be a sub-menu) self.dashboardMenu = QMenu("dashboard") # Add actions to the application menu self.dashboardMenu.addActions(self.actions.getDashboardActions()) # Create an options menu self.optionsMenu = QMenu("Options") # Add the dashboard menu to the options menu self.optionsMenu.addMenu(self.dashboardMenu) # Add actions to the options menu self.optionsMenu.addActions(self.actions.getOptionsActions()) # Add the options menu to the menu bar self.menuBar().addMenu(self.optionsMenu) # Create a tool bar self.toolBar = QToolBar() # Add actions to the tool bar self.toolBar.addActions(self.actions.getToolBarActions()) # Add the tool bar to this MainWindow self.addToolBar(self.toolBar) # Connect the signals self.actions.exitAction.triggered.connect(self.quit) self.mainWidget.quitApplication.connect(self.quit) self.actions.clearAction.triggered.connect(self.mainWidget.clearForm) self.actions.resetAction.triggered.connect(self.mainWidget.resetScores) self.actions.aboutAction.triggered.connect(self.mainWidget.aboutInfo)
class MainWindow(QMainWindow): """ We are modifying some of the attributes of a QMainWindow class Create an instance of CentralWidget class Variables: centralWidget <CentralWidget> Methods: Inherited from QMainWindow: setCentralWidget setWindowTitle """ def __init__(self): super().__init__() self.centralWidget = CentralWidget() self.centralWidget.setObjectName("centralWidget") self.centralWidget.setStyleSheet( "#centralWidget {background-color: blue ; color : #f8f8f8}") self.setCentralWidget(self.centralWidget) self.setWindowTitle("Character Select") """
def __init__(self, reactor): super().__init__() self.setFont(QFont("Calibri", 10)) self.setWindowTitle("Movie Scrapper") import configparser self.config = configparser.ConfigParser() self.config.read('scrapper.ini') self.initConfig() self.setCentralWidget(CentralWidget(self.config)) self.createToolbar() self.createMenu() self.setGeometry(self.left, self.top, self.width, self.height) self.reactor = reactor
def __init__(self): super().__init__() ###################################################################################################### # Change settings for central widget ###################################################################################################### self.centralWidget = CentralWidget() newPalette = self.centralWidget.palette() newPalette.setColor(self.centralWidget.backgroundRole(), QColor(0, 105, 105)) self.centralWidget.setAutoFillBackground( True ) self.centralWidget.setPalette(newPalette) self.centralWidget.setFixedWidth(580) self.centralWidget.setFixedHeight(600) self.setCentralWidget(self.centralWidget) self.setWindowTitle("The Game") ###################################################################################################### # Create menu bar ###################################################################################################### self.mainMenuBar = self.menuBar() fileMenu = self.mainMenuBar.addMenu('File') characterMenu = self.mainMenuBar.addMenu('Character') helpMenu = self.mainMenuBar.addMenu('Help') ###################################################################################################### # Create and set actions ###################################################################################################### openWebAction = QAction('Open Website', self) openWebAction.triggered.connect(self.centralWidget.launchWeb) uploadAction = QAction('Upload Game To Website', self) uploadAction.triggered.connect(self.centralWidget.uploadGameInfo) exitAction = QAction('Exit', self) exitAction.triggered.connect(qApp.quit) characterAction = QAction('Character Info', self) characterAction.triggered.connect(self.centralWidget.showCharacterInfo) inventoryAction = QAction('Inventory', self) inventoryAction.triggered.connect(self.centralWidget.showInventoryInfo) equipmentAction = QAction('Equipment', self) equipmentAction.triggered.connect(self.centralWidget.changeEquipmentGeneral) roomDescAction = QAction('Description', self) roomDescAction.triggered.connect(self.centralWidget.showRoomDesc) actionAvailAction = QAction('Actions', self) actionAvailAction.triggered.connect(self.centralWidget.showAvailActions) characterStuckAction = QAction('Stuck? Click here', self) characterStuckAction.triggered.connect(self.centralWidget.unstuckCharacter) helpMeAction = QAction('Helpful Info', self) helpMeAction.triggered.connect(self.centralWidget.showHelpfulInfo) ###################################################################################################### # Pair actions with menubar ###################################################################################################### fileMenu.addAction(openWebAction) fileMenu.addAction(uploadAction) fileMenu.addAction(exitAction) characterMenu.addAction(characterAction) characterMenu.addAction(inventoryAction) characterMenu.addAction(equipmentAction) helpMenu.addAction(roomDescAction) helpMenu.addAction(actionAvailAction) helpMenu.addAction(characterStuckAction) helpMenu.addAction(helpMeAction) ###################################################################################################### # Show menu visibility ###################################################################################################### self.mainMenuBar.setVisible(False) self.centralWidget.procShowMenu.connect(self.showMenuBar)
def start(self): ok = LoadProteinGroupsDialog.get_file_info(self, self.analysis) if ok: central_widget = CentralWidget(self.analysis, self) self.setCentralWidget(central_widget)
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())
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(QMainWindow): """ MainWindow class - derived from QMainWindow INPUTS: None. OUTPUTS: Holds the menu bar for the GUI as well as the CentralWidget. """ def __init__(self): """Initialize the main window. Input: None Output: Titles the window, creates instance of CentralWidget, sets up the menu bar menus and their actions. """ # Initialize the parent widget super().__init__() # Name the window self.setWindowTitle("Facial Recognition App") # Create a main widget object (the central widget) self.mainWidget = CentralWidget() # create the menu bar and its two menus: file and edit self.menuBar = QMenuBar() self.file = self.menuBar.addMenu("File") self.edit = self.menuBar.addMenu("Edit") # Add action for File->Exit self.file_exit = self.file.addAction("Exit") self.file_exit.triggered.connect(self.closeApp) # create menu bar action for toggling facial recognition self.file_recognize_faces = QAction("Facial Recognition", self.menuBar, checkable=True) self.file.addAction(self.file_recognize_faces) self.file_recognize_faces.triggered.connect( self.changeFacialRecognitionState) # Add actions for Edit # create menu bar action for subscribing to SMS alerts self.edit_subscribeAlerts = self.edit.addAction( "Subscribe to Alerts...") self.edit_subscribeAlerts.triggered.connect(self.subscribeToAlerts) # create menu bar action for adding a new face self.edit_addFace = self.edit.addAction("Add a New Face...") self.edit_addFace.triggered.connect(self.addNewFace) # create dialog widget to allow users to capturing face images (for adding a new face) self.captureFaceImagesDialog = CaptureFaceImagesDialog() # connect the dialog's capture signal ot the Engine's recognizeAndRecordCurrentFrame method self.captureFaceImagesDialog.capture.connect( self.mainWidget.engine.recognizeAndRecordCurrentFrame) # menu bar action for deleting a specific face self.edit_deleteFace = self.edit.addAction("Delete a Face...") self.edit_deleteFace.triggered.connect(self.deleteFace) # menu bar action for deleting all known faces from the application self.edit_deleteAllFaces = self.edit.addAction("Delete All Faces") self.edit_deleteAllFaces.triggered.connect(self.deleteAllFaces) # set the menu bar self.setMenuBar(self.menuBar) # Set the main widget object as the central widget of the main window self.setCentralWidget(self.mainWidget) def closeApp(self): """ MainWindow - closeApp INPUTS: None. OUTPUTS: Closes the app, same as clicking the x. """ self.close() def changeFacialRecognitionState(self): """ MainWindow - changeFacialRecognitionState :return: NOTES: depending on whether or not the File->Facial Recognition is toggled on or off, set the Engine's facial recognition state boolean. """ # determine if option is toggled on or off if self.file_recognize_faces.isChecked(): self.mainWidget.engine.setFacialRecognitionState(True) else: self.mainWidget.engine.setFacialRecognitionState(False) def subscribeToAlerts(self): """ MainWindow - subscribeToAlerts :return: NOTES: creates the AddSubscriberDialog, waits for acceptance and then call's the Engine's addObserver method. """ # create the dialog getPhoneNumberDialog = AddSubscriberDialog() # exec the dialog and wait for acceptance if (getPhoneNumberDialog.exec() == getPhoneNumberDialog.Accepted): # get the inputted phone number once accepted added_phone_number = getPhoneNumberDialog.number # Notify the user of success QMessageBox.information( self, "Number Added", "Alerts will now be sent to {}".format(added_phone_number)) # Add number to the AlertObserver (called from engine) self.mainWidget.engine.addObserver(added_phone_number) def addNewFace(self): """ MainWindow - addNewFace :return: NOTES: This method creates a dialog prompting the user to enter a new face name, gets the name, and then creates another dialog allowing the user to capture images of the new face to add. """ # make sure application is connected to the Pi so images can be captured if not self.mainWidget.isConnectedToPi(): # notify the user that they must connect to the Pi first QMessageBox.information( self, "Not Connected To Pi", "You must connect to the Pi before adding a new face.") else: # create dialog for getting new face name getNameDialog = GetFaceNameDialog("Enter a Name for the New Face", "Add") # exec the dialog and wait for acceptance if (getNameDialog.exec() == getNameDialog.Accepted): # get the inputted name from the dialog new_face_name = getNameDialog.name # make sure the name doesn't already exist in the database if self.mainWidget.engine.checkNameExistenceInDb( new_face_name): # warn the user that the given name already exists QMessageBox.warning( self, "Name Already Exists", "This face name is already present in the database.") else: # disable facial recognition so the user can see the face better when capturing images self.file_recognize_faces.setChecked(False) self.mainWidget.engine.setFacialRecognitionState(False) self.file_recognize_faces.setEnabled(False) # set the Engine's member for the name of the current face to add self.mainWidget.engine.setCurrentAddFaceName(new_face_name) # logic for capturing images # create the dialog prompting users to take pictures - clicking capture will signal the Engine if (self.captureFaceImagesDialog.exec() == self.captureFaceImagesDialog.Accepted): # print("Done capturing images.") # after dialog is accepted, tell the Engine to add the new face to the database self.mainWidget.engine.addFaceToDb() # re-enable the facial recognition toggle self.file_recognize_faces.setEnabled(True) # if dialog is rejected, reset Engine's add face data and re-enable the facial recognition toggle else: self.mainWidget.engine.resetCurrentAddFaceData() self.file_recognize_faces.setEnabled(True) def deleteFace(self): """ MainWidget - deleteFace :return: NOTES: creates a dialog prompting the user to enter a name for the face to delete, calls the Engine's method to delete a specific face (if it exists in the database). """ # create dialog to get the name of the face to delete getNameDialog = GetFaceNameDialog( "Enter the Name of the Face to Delete", "Delete") # wait for the dialog to be accepted if (getNameDialog.exec() == getNameDialog.Accepted): # get the name from the dialog delete_face_name = getNameDialog.name # make sure the name actually exists in the DB before attempting to delete it if not self.mainWidget.engine.checkNameExistenceInDb( delete_face_name): QMessageBox.warning( self, "Name Does Not Exist", "This face name does not exist in the database.") else: # delete the face and let the user know it was successful self.mainWidget.engine.deleteFaceFromDb(delete_face_name) QMessageBox.information( self, "Face Deleted", "The specified face has been successfully deleted.") def deleteAllFaces(self): """ MainWidget - deleteAllFaces :return: NOTES: prompts user for validation and then clears all face data from the database if they say yes. """ # create the validation message box validation = QMessageBox() # make the user confirm that they want to wipe the database ret = validation.question( self, '', "Are you sure you want to wipe the database?", validation.Yes | validation.No) # delete all faces from the database if user said yes if ret == validation.Yes: # wipe the db self.mainWidget.engine.deleteAllFacesFromDb()
def __init__(self): """Initialize the main window. Input: None Output: Titles the window, creates instance of CentralWidget, sets up the menu bar menus and their actions. """ # Initialize the parent widget super().__init__() # Name the window self.setWindowTitle("Facial Recognition App") # Create a main widget object (the central widget) self.mainWidget = CentralWidget() # create the menu bar and its two menus: file and edit self.menuBar = QMenuBar() self.file = self.menuBar.addMenu("File") self.edit = self.menuBar.addMenu("Edit") # Add action for File->Exit self.file_exit = self.file.addAction("Exit") self.file_exit.triggered.connect(self.closeApp) # create menu bar action for toggling facial recognition self.file_recognize_faces = QAction("Facial Recognition", self.menuBar, checkable=True) self.file.addAction(self.file_recognize_faces) self.file_recognize_faces.triggered.connect( self.changeFacialRecognitionState) # Add actions for Edit # create menu bar action for subscribing to SMS alerts self.edit_subscribeAlerts = self.edit.addAction( "Subscribe to Alerts...") self.edit_subscribeAlerts.triggered.connect(self.subscribeToAlerts) # create menu bar action for adding a new face self.edit_addFace = self.edit.addAction("Add a New Face...") self.edit_addFace.triggered.connect(self.addNewFace) # create dialog widget to allow users to capturing face images (for adding a new face) self.captureFaceImagesDialog = CaptureFaceImagesDialog() # connect the dialog's capture signal ot the Engine's recognizeAndRecordCurrentFrame method self.captureFaceImagesDialog.capture.connect( self.mainWidget.engine.recognizeAndRecordCurrentFrame) # menu bar action for deleting a specific face self.edit_deleteFace = self.edit.addAction("Delete a Face...") self.edit_deleteFace.triggered.connect(self.deleteFace) # menu bar action for deleting all known faces from the application self.edit_deleteAllFaces = self.edit.addAction("Delete All Faces") self.edit_deleteAllFaces.triggered.connect(self.deleteAllFaces) # set the menu bar self.setMenuBar(self.menuBar) # Set the main widget object as the central widget of the main window self.setCentralWidget(self.mainWidget)
class MainWindow(QMainWindow): """ We are modifying some of the attributes of a QMainWindow class Create an instance of CentralWidget class Variables: centralWidget <CentralWidget> newPalette <QPalette> is used to change the main background color of the widget mainMenuBar <menuBar> fileMenu <menu> characterMenu <menu> helpMenu <menu> openWebAction <QAction> uploadAction <QAction> exitAction <QAction> characterAction <QAction> inventoryAction <QAction> equipmentAction <QAction> roomDescAction <QAction> actionAvailAction <QAction> characterStuckAction <QAction> helpMeAction <QAction> Methods: Inherited from QMainWindow: setCentralWidget setPalette setWindowTitle addMenu addAction showMenuBar used to change the visibility of the menu bar """ def __init__(self): super().__init__() ###################################################################################################### # Change settings for central widget ###################################################################################################### self.centralWidget = CentralWidget() newPalette = self.centralWidget.palette() newPalette.setColor(self.centralWidget.backgroundRole(), QColor(0, 105, 105)) self.centralWidget.setAutoFillBackground( True ) self.centralWidget.setPalette(newPalette) self.centralWidget.setFixedWidth(580) self.centralWidget.setFixedHeight(600) self.setCentralWidget(self.centralWidget) self.setWindowTitle("The Game") ###################################################################################################### # Create menu bar ###################################################################################################### self.mainMenuBar = self.menuBar() fileMenu = self.mainMenuBar.addMenu('File') characterMenu = self.mainMenuBar.addMenu('Character') helpMenu = self.mainMenuBar.addMenu('Help') ###################################################################################################### # Create and set actions ###################################################################################################### openWebAction = QAction('Open Website', self) openWebAction.triggered.connect(self.centralWidget.launchWeb) uploadAction = QAction('Upload Game To Website', self) uploadAction.triggered.connect(self.centralWidget.uploadGameInfo) exitAction = QAction('Exit', self) exitAction.triggered.connect(qApp.quit) characterAction = QAction('Character Info', self) characterAction.triggered.connect(self.centralWidget.showCharacterInfo) inventoryAction = QAction('Inventory', self) inventoryAction.triggered.connect(self.centralWidget.showInventoryInfo) equipmentAction = QAction('Equipment', self) equipmentAction.triggered.connect(self.centralWidget.changeEquipmentGeneral) roomDescAction = QAction('Description', self) roomDescAction.triggered.connect(self.centralWidget.showRoomDesc) actionAvailAction = QAction('Actions', self) actionAvailAction.triggered.connect(self.centralWidget.showAvailActions) characterStuckAction = QAction('Stuck? Click here', self) characterStuckAction.triggered.connect(self.centralWidget.unstuckCharacter) helpMeAction = QAction('Helpful Info', self) helpMeAction.triggered.connect(self.centralWidget.showHelpfulInfo) ###################################################################################################### # Pair actions with menubar ###################################################################################################### fileMenu.addAction(openWebAction) fileMenu.addAction(uploadAction) fileMenu.addAction(exitAction) characterMenu.addAction(characterAction) characterMenu.addAction(inventoryAction) characterMenu.addAction(equipmentAction) helpMenu.addAction(roomDescAction) helpMenu.addAction(actionAvailAction) helpMenu.addAction(characterStuckAction) helpMenu.addAction(helpMeAction) ###################################################################################################### # Show menu visibility ###################################################################################################### self.mainMenuBar.setVisible(False) self.centralWidget.procShowMenu.connect(self.showMenuBar) def showMenuBar(self): self.mainMenuBar.setVisible(True)
class MainWindow(QMainWindow): """ We are modifying some of the attributes of a QMainWindow class Create an instance of CentralWidget class Variables: centralWidget <CentralWidget> Methods: Inherited from QMainWindow: setCentralWidget setWindowTitle """ def __init__(self): super().__init__() self.centralWidget = CentralWidget() newPalette = self.centralWidget.palette() newPalette.setColor(self.centralWidget.backgroundRole(), QColor(0, 105, 105)) self.centralWidget.setAutoFillBackground(True) self.centralWidget.setPalette(newPalette) self.centralWidget.setFixedWidth(355) self.centralWidget.setFixedHeight(580) # self.setGeometry(self.left, self.top, self.width, self.height) self.setCentralWidget(self.centralWidget) self.setWindowTitle("The Game") self.mainMenuBar = self.menuBar() fileMenu = self.mainMenuBar.addMenu('File') characterMenu = self.mainMenuBar.addMenu('Character') helpMenu = self.mainMenuBar.addMenu('Help') saveAction = QAction('Save', self) exitAction = QAction('Exit', self) exitAction.triggered.connect(qApp.quit) characterAction = QAction('Character Info', self) inventoryAction = QAction('Inventory', self) roomDescAction = QAction('Description', self) actionAvailAction = QAction('Actions', self) fileMenu.addAction(saveAction) fileMenu.addAction(exitAction) characterMenu.addAction(characterAction) characterMenu.addAction(inventoryAction) helpMenu.addAction(roomDescAction) helpMenu.addAction(actionAvailAction) self.mainMenuBar.setVisible(False) self.centralWidget.procShowMenu.connect(self.showMenuBar) def showMenuBar(self): self.mainMenuBar.setVisible(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
def __init__(self): super().__init__() self.centralWidget = CentralWidget() self.setCentralWidget(self.centralWidget) self.setWindowTitle("Wubba Lubba Dub Dub")
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())