def _showInfo(self, index): if self.infoLayout == None: self.infoLayout = SInfoLayout(cols=1) self.infoLayout.row_force_default = True self.infoLayout.row_default_height = 20 self.infoLayout.col_force_default = True self.infoLayout.padding = [2, 1, 2, 1] self.infoLayout.size_hint = (None, None) else: self.infoLayout.clear_widgets() if self.infoLayout.parent == None: self.layout.add_widget(self.infoLayout) aKey = self.keyList[self.scopeIdx[0] + index] aDict = self.dataDict.get(aKey) self.infoLayout.add_widget(self.info_time) self.info_time.text = sutil.formatDateTime(aKey) self.infoLayout.add_widget(self.info_vol) volume = aDict.get("VOL") valueStr = None if self.formatType == 1: valueStr = ("{:7.2f}".format(volume)).strip() elif self.formatType == 2: valueStr = "${:,}".format(volume) else: valueStr = str(volume) self.info_vol.text = valueStr maxLength = len(self.info_time.text) if maxLength < schartutil.calcCharNum(self.info_vol.text): maxLength = schartutil.calcCharNum(self.info_vol.text) layoutWidth = schartutil.getInfoLayoutWidth(maxLength) self.infoLayout.col_default_width = layoutWidth self.infoLayout.size = [layoutWidth, 44] x1 = self.chartPos[0] + (index + 1) * (self.tickWide + self.tickGap) - self.backGap halfNum = int(self.dispNum / 2) if index > halfNum: pos_x = x1 - self.infoLayout.width else: pos_x = x1 + 5 pos_y = self.chartPos[1] + self.chartSize[1] - self.infoLayout.height self.infoLayout.pos = (pos_x, pos_y)
def _showInfo(self, index): if self.infoLayout == None: self.infoLayout = SInfoLayout(cols=1) self.infoLayout.row_force_default = True self.infoLayout.row_default_height = 20 self.infoLayout.col_force_default = True self.infoLayout.col_default_width = 90 self.infoLayout.size = [90, 64] self.infoLayout.padding = [2, 1, 2, 1] self.infoLayout.size_hint = (None, None) else: self.infoLayout.clear_widgets() if self.infoLayout.parent == None: self.layout.add_widget(self.infoLayout) x1 = self.start_xaxis + index * self.xscale halfNum = int(self.chartNum / 2) if index > halfNum: pos_x = x1 - self.infoLayout.width else: pos_x = x1 + 5 pos_y = self.volume_yaxis + self.crossLine_height - self.infoLayout.height self.infoLayout.pos = (pos_x, pos_y) dataDict = self.minTimeList[index] self.infoLayout.add_widget(self.info_time) self.info_time.text = "時:" + sutil.formatTime(dataDict.get("TD")) price = dataDict.get("CloseP") self.infoLayout.add_widget(self.info_price) self.info_price.text = "價:" + ("{:7.2f}".format(price)).strip() self.info_price.color = self._getPriceColor(self.yesPrice, price) self.infoLayout.add_widget(self.info_vol) self.info_vol.text = "量:" + ("{:13.0f}".format( dataDict.get("Vol"))).strip()
def mousePos(self, *args): if len(args) >= 2: key = None xcord = None if len(self.profitPerNumDict) != 0 and len(self.xcordDict) != 0: for xkey in self.xcordDict.keys(): xcord = self.xcordDict.get(xkey) if args[1][0] < (xcord + 0.5) and args[1][0] < (xcord - 0.5): key = int(xkey) break if key == None: self.clearCrossLineAndInfo() return aNum = self.profitPerNumDict.get(str(key)) if aNum == None: self.clearCrossLineAndInfo() return self.drawCrossLine(str(key)) if self.infoLayout == None: self.infoLayout = SInfoLayout(cols=1) self.infoLayout.row_force_default = True self.infoLayout.row_default_height = 20 self.infoLayout.col_force_default = True self.infoLayout.col_default_width = 110 self.infoLayout.padding = [2, 1, 2, 1] self.infoLayout.size_hint = (None, None) else: self.infoLayout.clear_widgets() if self.infoLayout.parent == None: self.add_widget(self.infoLayout) index = key - self.min_tickNum center_pos = int(self.pillarPoint / 2) if key == 0: shift_xpos = self.ycordWidth elif key > 0: shift_xpos = self.ycordWidth * 2 else: shift_xpos = 0 x1 = int(self.pos[0] + self.shift_left + index * self.pillarSumPoint + shift_xpos + center_pos) if (self.width - x1) < (self.infoLayout.width + self.shift_right): pos_x = x1 - self.infoLayout.width else: pos_x = x1 + 5 y1 = int(self.pos[1] + self.shift_bottom + aNum * self.yscale) if (self.height - y1) < (self.infoLayout.height + self.shift_top): pos_y = y1 - self.infoLayout.height else: pos_y = y1 + 5 self.infoLayout.pos = (pos_x, pos_y) self.info_tradeNum = SLabel(text="") #交易次數 self.info_tradeNum.color = self.TRADE_INFO_FGCOLOR self.info_profitPer = SLabel(text="") #獲利率 self.info_profitPer.color = self.TRADE_INFO_FGCOLOR rowNum = 1 self.infoLayout.add_widget(self.info_profitPer) self.info_profitPer.text = "獲利率:" + str(key) + "%" rowNum += 1 self.infoLayout.add_widget(self.info_tradeNum) self.info_tradeNum.text = "交易次數:" + str(aNum) self.infoLayout.size = (110, rowNum * 20)
def mousePos(self, *args): if len(args) >= 2: if self.dataList != None and len(self.dataList) != 0: index = int( (args[1][0] - self.pos[0] - self.shift_left) / self.xscale) if index < len(self.dataList) and index >= 0: data = self.dataList[index] dateStr = str(data.get("date")) timeStr = str(data.get("time")) price = data.get("price") self.drawCrossLine(index) if self.infoLayout == None: self.infoLayout = SInfoLayout(cols=1) self.infoLayout.row_force_default = True self.infoLayout.row_default_height = 20 self.infoLayout.col_force_default = True self.infoLayout.col_default_width = 110 self.infoLayout.padding = [2, 1, 2, 1] self.infoLayout.size_hint = (None, None) else: self.infoLayout.clear_widgets() if self.infoLayout.parent == None: self.add_widget(self.infoLayout) x1 = int(self.pos[0] + self.shift_left + index * self.xscale) if (self.width - x1) < (self.infoLayout.width + self.shift_right): pos_x = x1 - self.infoLayout.width else: pos_x = x1 + 5 y1 = int(self.pos[1] + self.shift_bottom + (price - self.min_price) * self.yscale) if (self.height - y1) < (self.infoLayout.height + self.shift_top): pos_y = y1 - self.infoLayout.height else: pos_y = y1 + 5 self.infoLayout.pos = (pos_x, pos_y) rowNum = 1 self.infoLayout.add_widget(self.info_date) self.info_date.text = sutil.formatDate(dateStr) if timeStr != "" and timeStr != "0": rowNum += 1 self.infoLayout.add_widget(self.info_time) self.info_time.text = sutil.formatTime(timeStr) rowNum += 1 self.infoLayout.add_widget(self.info_price) self.info_price.text = "價:" + ( "{:7.2f}".format(price)).strip() rowNum += 1 self.infoLayout.add_widget(self.info_vol) self.info_vol.text = "量:" + ("{:13.0f}".format( data.get("vol"))).strip() rowNum += 1 self.infoLayout.add_widget(self.info_amt) self.info_amt.text = "金:" + ("{:13.0f}".format( data.get("amt"))).strip() bs = data.get("bs") bsprice = data.get("bsprice") if bs != "": rowNum += 1 self.infoLayout.add_widget(self.info_bs) self.info_bs.text = bs + ":" + ( "{:7.2f}".format(bsprice)).strip() self.infoLayout.size = (110, rowNum * 20) else: self.canvas.remove_group("cross_line") if self.infoLayout != None: if self.infoLayout.parent != None: self.remove_widget(self.infoLayout)