-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotterWidget.py
110 lines (66 loc) · 2.84 KB
/
plotterWidget.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
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 30 19:00:12 2017
@author: bowman
"""
from guiqwt.plot import CurveDialog, CurveWidget
from guiqwt.builder import make
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from stocksDataRetriver import *
import numpy as np
import matplotlib.pyplot as plt
import random
import sys
''' A Widget that could plot and get a Stock SYmbol when dropped '''
class plotWidget(QWidget):
def __init__(self,parent):
super(plotWidget, self).__init__()
self.setAcceptDrops(True)
# Just some button connected to `plot` method
self.resize(500,500)
self.gWindow = CurveDialog(edit=False, toolbar=True)
self.lay = QHBoxLayout()
self.teditor = QLabel("Hello How are you")
self.lay.addWidget(self.gWindow)
self.setLayout(self.lay)
def plot(self,pdDataFrame):
''' plot some random stuff '''
x1 = pdDataFrame.index
y1 = pdDataFrame['Close']
x = np.linspace(0, 100, 1000)
y = (np.random.rand(len(x))-0.5).cumsum()
curve = make.curve(x1, y1, "ab", "b")
range = make.range(0, 5)
disp2 = make.computations(range, "TL",
[(curve, "min=%.5f", lambda x,y: y.min()),
(curve, "max=%.5f", lambda x,y: y.max()),
(curve, "avg=%.5f", lambda x,y: y.mean())])
legend = make.legend("TR")
# items = [ curve, range, disp2, legend]
items = [curve]
self.plotw = self.gWindow.get_plot()
for item in items:
self.plotw.add_item(item)
# win.show()
def dragEnterEvent(self, event): # Defining the dragENterEvent
event.accept()
def dragMoveEvent(self, event): #Defning the DragMoveEvent
event.accept()
def dropEvent(self, event): #Defininf the Drop Event
stockSymbol = event.mimeData().text() #Getting MimeData Text, this text is set in DragableListWidget
print stockSymbol
if event.mimeData().hasFormat("+Stock+"): #Checking if the dropped item is a stock
#Plotting the StockSymbol
print stockSymbol
stockData = stockDataCollector("AAPL")
pdDataFrame = stockData._getStockdata()
self.plot(pdDataFrame)
else:
event.ignore()
if __name__ == '__main__':
app = QApplication(sys.argv)
main = plotWidget("APPL")
main.show()
sys.exit(app.exec_())