def do_config(self): # Save values that need to be synced between the dialog and the # search widget. self.config['open_external'] = self.open_external.isChecked() # Create the config dialog. It's going to put two config widgets # into a QTabWidget for displaying all of the settings. d = QDialog(self) button_box = QDialogButtonBox(QDialogButtonBox.Close) v = QVBoxLayout(d) button_box.accepted.connect(d.accept) button_box.rejected.connect(d.reject) d.setWindowTitle(_('Customize get books search')) tab_widget = QTabWidget(d) v.addWidget(tab_widget) v.addWidget(button_box) chooser_config_widget = StoreChooserWidget() search_config_widget = StoreConfigWidget(self.config) tab_widget.addTab(chooser_config_widget, _('Choose stores')) tab_widget.addTab(search_config_widget, _('Configure search')) # Restore dialog state. geometry = self.config.get('config_dialog_geometry', None) if geometry: d.restoreGeometry(geometry) else: d.resize(800, 600) tab_index = self.config.get('config_dialog_tab_index', 0) tab_index = min(tab_index, tab_widget.count() - 1) tab_widget.setCurrentIndex(tab_index) d.exec_() # Save dialog state. self.config['config_dialog_geometry'] = bytearray(d.saveGeometry()) self.config['config_dialog_tab_index'] = tab_widget.currentIndex() search_config_widget.save_settings() self.config_changed() self.gui.load_store_plugins() self.setup_store_checks()
class Ui_ReportsDockWidget(QDockWidget): """ The Ui_ReportsDockWidget class provides a DockWidget containing a tabbed widget providing convenient access to "reports". It is docked at the bottom of the NE1 main window. Currently, the history widget is the only report available. Future ideas for inclusion: - Python command line tab - NE1 command line tab - NE1 Job Manager tab """ _title = "Reports" def __init__(self, win): """ Constructor for Ui_ReportsDockWidget. @param win: The main window @type win: QMainWindow """ QDockWidget.__init__(self, win) self.win = win #Define layout self._containerWidget = QWidget() self.setWidget(self._containerWidget) # Create vertical box layout self.vBoxLayout = QVBoxLayout(self._containerWidget) vBoxLayout = self.vBoxLayout vBoxLayout.setMargin(0) vBoxLayout.setSpacing(0) self.setEnabled(True) self.setFloating(False) self.setVisible(True) self.setWindowTitle(self._title) self.setAutoFillBackground(True) self.setPalette(getPalette( None, QPalette.Window, pmGrpBoxColor)) # Create the reports tabwidget. It will contain the history tab # and possibly other tabs containing reports. self.reportsTabWidget = QTabWidget() self.reportsTabWidget.setObjectName("reportsTabWidget") self.reportsTabWidget.setCurrentIndex(0) self.reportsTabWidget.setAutoFillBackground(True) vBoxLayout.addWidget(self.reportsTabWidget) # Create the history tab. It will contain the history widget. self.historyTab = QWidget() self.historyTab.setObjectName("historyTab") self.reportsTabWidget.addTab(self.historyTab, "History") self.historyTabLayout = QVBoxLayout(self.historyTab) historyTabLayout = self.historyTabLayout historyTabLayout.setMargin(0) historyTabLayout.setSpacing(0) self._addHistoryWidget() self.setMinimumHeight(100) self.setSizePolicy( QSizePolicy(QSizePolicy.Policy(QSizePolicy.Expanding), QSizePolicy.Policy(QSizePolicy.Expanding))) win.addDockWidget(Qt.BottomDockWidgetArea, self) # Since the connection to the toggle() slot hasn't been made yet, # we must set the checkmark and hide/show self manually. if env.prefs[displayReportsWidget_prefs_key]: self.win.viewReportsAction.setChecked(True) # No slot connected yet, so show self manually. self.show() else: self.win.viewReportsAction.setChecked(False) # No slot connected yet, so hide self manually. self.hide() def _addHistoryWidget(self): """ Sets up and adds the history widget. """ histfile = make_history_filename() #@@@ ninad 061213 This is likely a new bug for multipane concept # as each file in a session will have its own history widget qt4todo('histfile = make_history_filename()') #bruce 050913 renamed self.history to self.history_object, and # deprecated direct access to self.history; code should use env.history # to emit messages, self.history_widget to see the history widget, # or self.history_object to see its owning object per se # rather than as a place to emit messages (this is rarely needed). self.history_object = HistoryWidget(self, filename = histfile, mkdirs = 1) # this is not a Qt widget, but its owner; # use self.history_widget for Qt calls that need the widget itself. self.history_widget = self.history_object.widget self.history_widget.setSizePolicy(QSizePolicy.Ignored,QSizePolicy.Ignored) # bruce 050913, in case future code splits history widget # (as main window subwidget) from history message recipient # (the global object env.history). env.history = self.history_object #bruce 050727, revised 050913 self.historyTabLayout.addWidget(self.history_widget) def show(self): """ Show this widget. Makes sure that this widget is shown only when the B{View > Reports} action is checked @see: B{self.closeEvent} """ if not env.prefs[displayReportsWidget_prefs_key]: return if not self.win.viewReportsAction.isChecked(): self.win.viewReportsAction.setChecked(True) return QDockWidget.show(self) def closeEvent(self, event): """ Makes sure that this widget is closed (hidden) only when the B{View > Reports} action is unchecked. Overrides QDockWidget.closeEvent() @parameter event: closeEvent for the QDockWidget """ if self.win.viewReportsAction.isChecked(): self.win.viewReportsAction.setChecked(False) # setChecked() generates signal and calls toggle() slot. return QDockWidget.closeEvent(self, event) def hide_DISABLED(self): """ Hide this widget. Makes sure that this widget is closed (hidden ) only when the B{View > Reports} action is unchecked @see: self.closeEvent @deprecated: Not needed and marked for removal. Mark 2008-01-18 """ if self.win.viewReportsAction.isChecked(): self.win.viewReportsAction.setChecked(False) # setChecked() generates signal and calls toggle() slot. return QDockWidget.hide(self) def toggle(self, isChecked): """ Hides or shows the Reports DockWidget. @param isChecked: Checked state of the B{View > Reports} menu item @type isChecked: boolean """ if isChecked: env.prefs[displayReportsWidget_prefs_key] = True self.show() else: env.prefs[displayReportsWidget_prefs_key] = False self.hide()
class Editor(QWidget): # {{{ def __init__(self, parent=None, one_line_toolbar=False): QWidget.__init__(self, parent) self.toolbar1 = QToolBar(self) self.toolbar2 = QToolBar(self) self.toolbar3 = QToolBar(self) for i in range(1, 4): t = getattr(self, 'toolbar%d'%i) t.setIconSize(QSize(18, 18)) self.editor = EditorWidget(self) self.tabs = QTabWidget(self) self.tabs.setTabPosition(self.tabs.South) self.wyswyg = QWidget(self.tabs) self.code_edit = QPlainTextEdit(self.tabs) self.source_dirty = False self.wyswyg_dirty = True self._layout = QVBoxLayout(self) self.wyswyg.layout = l = QVBoxLayout(self.wyswyg) self.setLayout(self._layout) l.setContentsMargins(0, 0, 0, 0) if one_line_toolbar: tb = QHBoxLayout() l.addLayout(tb) else: tb = l tb.addWidget(self.toolbar1) tb.addWidget(self.toolbar2) tb.addWidget(self.toolbar3) l.addWidget(self.editor) self._layout.addWidget(self.tabs) self.tabs.addTab(self.wyswyg, _('Normal view')) self.tabs.addTab(self.code_edit, _('HTML Source')) self.tabs.currentChanged[int].connect(self.change_tab) self.highlighter = Highlighter(self.code_edit.document()) self.layout().setContentsMargins(0, 0, 0, 0) # toolbar1 {{{ self.toolbar1.addAction(self.editor.action_undo) self.toolbar1.addAction(self.editor.action_redo) self.toolbar1.addAction(self.editor.action_select_all) self.toolbar1.addAction(self.editor.action_remove_format) self.toolbar1.addAction(self.editor.action_clear) self.toolbar1.addSeparator() for x in ('copy', 'cut', 'paste'): ac = getattr(self.editor, 'action_'+x) self.toolbar1.addAction(ac) self.toolbar1.addSeparator() self.toolbar1.addAction(self.editor.action_background) # }}} # toolbar2 {{{ for x in ('', 'un'): ac = getattr(self.editor, 'action_%sordered_list'%x) self.toolbar2.addAction(ac) self.toolbar2.addSeparator() for x in ('superscript', 'subscript', 'indent', 'outdent'): self.toolbar2.addAction(getattr(self.editor, 'action_' + x)) if x in ('subscript', 'outdent'): self.toolbar2.addSeparator() self.toolbar2.addAction(self.editor.action_block_style) w = self.toolbar2.widgetForAction(self.editor.action_block_style) w.setPopupMode(w.InstantPopup) self.toolbar2.addAction(self.editor.action_insert_link) # }}} # toolbar3 {{{ for x in ('bold', 'italic', 'underline', 'strikethrough'): ac = getattr(self.editor, 'action_'+x) self.toolbar3.addAction(ac) self.toolbar3.addSeparator() for x in ('left', 'center', 'right', 'justified'): ac = getattr(self.editor, 'action_align_'+x) self.toolbar3.addAction(ac) self.toolbar3.addSeparator() self.toolbar3.addAction(self.editor.action_color) # }}} self.code_edit.textChanged.connect(self.code_dirtied) self.editor.page().contentsChanged.connect(self.wyswyg_dirtied) @dynamic_property def html(self): def fset(self, v): self.editor.html = v def fget(self): self.tabs.setCurrentIndex(0) return self.editor.html return property(fget=fget, fset=fset) def change_tab(self, index): # print 'reloading:', (index and self.wyswyg_dirty) or (not index and # self.source_dirty) if index == 1: # changing to code view if self.wyswyg_dirty: self.code_edit.setPlainText(self.editor.html) self.wyswyg_dirty = False elif index == 0: # changing to wyswyg if self.source_dirty: self.editor.html = unicode(self.code_edit.toPlainText()) self.source_dirty = False def wyswyg_dirtied(self, *args): self.wyswyg_dirty = True def code_dirtied(self, *args): self.source_dirty = True def hide_toolbars(self): self.toolbar1.setVisible(False) self.toolbar2.setVisible(False) self.toolbar3.setVisible(False) def set_readonly(self, what): self.editor.set_readonly(what) def hide_tabs(self): self.tabs.tabBar().setVisible(False)
class Editor(QWidget): # {{{ def __init__(self, parent=None, one_line_toolbar=False): QWidget.__init__(self, parent) self.toolbar1 = QToolBar(self) self.toolbar2 = QToolBar(self) self.toolbar3 = QToolBar(self) for i in range(1, 4): t = getattr(self, 'toolbar%d' % i) t.setIconSize(QSize(18, 18)) self.editor = EditorWidget(self) self.tabs = QTabWidget(self) self.tabs.setTabPosition(self.tabs.South) self.wyswyg = QWidget(self.tabs) self.code_edit = QPlainTextEdit(self.tabs) self.source_dirty = False self.wyswyg_dirty = True self._layout = QVBoxLayout(self) self.wyswyg.layout = l = QVBoxLayout(self.wyswyg) self.setLayout(self._layout) l.setContentsMargins(0, 0, 0, 0) if one_line_toolbar: tb = QHBoxLayout() l.addLayout(tb) else: tb = l tb.addWidget(self.toolbar1) tb.addWidget(self.toolbar2) tb.addWidget(self.toolbar3) l.addWidget(self.editor) self._layout.addWidget(self.tabs) self.tabs.addTab(self.wyswyg, _('Normal view')) self.tabs.addTab(self.code_edit, _('HTML Source')) self.tabs.currentChanged[int].connect(self.change_tab) self.highlighter = Highlighter(self.code_edit.document()) # toolbar1 {{{ self.toolbar1.addAction(self.editor.action_undo) self.toolbar1.addAction(self.editor.action_redo) self.toolbar1.addAction(self.editor.action_select_all) self.toolbar1.addAction(self.editor.action_remove_format) self.toolbar1.addAction(self.editor.action_clear) self.toolbar1.addSeparator() for x in ('copy', 'cut', 'paste'): ac = getattr(self.editor, 'action_' + x) self.toolbar1.addAction(ac) self.toolbar1.addSeparator() self.toolbar1.addAction(self.editor.action_background) # }}} # toolbar2 {{{ for x in ('', 'un'): ac = getattr(self.editor, 'action_%sordered_list' % x) self.toolbar2.addAction(ac) self.toolbar2.addSeparator() for x in ('superscript', 'subscript', 'indent', 'outdent'): self.toolbar2.addAction(getattr(self.editor, 'action_' + x)) if x in ('subscript', 'outdent'): self.toolbar2.addSeparator() self.toolbar2.addAction(self.editor.action_block_style) w = self.toolbar2.widgetForAction(self.editor.action_block_style) w.setPopupMode(w.InstantPopup) self.toolbar2.addAction(self.editor.action_insert_link) # }}} # toolbar3 {{{ for x in ('bold', 'italic', 'underline', 'strikethrough'): ac = getattr(self.editor, 'action_' + x) self.toolbar3.addAction(ac) self.toolbar3.addSeparator() for x in ('left', 'center', 'right', 'justified'): ac = getattr(self.editor, 'action_align_' + x) self.toolbar3.addAction(ac) self.toolbar3.addSeparator() self.toolbar3.addAction(self.editor.action_color) # }}} self.code_edit.textChanged.connect(self.code_dirtied) self.editor.page().contentsChanged.connect(self.wyswyg_dirtied) @dynamic_property def html(self): def fset(self, v): self.editor.html = v def fget(self): self.tabs.setCurrentIndex(0) return self.editor.html return property(fget=fget, fset=fset) def change_tab(self, index): #print 'reloading:', (index and self.wyswyg_dirty) or (not index and # self.source_dirty) if index == 1: # changing to code view if self.wyswyg_dirty: self.code_edit.setPlainText(self.editor.html) self.wyswyg_dirty = False elif index == 0: #changing to wyswyg if self.source_dirty: self.editor.html = unicode(self.code_edit.toPlainText()) self.source_dirty = False def wyswyg_dirtied(self, *args): self.wyswyg_dirty = True def code_dirtied(self, *args): self.source_dirty = True def hide_toolbars(self): self.toolbar1.setVisible(False) self.toolbar2.setVisible(False) self.toolbar3.setVisible(False)