Sun, 06 Jul 2014 14:17:24 +0200
Ported to PyQt5 and eric6.
# -*- coding: utf-8 -*- # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the Inline dialog. """ from __future__ import unicode_literals from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QDialogButtonBox, QAbstractButton import rope.refactor.inline from Ui_InlineDialog import Ui_InlineDialog from RefactoringDialogBase import RefactoringDialogBase class InlineDialog(RefactoringDialogBase, Ui_InlineDialog): """ Class implementing the Inline dialog. """ def __init__(self, refactoring, title, inliner, parent=None): """ Constructor @param refactoring reference to the main refactoring object (Refactoring) @param title title of the dialog (string) @param inliner reference to the inliner object (rope.refactor.inline.InlineMethod, rope.refactor.inline.InlineVariable or rope.refactor.inline.InlineParameter) @param parent reference to the parent widget (QWidget) """ RefactoringDialogBase.__init__(self, refactoring, title, parent) self.setupUi(self) self.__inliner = inliner # polish up the dialog if isinstance(self.__inliner, rope.refactor.inline.InlineParameter): self.removeCheckBox.setVisible(False) self.currentCheckBox.setVisible(False) self.hierarchyCheckBox.setVisible(True) else: self.removeCheckBox.setVisible(True) self.currentCheckBox.setVisible(True) self.hierarchyCheckBox.setVisible(False) self.resize(500, 20) self.description.setText( self.tr("Inlining occurrences of <b>{0}</b> (type {1}).") .format(self.__inliner.name, self.__inliner.get_kind())) self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) self.__previewButton = self.buttonBox.addButton( self.tr("Preview"), QDialogButtonBox.ActionRole) self.__previewButton.setDefault(True) msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) @pyqtSlot(QAbstractButton) def on_buttonBox_clicked(self, button): """ Private slot to act on the button pressed. @param button reference to the button pressed (QAbstractButton) """ if button == self.__previewButton: self.previewChanges() elif button == self.__okButton: self.applyChanges() def _calculateChanges(self, handle): """ Protected method to calculate the changes. @param handle reference to the task handle (rope.base.taskhandle.TaskHandle) @return reference to the Changes object (rope.base.change.ChangeSet) """ try: if isinstance(self.__inliner, rope.refactor.inline.InlineParameter): opts = { "in_hierarchy": self.hierarchyCheckBox.isChecked(), } else: opts = { "remove": self.removeCheckBox.isChecked(), "only_current": self.currentCheckBox.isChecked(), } changes = self.__inliner.get_changes(task_handle=handle, **opts) return changes except Exception as err: self._refactoring.handleRopeError(err, self._title, handle) return None