Commits

Alain Leufroy committed ddce717

[gui.qt] add the main window definition

Comments (0)

Files changed (4)

ui/gui/__init__.py

+"""
+Graphical User interface parts
+"""

ui/gui/qt/mainwindow.py

+# -*- coding: utf-8 -*-
+"""
+This module contains the Qt user interface for the main window.
+"""
+
+from PyQt4 import QtCore, QtGui
+from limma.ui.gui.qt.utils import load_ui
+
+__all__ = ['MainWindow']
+
+class MainWindow(QtGui.QMainWindow):
+    __Ui__ = load_ui('mainwindow')
+
+    def __init__(self, *ags, **kws):
+        super(MainWindow, self).__init__(*ags, **kws)
+        self._ui = self.__Ui__()
+        self._ui.setupUi(self)
+
+# used for tests
+if __name__ == '__main__':
+    import sys
+    app = QtGui.QApplication(sys.argv)
+    main_window = MainWindow()
+    main_window.show()
+    sys.exit(app.exec_())
+

ui/gui/qt/uis/mainwindow.ui

+<?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>572</width>
+    <height>489</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="container">
+   <layout class="QVBoxLayout" name="verticalLayout_2"/>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>572</width>
+     <height>23</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuFile">
+    <property name="title">
+     <string>File</string>
+    </property>
+    <addaction name="quited"/>
+   </widget>
+   <addaction name="menuFile"/>
+  </widget>
+  <action name="quited">
+   <property name="text">
+    <string>Quit</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+Q</string>
+   </property>
+  </action>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>quited</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>285</x>
+     <y>244</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>

ui/gui/qt/utils.py

+"""
+This module contains usefull funtions for the Qt user interface.
+"""
+# XXX the actual implementation is not compatible with py2exe
+# as the .ui files are searched within this package folder
+
+import os.path as osp
+from PyQt4.uic import loadUiType
+
+__all__ = ['load_ui']
+
+_HERE = __file__
+_UIPATH = osp.join(osp.dirname(osp.abspath(__file__)), 'uis')
+_UIEXT = 'ui'
+
+def get_ui(ui_name):
+    """Return the absolute path of the .ui file of the given ui name"""
+    filepath = osp.join(_UIPATH, osp.extsep.join((ui_name, _UIEXT)))
+    if not osp.isfile(filepath):
+        raise OSError('Qt designer .ui file not found: ' % filepath)
+    return filepath
+
+def load_ui(ui_name):
+    """Return the ui class of the given interface name"""
+    filepath = get_ui(ui_name)
+    return loadUiType(filepath)[0]
+