Skip to content

Commit 957e140

Browse files
committed
tab change updates plugin table ref
1 parent 930b24c commit 957e140

File tree

9 files changed

+121
-64
lines changed

9 files changed

+121
-64
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-----
2-
0.6.0
2+
0.5.1
33
-----
44

55
* fix to duplicate sheet bug

tablexplore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .core import *
2-
__version__='0.6.0'
2+
__version__='0.5.1'

tablexplore/app.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(self, project_file=None, csv_file=None, excel_file=None):
102102
self.recent_files = ['']
103103
self.recent_urls = []
104104
self.scratch_items = {}
105+
self.openplugins = {}
105106

106107
self.loadSettings()
107108
self.setTheme()
@@ -210,6 +211,8 @@ def tabSelected(self, index):
210211
#print (table.pf)
211212
#get plot options and update widgets
212213
self.updatePlotWidgets(table)
214+
#update any plugins to use the current table if needed
215+
self.updatePlugins()
213216
return
214217

215218
def updatePlotWidgets(self, table):
@@ -222,6 +225,15 @@ def updatePlotWidgets(self, table):
222225
table.pf.updateData()
223226
return
224227

228+
def updatePlugins(self):
229+
"""Update table for a plugin if it needs it"""
230+
231+
for o in self.openplugins:
232+
print (o)
233+
w = self.getCurrentTable()
234+
self.openplugins[o].table = w
235+
return
236+
225237
def startLogging(self):
226238
"""Logging"""
227239

@@ -1283,9 +1295,9 @@ def loadPlugin(self, plugin):
12831295
index = self.tabs.currentIndex()
12841296
name = self.tabs.tabText(index)
12851297
tablew = self.sheets[name]
1286-
if not hasattr(tablew, 'openplugins'):
1287-
tablew.openplugins = {}
1288-
openplugins = tablew.openplugins
1298+
if not hasattr(self, 'openplugins'):
1299+
self.openplugins = {}
1300+
openplugins = self.openplugins
12891301

12901302
if plugin.name in openplugins:
12911303
p = openplugins[plugin.name]

tablexplore/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def createPlotViewer(self, parent=None):
391391

392392
if self.pf == None:
393393
self.pf = plotting.PlotViewer(table=self.table, parent=parent)
394+
#self.table.selectionModel().selectionChanged.connect(self.pf.updateSeries)
394395
if parent == None:
395396
self.pf.show()
396397
return self.pf

tablexplore/dialogs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ def setColor(self, color):
320320
if self._color:
321321
self.setStyleSheet("background-color: %s;" % self._color)
322322
else:
323-
self.setStyleSheet("")
323+
self.setStyleSheet("")
324+
return
324325

325326
def color(self):
326327
return self._color
@@ -721,7 +722,7 @@ def __init__(self, parent, title=None):
721722
self.setWindowTitle(title)
722723
self.setGeometry(QtCore.QRect(400, 300, 1000, 600))
723724
self.resize(500, 200)
724-
self.layout = QVBoxLayout(self)
725+
self.layout = QVBoxLayout(self)
725726
self.show()
726727
return
727728

tablexplore/plotting.py

