def get_description(self): desc = None try: desc = l("undo_type_" + self._change_class_name) except KeyError: desc = l("undo_type_unknown").format(self._change_class_name) return desc
def __init__(self, parent_window): super(AboutEngineLibsWindow, self).__init__( parent_window, l("aboutwin_title_engine_libs"), l("aboutwin_engine_libs_intro"), self.about_engine_html(), l("aboutwin_button_close"), )
def __init__(self, parent): super(OpenProjectWindow, self).__init__(parent, Qt.WindowTitleHint) self.project_win = parent self.project_win.modal_dialog = True self.setWindowTitle(l("openprojwin_title")) # Compose layout: layout = QVBoxLayout() self.recent_select = QRadioButton( l("openprojwin_label_recent_projects"), self) self.recent_select.toggle() layout.addWidget(self.recent_select) self.recent_list = QListView(self) self.recent_list_model = QStandardItemModel(self.recent_list) for project in self.project_win.app.settings.recent_projects(): item = QStandardItem() item.setText(project) self.recent_list_model.appendRow(item) self.recent_list.setModel(self.recent_list_model) self.recent_list.setCurrentIndex(self.recent_list_model.createIndex(\ 0, 0)) layout.addWidget(self.recent_list) self.browse_select = QRadioButton( l("openprojwin_label_browse"), self) layout.addWidget(self.browse_select) layout_buttons = QHBoxLayout() self.buttonOpen = QPushButton(l("openprojwin_button_do"), self) self.buttonOpen.clicked.connect(self.open_project) layout_buttons.addWidget(self.buttonOpen) layout_buttons.addSpacing(5) self.buttonCancel = QPushButton(l("openprojwin_button_cancel"), self) self.buttonCancel.clicked.connect(self.close) layout_buttons.addWidget(self.buttonCancel) layout_buttons.addStretch(1) layout.addStretch(1) layout.addItem(layout_buttons) self.setLayout(layout) self.setWindowModality(Qt.WindowModal) size = self.size() wantheight = max(size.height(), 250) size.setHeight(wantheight) size.setWidth(size.width() + 400) self.resize(size)
def __init__(self, project_window, for_one_file_only=False): self.proj_win = project_window assert(hasattr(self.proj_win, "project")) super(ProjectToolbar, self).__init__() self.new_a = self.addAction(QIcon.fromTheme("document-new"), l("fileview_toolbar_new")) self.save_a = self.addAction(QIcon.fromTheme("document-save"), l("fileview_toolbar_save")) self.addSeparator() self.undo_a = self.addAction(QIcon.fromTheme("edit-undo"), l("fileview_toolbar_undo")) self.redo_a = self.addAction(QIcon.fromTheme("edit-redo"), l("fileview_toolbar_redo")) self.setStyleSheet("QToolBar { border: 0px }") self.update_toolbar()
def __init__(self, arguments=[]): super(BlitwizardIDE, self).__init__(arguments) # show splashscreen: self.splash = SplashScreen() self.splash.show() self.splash.force_repaint(self) # wait a very small amount of time to show the splash: time.sleep(0.4) # load icon theme: if QIcon.themeName() == "": paths = QIcon.themeSearchPaths() paths.append(os.path.abspath("icons")) QIcon.setThemeSearchPaths(paths) assert(os.path.abspath("icons") in QIcon.themeSearchPaths()) QIcon.setThemeName("Tango") assert(QIcon.themeName() == "Tango") assert(len(QIcon.themeName()) > 0) self.splash.setPercentage(10) # scan for blitwizard instances: self.splash.setText(l(\ "splashscreen_scanning_for_blitwizard_instances")) self.splash.force_repaint(self) # ... do stuff here self.splash.setPercentage(80) self.splash.force_repaint(self) # load settings: self.settings = EditorSettings() self.open_project_window()
def __init__(self, widget_selector, lang_str, option_model): super(AbstractOption, self).__init__() # This is the widget selector that will return the QWidget instances # which currently represent this option (and all its copy instances): self.widget_selector = widget_selector # The option model which knows how to emit a proper undoable change # and save the option to file once it changes: self.option_model = option_model # the translatable language string for our label describing the # option: self.lang_str = lang_str # whether we want to trigger the .change() event on next change, # or rather ont: self.ignore_change = False # construct basic layout with label describing the option. # the derived non-abstract option will add in their widget here: self._layout = QHBoxLayout() self.label = QLabel(l(self.lang_str)) self._layout.addWidget(self.label) self._layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self._layout)
def evaluate_input(self): folder = self.folderentry.text().strip() name = self.nameentry.text().strip() # ensure project name is given: if len(name) == 0: self.resultlabel.setText(l("newprojwin_label_result_noname")) self.buttonCreate.setEnabled(0) return # project should also have remaining characters after sanitization: if len(self.sanitize_name(name)) == 0: self.resultlabel.setText(l("newprojwin_label_result_noregularchars")) self.buttonCreate.setEnabled(0) return # ensure folder name is given: if len(folder) == 0: self.resultlabel.setText( l("newprojwin_label_result_nofolder")) self.buttonCreate.setEnabled(0) return # specified projects folder or direct parent needs to exist: if os.path.exists(folder): if os.path.isfile(folder): # may not be a file! self.resultlabel.setText( l("newprojwin_label_result_isfile").format(folder)) self.buttonCreate.setEnabled(0) return else: parentpath = os.path.dirname(folder) if not os.path.exists(parentpath): self.resultlabel.setText( l("newprojwin_label_result_nosuchparent" ).format(parentpath)) self.buttonCreate.setEnabled(0) return # calculate paths: resultingfolderpath = os.path.join(folder, self.sanitize_name(name)) resultingprojectfilepath = os.path.join(resultingfolderpath, self.sanitize_name(name) + ".proj.xml") # calculated actual project's folder must not exist or be empty: if os.path.exists(resultingfolderpath): folderempty = True for filename in os.listdir(resultingfolderpath): if filename == "." or filename == "..": continue folderempty = False if not folderempty: self.resultlabel.setText( l("newprojwin_label_result_notempty" ).format(resultingfolderpath)) self.buttonCreate.setEnabled(0) return # everything seems fine, enable "create" button: self.buttonCreate.setEnabled(1) self.resultlabel.setText( l("newprojwin_label_result").format( self.shorten_path(resultingfolderpath), self.shorten_path(resultingprojectfilepath)))
def _rebuild_file_list_forget_index(self): if self.no_update_file_list: return title = "Unknown list" mime_types = None index = self.combo.currentIndex() if index == self.CODE_INDEX: mime_types = ["text/lua"] title = l("projwin_filelist_code_list_title") if index == self.ALL_INDEX: title = l("projwin_filelist_all_list_title") self.file_list_model = ProjectFileTreeModel(self.project, title, mime_types) self.file_list.setModel(self.file_list_model) selection_model = self.file_list.selectionModel() self.file_list.doubleClicked.connect(\ self._file_list_open_file) self._change_index_to(0) return
def open_project(self): selected_index = self.recent_list.currentIndex().row() fileName = None if self.browse_select.isChecked(): dirpath = self.project_win.app.settings.get( ["paths", "projects_folder"]) if not os.path.exists(dirpath): try: os.mkdir(dirpath) except: pass fileName = QFileDialog.getOpenFileName(self, l("openprojwin_file_dialog_title"), dirpath, l("openprojwin_file_dialog_filter"))[0] if len(fileName.strip()) == 0: return else: fileName = self.recent_list_model.item(selected_index).text() if len(fileName.strip()) == 0: return # load project: if not os.path.exists(fileName): QMessageBox.warning(self, l("openprojwin_error_dlg_title"), l("openprojwin_error_dlg_nosuchfile").format(\ fileName), QMessageBox.Ok, QMessageBox.Ok) return self.project_win.project = Project(None, fileName, create_if_not_exists=False, notify_on_change_func=\ self.project_win.project_change_notify) self.project_win.update_menu() self.project_win.update_title() self.project_win.show_content() self.project_win.update_undo() self.project_win.modal_dialog = False self.project_win.app.settings.add_recent_project( fileName) self.close() return
def show_context_menu(self, pos): """ Since we have our own undo/redo system, we need to reimplement the context menu to use it. """ global ide new_menu = QMenu() undo_a = new_menu.addAction(l("undo_undo_prefix"), self.execute_undo_func) if not self.check_undo_func(): undo_a.setEnabled(0) redo_a = new_menu.addAction(l("undo_redo_prefix"), self.execute_redo_func) if not self.check_redo_func(): redo_a.setEnabled(0) new_menu.addSeparator() copy_a = new_menu.addAction(l("projwin_menu_edit_copy"), self.do_copy) cut_a = new_menu.addAction(l("projwin_menu_edit_cut"), self.do_cut) if not self.hasSelectedText(): copy_a.setEnabled(0) cut_a.setEnabled(0) paste_a = new_menu.addAction(l("projwin_menu_edit_paste"), self.do_paste) if len(get_app_singleton().clipboard().text(QClipboard.Clipboard)) == 0: paste_a.setEnabled(0) new_menu.addSeparator() select_all_a = new_menu.addAction(l("projwin_menu_edit_select_all"), self.do_select_all) if len(self.text()) == 0: select_all_a.setEnabled(0) new_menu.exec_(QCursor.pos())
def update_title(self): name = None if self.project != None: name = self.project.name modifiedIndicator = "" if name == None: name = l("projwin_no_project") modifiedIndicator = "" if self.project != None: if self.project.has_unsaved_changes(): modifiedIndicator = "*" fileName = "" fileModifiedIndicator = "" if self.content_shown and self.contentwidget != None: if self.contentwidget.fileshown != None: fileName = self.contentwidget.fileshown if self.project.changestracker.file_has_changes(fileName): fileModifiedIndicator = "* - " else: fileModifiedIndicator = " - " self.setWindowTitle(name + modifiedIndicator + " - " + \ fileName + fileModifiedIndicator + l("projwin_title"))
def get_title(self): print("get_title.") t = os.path.basename(self.filename) if not self.language_str_append is None: print("language_str_append: " + \ str(self.language_str_append)) t = t + " - " + l(self.language_str_append) else: print("no language_str_append!") if self.tabnotebook().proj_win().project.\ changestracker.file_has_changes(self.filename): t = t + "*" return t
def update_toolbar(self): if not self.proj_win.project or not self.filename: self.undo_a.setEnabled(0) self.undo_a.setText(l("undo_undo_prefix") + \ ": " + l("undo_none")) self.redo_a.setEnabled(0) self.redo_a.setText(l("undo_redo_prefix") + \ ": " + l("undo_none_redo")) self.save_a.setEnabled(0) return # check if undo available: can_undo = False undo_name = l("undo_undo_prefix") + ": " change = self.proj_win.project.changestracker.\ get_undoable_change_of_file(self.filename) if change: can_undo = True undo_name = undo_name + change.get_description() else: undo_name = undo_name + l("undo_none") # check if redo available: can_redo = False redo_name = l("undo_redo_prefix") + ": " change = self.proj_win.project.changestracker.\ get_redoable_change_of_file(self.filename) if change: can_redo = True redo_name = redo_name + change.get_description() else: redo_name = redo_name + l("undo_none_redo") # apply undo/redo to toolbar: if can_undo: self.undo_a.setEnabled(1) else: self.undo_a.setEnabled(0) self.undo_a.setText(undo_name) if can_redo: self.redo_a.setEnabled(1) else: self.redo_a.setEnabled(0) self.redo_a.setText(redo_name) # check save/dirty status: if self.proj_win.project.changestracker.file_has_changes(\ self.filename): self.save_a.setEnabled(1) else: self.save_a.setEnabled(0) return
def __init__(self, parent_window): super(WelcomeWidget, self).__init__(parent_window) self.parent_window = parent_window layout = QVBoxLayout() page_title = PageTitleWidget("gui/gfx/logo_welcome.png", "welcomewidget_page_title") layout.addWidget(page_title) lbl = QLabel(l("welcomewidget_intro")) lbl.setWordWrap(True) layout.addWidget(lbl) layout_buttons = QVBoxLayout() self.buttonNew = QPushButton(l("welcomewidget_choice_new_project"), self) self.buttonNew.clicked.connect(self.parent_window.new_project_window) layout_buttons.addWidget(self.buttonNew) layout_buttons.addSpacing(5) self.buttonOpen = QPushButton(l("welcomewidget_choice_open_project"), self) self.buttonOpen.clicked.connect(self.parent_window.\ open_project_window) layout_buttons.addWidget(self.buttonOpen) layout_hbox_buttons = QHBoxLayout() layout_hbox_buttons.addItem(layout_buttons) layout_hbox_buttons.addStretch(1) layout.addItem(layout_hbox_buttons) layout.addStretch(1) layoutwidget = QWidget() layoutwidget.setLayout(layout) self.addTab(layoutwidget, l("welcomewidget_tab_title"))
def __init__(self, project, title_language_str, title_filename_str, filename): super(AbstractFileView, self).__init__(None) self.project = project self.filename = filename self.title_language_str = title_language_str self.title_filename_str = title_filename_str self._innerfileviewbox = QWidget() # toolbar buttons layout: buttonsLayout = QVBoxLayout() buttonsLayout.setContentsMargins(0, 0, 0, 0) buttonsLayoutWidget = QWidget() buttonsLayoutWidget.setLayout(buttonsLayout) # add toolbar and buttons: toolbar = QToolBar() stretcher = QWidget() stretcher.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) toolbar.addWidget(stretcher) toolbar.addAction(QIcon.fromTheme("view-fullscreen"), l("fileview_toolbar_popout"), self.pop_out) toolbar.setStyleSheet("QToolBar { border: 0px }") buttonsLayout.addWidget(toolbar) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) linepaddinglayout = QHBoxLayout() linepaddinglayout.setContentsMargins(5, 0, 5, 0) linepaddinglayout.addWidget(line) linepadding = QFrame() linepadding.setLayout(linepaddinglayout) buttonsLayout.addWidget(linepadding) # inner stuff layout: self._vboxinnerfileviewlayout = QVBoxLayout() self._vboxinnerfileviewlayout.setContentsMargins(0, 0, 0, 0) self._vboxinnerfileviewlayout.addWidget(buttonsLayoutWidget) self._have_inner_vbox_contents = False self._innerfileviewbox.setLayout(self._vboxinnerfileviewlayout) layout_outer = QVBoxLayout() layout_outer.setContentsMargins(0, 0, 0, 0) #layout_outer.addWidget(toolbar) layout_outer.addWidget(self._innerfileviewbox) super(AbstractFileView, self).setLayout(layout_outer) AbstractFileView.update_language(self) self.update_toolbar()
def rebuild_combo_contents(self): index = self.combo.currentIndex() if index < 0 or self.combo.count() <= 1: index = 1 while self.combo.count() > 0: self.combo.removeItem(0) self.combo.addItem(l("projwin_filelist_project")) self.combo.addItem(l("projwin_filelist_code")) self.combo.addItem(l("projwin_filelist_scenes")) self.combo.addItem(l("projwin_filelist_objects")) self.combo.addItem(l("projwin_filelist_resources")) self.combo.addItem(l("projwin_filelist_all")) self.combo.setCurrentIndex(index)
def __init__(self, project_window): super(AboutWindow, self).__init__() self.setWindowModality(Qt.ApplicationModal) self.project_window = project_window # Compose layout: layout = QVBoxLayout() lbl = QLabel(l("aboutwin_main_info").replace("[version]", "0.1")); lbl.setWordWrap(True) layout.addWidget(lbl) self.buttonEditor = QPushButton(l("aboutwin_button_editor_authors"), self) self.buttonEditor.clicked.connect(self.show_editor_info) layout.addWidget(self.buttonEditor) self.buttonQt = QPushButton(l("aboutwin_button_qt_licensing"), self) self.buttonQt.clicked.connect(self.show_qt_info) layout.addWidget(self.buttonQt) self.buttonEditorLibs = QPushButton(l("aboutwin_button_editor_libs"), self) self.buttonEditorLibs.clicked.connect(self.show_editor_libs_info) layout.addWidget(self.buttonEditorLibs) self.buttonEngineLibs = QPushButton(l("aboutwin_button_engine_libs"), self) self.buttonEngineLibs.clicked.connect(self.show_engine_libs_info) layout.addWidget(self.buttonEngineLibs) self.buttonClose = QPushButton(l("aboutwin_button_close"), self) self.buttonClose.clicked.connect(self.close_dialog) buttonCloseLayout = QHBoxLayout() buttonCloseLayout.addStretch() buttonCloseLayout.addWidget(self.buttonClose) layout.addItem(buttonCloseLayout) # Set layout and central widget: layout.setSizeConstraint(QLayout.SetFixedSize) self.setLayout(layout) self.setWindowTitle(l("aboutwin_title")) self.setFixedSize(self.size())
def __init__(self, imgpath, title_language_str): super(PageTitleWidget, self).__init__() self.title_language_str = title_language_str layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.title_img = QImage(imgpath) self.title_img_label = QLabel() self.title_img_label.setPixmap(QPixmap.fromImage(self.title_img)) layout.addWidget(self.title_img_label) font = QFont() font.setPointSize(font.pointSize() * 2) font.setBold(True) self.title_label = QLabel(l(title_language_str)) self.title_label.setFont(font) layout.addWidget(self.title_label) layout.addStretch() self.setLayout(layout)
def __init__(self, parent, project, on_file_open=None, on_visibility_change=None): self.no_update_file_list = True self.project = project self.on_file_open = on_file_open super(ProjectFileListWidget, self).__init__("BLAH", parent, 0) if on_visibility_change: self.visibilityChanged.connect(lambda: on_visibility_change()) self.layout = QVBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.setWindowTitle(l("projwin_filelist_title")) self.box = QWidget() self.layout.addWidget(self.box) self.layout_inner = QVBoxLayout() self.box.setLayout(self.layout_inner) self.combo = QComboBox() self.combo.addItem("test") self.combo.currentIndexChanged.connect(\ self._rebuild_file_list_forget_index) self.layout_inner.addWidget(self.combo) self.file_list = QTreeView(self) self.file_list.setMinimumSize(250, 20) self.layout_inner.addWidget(self.file_list) mainwidget = QWidget() mainwidget.setLayout(self.layout) self.setWidget(mainwidget) self.rebuild_combo_contents() self.no_update_file_list = False self._rebuild_file_list_forget_index()
def update_undo(self): """ Check if there's stuff to undo/redo and enable menu entries accordingly. """ if self.project == None: return undo_file_name = l("undo_undo_prefix") redo_file_name = l("undo_redo_prefix") undo_file_enabled = False redo_file_enabled = False gotfile = None if self.content_shown and self.contentwidget != None: gotfile = self.contentwidget.fileshown if gotfile != None: # per file changes: change = self.project.changestracker.get_undoable_change_of_file(\ gotfile) if change != None: undo_file_enabled = True undo_file_name = undo_file_name + ": " + change.\ get_description() else: undo_file_name = undo_file_name + ": " + l("undo_none") change = self.project.changestracker.get_redoable_change_of_file(\ gotfile) if change != None: redo_file_enabled = True redo_file_name = redo_file_name + ": " + change.\ get_description() else: redo_file_name = redo_file_name + ": " + l("undo_none_redo") else: undo_file_name = undo_file_name + ": " + l("undo_nofile") redo_file_name = redo_file_name + ": " + l("undo_nofile") # global changes: undo_global_name = l("undo_undo_global_prefix") redo_global_name = l("undo_redo_global_prefix") undo_global_enabled = False redo_global_enabled = False change = self.project.changestracker.get_undoable_global_change() if change != None: undo_global_enabled = True undo_global_name = undo_global_name + ": " + change.\ get_description() else: undo_global_name = undo_global_name + ": " + l("undo_none") change = self.project.changestracker.get_redoable_global_change() if change != None: redo_global_enabled = True redo_global_name = redo_global_name + ": " + change.\ get_description() else: redo_global_name = redo_global_name + ": " + l("undo_none_redo") # apply text and enabled states: self.editmenuactions["undo"].setText(undo_file_name) self.editmenuactions["redo"].setText(redo_file_name) self.editmenuactions["undo_global"].setText(undo_global_name) self.editmenuactions["redo_global"].setText(redo_global_name) if undo_file_enabled: self.editmenuactions["undo"].setEnabled(1) else: self.editmenuactions["undo"].setEnabled(0) if redo_file_enabled: self.editmenuactions["redo"].setEnabled(1) else: self.editmenuactions["redo"].setEnabled(0) if undo_global_enabled: self.editmenuactions["undo_global"].setEnabled(1) else: self.editmenuactions["undo_global"].setEnabled(0) if redo_global_enabled: self.editmenuactions["redo_global"].setEnabled(1) else: self.editmenuactions["redo_global"].setEnabled(0)
def update_language(self): self.setWindowTitle(l("projwin_filelist_title")) self.no_update_file_list = True self.rebuild_combo_contents() self.no_update_file_list = False self.rebuild_file_list()
def update_language(self): """ Update the language string of the option description label. """ self.label.setText(l(self.lang_str))
def __init__(self, parent): super(NewProjectWindow, self).__init__(parent, Qt.WindowTitleHint) self.project_win = parent self.project_win.modal_dialog = True self.setWindowTitle(l("newprojwin_title")) # Compose layout: layout = QVBoxLayout() lbl = QLabel(l("newprojwin_intro")) lbl.setWordWrap(True) layout.addWidget(lbl) lbl = QLabel(l("newprojwin_label_name")) lbl.setWordWrap(True) layout.addWidget(lbl) self.nameentry = QLineEdit() self.nameentry.textChanged.connect(self.evaluate_input) layout.addWidget(self.nameentry) lbl = QLabel(l("newprojwin_label_folder")) lbl.setWordWrap(True) layout.addWidget(lbl) self.folderentry = QLineEdit() self.folderentry.setText(self.project_win.app.\ settings.get(["paths", "projects_folder"])) self.folderentry.textChanged.connect(self.evaluate_input) layout.addWidget(self.folderentry) self.resultlabel = QLabel(l("newprojwin_label_result_noname")) self.resultlabel.setWordWrap(True) layout.addWidget(self.resultlabel) layout_buttons = QHBoxLayout() self.buttonCreate = QPushButton(l("newprojwin_button_create"), self) self.buttonCreate.clicked.connect(self.create_project) self.buttonCreate.setEnabled(0) layout_buttons.addWidget(self.buttonCreate) layout_buttons.addSpacing(5) self.buttonCancel = QPushButton(l("newprojwin_button_cancel"), self) self.buttonCancel.clicked.connect(self.close) layout_buttons.addWidget(self.buttonCancel) layout_buttons.addStretch(1) layout.addStretch(1) layout.addItem(layout_buttons) self.setLayout(layout) self.setWindowModality(Qt.WindowModal) # get some additional spacing in the dialog: size = self.size() wantheight = max(size.height(), 350) size.setHeight(wantheight) size.setWidth(size.width() + 400) self.resize(size)
def update_language(self): self.title_label.setText(l(self.title_language_str))
def pop_out_title_name(self): return l("fileview_properties_title").format(self.filename)
def __init__(self, parent_window): super(AboutQtWindow, self).__init__(parent_window, l("aboutwin_title_qt"), l("aboutwin_qt_licensing_intro"), self.about_qt_html(), l("aboutwin_button_close"))
def update_menu(self): self.update_window_menu() if self.project == None: self.projectmenuactions["save"].setEnabled(0) self.projectmenuactions["saveas"].setEnabled(0) self.projectmenuactions["close"].setEnabled(1) self.filemenu.setEnabled(0) self.editmenu.setEnabled(0) self.runmenu.setEnabled(0) self.projectmenuactions["close"].setText(\ l("projwin_menu_project_closewindow")) else: if self.project.has_unsaved_changes(): self.projectmenuactions["save"].setEnabled(1) else: self.projectmenuactions["save"].setEnabled(0) self.runmenu.setEnabled(1) self.editmenu.setEnabled(1) self.projectmenuactions["saveas"].setEnabled(1) self.projectmenuactions["close"].setEnabled(1) self.projectmenuactions["close"].setText(\ l("projwin_menu_project_close")) self.filemenu.setEnabled(1) if self.is_game_running(): self.runmenuactions["run_in_editor"].setEnabled(0) self.runmenuactions["run_in_editor_from_start"].setEnabled(0) self.runmenuactions["run_external"].setEnabled(0) self.runmenuactions["run_pause"].setEnabled(1) self.runmenuactions["run_stop"].setEnabled(1) else: self.runmenuactions["run_in_editor"].setEnabled(1) self.runmenuactions["run_in_editor_from_start"].setEnabled(1) self.runmenuactions["run_external"].setEnabled(1) self.runmenuactions["run_pause"].setEnabled(0) self.runmenuactions["run_stop"].setEnabled(0) # if file shown: if self.contentwidget != None and \ self.contentwidget.isFileShown(): self.filemenuactions["save"].setEnabled(0) if self.project.changestracker.file_has_changes(\ self.contentwidget.fileshown): self.filemenuactions["save"].setEnabled(1) self.filemenuactions["rename"].setEnabled(1) self.filemenuactions["remove"].setEnabled(1) # if text editable focussed: if self.copy_paste_target_widget != None: if self.copy_paste_target_widget.hasSelectedText(): self.editmenuactions["cut"].setEnabled(1) self.editmenuactions["copy"].setEnabled(1) else: self.editmenuactions["cut"].setEnabled(0) self.editmenuactions["copy"].setEnabled(0) if len(get_app_singleton().clipboard().text(\ QClipboard.Clipboard)) > 0: self.editmenuactions["paste"].setEnabled(1) else: self.editmenuactions["paste"].setEnabled(0) text = self.copy_paste_target_widget.text() if len(text) > 0: self.editmenuactions["select_all"].setEnabled(1) else: self.editmenuactions["select_all"].setEnabled(0) else: self.editmenuactions["cut"].setEnabled(0) self.editmenuactions["copy"].setEnabled(0) self.editmenuactions["paste"].setEnabled(0) self.editmenuactions["select_all"].setEnabled(0) else: # ..otherwise: self.filemenuactions["save"].setEnabled(0) self.filemenuactions["rename"].setEnabled(0) self.filemenuactions["remove"].setEnabled(0) self.editmenuactions["cut"].setEnabled(0) self.editmenuactions["copy"].setEnabled(0) self.editmenuactions["paste"].setEnabled(0) self.editmenuactions["select_all"].setEnabled(0)
def __init__(self, parent_window): super(AboutEditorWindow, self).__init__(parent_window, l("aboutwin_title_editor_authors"), l("aboutwin_editor_authors_intro"), self.about_editor_html(), l("aboutwin_button_close"))
def construct_menu_bar(self): bar = QMenuBar() # Project menu: self.projectmenuactions = dict() projectmenu = QMenu(l("projwin_menu_project")) self.projectmenuactions["new"] = \ projectmenu.addAction(QIcon.fromTheme("document-new"), l("projwin_menu_project_new"), self.new_project_window) self.projectmenuactions["open"] = \ projectmenu.addAction(QIcon.fromTheme("document-open"), l("projwin_menu_project_open"), self.open_project_window) projectmenu.addSeparator() self.projectmenuactions["save"] = \ projectmenu.addAction(QIcon.fromTheme("document-save"), l("projwin_menu_project_saveall")) self.projectmenuactions["save"].setShortcut( QKeySequence.Save) self.projectmenuactions["saveas"] = \ projectmenu.addAction( l("projwin_menu_project_saveas")) projectmenu.addSeparator() if self.project != None: self.projectmenuactions["close"] = \ projectmenu.addAction( l("projwin_menu_project_close"), self.close_window) else: self.projectmenuactions["close"] = \ projectmenu.addAction( l("projwin_menu_project_closewindow"), self.close_window) self.projectmenuactions["quit"] = \ projectmenu.addAction(QIcon.fromTheme("application-exit"), l("projwin_menu_project_quit"), self.app.close_all) # File menu: filemenu = QMenu(l("projwin_menu_file")) self.filemenu = filemenu self.filemenuactions = dict() self.filemenuactions["new"] = \ filemenu.addAction(QIcon.fromTheme("document-new"), l("projwin_menu_file_new")) self.filemenuactions["add"] = \ filemenu.addAction(l("projwin_menu_file_add")) self.filemenuactions["addfolder"] = \ filemenu.addAction(QIcon.fromTheme("folder-new"), l("projwin_menu_file_addfolder")) filemenu.addSeparator() self.filemenuactions["save"] = \ filemenu.addAction(QIcon.fromTheme("document-save"), l("projwin_menu_file_save")) self.filemenuactions["rename"] = \ filemenu.addAction(l("projwin_menu_file_rename")) filemenu.addSeparator() self.filemenuactions["remove"] = \ filemenu.addAction(QIcon.fromTheme("edit-delete"), l("projwin_menu_file_remove")) # Edit menu: editmenu = QMenu(l("projwin_menu_edit")) self.editmenu = editmenu self.editmenu.aboutToShow.connect(self.update_menu) self.editmenuactions = dict() self.editmenuactions["undo"] = \ editmenu.addAction(QIcon.fromTheme("edit-undo"), "undo_local", self.do_edit_undo_local) self.editmenuactions["undo"].setShortcut( QKeySequence.Undo) self.editmenuactions["redo"] = \ editmenu.addAction(QIcon.fromTheme("edit-redo"), "redo_local", self.do_edit_redo_local) self.editmenuactions["redo"].setShortcut( QKeySequence.Redo) editmenu.addSeparator() self.editmenuactions["undo_global"] = \ editmenu.addAction(QIcon.fromTheme("edit-undo"), "undo_global") self.editmenuactions["redo_global"] = \ editmenu.addAction(QIcon.fromTheme("edit-redo"), "redo_global") self.update_undo() editmenu.addSeparator() self.editmenuactions["cut"] = \ editmenu.addAction(QIcon.fromTheme("edit-cut"), l("projwin_menu_edit_cut"), self.do_edit_cut) self.editmenuactions["cut"].setShortcut( QKeySequence.Cut) self.editmenuactions["copy"] = \ editmenu.addAction(QIcon.fromTheme("edit-copy"), l("projwin_menu_edit_copy"), self.do_edit_copy) self.editmenuactions["copy"].setShortcut( QKeySequence.Copy) self.editmenuactions["paste"] = \ editmenu.addAction(QIcon.fromTheme("edit-paste"), l("projwin_menu_edit_paste"), self.do_edit_paste) self.editmenuactions["paste"].setShortcut( QKeySequence.Paste) editmenu.addSeparator() self.editmenuactions["select_all"] = \ editmenu.addAction( l("projwin_menu_edit_select_all"), self.do_edit_select_all) self.editmenuactions["select_all"].setShortcut( QKeySequence.SelectAll) # Run menu runmenu = QMenu(l("projwin_menu_run")) self.runmenu = runmenu self.runmenuactions = dict() self.runmenuactions["run_in_editor"] = \ runmenu.addAction(QIcon.fromTheme("media-playback-start"), l("projwin_menu_run_in_editor")) runmenu.addSeparator() self.runmenuactions["run_in_editor_from_start"] = \ runmenu.addAction( l("projwin_menu_run_in_editor_from_start")) self.runmenuactions["run_external"] = \ runmenu.addAction(QIcon.fromTheme("go-jump"), l("projwin_menu_run_external")) runmenu.addSeparator() self.runmenuactions["run_pause"] = \ runmenu.addAction(QIcon.fromTheme("media-playback-pause"), l("projwin_menu_run_pause")) runmenu.addSeparator() self.runmenuactions["run_stop"] = \ runmenu.addAction(QIcon.fromTheme("process-stop"), l("projwin_menu_run_stop")) # Settings > Language menu languagesmenu = QMenu(l("projwin_menu_settings_language")) languagesmenu.setIcon(QIcon.fromTheme("preferences-desktop-locale")) def other_language(language): change_language(language) assert(get_current_language() == language) self.app.update_language() for (id, name) in list_languages(): a = languagesmenu.addAction( name, lambda id=id: other_language(id) ) if id == get_current_language(): a.setCheckable(True) a.setChecked(True) # Settings menu self.settingsmenuactions = dict() settingsmenu = QMenu(l("projwin_menu_settings")) settingsmenu.addMenu(languagesmenu) # Window menu self.windowmenuactions = dict() windowmenu = QMenu(l("projwin_menu_window")) self.windowmenuactions["new"] = \ windowmenu.addAction(QIcon.fromTheme("window-new"), l("projwin_menu_window_new"), self.new_window) windowmenu.addSeparator() self.windowmenuactions["dock_filelist"] = \ windowmenu.addAction( l("projwin_menu_window_dock_filelist"), lambda: self.contentwidget.toggle_dock_visible("filelist")) self.windowmenuactions["dock_filelist"].setCheckable(True) windowmenu.addSeparator() self.windowmenuactions["close"] = \ windowmenu.addAction(l("projwin_menu_window_close"), self.close_window) # About menu self.aboutmenuactions = dict() aboutmenu = QMenu(l("projwin_menu_about")) self.aboutmenuactions["new"] = \ aboutmenu.addAction(QIcon.fromTheme("help-about"), l("projwin_menu_about_about"), lambda pwin=self: pwin.open_about_dlg()) bar.addMenu(projectmenu) bar.addMenu(self.filemenu) bar.addMenu(self.editmenu) bar.addMenu(self.runmenu) bar.addMenu(settingsmenu) bar.addMenu(windowmenu) bar.addMenu(aboutmenu) return bar