From dec88884c9767ccba25530c82e581fa733905234 Mon Sep 17 00:00:00 2001 From: Damien Farrell Date: Sat, 2 Oct 2021 20:44:51 +0100 Subject: [PATCH] plot style pref --- CHANGES | 4 ++++ tablexplore/app.py | 11 +++++++---- tablexplore/core.py | 11 +++++++++++ tablexplore/dialogs.py | 29 ++++++++++++++++++----------- tablexplore/plotting.py | 2 +- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index 746a161..f42b336 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,10 @@ * fix to saving when filtered * align header labels left +* remember current sheet when saving +* added enlarge/reduce buttons to plotter +* icon size preference +* fix to plot style ----- 0.4.0 diff --git a/tablexplore/app.py b/tablexplore/app.py index a2a55e5..1b6c910 100755 --- a/tablexplore/app.py +++ b/tablexplore/app.py @@ -105,6 +105,7 @@ def loadSettings(self): core.COLUMNWIDTH = int(s.value("columnwidth")) core.TIMEFORMAT = s.value("timeformat") core.SHOWPLOTTER = util.valueToBool(s.value("showplotter")) + core.PLOTSTYLE = s.value("plotstyle") core.ICONSIZE = int(s.value("iconsize")) r = s.value("recent_files") if r != '': @@ -129,6 +130,7 @@ def saveSettings(self): self.settings.setValue('fontsize', core.FONTSIZE) self.settings.setValue('timeformat', core.TIMEFORMAT) self.settings.setValue('showplotter', core.SHOWPLOTTER) + self.settings.setValue('plotstyle', core.PLOTSTYLE) self.settings.setValue('recent_files',','.join(self.recent_files)) self.settings.setValue('recent_urls','^^'.join(self.recent_urls)) if hasattr(self, 'plotgallery'): @@ -566,7 +568,7 @@ def saveMeta(self, tablewidget): #print (meta['plotviewer']) #save child table if present if tablewidget.subtable != None: - meta['subtable'] = tablewidget.subtable.table.model.df + meta['subtable'] = tablewidget.subtable.table.model.df return meta @@ -710,13 +712,14 @@ def addSheet(self, name=None, df=None, meta=None): dfw = DataFrameWidget(sheet, dataframe=df, app=self, font=core.FONT, fontsize=core.FONTSIZE, columnwidth=core.COLUMNWIDTH, timeformat=core.TIMEFORMAT) - sheet.addWidget(dfw) - + sheet.addWidget(dfw) self.sheets[name] = dfw self.currenttable = dfw pf = dfw.createPlotViewer(sheet) sheet.addWidget(pf) sheet.setSizes((500,1000)) + pf.generalopts.setWidgetValue('style', core.PLOTSTYLE) + #pf.applyPlotoptions() #reload attributes of table and plotter if present if meta != None: self.loadMeta(dfw, meta) @@ -1088,7 +1091,7 @@ def preferences(self): from . import dialogs opts = {'font':core.FONT, 'fontsize':core.FONTSIZE, 'showplotter': core.SHOWPLOTTER, - 'iconsize':core.ICONSIZE, + 'iconsize':core.ICONSIZE, 'plotstyle':core.PLOTSTYLE, 'columnwidth':core.COLUMNWIDTH, 'timeformat':core.TIMEFORMAT} dlg = dialogs.PreferencesDialog(self, opts) dlg.exec_() diff --git a/tablexplore/core.py b/tablexplore/core.py index 5e7d428..0587067 100644 --- a/tablexplore/core.py +++ b/tablexplore/core.py @@ -42,6 +42,7 @@ ROWHEIGHT = 20 SHOWPLOTTER = True ICONSIZE = 26 +PLOTSTYLE = 'default' try: _fromUtf8 = QtCore.QString.fromUtf8 @@ -1384,6 +1385,16 @@ def getSelectedDataFrame(self): cols = list(dict.fromkeys(cols).keys()) return df.iloc[rows,cols] + def setSelected(self, row, col): + """Set selection programmatically""" + + + top = self.model.index(row, 0) + lower = self.model.index(row, col) + selection = QItemSelection(top, lower) + self.selectionModel().select(selection, SelectionFlag.ClearAndSelect) + return + def handleDoubleClick(self, item): cellContent = item.data() diff --git a/tablexplore/dialogs.py b/tablexplore/dialogs.py index 4cbd503..22a5b3a 100644 --- a/tablexplore/dialogs.py +++ b/tablexplore/dialogs.py @@ -1146,7 +1146,7 @@ def __init__(self, parent, options={}): super(PreferencesDialog, self).__init__(parent) self.parent = parent self.setWindowTitle('Preferences') - self.resize(700, 200) + self.resize(450, 200) self.setGeometry(QtCore.QRect(300,300, 600, 200)) self.setMaximumWidth(600) self.setMaximumHeight(300) @@ -1169,22 +1169,28 @@ def createWidgets(self, options): '%d-%b-%Y','%b-%d-%Y', '%Y-%m-%d %H:%M:%S','%Y-%m-%d %H:%M', '%d-%m-%Y %H:%M:%S','%d-%m-%Y %H:%M'] - self.opts = {'rowheight':{'type':'spinbox','default':18,'range':(5,50),'label':'row height'}, - 'columnwidth':{'type':'spinbox','range':(10,300), - 'default': options['columnwidth'], 'label':'column width'}, - 'alignment':{'type':'combobox','default':'w','items':['left','right','center'],'label':'text align'}, + plotstyles = ['','default', 'classic', 'fivethirtyeight', + 'seaborn-pastel','seaborn-whitegrid', 'ggplot','bmh', + 'grayscale','dark_background'] + self.opts = {'rowheight':{'type':'spinbox','default':18,'range':(5,50),'label':'Row height'}, + #'columnwidth':{'type':'spinbox','range':(10,300), + #'default': options['columnwidth'], 'label':'column width'}, + 'alignment':{'type':'combobox','default':'w','items':['left','right','center'],'label':'Text Align'}, 'font':{'type':'font','default':defaultfont,'default':options['font']}, 'fontsize':{'type':'spinbox','default':options['fontsize'],'range':(5,40), 'interval':1,'label':'font size'}, 'timeformat':{'type':'combobox','default':options['timeformat'], 'items':timeformats,'label':'Date/Time format'}, - 'showplotter': {'type':'checkbox','default':bool(options['showplotter']), 'label':'show plotter'}, - 'iconsize':{'type':'spinbox','default':options['iconsize'],'range':(16,64), 'label':'icon size'}, + 'showplotter': {'type':'checkbox','default':bool(options['showplotter']), 'label':'Show Plotter'}, + 'plotstyle':{'type':'combobox','default':options['plotstyle'], + 'items':plotstyles,'label':'Plot Style'}, + 'iconsize':{'type':'spinbox','default':options['iconsize'],'range':(16,64), 'label':'Icon Size'}, #'floatprecision':{'type':'spinbox','default':2, 'label':'precision'}, } - sections = {'table':['alignment','rowheight','columnwidth'], - 'view':['iconsize','showplotter'], - 'formats':['font','fontsize','timeformat']} + sections = {'table':['alignment','rowheight',#'columnwidth', + 'font','fontsize','timeformat'], + 'view':['iconsize','plotstyle','showplotter'] + } dialog, self.widgets = dialogFromOptions(self, self.opts, sections) @@ -1214,9 +1220,10 @@ def apply(self): from . import core core.FONT = kwds['font'] core.FONTSIZE = kwds['fontsize'] - core.COLUMNWIDTH = kwds['columnwidth'] + #core.COLUMNWIDTH = kwds['columnwidth'] core.TIMEFORMAT = kwds['timeformat'] core.SHOWPLOTTER = kwds['showplotter'] + core.PLOTSTYLE = kwds['plotstyle'] core.ICONSIZE = kwds['iconsize'] self.parent.refresh() self.parent.applySettings() diff --git a/tablexplore/plotting.py b/tablexplore/plotting.py index ea5b44d..7c82424 100644 --- a/tablexplore/plotting.py +++ b/tablexplore/plotting.py @@ -873,7 +873,7 @@ def _doplot(self, data, ax, kind, axes_layout, errorbars, useindex, bw, yerr, def setStyle(self): """Apply style""" - if self.style == None: + if self.style == None or self.style == '': mpl.rcParams.update(mpl.rcParamsDefault) else: plt.style.use(self.style)