-
Notifications
You must be signed in to change notification settings - Fork 3
/
opensomething.py
62 lines (46 loc) · 1.7 KB
/
opensomething.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vim: tabstop=4:softtabstop=4:shiftwidth=4:expandtab
"""
OpenSomething: Qt widget to open a file
"""
from __future__ import print_function
from __future__ import division
import os, sys
# Importing all the stuff for the IPython console widget
from PyQt4 import QtGui, QtCore
# Importing all the stuff for the matplotlib widget
import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.figure import Figure
# Numpy etc.
import numpy as np
class OpenSomethingWidget(QtGui.QWidget):
"""
The open-something Widget. First shown in the main window, if it is not
started with a command to open any file to begin with. This way, we don't
have to show an empty graph
"""
def __init__(self, parent=None, openFile=None, **kwargs):
super(OpenSomethingWidget, self).__init__(parent, **kwargs)
self.parent = parent
self.openFileFn = openFile
self.initOSWidget()
def initOSWidget(self):
"""
Initialise the widget with a button and a label
"""
self.vbox = QtGui.QVBoxLayout()
button = QtGui.QPushButton("Open a file...")
button.clicked.connect(self.openFile)
self.vbox.addWidget(button)
self.setLayout(self.vbox)
def openFile(self):
"""
Display the open file dialog, and send the parent window the order to
open the file
"""
if not self.openFileFn is None:
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '~/')
self.openFileFn(filename)