def addListRow(self, alist): rowList = [] funcLayout = SBoxLayout(size_hint=(.15, None), height=30) funcLayout.orientation = "horizontal" funcLayout.padding = (1, 1, 1, 1) funcLayout.add_widget(BoxLayout(size_hint=(.1, 1))) btn = SInfoButton(extra_info=alist[0], text="刪", size_hint=(.8, 1)) btn.halign = "center" btn.valign = "middle" btn.bind(on_release=self.deleteRecordPopup) funcLayout.add_widget(btn) funcLayout.add_widget(BoxLayout(size_hint=(.1, 1))) rowList.append(funcLayout) self.contentLayout.add_widget(funcLayout) contentLabel = SContentLabel(text=alist[0][2:], size_hint=(.2, None), height=30) contentLabel.color = colorHex("#000000") contentLabel.halign = "center" contentLabel.valign = "middle" rowList.append(contentLabel) self.contentLayout.add_widget(contentLabel) contentLabel = SContentLabel(text=alist[1], size_hint=(.65, None), height=30) contentLabel.color = colorHex("#000000") contentLabel.halign = "left" contentLabel.valign = "middle" rowList.append(contentLabel) self.contentLayout.add_widget(contentLabel) self.def_ids[alist[0]] = rowList
def on_mouse_pos(self, *args): if not self.get_root_window(): return pos = args[1] if self.collide_point(*self.to_widget(*pos)): if self.isMouseInFlag == True: return else: self.isMouseInFlag = True self.color = colorHex("#0000FF") self.suniteMenu.removeMenu() if self.text == "用戶中心": self.menuLayout = self.suniteMenu.userMenu(self) elif self.text == "交易執行": self.menuLayout = self.suniteMenu.executeMenu(self) elif self.text == "交易分析": self.menuLayout = self.suniteMenu.analyzeMenu(self) else: if self.isMouseInFlag == True: self.isMouseInFlag = False self.color = colorHex("#000000") if self.menuLayout != None: layoutWidth_posX = self.menuLayout.pos[ 0] + self.menuLayout.size[0] if pos[1] > self.pos[1] or pos[1] < self.menuLayout.pos[ 1] or pos[0] < self.pos[0] or pos[ 0] > layoutWidth_posX: self.suniteMenu.removeMenu()
def on_mouse_pos(self, *args): if not self.get_root_window(): return pos = args[1] if self.collide_point(*self.to_widget(*pos)): self.color = colorHex("#FFFFFF") else: self.color = colorHex("#000000")
def addListRow(self, alist, aflag): if aflag: self.deleteRow(self.maxIndex) rowList = [] funcLayout = SBoxLayout(size_hint=(.15, None), height=30) funcLayout.orientation = "horizontal" funcLayout.padding = (1, 1, 1, 1) funcLayout.add_widget(BoxLayout(size_hint=(.09, 1))) btn = SInfoButton(extra_info=self.maxIndex, text="修", size_hint=(.4, 1)) btn.halign = "center" btn.valign = "middle" btn.bind(on_release=self.updateRecordPopup) funcLayout.add_widget(btn) funcLayout.add_widget(BoxLayout(size_hint=(.02, 1))) btn = SInfoButton(extra_info=self.maxIndex, text="刪", size_hint=(.4, 1)) btn.halign = "center" btn.valign = "middle" btn.bind(on_release=self.deleteRecordPopup) if alist[0] == "證券普通股" or alist[0] == "台指期貨": btn.disabled = True funcLayout.add_widget(btn) funcLayout.add_widget(BoxLayout(size_hint=(.09, 1))) rowList.append(funcLayout) self.contentLayout.add_widget(funcLayout) contentLabel = SContentLabel(text=alist[0], size_hint=(.4, None), height=30) contentLabel.color = colorHex("#000000") contentLabel.halign = "left" contentLabel.valign = "middle" rowList.append(contentLabel) self.contentLayout.add_widget(contentLabel) contentLabel = SContentLabel(text=alist[1], size_hint=(.25, None), height=30) contentLabel.color = colorHex("#000000") contentLabel.halign = "right" contentLabel.valign = "middle" rowList.append(contentLabel) self.contentLayout.add_widget(contentLabel) contentLabel = SContentLabel(text=alist[2], size_hint=(.2, None), height=30) contentLabel.color = colorHex("#000000") contentLabel.halign = "right" contentLabel.valign = "middle" rowList.append(contentLabel) self.contentLayout.add_widget(contentLabel) self.def_ids[self.maxIndex] = rowList
def on_mouse_pos(self, *args): if not self.get_root_window(): return pos = args[1] if self.collide_point(*self.to_widget(*pos)): if self.isMouseInFlag == True: return else: self.isMouseInFlag = True self.color = colorHex("#0000FF") else: if self.isMouseInFlag == True: self.isMouseInFlag = False self.color = colorHex("#000000")
def __init__(self, paramDict, **kwargs): super(STradeGraph, self).__init__(**kwargs) self.paramDict = paramDict self.btmenu = self.paramDict.get(CONSTS.S_BTMENU) self.dataList = self.paramDict.get("dataList") # 1001-Start: 計算最大及最小獲利率 self.min_profitPer = 0 self.max_profitPer = 0 tmpProfitPer = None if self.dataList != None and len(self.dataList) != 0: for profitPer in self.dataList: if profitPer < 0: tmpProfitPer = math.floor(profitPer) else: tmpProfitPer = math.ceil(profitPer) if tmpProfitPer > self.max_profitPer: self.max_profitPer = tmpProfitPer if tmpProfitPer < self.min_profitPer: self.min_profitPer = tmpProfitPer self.min_profitPer = int(self.min_profitPer) self.max_profitPer = int(self.max_profitPer) # 1001-End. self.maxNum = 5 self.yscale = 1 tradeGraphDict = sutil.getDictFromFile(os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "trade_graph.ini")) self.shift_left = int(tradeGraphDict.get("SHIFT_LEFT")) self.shift_right = int(tradeGraphDict.get("SHIFT_RIGHT")) self.shift_bottom = int(tradeGraphDict.get("SHIFT_BOTTOM")) self.shift_top = int(tradeGraphDict.get("SHIFT_TOP")) self.ycordWidth = int(tradeGraphDict.get("YCORD_WIDTH")) self.pillarPoint = int(tradeGraphDict.get("PILLAR_POINT")) self.pillarGapPoint = int(tradeGraphDict.get("PILLAR_GAP_POINT")) self.pillarSumPoint = self.pillarPoint + self.pillarGapPoint self.FRAME_COLOR = colorHex(tradeGraphDict.get("FRAME_COLOR")) self.GRID_COLOR = colorHex(tradeGraphDict.get("GRID_COLOR")) self.CORD_INFO_COLOR = colorHex(tradeGraphDict.get("CORD_INFO_COLOR")) self.CROSS_LINE_COLOR = colorHex(tradeGraphDict.get("CROSS_LINE_COLOR")) self.TRADE_INFO_FGCOLOR = colorHex(tradeGraphDict.get("TRADE_INFO_FGCOLOR")) 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 self.bind(pos=self.charting) self.bind(size=self.charting) Window.bind(mouse_pos=self.mousePos)
def __init__(self, paramDict, **kwargs): super(SOptionElement, self).__init__(**kwargs) optionDict = paramDict.get("OptionDict") self.formulaId = optionDict.get("FormulaID") self.paraDesc = optionDict.get("ParaDesc") self.paraDict = {} self.paraStrDict = {} self.paraList = optionDict.get("ParameterList") for aDict in self.paraList: self.paraDict[aDict.get("Name")] = aDict self._objDict = {} self.size_hint = (1, .98) self.orientation = "horizontal" self._isSelected_id = CheckBox() self._isSelected_id.active = False self._isSelected_id.size_hint = (.1, 1) self._isSelected_id.color = colorHex("#000000") self.add_widget(self._isSelected_id) self.add_widget(BoxLayout(size_hint=(.01, 1))) self.contentLayout = BoxLayout(size_hint=(.89, 1), orientation="horizontal") self.add_widget(self.contentLayout) if self.hasFunc(self.paraDesc): strList = self.paraDesc.split(" ") for astr in strList: if self.hasFunc(astr): paraName = astr[astr.find("#") + 1:] self.paraStrDict[paraName] = astr _atextInput = SOptionTextInput(paraName=paraName, size_hint=(None, 1)) _atextInput.text = self.paraDict.get(paraName).get("Def") _atextInput.width = 60 self.contentLayout.add_widget(_atextInput) self._objDict[paraName] = _atextInput else: _alabel = SLabel(text=astr, size_hint=(None, 1)) _alabel.width = self.calcStrWidth(astr) _alabel.color = colorHex("#000000") self.contentLayout.add_widget(_alabel) else: _alabel = SLabel(text=self.paraDesc, size_hint=(1, 1)) _alabel.color = colorHex("#000000") self.contentLayout.add_widget(_alabel)
def _shiftDispField(self): for headId in self.fieldMapping.keys(): #將id及name以外的欄位,重新設置欄位對應 if headId == "id" or headId == "name": continue self.fieldMapping[headId] = "" headIdIndex = -1 for colIndexStr in self.dispFieldMapping.keys(): headId = self.dispFieldMapping.get(colIndexStr) if headId == "id" or headId == "name": continue headIdIndex += 1 headId = self.fieldIdList[headIdIndex] self.dispFieldMapping[colIndexStr] = headId self.fieldMapping[headId] = colIndexStr for stkId in self.dispDict.keys(): dispObjDict = self.dispDict.get(stkId) aQuoteDict = self.quoteDataDict.get(stkId) for rowNum in dispObjDict.keys(): kvObj = dispObjDict.get(rowNum) headId = self.dispFieldMapping.get(rowNum) aDataList = aQuoteDict.get(headId) if headId == "id": kvObj.text = aDataList[0][2:] else: kvObj.text = aDataList[0] kvObj.color = colorHex(aDataList[1]) if headId == "id" or headId == "name" or headId == "TT": kvObj.halign = "center" else: kvObj.halign = "right"
def _getDefaultRowDict(self, aDict): dispObjDict = {} for colIndexStr in self.dispFieldMapping.keys(): headId = self.dispFieldMapping.get(colIndexStr) fieldList = aDict.get(headId) contentObj = None if headId == "id": contentObj = SButton(size_hint = (self.idWidth_hint, None), height=30) contentObj.text = fieldList[0] contentObj.halign = "center" contentObj.bind(on_press=self._id_press) elif headId == "name": contentObj = SButton(size_hint = (self.idWidth_hint, None), height=30) contentObj.text = fieldList[0] contentObj.halign = "center" contentObj.bind(on_press=self._name_press) else: contentObj = SContentLabel(size_hint = (self.otherWidth_hint, None), height=30) contentObj.text = fieldList[0] contentObj.color = colorHex(fieldList[1]) if headId == "TT": contentObj.halign = "center" else: contentObj.halign = "right" dispObjDict[colIndexStr] = contentObj return dispObjDict
def _createMixedChartInfoObj(self, lineSetupList): if lineSetupList == None or len(lineSetupList) == 0: return self.mixedChartInfo_layout.clear_widgets() aLabel = SLabel(text=" ", size_hint=(None, 1), width=10) aLabel.color = colorHex("#00142D") self.mixedChartInfo_layout.add_widget(aLabel) self.mixedChartInfoObjDict = {} isAmt = False for aDict in lineSetupList: aName = aDict.get("name") if aName == "成交金額": isAmt = True lwidth = schartutil.getInfoLayoutWidth( schartutil.calcCharNum(aName)) aLabel = SLabel(text=aName + " ", size_hint=(None, 1), width=lwidth) aLabel.color = aDict.get("color") self.mixedChartInfo_layout.add_widget(aLabel) if isAmt == True: lwidth = DEFAULT_WIDTH2 else: lwidth = DEFAULT_WIDTH aLabel = SLabel(text="", size_hint=(None, 1), width=lwidth) aLabel.color = DEFAULT_COLOR aLabel.halign = "left" self.mixedChartInfo_layout.add_widget(aLabel) self.mixedChartInfoObjDict[aName] = aLabel
def showExplain(self): filePath = os.path.join(os.path.dirname(__file__), "../conf/explain.ini") with open(filePath, 'r', encoding='utf-8-sig') as f: lineList = f.readlines() explainStr = "" for astr in lineList: explainStr += astr contentLayout = STableBoxLayout(size_hint=(1, 1), orientation="vertical") slview = STableScrollView(size_hint=(1, .92)) contentLayout.add_widget(slview) explainLayout = STableBoxLayout(size_hint=(1, None)) explainLayout.bind(minimum_height=explainLayout.setter('height')) explainLabel = SLabel(text=explainStr, size_hint=(1, None)) explainLabel.font_name = CONSTS.FONT_NAME explainLabel.color = colorHex("#000000") explainLayout.add_widget(explainLabel) slview.add_widget(explainLayout) bottomLayout = BoxLayout(size_hint=(1, .08)) closebtn_id = SButton(text="關閉", size_hint=(1, .8)) bottomLayout.add_widget(closebtn_id) contentLayout.add_widget(bottomLayout) popup = SPopup(title="股票代碼說明", content=contentLayout, size_hint=(None, None), size=(500, 400), auto_dismiss=False) closebtn_id.bind(on_press=popup.dismiss) popup.title_font = CONSTS.FONT_NAME popup.open()
def showSelectedOptionDesc(self): if self.optionList == None: return mainContent = BoxLayout(size_hint=(1, 1), orientation="vertical") slview = STableScrollView() slview.size_hint = (1, None) slview.size = (480, 160) contentLayout = STableGridLayout(cols=1, spacing=2, size_hint_y=None) # Make sure the height is such that there is something to scroll. contentLayout.bind(minimum_height=contentLayout.setter('height')) slview.add_widget(contentLayout) aLabel = None rowIndex = 0 for aObj in self.optionList: if aObj.isSelected() != True: continue rowIndex += 1 aStr = str(rowIndex) + ". " + aObj.getOptionDesc() aLabel = SLabel(text=aStr,size_hint=(1, None), height=30) aLabel.color = colorHex("#000000") contentLayout.add_widget(aLabel) showSelectFile_popup = SPopup(title="已選條件", content=mainContent, size_hint=(None, None), size=(480, 250), auto_dismiss=False) showSelectFile_popup.title_font = CONSTS.FONT_NAME mainContent.add_widget(slview) closeBtn = SButton(text="關閉") closeBtn.bind(on_press=showSelectFile_popup.dismiss) mainContent.add_widget(closeBtn) showSelectFile_popup.open()
def _addContentData(self): self.gridLayout.clear_widgets() startIdx = (self.page_num - 1) * NUM_PER_PAGE endIdx = self.page_num * NUM_PER_PAGE if endIdx > len(self.resultIdNameList): endIdx = len(self.resultIdNameList) idNameList = None refParam = None for aIdx in range(startIdx, endIdx): idNameList = self.resultIdNameList[aIdx] funcLayout = SBoxLayout(size_hint=(.15, None), height=30) funcLayout.orientation = "horizontal" funcLayout.padding = (1, 1, 1, 1) funcLayout.add_widget(BoxLayout(size_hint=(.1, 1))) refParam = {} refParam["idNameList"] = idNameList acbObj = SCheckBox(refParam) acbObj.size_hint = (1, 1) if idNameList[0] in self.selectDict: acbObj.active = True else: acbObj.active = False acbObj.bind(active=self._on_checkbox_active) funcLayout.add_widget(acbObj) funcLayout.add_widget(BoxLayout(size_hint=(.1, 1))) self.gridLayout.add_widget(funcLayout) contentLabel = SContentLabel(text=idNameList[0][2:], size_hint=(.2, None), height=30) contentLabel.color = colorHex("#000000") contentLabel.halign = "center" contentLabel.valign = "middle" self.gridLayout.add_widget(contentLabel) contentLabel = SContentLabel(text=idNameList[1], size_hint=(.65, None), height=30) contentLabel.color = colorHex("#000000") contentLabel.halign = "left" contentLabel.valign = "middle" self.gridLayout.add_widget(contentLabel)
def _getLineSetupList(self, lineSetup): lineSetupList = lineSetup.split(";") tarLineSetupList = [] aDict = None for aStr in lineSetupList: if aStr == "": continue aList = aStr.split("|") if len(aList) < 3: continue aDict = {} if len(aList) > 3: aDict["name"] = aList[0] aDict["color"] = colorHex("#FFFFFF") else: aDict["name"] = aList[0] aDict["color"] = colorHex("#" + aList[2]) tarLineSetupList.append(aDict) return tarLineSetupList
def showErrorView(self, isGetMsgDesc, msgCode, msgDesc=None): contentLayout = BoxLayout() contentLayout.orientation = "vertical" contentLayout.size_hint = (1, 1) if isGetMsgDesc == True: msgCodeDict = self.confDict.get(CONSTS.MSG_CODE_DICT) msgText = msgCodeDict.get(msgCode) if msgText == None: msgText = "Unknow error code->" + str(msgCode) else: msgText = str(msgCode) + "->" + msgText if msgDesc == None or msgDesc == "": contentLabel = SLabel(text=msgText, size_hint=(1, .8)) contentLabel.halign = "center" contentLayout.add_widget(contentLabel) else: titleLabel = SLabel(text=msgText, size_hint=(1, .2)) titleLabel.halign = "center" contentLayout.add_widget(titleLabel) slview = ScrollView(size_hint=(1, .6)) contentLayout.add_widget(slview) explainLayout = STableGridLayout(cols=1, spacing=1, size_hint_y=None) explainLayout.bind( minimum_height=explainLayout.setter('height')) for aStr in msgDesc: explainLabel = SLabel(text=aStr, size_hint=(1, None), height=20) explainLabel.halign = "center" explainLabel.color = colorHex("#000000") explainLabel.font_name = CONSTS.FONT_NAME explainLayout.add_widget(explainLabel) slview.add_widget(explainLayout) else: msgText = str(msgCode) + "->" + msgDesc contentLabel = SLabel(text=msgText, size_hint=(1, .8)) contentLabel.halign = "center" contentLayout.add_widget(contentLabel) sysConfDict = self.confDict.get(CONSTS.SYS_CONF_DICT) contentBtn = SButton(text=sysConfDict.get("MSG_CONFIRM"), size_hint=(1, .2)) contentLayout.add_widget(contentBtn) popup = Popup(title=sysConfDict.get("MSG_TITLE"), content=contentLayout, size_hint=(None, None), size=(200, 200), auto_dismiss=False) contentBtn.bind(on_press=popup.dismiss) popup.title_font = CONSTS.FONT_NAME popup.open()
def updateQuote(self, quoteList): """ """ if quoteList == None or len(quoteList) == 0: return #5001-Start: 若無id欄位,則不添加至報價列表;若資料已存在,則更新資料 for aDict in quoteList: id_dataList = aDict.get("id") if id_dataList == None: continue else: existFlag = True stkId = id_dataList[0] existDict = self.quoteDataDict.get(stkId) if existDict == None: #若無報價資料,初始化一筆報價資料 existFlag = False existDict = self._getDefaultDict() # 初始化報價資料 dispObjDict = None if existFlag == True: #若已存在報價資料,則直接取得畫面上顯示之物件 dispObjDict = self.dispDict.get(stkId) else: #若無報價資料,則初始化一筆畫面上顯示之物件 dispObjDict = self._getDefaultRowDict(existDict) self.dispDict[stkId] = dispObjDict for rowNum in dispObjDict.keys(): self.contentLayout.add_widget(dispObjDict.get(rowNum)) tmpId = None for headId in aDict.keys(): tmpHeadId = existDict.get(headId) if tmpHeadId != None: existDict[headId] = aDict.get(headId) fieldIdx = self.fieldMapping.get(headId) #取得欄位對應之顯示欄位的index if fieldIdx != None and fieldIdx != "": kvObj = dispObjDict.get(fieldIdx) valueList = aDict.get(headId) if headId == "id": kvObj.text = valueList[0][2:] else: kvObj.text = valueList[0] if headId != "id" and headId != "name": kvObj.color = colorHex(valueList[1]) time.sleep(0.0001) # 2020/10/28 調整,因應欄位顯示空白問題 self.quoteDataDict[stkId] = existDict
def _createPriceInfoObj(self, lineSetupList): if lineSetupList == None or len(lineSetupList) == 0: return self.head_layout.clear_widgets() aLabel = SLabel(text=" ", size_hint=(None, 1), width=10) aLabel.color = colorHex("#00142D") self.head_layout.add_widget(aLabel) self.priceInfoObjDict = {} for aDict in lineSetupList: aName = aDict.get("name") lwidth = schartutil.getInfoLayoutWidth( schartutil.calcCharNum(aName)) aLabel = SLabel(text=aName + " ", size_hint=(None, 1), width=lwidth) aLabel.color = aDict.get("color") self.head_layout.add_widget(aLabel) aLabel = SLabel(text="", size_hint=(None, 1), width=DEFAULT_WIDTH) aLabel.color = DEFAULT_COLOR aLabel.halign = "left" self.head_layout.add_widget(aLabel) self.priceInfoObjDict[aName] = aLabel
def _addStockData(self): self.contentLayout.clear_widgets() dataFields = self.result.get("DataFields") headNum = len(dataFields) for aData in self.currStockDataList: if aData == "": continue aFieldList = aData.split("|") num = -1 for aField in aFieldList: if aField == "": continue num += 1 contentLabel = SContentLabel(size_hint=(1.0 / headNum, None), height=30) contentLabel.color = colorHex("#000000") if dataFields[num] == "ID" or dataFields[num] == "NAME": contentLabel.text = aField contentLabel.halign = "center" else: contentLabel.text = "{:.2f}".format(float(aField)) contentLabel.halign = "right" contentLabel.valign = "middle" self.contentLayout.add_widget(contentLabel)
def __init__(self, paramDict, **kwargs): super(STechChart, self).__init__(**kwargs) self.mixedChartInfo_layout = SSysBoxLayout(size_hint=(1, .05), pos_hint={ 'x': 0, 'y': .29 }) self.add_widget(self.mixedChartInfo_layout) self.paramDict = paramDict self.app = self.paramDict.get(CONSTS.S_APP) self.stkId = self.paramDict.get("StkId") #股票id self.stkName = self.paramDict.get("StkName") #股票名稱 self.lastTradeDate = self.paramDict.get("LTD") #最後交易日 self.decimal = self.paramDict.get("Decimal") #小數點位數 self.idNameDate_id.text = self.stkId[ 2:] + " " + self.stkName + " " + sutil.formatDate( self.lastTradeDate) self.idNameDate_id.halign = "left" techChartDict = sutil.getDictFromFile( os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "stech_chart.ini")) techChartParam = {} techChartParam["FRAME_COLOR"] = colorHex( techChartDict.get("FRAME_COLOR")) #邊框的線條顏色 techChartParam["GRID_COLOR"] = colorHex( techChartDict.get("GRID_COLOR")) #直線條及橫線條的線條顏色 techChartParam["CORD_INFO_COLOR"] = colorHex( techChartDict.get("CORD_INFO_COLOR")) #座標資訊的文字顏色 techChartParam["DATA_INFO_COLOR"] = colorHex( techChartDict.get("DATA_INFO_COLOR")) #資訊的文字顏色 techChartParam["CROSS_LINE_COLOR"] = colorHex( techChartDict.get("CROSS_LINE_COLOR")) #十字線顏色 self.tickGap = int(techChartDict.get("TICK_GAP")) #每筆資料間之間隔點數 self.shift_right = int(techChartDict.get("SHIFT_RIGHT")) #繪圖右邊位移距離 self.shift_bottom = int(techChartDict.get("SHIFT_BOTTOM")) #繪圖下方位移距離 self.shift_gap = int(techChartDict.get("SHIFT_GAP")) #兩圖形之間距 self.recordCount = int(techChartDict.get("RECORD_COUNT")) #下載筆數 self.priceFormulaId = int( techChartDict.get("PRICE_FORMULA_ID")) #價格MA公式代碼 self.next_id.disabled = True self.smaller_id.disabled = True self._klineDataTypeDropDown() self._technicalDropDown() refParam = {} for aKey in paramDict.keys(): refParam[aKey] = paramDict.get(aKey) for aKey in techChartParam.keys(): refParam[aKey] = techChartParam.get(aKey) refParam["Layout"] = self.body_layout #繪圖之layout refParam["Canvas"] = self.body_layout.canvas #繪圖之canvas refParam["TickWide"] = self.tickWide #一個tick的寬度(共有幾個點) refParam["TickGap"] = self.tickGap #tick與tick之間點數 self._calcDispNum() refParam["DispNum"] = self.dispNum #畫面顯示筆數 refParam["CurrentPage"] = self.currentPage #當前的頁次 refParam["InfoFunc"] = self._showInfo #顯示訊息之函式 refParam["IsDrawRect"] = True #是否畫外框 refParam["IsDrawXCordLine"] = True #是否顯示X軸直線 refParam["IsDrawXCordInfo"] = False #是否顯示X軸座標訊息 refParam["IsDrawYCordLine"] = True #是否顯示Y軸直線 refParam["IsDrawYCordInfo"] = True #是否顯示Y軸座標訊息 refParam["IsDrawCrossLine"] = True #是否顯示十字線 refParam["InstGroup"] = "KLine_chart" #InstructionGroup所使用之group值 refParam[ "FormatType"] = 1 #0.No format,1.float format,2.currency format refParam["DataType"] = self.klineDataType_index #資料類型 self.klineChart = SKLineChart(refParam) priceRefParam = {} for aKey in refParam.keys(): priceRefParam[aKey] = refParam.get(aKey) priceRefParam["IsPriceMA"] = True priceRefParam["InfoFunc"] = self._showPriceInfo #顯示訊息之函式 priceRefParam["IsDrawRect"] = False #是否畫外框 priceRefParam["IsDrawXCordLine"] = False #是否顯示X軸直線 priceRefParam["IsDrawXCordInfo"] = False #是否顯示X軸座標 priceRefParam["IsDrawYCordLine"] = False #是否顯示Y軸直線 priceRefParam["IsDrawYCordInfo"] = False #是否顯示Y軸座標 priceRefParam["IsDrawCrossLine"] = False #是否顯示十字線 priceRefParam["InstGroup"] = "PriceMaChart" lineSetup = self.formulaMapping.get(str(self.priceFormulaId))[0] priceRefParam["LineSetup"] = lineSetup self._createPriceInfoObj(self._getLineSetupList(lineSetup)) self.priceMixedChart = SMixedChart(priceRefParam) secRefParam = {} for aKey in refParam.keys(): secRefParam[aKey] = refParam.get(aKey) secRefParam["IsPriceMA"] = False secRefParam["InfoFunc"] = self._showMixedChartInfo #顯示訊息之函式 secRefParam["IsDrawRect"] = True #是否畫外框 secRefParam["IsDrawXCordLine"] = True #是否顯示X軸直線 secRefParam["IsDrawXCordInfo"] = True #是否顯示X軸座標訊息 secRefParam["IsDrawYCordLine"] = True #是否顯示Y軸直線 secRefParam["IsDrawYCordInfo"] = True #是否顯示Y軸座標訊息 secRefParam["IsDrawCrossLine"] = True #是否顯示十字線 secRefParam["InstGroup"] = "SecMixedChart" #InstructionGroup所使用之group值 lineSetup = self.formulaMapping.get(str(self.techType_index))[0] secRefParam["LineSetup"] = lineSetup self._createMixedChartInfoObj(self._getLineSetupList(lineSetup)) self.secMixedChart = SMixedChart(secRefParam) Clock.schedule_once(self.doQuoteStart, .5) #此段用意為讓畫面先顯示出來,再做後續的動作 self.bind(pos=self._charting) self.bind(size=self._charting) Window.bind(mouse_pos=self._mousePos)
from kivy.utils import get_color_from_hex as colorHex from kivy.core.window import Window from kivy.clock import Clock from kivy.lang import Builder from kivy.uix.floatlayout import FloatLayout from kivy.uix.dropdown import DropDown from kivy.properties import ObjectProperty from selements import SInfoButton, SLabel, SSysBoxLayout import sconsts as CONSTS import schartutil from skline_chart import SKLineChart from smixed_chart import SMixedChart import sutil DEFAULT_COLOR = colorHex("#FFFFFF") DEFAULT_WIDTH = 80 DEFAULT_WIDTH2 = 110 stkBase_col_obj = abxtoolkit.stkBaseInfo_columns_sets() stkRef_col_obj = abxtoolkit.stkInfo_columns_sets() trade_col_obj = abxtoolkit.trade_columns_sets() order1_col_obj = abxtoolkit.order_1_columns_sets() others_col_obj = abxtoolkit.others_columns_sets() with open(os.path.join(os.path.dirname(__file__), "stech_chart.kv"), encoding="utf-8") as f: Builder.load_string(f.read()) class STechChart(FloatLayout):
def setLineSetup(self, lineSetup): self.mixedGraphList.clear() lineSetupList = lineSetup.split(";") isFirstRecord = True aIdx = -1 for aStr in lineSetupList: if aStr == "": continue aList = aStr.split("|") if len(aList) < 2: continue mixedParam = {} for aKey in self.refParam.keys(): mixedParam[aKey] = self.refParam.get(aKey) if isFirstRecord == True: isFirstRecord = False if self.isDrawRect == True: mixedParam["IsDrawRect"] = True else: mixedParam["IsDrawRect"] = False if self.isDrawXCordLine == True: mixedParam["IsDrawXCordLine"] = True else: mixedParam["IsDrawXCordLine"] = False if self.isDrawXCordInfo == True: mixedParam["IsDrawXCordInfo"] = True else: mixedParam["IsDrawXCordInfo"] = False if self.isDrawYCordLine == True: mixedParam["IsDrawYCordLine"] = True else: mixedParam["IsDrawYCordLine"] = False if self.isDrawYCordInfo == True: mixedParam["IsDrawYCordInfo"] = True else: mixedParam["IsDrawYCordInfo"] = False if self.isDrawCrossLine == True: mixedParam["IsDrawCrossLine"] = True else: mixedParam["IsDrawCrossLine"] = False else: mixedParam["IsDrawRect"] = False mixedParam["IsDrawXCordLine"] = False mixedParam["IsDrawXCordInfo"] = False mixedParam["IsDrawYCordLine"] = False mixedParam["IsDrawYCordInfo"] = False mixedParam["IsDrawCrossLine"] = False aIdx += 1 if aList[1] == "LINE": mixedParam["TechType"] = aList[0] mixedParam["CURV_COLOR"] = colorHex("#" + aList[2]) mixedParam["InstGroup"] = self.refParam.get( "InstGroup") + "_" + str(aIdx) aGraph = SCurvGraph(mixedParam) self.mixedGraphList.append(aGraph) elif aList[1] == "VOLSTICK": mixedParam["TechType"] = aList[0] mixedParam["UP_COLOR"] = colorHex("#" + aList[2]) mixedParam["DOWN_COLOR"] = colorHex("#" + aList[3]) mixedParam["EQUAL_COLOR"] = colorHex("#" + aList[4]) mixedParam["InstGroup"] = self.refParam.get( "InstGroup") + "_" + str(aIdx) aGraph = SVolBarGraph(mixedParam) self.mixedGraphList.append(aGraph) elif aList[1] == "STICK": mixedParam["TechType"] = aList[0] mixedParam["UP_COLOR"] = colorHex("#" + aList[2]) mixedParam["DOWN_COLOR"] = colorHex("#" + aList[3]) mixedParam["EQUAL_COLOR"] = colorHex("#" + aList[3]) mixedParam["InstGroup"] = self.refParam.get( "InstGroup") + "_" + str(aIdx) aGraph = SBarGraph(mixedParam) self.mixedGraphList.append(aGraph)
def dateSelectEvent(self, instance): self.selectDateDict[self.dayInt].background_color = colorHex("#576161") self.dayInt = int(instance.text) self.selectDateDict[self.dayInt].background_color = colorHex("#137F83") self.changeDateText()
def __init__(self, paramDict, **kwargs): super(SelfStkSetting, self).__init__(**kwargs) self.paramDict = paramDict self.app = self.paramDict.get(CONSTS.S_APP) self.selfgroup_index = self.paramDict.get("SelfGroupIndex") self.selfgroup_name = self.paramDict.get("SelfGroupName") self.selfStkList = self.paramDict.get("SelfStkList") self.size_hint = (1, 1) self.orientation = "vertical" self.add_widget(STableBoxLayout(size_hint=(1, None), height=1)) nameLayout = SBoxLayout(size_hint=(1, None), height=30) nameLayout.orientation = "horizontal" nameLayout.add_widget(STableBoxLayout(size_hint=(.02, 1))) nameLabel = SLabel(text="名稱:", size_hint=(.15, 1)) nameLabel.color = colorHex("#000000") nameLayout.add_widget(nameLabel) self.selfgroup_name_id = STextInput(text=self.selfgroup_name, size_hint=(.65, 1)) nameLayout.add_widget(self.selfgroup_name_id) nameLayout.add_widget(STableBoxLayout(size_hint=(.23, 1))) self.add_widget(nameLayout) self.add_widget(STableBoxLayout(size_hint=(1, None), height=1)) headLayout = STableGridLayout(cols=3, rows=1, spacing=2, size_hint=(1, None), height=30) headLabel = SHeadLabel(text="功能", size_hint=(.15, 1)) headLabel.halign: 'center' headLabel.valign: 'middle' headLayout.add_widget(headLabel) headLabel = SHeadLabel(text="代碼", size_hint=(.2, 1)) headLabel.halign: 'center' headLabel.valign: 'middle' headLayout.add_widget(headLabel) headLabel = SHeadLabel(text="名稱", size_hint=(.65, 1)) headLabel.halign: 'center' headLabel.valign: 'middle' headLayout.add_widget(headLabel) self.add_widget(headLayout) self.add_widget(STableBoxLayout(size_hint=(1, None), height=2)) self.def_ids = {} slview = STableScrollView() slview.size_hint = (1, None) slview.size = (360, 320) self.contentLayout = STableGridLayout(cols=3, spacing=2, size_hint_y=None) # Make sure the height is such that there is something to scroll. self.contentLayout.bind( minimum_height=self.contentLayout.setter('height')) tmpList = None stkName = None for stkId in self.selfStkList: tmpList = [] tmpList.append(stkId) stkName = self.app.stkNameDict.get(stkId) if stkName == None: tmpList.append("") else: tmpList.append(stkName) self.addListRow(tmpList) self.addInsertRow() slview.add_widget(self.contentLayout) self.add_widget(slview) bottomLayout = BoxLayout(size_hint=(1, None), height=30) self.ensurebtn_id = SButton(text="確定", size_hint=(.49, 1)) bottomLayout.add_widget(self.ensurebtn_id) bottomLayout.add_widget(BoxLayout(size_hint=(.02, 1))) self.cancelbtn_id = SButton(text="取消", size_hint=(.49, 1)) bottomLayout.add_widget(self.cancelbtn_id) self.add_widget(bottomLayout)
def __init__(self, paramDict, **kwargs): super(STrendGraph, self).__init__(**kwargs) with self.canvas: Color(0, 20 / 255, 45 / 255) Rectangle(pos=self.pos, size=self.size) self.paramDict = paramDict self.btmenu = self.paramDict.get(CONSTS.S_BTMENU) self.tickNum = self.paramDict.get("ticknum") self.dataList = self.paramDict.get("datalist") if self.tickNum == 600: self.xgrid_num = 100 elif self.tickNum == 500: self.xgrid_num = 90 elif self.tickNum == 400: self.xgrid_num = 70 elif self.tickNum == 300: self.xgrid_num = 50 elif self.tickNum == 200: self.xgrid_num = 40 else: self.xgrid_num = 30 self.crossLineXIndex = -1 self.crossLineYIndex = -1 trendGraphDict = sutil.getDictFromFile( os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "trend_graph.ini")) self.shift_left = int(trendGraphDict.get("SHIFT_LEFT")) self.shift_right = int(trendGraphDict.get("SHIFT_RIGHT")) self.shift_bottom = int(trendGraphDict.get("SHIFT_BOTTOM")) self.shift_top = int(trendGraphDict.get("SHIFT_TOP")) self.CORD_INFO_COLOR = colorHex(trendGraphDict.get("CORD_INFO_COLOR")) self.UP_COLOR = colorHex(trendGraphDict.get("UP_COLOR")) self.DOWN_COLOR = colorHex(trendGraphDict.get("DOWN_COLOR")) self.EQUAL_COLOR = colorHex(trendGraphDict.get("EQUAL_COLOR")) self.VOLUME_COLOR = colorHex(trendGraphDict.get("VOLUME_COLOR")) self.FRAME_COLOR = colorHex(trendGraphDict.get("FRAME_COLOR")) self.GRID_COLOR = colorHex(trendGraphDict.get("GRID_COLOR")) self.CROSS_LINE_COLOR = colorHex( trendGraphDict.get("CROSS_LINE_COLOR")) self.TRADEB_SIG_COLOR = colorHex( trendGraphDict.get("TRADEB_SIG_COLOR")) self.TRADES_SIG_COLOR = colorHex( trendGraphDict.get("TRADES_SIG_COLOR")) self.TRADE_INFO_FGCOLOR = colorHex( trendGraphDict.get("TRADE_INFO_FGCOLOR")) self.info_date = SLabel(text="") #日期 self.info_date.color = self.TRADE_INFO_FGCOLOR self.info_time = SLabel(text="") #時間 self.info_time.color = self.TRADE_INFO_FGCOLOR self.info_price = SLabel(text="") #成交價 self.info_price.color = self.TRADE_INFO_FGCOLOR self.info_vol = SLabel(text="") #成交量 self.info_vol.color = self.TRADE_INFO_FGCOLOR self.info_amt = SLabel(text="") #金額 self.info_amt.color = self.TRADE_INFO_FGCOLOR self.info_bs = SLabel(text="") #買賣訊號及買(賣)價 self.info_bs.color = self.TRADE_INFO_FGCOLOR self.calcMaxTick() self.bind(pos=self.charting) self.bind(size=self.charting) Window.bind(mouse_pos=self.mousePos)
def _queryStk(self): queryStr = self.queryStr_id.text self.resultIdNameList.clear() self.selectDict.clear() stkName = None for stkId in self.app.stkNameDict.keys(): stkName = self.app.stkNameDict.get(stkId) if stkId[2:].find(queryStr) != -1 or stkName.find(queryStr) != -1: self.resultIdNameList.append([stkId, stkName]) self.body_layout.remove_widget(self.content_layout) if self.contentView != None: self.contentView.clear_widgets() if self.pageLayout != None: self.pageLayout.clear_widgets() if self.enterPageLayout != None: self.enterPageLayout.clear_widgets() if self.nextPreLayout != None: self.nextPreLayout.clear_widgets() if len(self.resultIdNameList) == 0: return self.contentView = STableBoxLayout(size_hint=(1, 1), orientation="vertical") if len(self.resultIdNameList) > NUM_PER_PAGE: self.pageLayout = SSysBoxLayout(orientation="horizontal", size_hint=(1, None), height=30, padding=2) self.pageLayout.add_widget(BoxLayout(size_hint=(.50, 1))) self.enterPageLayout = BoxLayout(orientation="horizontal", size_hint=(.20, 1)) self.enterPageLayout.add_widget( SLabel(text="第", color=colorHex("#FFFFFF"), size_hint=(.16, 1), halign="right")) self.page_id = STextInput(text="1", multiline=False, size_hint=(.32, 1)) self.page_id.bind(on_text_validate=self._on_page_id_enter) self.enterPageLayout.add_widget(self.page_id) self.enterPageLayout.add_widget( SLabel(text="/", color=colorHex("#FFFFFF"), size_hint=(.16, 1), halign="center")) self.totalpage_id = SLabel(text="1", color=colorHex("#FFFFFF"), size_hint=(.32, 1), halign="left") self.enterPageLayout.add_widget(self.totalpage_id) self.enterPageLayout.add_widget(BoxLayout(size_hint=(.04, 1))) self.pageLayout.add_widget(self.enterPageLayout) self.nextPreLayout = BoxLayout(orientation="horizontal", size_hint=(.3, 1)) self.prepage_id = SButton(text="上一頁", size_hint=(.28, 1), halign="center", valign="middle") self.prepage_id.bind(on_release=self._onChangePage) self.nextPreLayout.add_widget(self.prepage_id) self.nextPreLayout.add_widget(BoxLayout(size_hint=(.01, 1))) self.nextpage_id = SButton(text="下一頁", size_hint=(.28, 1), halign="center", valign="middle") self.nextpage_id.bind(on_release=self._onChangePage) self.nextPreLayout.add_widget(self.nextpage_id) self.pageLayout.add_widget(self.nextPreLayout) self.contentView.add_widget(self.pageLayout) self._calcPageInfo() headLayout = STableGridLayout(cols=3, rows=1, spacing=2, size_hint=(1, None), height=30) headLabel = SHeadLabel(text="勾選", size_hint=(.15, 1)) headLabel.halign: 'center' headLabel.valign: 'middle' headLayout.add_widget(headLabel) headLabel = SHeadLabel(text="代碼", size_hint=(.2, 1)) headLabel.halign: 'center' headLabel.valign: 'middle' headLayout.add_widget(headLabel) headLabel = SHeadLabel(text="名稱", size_hint=(.65, 1)) headLabel.halign: 'center' headLabel.valign: 'middle' headLayout.add_widget(headLabel) self.contentView.add_widget(headLayout) slview = STableScrollView() if len(self.resultIdNameList) > NUM_PER_PAGE: slview.size_hint = (1, .95) else: slview.size_hint = (1, .95) self.gridLayout = STableGridLayout(cols=3, spacing=2, size_hint_y=None) # Make sure the height is such that there is something to scroll. self.gridLayout.bind(minimum_height=self.gridLayout.setter('height')) slview.add_widget(self.gridLayout) self.contentView.add_widget(slview) self._addContentData() self.content_layout = self.contentView self.body_layout.add_widget(self.content_layout)
def __init__(self, paramDict, **kwargs): super(STrendChart, self).__init__(**kwargs) self.paramDict = paramDict self.app = self.paramDict.get(CONSTS.S_APP) self.stkId = self.paramDict.get("StkId") #股票id self.stkName = self.paramDict.get("StkName") #股票名稱 self.lastTradeDate = self.paramDict.get("LTD") #最後交易日 self.startTime = self.paramDict.get("StartTime") #起始時間 self.endTime = self.paramDict.get("EndTime") #截止時間 self.yesPrice = self.paramDict.get("YesPrice") #昨收價 self.decimal = self.paramDict.get("Decimal") #小數點位數 self.chartNum = sutil.calcTimeNum(int(self.startTime), int(self.endTime)) self.stkIdAndName.text = self.stkId[2:] + " " + self.stkName self.stkIdAndName.halign = "left" self.lastTradeDate_id.text = sutil.formatDate(self.lastTradeDate) refParam = {} for aKey in paramDict.keys(): refParam[aKey] = paramDict.get(aKey) trendGraphDict = sutil.getDictFromFile( os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "strend_chart.ini")) self.shift_left = int(trendGraphDict.get("SHIFT_LEFT")) #圖形左邊位移距離 refParam["SHIFT_LEFT"] = self.shift_left refParam["SHIFT_GAPHEIGHT"] = int( trendGraphDict.get("SHIFT_GAPHEIGHT")) #價圖及量圖的間距 refParam["SHIFT_BOTTOM"] = int( trendGraphDict.get("SHIFT_BOTTOM")) #圖形底部位移距離 refParam["SHIFT_TOP"] = int(trendGraphDict.get("SHIFT_TOP")) #圖形上方位移距離 refParam["PRICE_HEIGHT_PER"] = int( trendGraphDict.get("PRICE_HEIGHT_PER")) #價圖高度佔比 refParam["VOLUME_HEIGHT_PER"] = int( trendGraphDict.get("VOLUME_HEIGHT_PER")) #量圖高度佔比 refParam["CORD_INFO_COLOR"] = colorHex( trendGraphDict.get("CORD_INFO_COLOR")) #座標資訊的文字顏色 refParam["DATA_INFO_COLOR"] = colorHex( trendGraphDict.get("DATA_INFO_COLOR")) #資訊的文字顏色 self.UP_COLOR = colorHex(trendGraphDict.get("UP_COLOR")) #上漲時線條顏色 self.DOWN_COLOR = colorHex(trendGraphDict.get("DOWN_COLOR")) #下跌時線條顏色 self.EQUAL_COLOR = colorHex( trendGraphDict.get("EQUAL_COLOR")) #持平時線條顏色 refParam["UP_COLOR"] = self.UP_COLOR refParam["DOWN_COLOR"] = self.DOWN_COLOR refParam["EQUAL_COLOR"] = self.EQUAL_COLOR refParam["VOLUME_COLOR"] = colorHex( trendGraphDict.get("VOLUME_COLOR")) #量的線條顏色 refParam["FRAME_COLOR"] = colorHex( trendGraphDict.get("FRAME_COLOR")) #邊框的線條顏色 refParam["GRID_COLOR"] = colorHex( trendGraphDict.get("GRID_COLOR")) #格線的線條顏色 refParam["CROSS_LINE_COLOR"] = colorHex( trendGraphDict.get("CROSS_LINE_COLOR")) #十字線線條顏色 refParam["UP_DOWN_PER"] = float( trendGraphDict.get("UP_DOWN_PER")) #漲跌幅度 refParam["InfoFunc"] = self.showInfo #顯示訊息的函式 refParam["ChartNum"] = self.chartNum #時間總筆數 refParam["Layout"] = self.body_layout refParam["Canvas"] = self.body_layout.canvas self.strendChart = SMinuteTimeChart(refParam) Clock.schedule_once(self.doQuoteStart, .5) #此段用意為讓畫面先顯示出來,再做後續的動作 self.bind(pos=self.charting) self.bind(size=self.charting) Window.bind(mouse_pos=self.mousePos)