def show_popup_bar(self): #editor = _ide.python_editor.editor #layout = _ide.python_editor.tabeditor.layout() editor = self.editor layout = self.tabeditor.layout() # first remove any previous widgets name = 'Document out of sync warning' for i in range(layout.count()): item = layout.itemAt(i) if item is None: continue widget = item.widget() if widget.objectName() != name: continue layout.removeItem(item) widget.deleteLater() popup_bar = QtWidgets.QWidget() popup_bar.setObjectName('Document out of sync warning') bar_layout = QtWidgets.QHBoxLayout(popup_bar) l = QtWidgets.QLabel() l.setText('This tab is out of sync with the autosave.') new_button = QtWidgets.QPushButton('Load into New Tab') save_button = QtWidgets.QPushButton('Save This Version') update_button = QtWidgets.QPushButton('Update From Autosave') diff_button = QtWidgets.QPushButton('Show Diff') stylesheet = """ QPushButton { background-color: #444; } QPushButton:hover { background-color: orange; } """ for b in new_button, save_button, update_button, diff_button: #b.setFlat(True) b.setStyleSheet(stylesheet) for b in l, new_button, save_button, update_button, diff_button: bar_layout.addWidget(b) layout.insertWidget(1, popup_bar) popup_bar.setMaximumHeight(0) #print popup_bar.maximumHeight() #popup_bar.setMaximumHeight(46) def anim_popup_bar(popup_bar): anim = QtCore.QPropertyAnimation( popup_bar, 'maximumHeight' ) anim.setStartValue(0) anim.setEndValue(46) anim.setDuration(400) anim.start() anim_popup_bar.anim = anim anim_popup_bar(popup_bar)
def setup_new_tab_btn(self): """ Adds a new tab [+] button to the right of the tabs. """ widget = QtWidgets.QWidget() widget.setObjectName('Tab_Widget_New_Button') self.insertTab(0, widget, '') nb = self.new_btn = QtWidgets.QToolButton() nb.setMinimumSize(QtCore.QSize(50, 10)) nb.setText('+') # you could set an icon instead of text nb.setAutoRaise(True) nb.clicked.connect(self.new_tab) tabBar = self.tabBar() tabBar.setTabButton(0, QtWidgets.QTabBar.RightSide, nb) tabBar.setTabEnabled(0, False)
def build_layout(self): """ Create the layout. """ layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) # self.setup_menu() self.menubar = menubar.MenuBar(self) left_widget = QtWidgets.QWidget() left_layout = QtWidgets.QVBoxLayout(left_widget) path_edit = QtWidgets.QLineEdit() path_edit.textChanged.connect(self.update_tree) self.path_edit = path_edit splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal) self.splitter = splitter self.xpanded = False self.setLayout(layout) self.tool_button = QtWidgets.QToolButton() self.tool_button.setText('<') self.tool_button.clicked.connect(self.xpand) self.tool_button.setMaximumWidth(20) layout.addWidget(splitter) browse = browser.FileTree(NUKE_DIR) self.browser = browse left_layout.addWidget(self.path_edit) left_layout.addWidget(self.browser) self.tabs = edittabs.EditTabs() widgets = [left_widget, self.tool_button, self.tabs] for w in widgets: splitter.addWidget(w) splitter.setSizes([200, 10, 800]) self.install_features() self.check_modified_tabs() if self.tabs.count() == 0: self.tabs.new_tab()
def build_layout(self): """ Create the layout. """ layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) # self.setup_menu() self.read_only = True self.menubar = menubar.MenuBar(self) left_widget = QtWidgets.QWidget() left_layout = QtWidgets.QVBoxLayout(left_widget) path_edit = QtWidgets.QLineEdit() path_edit.textChanged.connect(self.update_tree) self.path_edit = path_edit splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal) self.splitter = splitter self.xpanded = False self.setLayout(layout) self.tool_button = QtWidgets.QToolButton() self.tool_button.setText('<') self.tool_button.clicked.connect(self.xpand) self.tool_button.setMaximumWidth(20) layout.addWidget(splitter) browse = browser.FileTree(NUKE_DIR) self.browser = browse left_layout.addWidget(self.path_edit) left_layout.addWidget(self.browser) self.editor = editor.Editor(handle_shortcuts=True) self.editor.path = 'C:/Users/tsalx/Desktop/temp_editor_save.py' widgets = [left_widget, self.tool_button, self.editor] for w in widgets: splitter.addWidget(w) splitter.setSizes([200, 10, 800]) self.browser.path_signal.connect(self.read) self.editor.textChanged.connect(self.write) self.editor.modificationChanged.connect(self.handle_changed)
def __init__(self, parent=None): super(TabEditor, self).__init__(parent) if parent is not None: self.setParent(parent) self.setLayout(QtWidgets.QVBoxLayout(self)) self.layout().setContentsMargins(0, 0, 0, 0) self.tab_widget = QtWidgets.QWidget() twl = QtWidgets.QHBoxLayout(self.tab_widget) self.tab_widget_layout = twl self.tab_widget_layout.setContentsMargins(0, 0, 0, 0) self.tabs = Tabs() self.tab_widget_layout.addWidget(self.tabs) # add corner buttons tb = QtWidgets.QToolButton() self.tab_list_button = tb tb.setArrowType(QtCore.Qt.DownArrow) tb.setToolTip('Click for a list of tabs.') tb.setAutoRaise(True) tb.setFixedSize(24, 24) self.tab_list_button.clicked.connect(self.show_tab_menu) nb = QtWidgets.QToolButton() self.new_tab_button = nb nb.setToolTip('Click to add a new tab.') nb.setText('+') nb.setAutoRaise(True) self.new_tab_button.clicked.connect(self.new_tab) for button in [self.new_tab_button, self.tab_list_button]: self.tab_widget_layout.addWidget(button) self.editor = editor.Editor(handle_shortcuts=False) for widget in self.tab_widget, self.editor: self.layout().addWidget(widget) # Give the autosave a chance to load all # tabs before connecting signals between # tabs and editor. QtCore.QTimer.singleShot(0, self.connect_signals)
""" return False def quit(self): print(self.__class__, 'exiting') self.silent_quit() def remove_event_filter(self): QtCore.QCoreApplication.removeEventFilter(self.target, self) def silent_quit(self): self.remove_event_filter() self.deleteLater() class InfoFilter(GenericEventFilter): """ Example Filter that prints object and event information. """ def event_filter(self, obj, event): print(obj.metaObject().className(), event.type()) return False if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) w = QtWidgets.QWidget() f = GenericEventFilter(target=w) w.show() app.exec_()
def show_diff_text_popup(self, subscript): popup_bar = QtWidgets.QWidget() self.popup_bar = popup_bar name = 'Document out of sync warning' popup_bar.setObjectName(name) popup_bar.setLayout( QtWidgets.QHBoxLayout(popup_bar) ) label = QtWidgets.QLabel() label.setText( 'This tab is out of sync\n'\ 'with the autosave.' ) popup_bar.layout().addWidget(label) B = QtWidgets.QPushButton new_button = B('Load into New Tab') new_button.setToolTip( 'Click to load the text inside '\ 'the editor into a fresh tab, '\ 'updating the autosaved version '\ 'into the previous tab.' ) save_button = B('Save This Version') save_button.setToolTip( 'Click to choose this version '\ 'as the version to save.' ) update_button = B('Update From Autosave') update_button.setToolTip( 'Load the version from the '\ 'autosave into this tab.' ) diff_button = B('Show Diff') diff_button.setToolTip( 'Show the difference between the two.' ) remove = partial( self.remove_existing_popups, name ) layout = self.tabeditor.layout() layout.insertWidget(1, popup_bar) stylesheet = """ QPushButton { background-color: #444; } QPushButton:hover { background-color: orange; } """ buttons = ( new_button, save_button, update_button, diff_button ) for b in buttons: popup_bar.layout().addWidget(b) b.setStyleSheet(stylesheet) # wire signals into buttons new = partial( self.load_into_new_tab, subscript ) new_button.clicked.connect(new) new_button.clicked.connect(remove) save = partial( self.save_this_version, subscript ) save_button.clicked.connect(save) save_button.clicked.connect(remove) update = partial( self.update_from_autosave, subscript ) update_button.clicked.connect(update) update_button.clicked.connect(remove) show_diff = partial( self.show_diff_text, subscript.text ) diff_button.clicked.connect(show_diff) self.editor.modificationChanged.connect( self.check_diff_modified )