Skip to content

Commit e248d8a

Browse files
committed
Fix: The correct chart was not loaded by default in cas of multiple files loaded
1 parent dae9ae2 commit e248d8a

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

Controller.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
from observers.SkinokObserver import SkinokObserver
3939
from wallet import Wallet
4040

41+
42+
4143
class Controller:
4244

4345
def __init__(self):
@@ -64,6 +66,9 @@ def __init__(self):
6466
# Once everything is created, initialize data
6567
self.interface.initialize()
6668

69+
# Timeframes
70+
self.timeFrameIndex = {"M1" : 0, "M5" : 10, "M15": 20, "M30": 30, "H1":40, "H4":50, "D":60, "W":70}
71+
6772
pass
6873

6974

@@ -127,12 +132,16 @@ def loadData(self, dataPath, datetimeFormat, separator):
127132

128133
return True, ""
129134

130-
def importData(self, fileNamesOrdered):
135+
def importData(self, fileNames):
131136

132137
try:
138+
139+
# Sort data by timeframe
140+
# For cerebro, we need to add lower timeframes first
141+
fileNames.sort( key=lambda x: self.timeFrameIndex[self.findTimeFrame(self.dataframes[x])])
133142

134143
# Files should be loaded in the good order
135-
for fileName in fileNamesOrdered:
144+
for fileName in fileNames:
136145

137146
df = self.dataframes[fileName]
138147

@@ -145,7 +154,7 @@ def importData(self, fileNamesOrdered):
145154
# Add data to cerebro : only add data when all files have been selected for multi-timeframes
146155
self.cerebro.adddata(self.data) # Add the data feed
147156

148-
# find the time frame
157+
# Find timeframe
149158
timeframe = self.findTimeFrame(df)
150159

151160
# Create the chart window for the good timeframe (if it does not already exists?)
@@ -159,14 +168,16 @@ def importData(self, fileNamesOrdered):
159168

160169
return True
161170

171+
except AttributeError as e:
172+
print("AttributeError error:" + str(e))
173+
except KeyError as e:
174+
print("KeyError error:" + str(e))
162175
except:
163-
164176
print("Unexpected error:" + str(sys.exc_info()[0]))
165177
return False
166-
167178
pass
168179

169-
def findTimeFrame(self,df):
180+
def findTimeFrame(self, df):
170181

171182
if len(df.index) > 2:
172183
dtDiff = df.index[1] - df.index[0]

loadDataFilesUI.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def importFiles(self):
8181
for x in range(self.dataFilesListWidget.count()):
8282
items.append(self.dataFilesListWidget.item(x).text())
8383

84+
# Sort item by timeframe
85+
86+
8487
# Give all ordered data path to the controller
8588
if self.controller.importData(items):
8689
self.dataFilesListWidget.clear()

userInterface.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ def createChartDock(self, timeframe):
139139
self.timeFramePB[timeframe].setCheckable(True)
140140
self.timeFramePB[timeframe].setMaximumWidth(100)
141141
self.timeFramePB[timeframe].toggled.connect(lambda: self.toogleTimeframe(timeframe) )
142-
self.controlPanelLayout.insertWidget(0,self.timeFramePB[timeframe])
142+
self.timeFramePB[timeframe].toggle()
143143

144-
self.stackedCharts.setCurrentIndex(0)
144+
self.controlPanelLayout.insertWidget(0,self.timeFramePB[timeframe])
145145

146146
# init checked after connecting the slot
147147
if self.darkmodeCB.isChecked():
@@ -625,13 +625,13 @@ def dark_mode_toggle(self):
625625
##########
626626
def toogleTimeframe(self, timeframe):
627627

628-
print("Display " + timeframe)
629-
self.current_timeframe = timeframe
630-
631-
self.stackedCharts.setCurrentIndex( self.stackedCharts.indexOf( self.dockAreaTimeframes[timeframe]) )
628+
if self.timeFramePB[timeframe].isChecked():
629+
print("Display " + timeframe)
630+
self.current_timeframe = timeframe
631+
index = self.stackedCharts.indexOf( self.dockAreaTimeframes[timeframe])
632+
self.stackedCharts.setCurrentIndex( index )
633+
self.togglePnLWidget()
632634

633-
self.togglePnLWidget()
634-
635635
pass
636636

637637
def togglePnLWidget(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy