def edit_cell ( self, parent, row, column ): """ Returns the editor widget to use for editing a specified cell's value. """ self.cell_row = self.data_row_for( row ) # Get the editor factory to use. If none, exit (read-only cell): editor_factory = self.grid_adapter.get_editor( self.cell_row, column ) if editor_factory is None: return None # Create the requested type of editor from the editor factory: # Note: We save the editor reference so that the editor doesn't get # garbage collected too soon. self.cell_column = column object, name = self.grid_adapter.get_alias( self.cell_row, column ) editor = editor_factory.simple_editor( self.ui, object, name, '' ).set( item = self.item, object_name = '' ) # Tell the editor to actually build the editing widget: editor.prepare( control_adapter( parent ) ) # Make sure that the editor is a control (and not a layout): self._editor = editor control = editor.control if not isinstance( control, QWidget ): layout = control control = QWidget( parent ) control.setLayout( layout ) layout.setContentsMargins( 5, 0, 5, 0 ) control._editor = editor # Adjust the row height of the grid row to fit the editor control: height = control.height() if height > self.height: if (self.height - height) <= 4: # If the difference is not too great, then we will just adjust # the grid height to accomodate it: self.row_height( height ) else: # Otherwise, just adjust the height of this row temporarily: control._row = row self.control.verticalHeader().resizeSection( row, height ) # Resize the grid column width to fit the editor if necessary: width = control.width() header = self.control.horizontalHeader() column_width = header.sectionSize( column ) if width > column_width: control._column = column control._width = column_width header.resizeSection( column, width ) # Return the editing widget as the result: return control
def __init__(self): generic.GenericGui.__init__(self) window = QWidget() window.setWindowTitle('quichem-pyside') self.compiler_view = QListWidget() self.compiler_view.currentRowChanged.connect(self.show_source) self.stacked_widget = QStackedWidget() self.stacked_widget.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) self.edit = QLineEdit() self.edit.setPlaceholderText('Type quichem input...') self.edit.textChanged.connect(self.change_value) self.view = QWebView() self.view.page().mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff) self.view.page().action(QWebPage.Reload).setVisible(False) self.view.setMaximumHeight(0) self.view.setUrl('qrc:/web/page.html') self.view.setZoomFactor(2) self.view.page().mainFrame().contentsSizeChanged.connect( self._resize_view) # For debugging JS: ## from PySide.QtWebKit import QWebSettings ## QWebSettings.globalSettings().setAttribute( ## QWebSettings.DeveloperExtrasEnabled, True) button_image = QPushButton('Copy as Image') button_image.clicked.connect(self.set_clipboard_image) button_image.setToolTip('Then paste into any graphics program') button_word = QPushButton('Copy as MS Word Equation') button_word.clicked.connect(self.set_clipboard_word) button_html = QPushButton('Copy as Formatted Text') button_html.clicked.connect(self.set_clipboard_html) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) button_layout = QHBoxLayout() button_layout.addStretch() button_layout.addWidget(button_image) button_layout.addWidget(button_word) button_layout.addWidget(button_html) source_layout = QHBoxLayout() source_layout.addWidget(self.compiler_view) source_layout.addWidget(self.stacked_widget, 1) QVBoxLayout(window) window.layout().addWidget(self.edit) window.layout().addWidget(self.view) window.layout().addLayout(button_layout) window.layout().addWidget(line) window.layout().addLayout(source_layout, 1) window.show() window.resize(window.minimumWidth(), window.height()) # To prevent garbage collection of internal Qt object. self._window = window