Lines changed: 98 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
colormaps = sorted(m for m in plt.cm.datad if not m.endswith("_r"))
5353
markers = ['','o','.','^','v','>','<','s','+','x','p','d','h','*']
5454
linestyles = ['-','--','-.',':']
55+
plotkinds = ['line', 'bar', 'barh', 'scatter', 'pie', 'histogram', 'boxplot', 'violinplot', 'dotplot',
56+
'heatmap', 'area', 'hexbin', 'scatter_matrix', 'density', 'radviz']
5557
valid_kwds = {'line': ['alpha', 'colormap', 'grid', 'legend', 'linestyle','ms',
5658
'linewidth', 'marker', 'subplots', 'rotx', 'logx', 'logy',
5759
'sharex','sharey', 'kind'],
@@ -139,7 +141,7 @@ def __init__(self, table, parent=None):
139141
self.table = table
140142
self.createWidgets()
141143
self.createOptions()
142-
self.seriesopts = SeriesOptions(plotviewer=self)
144+
#self.seriesopts = SeriesOptions(plotviewer=self)
143145
self.currentdir = os.path.expanduser('~')
144146
sizepolicy = QSizePolicy()
145147
self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
@@ -157,7 +159,7 @@ def addPlotWidget(self):
157159
self.toolbar = NavigationToolbar(self.canvas, layout)
158160

159161
#add custom buttons
160-
iconfile = os.path.join(iconpath,'plotseries.png')
162+
#iconfile = os.path.join(iconpath,'plotseries.png')
161163
#a = QAction(QIcon(iconfile), "Customise Series", self)
162164
#a.triggered.connect(self.customiseSeries)
163165
#self.toolbar.addAction(a)
@@ -173,38 +175,68 @@ def addPlotWidget(self):
173175
vbox.addWidget(self.canvas)
174176
return
175177

178+
def updateSeries(self, event=None):
179+
"""Update series with new plots"""
180+
181+
data = self.table.getSelectedDataFrame()
182+
self.seriesopts.series = self.getSeries(data)
183+
return
184+
176185
def customiseSeries(self):
177186
"""
178187
Show custom options for current plot series. Allows plot types to
179188
be specified per series and uses a custom plot function.
180189
"""
181190

182-
data = self.table.getSelectedDataFrame()
183191
if self.seriesopts.series == {}:
184-
self.seriesopts.series = self.getSeries(data)
192+
self.updateSeries()
185193
dlg = self.seriesopts.showDialog(self)
186194
dlg.exec_()
187195
return
188196

189197
def customPlot(self):
190198
"""plot custom series """
191199

200+
self.applyPlotoptions()
201+
self.setStyle()
202+
kwds = self.opts['general'].kwds
203+
formatkwds = self.opts['format'].kwds
204+
kwds.update(formatkwds)
205+
axes_layout = kwds['axes_layout']
206+
lkwds = self.opts['labels'].kwds.copy()
207+
axkwds = self.opts['axes'].kwds
208+
192209
data = self.table.getSelectedDataFrame()
193210
layout='single'
194211
self.clear()
195212
self.ax = self.fig.add_subplot(111)
196213
series = self.seriesopts.series
197214
for s in series:
198215
df = data[s]
199-
kwds = series[s]
200-
kind=kwds['kind']
201-
color = kwds['color']
202-
print (kwds)
203-
df.plot(kind=kind,layout=layout,color=color,ax=self.ax)
216+
skwds = series[s]
217+
kind = skwds['kind']
218+
#skwds = self.check_kwds(skwds, kind)
219+
#print (skwds)
220+
df.plot(layout=layout,ax=self.ax,**skwds)
204221
self.fig.legend()
222+
223+
axs=self.ax
224+
lkwds.update(kwds)
225+
self.setFigureOptions(axs, lkwds)
205226
self.canvas.draw()
206227
return
207228

229+
def check_kwds(self, kwds, kind):
230+
return dict((k, kwds[k]) for k in valid_kwds[kind] if k in kwds)
231+
232+
def colorsfromColormap(self, df, cmap):
233+
"""Column colors from cmap"""
234+
235+
cols = df.columns
236+
clrs = util.gen_colors(cmap,len(cols))
237+
colordict = dict(zip(cols,clrs))
238+
return colordict
239+
208240
def showTools(self):
209241
"""Show/hide tools dock"""
210242

@@ -217,7 +249,6 @@ def showTools(self):
217249
def createWidgets(self):
218250
"""Create widgets. Plot on left and dock for tools on right."""
219251

220-
#self.main = QSplitter(Qt.Horizontal, self)
221252
self.main = QWidget(self)
222253
hbox = QHBoxLayout(self)
223254
self.left = left = QWidget(self.main)
@@ -301,8 +332,7 @@ def replot(self, data=None):
301332
self.data = data
302333

303334
self.applyPlotoptions()
304-
#self.getSeries(data)
305-
335+
#self.updateSeries()
306336
self.setStyle()
307337
self.plotCurrent()
308338
return
@@ -325,13 +355,20 @@ def plotCurrent(self, redraw=True):
325355
def getSeries(self, data):
326356

327357
kwds = self.opts['general'].kwds
328-
ptype = kwds['kind']
358+
fkwds = self.opts['format'].kwds
359+
kwds.update(fkwds)
329360
self.series = series = {}
361+
colordict = self.colorsfromColormap(data, fkwds['colormap'])
362+
#print (colordict)
363+
basekwds = ['kind','marker','ms','linestyle', 'linewidth', 'alpha']
364+
skwds = {k:kwds[k] for k in basekwds}
365+
#print (fkwds)
330366
for c in data.columns:
331-
series[c] = {}
332-
series[c]['kind'] = ptype
333-
series[c]['color'] = ''
334-
#print (self.series)
367+
series[c] = skwds.copy()
368+
#series[c]['kind'] = kind
369+
series[c]['color'] = colordict[c]
370+
print (series[c])
371+
print (self.series)
335372
return series
336373

337374
def applyPlotoptions(self):
@@ -838,7 +875,7 @@ def _doplot(self, data, ax, kind, axes_layout, errorbars, useindex, bw, yerr,
838875
return
839876
#adjust colormap to avoid white lines
840877
if cmap != None:
841-
cmap = util.adjustColorMap(cmap, 0.15,1.0)
878+
#cmap = util.adjustColorMap(cmap, 0.15,1.0)
842879
del kwargs['colormap']
843880
if kind == 'barh':
844881
kwargs['xerr']=yerr
@@ -1456,8 +1493,6 @@ class MPLBaseOptions(BaseOptions):
14561493
"""Class to provide a dialog for matplotlib options and returning
14571494
the selected prefs"""
14581495

1459-
kinds = ['line', 'bar', 'barh', 'scatter', 'pie', 'histogram', 'boxplot', 'violinplot', 'dotplot',
1460-
'heatmap', 'area', 'hexbin', 'scatter_matrix', 'density', 'radviz']
14611496
legendlocs = ['best','upper right','upper left','lower left','lower right','right','center left',
14621497
'center right','lower center','upper center','center']
14631498

@@ -1484,7 +1519,7 @@ def __init__(self):
14841519
'sharex':{'type':'checkbox','default':0,'label':'share x'},
14851520
'sharey':{'type':'checkbox','default':0,'label':'share y'},
14861521
'legend':{'type':'checkbox','default':1,'label':'legend'},
1487-
'kind':{'type':'combobox','default':'line','items':self.kinds,'label':'plot type'},
1522+
'kind':{'type':'combobox','default':'line','items':plotkinds,'label':'plot type'},
14881523
'stacked':{'type':'checkbox','default':0,'label':'stacked'},
14891524
'axes_layout':{'type':'combobox','default':'single','items':layouts,'label':'axes layout'},
14901525
'bins':{'type':'spinbox','default':20,'width':5},
@@ -1686,27 +1721,33 @@ def createSeriesWidgets(self, parent):
16861721

16871722
l = parent.layout
16881723
l.setAlignment(QtCore.Qt.AlignTop)
1689-
kinds= ['line','bar','scatter']
1724+
16901725
row = QWidget()
16911726
l.addWidget(row)
16921727
l2 = QHBoxLayout(row)
1693-
l2.addWidget(QLabel('name'))
1694-
l2.addWidget(QLabel('kind'))
1695-
l2.addWidget(QLabel('color'))
1696-
l2.addWidget(QLabel('linestyle'))
1728+
for i in ['name','kind','color','line style','marker','marker size','alpha']:
1729+
w=QLabel(i)
1730+
l2.addWidget(w)
1731+
#w.setFixedWidth(100)
1732+
kinds = ['line','bar']
16971733
self.widgets = {}
16981734
for s in self.series:
16991735
self.widgets[s] = {}
17001736
opt=self.series[s]
17011737
row = QWidget()
17021738
l.addWidget(row)
17031739
l2 = QHBoxLayout(row)
1704-
l2.addWidget(QLabel(s))
1740+
w=QLabel(s)
1741+
w.setFixedWidth(100)
1742+
l2.addWidget(w)
17051743
w=QComboBox()
17061744
w.addItems(kinds)
17071745
val = self.series[s]['kind']
17081746
index = w.findText(val)
17091747
w.setCurrentIndex(index)
1748+
w.setFixedWidth(80)
1749+
if val not in ['line','bar']:
1750+
w.setEnabled(False)
17101751
l2.addWidget(w)
17111752
self.widgets[s]['kind'] = w
17121753
w = ColorButton()
@@ -1716,8 +1757,36 @@ def createSeriesWidgets(self, parent):
17161757
self.widgets[s]['color'] = w
17171758
w=QComboBox()
17181759
w.addItems(linestyles)
1760+
val = self.series[s]['linestyle']
1761+
index = w.findText(val)
1762+
w.setCurrentIndex(index)
17191763
l2.addWidget(w)
17201764
self.widgets[s]['linestyle'] = w
1765+
w=QSpinBox()
1766+
val = self.series[s]['linewidth']
1767+
w.setValue(int(val))
1768+
l2.addWidget(w)
1769+
self.widgets[s]['linewidth'] = w
1770+
w=QComboBox()
1771+
w.addItems(markers)
1772+
val = self.series[s]['marker']
1773+
index = w.findText(val)
1774+
w.setCurrentIndex(index)
1775+
self.widgets[s]['marker'] = w
1776+
l2.addWidget(w)
1777+
w=QSpinBox()
1778+
val = self.series[s]['ms']
1779+
w.setValue(int(val))
1780+
l2.addWidget(w)
1781+
self.widgets[s]['ms'] = w
1782+
w=QDoubleSpinBox()
1783+
val = self.series[s]['alpha']
1784+
w.setValue(val)
1785+
w.setRange(0,1)
1786+
w.setSingleStep(0.1)
1787+
l2.addWidget(w)
1788+
self.widgets[s]['alpha'] = w
1789+
17211790
return
17221791

17231792
def update(self, event=None):
@@ -1727,37 +1796,12 @@ def update(self, event=None):
17271796
for i in self.widgets[s]:
17281797
w = self.widgets[s][i]
17291798
val = getWidgetValue(w)
1730-
#print (val)
1799+
#print (s,i,val)
17311800
self.series[s][i] = val
1732-
print (self.series)
1801+
#print (self.series)
17331802
self.plotviewer.customPlot()
17341803
return
17351804

17361805
def close(self):
17371806
self.dlg.destroy()
17381807
return
1739-
1740-
class CustomiseDialog(QDialog):
1741-
"""Preferences dialog from config parser options"""
1742-
1743-
def __init__(self, parent, options={}):
1744-
1745-
super(CustomiseDialog, self).__init__(parent)
1746-
self.parent = parent
1747-
self.setWindowTitle('Custom plot')
1748-
self.resize(400, 200)
1749-
self.setGeometry(QtCore.QRect(300,300, 600, 200))
1750-
self.setMaximumWidth(600)
1751-
self.setMaximumHeight(300)
1752-
self.show()
1753-
return
1754-
1755-
def createWidgets(self):
1756-
"""create widgets"""
1757-
1758-
self.tabs = QTabWidget()
1759-
l = self.layout = QVBoxLayout(self)
1760-
l.addWidget(self.tabs)
1761-
w = QWidget()
1762-
idx = self.tabs.addTab(w, 'legend')
1763-
return

tablexplore/plugins/colormaps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def loadCustom(self):
123123
return
124124

125125
def showColorMaps(self):
126-
126+
"""Show sample colormaps"""
127+
127128
cmaps = sorted(m for m in plt.cm.datad if not m.endswith("_r"))
128129
pf = self.table.pf
129130
n=20

tablexplore/plugins/example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def __init__(self, parent=None, table=None):
4444
return
4545
self.parent = parent
4646
self.table = table
47-
self.ID = 'Example Plugin'
4847
self.createWidgets()
4948
return
5049

0 commit comments

Comments
 (0)