This commit is contained in:
Julien Pagès 2015-03-05 23:03:20 +01:00
Родитель 81f94be894
Коммит a52a472afc
4 изменённых файлов: 199 добавлений и 76 удалений

5
.gitignore поставляемый
Просмотреть файл

@ -10,6 +10,5 @@ gui/build/
gui/dist/
gui/venv/
gui/mozregression-gui.spec
gui/ui/intro.py
gui/ui/inbound.py
gui/ui/nightlies.py
gui/ui/*.py
!gui/ui/__init__.py

Просмотреть файл

@ -1,88 +1,31 @@
# Import PySide classes
import sys
from PySide.QtGui import QApplication, QWizard, QWizardPage, QStringListModel
from PySide.QtGui import QApplication, QMainWindow
from PySide.QtCore import Slot
from ui.intro import Ui_Intro
from ui.nightlies import Ui_Nightlies
from ui.inbound import Ui_Inbound
from mozregression.launchers import REGISTRY
from ui.mainwindow import Ui_MainWindow
from wizard import BisectionWizard
class Wizard(QWizardPage):
UI_CLASS = None
TITLE = ''
SUBTITLE = ''
FIELDS = {}
class MainWindow(QMainWindow):
def __init__(self):
QWizardPage.__init__(self)
self.setTitle(self.TITLE)
self.setSubTitle(self.SUBTITLE)
self.ui = self.UI_CLASS()
QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
for name, widget_name in self.FIELDS.iteritems():
self.registerField(name, getattr(self.ui, widget_name))
class IntroPage(Wizard):
UI_CLASS = Ui_Intro
TITLE = "Starting a bisection"
SUBTITLE = "Please choose an application and a type of bisection."
FIELDS = {'application': 'app_combo', 'bisect_type': 'bisect_combo'}
ID = 0
def initializePage(self):
app_model = QStringListModel(REGISTRY.names())
self.ui.app_combo.setModel(app_model)
bisect_model = QStringListModel(['nightlies', 'inbound'])
self.ui.bisect_combo.setModel(bisect_model)
def nextId(self):
if self.ui.bisect_combo.currentText() == 'nightlies':
return NightliesPage.ID
else:
return InboundPage.ID
class NightliesPage(Wizard):
UI_CLASS = Ui_Nightlies
TITLE = "Select the nightlies date range"
FIELDS = {"start_date": "start_date", "end_date": "end_date"}
ID = 1
def initializePage(self):
pass
class InboundPage(Wizard):
UI_CLASS = Ui_Inbound
TITLE = "Select the inbound changesets range"
FIELDS = {"start_changeset": "start_changeset",
"end_changeset": "end_changeset"}
ID = 2
def initializePage(self):
pass
def create_wizard():
wizard = QWizard()
# associate current text to comboboxes fields instead of current index
wizard.setDefaultProperty("QComboBox", "currentText",
"currentIndexChanged")
wizard.addPage(IntroPage())
wizard.addPage(NightliesPage())
wizard.addPage(InboundPage())
return wizard
@Slot()
def start_bisection_wizard(self):
wizard = BisectionWizard(self)
if wizard.exec_() == wizard.Accepted:
print wizard.field_options()
if __name__ == '__main__':
# Create a Qt application
app = QApplication(sys.argv)
# Create the wizard and show it
wizard = create_wizard()
wizard.show()
# Create the main window and show it
win = MainWindow()
win.show()
win.start_bisection_wizard()
# Enter Qt application main loop
sys.exit(app.exec_())

86
gui/ui/mainwindow.ui Normal file
Просмотреть файл

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Mozregression-gui</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>27</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionStart_a_new_bisection"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionStart_a_new_bisection">
<property name="text">
<string>Start a new bisection</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
</property>
</action>
</widget>
<resources/>
<connections>
<connection>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionStart_a_new_bisection</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>start_bisection_wizard()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>start_bisection_wizard()</slot>
</slots>
</ui>

95
gui/wizard.py Normal file
Просмотреть файл

@ -0,0 +1,95 @@
from PySide.QtGui import QWizard, QWizardPage, QStringListModel
from ui.intro import Ui_Intro
from ui.nightlies import Ui_Nightlies
from ui.inbound import Ui_Inbound
from mozregression.launchers import REGISTRY
def get_all_subclasses(cls):
all_subclasses = []
for subclass in cls.__subclasses__():
all_subclasses.append(subclass)
all_subclasses.extend(get_all_subclasses(subclass))
return all_subclasses
class Wizard(QWizardPage):
UI_CLASS = None
TITLE = ''
SUBTITLE = ''
FIELDS = {}
def __init__(self):
QWizardPage.__init__(self)
self.setTitle(self.TITLE)
self.setSubTitle(self.SUBTITLE)
self.ui = self.UI_CLASS()
self.ui.setupUi(self)
for name, widget_name in self.FIELDS.iteritems():
self.registerField(name, getattr(self.ui, widget_name))
class IntroPage(Wizard):
UI_CLASS = Ui_Intro
TITLE = "Starting a bisection"
SUBTITLE = "Please choose an application and a type of bisection."
FIELDS = {'application': 'app_combo', 'bisect_type': 'bisect_combo'}
ID = 0
def initializePage(self):
app_model = QStringListModel(REGISTRY.names())
self.ui.app_combo.setModel(app_model)
bisect_model = QStringListModel(['nightlies', 'inbound'])
self.ui.bisect_combo.setModel(bisect_model)
def nextId(self):
if self.ui.bisect_combo.currentText() == 'nightlies':
return NightliesPage.ID
else:
return InboundPage.ID
class NightliesPage(Wizard):
UI_CLASS = Ui_Nightlies
TITLE = "Select the nightlies date range"
FIELDS = {"start_date": "start_date", "end_date": "end_date"}
ID = 1
def nextId(self):
return -1
class InboundPage(Wizard):
UI_CLASS = Ui_Inbound
TITLE = "Select the inbound changesets range"
FIELDS = {"start_changeset": "start_changeset",
"end_changeset": "end_changeset"}
ID = 2
def nextId(self):
return -1
class BisectionWizard(QWizard):
def __init__(self, parent=None):
QWizard.__init__(self, parent)
self.setWindowTitle("Bisection wizard")
# associate current text to comboboxes fields instead of current index
self.setDefaultProperty("QComboBox", "currentText",
"currentIndexChanged")
self.addPage(IntroPage())
self.addPage(NightliesPage())
self.addPage(InboundPage())
def field_options(self):
options = {}
for wizard_class in get_all_subclasses(Wizard):
for fieldname in wizard_class.FIELDS:
options[fieldname] = self.field(fieldname)
return options