This repository was archived by the owner on Feb 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwidgets.py
More file actions
146 lines (106 loc) · 3.73 KB
/
widgets.py
File metadata and controls
146 lines (106 loc) · 3.73 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# -*- coding: utf-8 -*-
"""
widgets used by spread builder
Copyright 2015 Jev Kuznetsov
licence : BSD
"""
from PyQt4.QtCore import Qt
from PyQt4.QtGui import *
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
from tradingWithPython_dev.lib import qtpandas
from scratchpad import fakeData
class Dock(QDockWidget):
""" Simplified interface to QDockWidget.
"""
def __init__(self, title, parent, childType,
area=Qt.LeftDockWidgetArea,
allowedAreas=Qt.AllDockWidgetAreas,
autoAddDock=True,
features=QDockWidget.AllDockWidgetFeatures):
""" Constructor.
Parameters
------------
title : dock title
parent : ancestor widget
childType : callable to produce child widget
area : default dock area
allowedAreas : dock widget allowed areas
autoAddDock : if True, dock widget is added to parent
features : dock widget features
"""
QDockWidget.__init__(self, title, parent)
self.setObjectName(title)
#self.setAllowedAreas(allowedAreas)
self.setFeatures(features)
self.setWidget(childType(self))
if autoAddDock:
parent.addDockWidget(area, self)
class SymbolsList(QListWidget):
"""
list of stock symbols
"""
def __init__(self, parent=None):
QListWidget.__init__(self,parent)
self.setMaximumWidth(80)
self.setContextMenuPolicy(Qt.ActionsContextMenu)
def setSymbols(self,symbols):
self.clear()
for symbol in symbols:
self.addItem(symbol)
class PlotWidget(QWidget):
"""
matplotlib plot widget
"""
def __init__(self,parent):
super(PlotWidget,self).__init__(parent)
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
self.ax = self.figure.add_subplot(111) # create an axis
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
self.setLayout(layout)
def clear(self):
self.ax.cla()
def test(self):
""" plot random data """
df = fakeData()
#self.ax.hold(False) # discard old data
#self.ax.plot(df,'o-')
self.clear()
df.plot(ax=self.ax)
self.canvas.draw()
class SpreadWidget(QWidget):
""" main widget for working with spreads """
def __init__(self,parent):
super(SpreadWidget,self).__init__(parent)
self.table = qtpandas.DataFrameWidget(self)
self.plot = PlotWidget(self)
layout = QVBoxLayout()
#layout.addWidget(self.table)
layout.addWidget(self.plot)
self.setLayout(layout)
def test(self):
self.plot.test()
# --------------------------- test code -------------------------------
class MainWindow(QDialog):
def __init__(self):
super(MainWindow, self).__init__()
widget = SpreadWidget(self)
button = QPushButton('Test')
button.clicked.connect(widget.test)
layout = QVBoxLayout()
layout.addWidget(widget)
layout.addWidget(button)
self.setLayout(layout)
if __name__ == '__main__':
print 'starting'
import sys
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
print 'done.'