Exemplo n.º 1
0
    def __init__(self, paramDict, **kwargs):
        super(SStrategy, self).__init__(**kwargs)
        
        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)        

        self.size_hint = (1, 1)
        self.orientation = "vertical"

        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=(.6, 1))
        headLabel.halign: 'center'
        headLabel.valign: 'middle'
        headLayout.add_widget(headLabel)
        headLabel = SHeadLabel(text="檔案名稱", size_hint=(.25, 1))
        headLabel.halign: 'center'
        headLabel.valign: 'middle'
        headLayout.add_widget(headLabel)
        self.add_widget(headLayout)
        
        gapLayout = STableBoxLayout(size_hint=(1, None), height=2)
        self.add_widget(gapLayout)
        
        self.maxIndex = 0
        self.def_ids = {}
        
        slview = STableScrollView()
        slview.size_hint = (1, None)
        slview.size = (540, 350)
        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'))
        
        filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "strategy.ini")
        if not os.path.exists(filePath):
            with open(filePath, 'w'): pass        
            
        alist = sutil.getListFromFile(filePath)
        for astr in alist:
            tmpList = astr.strip().split(",")
            if len(tmpList) < 2:
                continue
            self.addListRow(tmpList, False)
            self.maxIndex += 1            

        self.addInsertRow(str(self.maxIndex))
        slview.add_widget(self.contentLayout)
        
        self.add_widget(slview)
        
        closeLayout = BoxLayout(size_hint=(1, None), height=36)
        self.closebtn_id = SButton(text="關閉", size_hint=(1, 1))
        closeLayout.add_widget(self.closebtn_id)
        self.add_widget(closeLayout)
Exemplo n.º 2
0
    def __init__(self, refDict, **kwargs):
        super(SOptionSelect, self).__init__(**kwargs)

        self.app = refDict.get(CONSTS.S_APP)
        self.sysConfDict = self.app.confDict.get(CONSTS.SYS_CONF_DICT)
 
        slview = STableScrollView()
        slview.size_hint = (1, 1)
        self.stgLayout = STableGridLayout(cols=1, spacing=2, size_hint_y=None)
        # Make sure the height is such that there is something to scroll.
        self.stgLayout.bind(minimum_height=self.stgLayout.setter('height'))
        slview.add_widget(self.stgLayout)
        
        self.contentLayout_id.add_widget(slview)
        
        self._doQueryFormulaId()
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    def _finishedSelectStock(self, gwResult):

        self.result = gwResult
        dataFields = gwResult.get("DataFields")
        headNum = len(dataFields)
        
        self.currentHeadIndex = 0
        self.sortedDirection = 1
        self.headButtonList = []
        headLayout = STableGridLayout(cols=headNum, rows=1, spacing=2, size_hint=(1, None), height=30)
        headIndex = -1
        for field in dataFields:            
            headIndex += 1
            headButton = SHeadSortedButton(headText = field, headIndex = headIndex, text = field, size_hint = (1.0 / headNum, 1))
            if headIndex == 0:
                headButton.text = field + " ▼"
            headButton.bind(on_release=self._sortedData)
            headLayout.add_widget(headButton)
            self.headButtonList.append(headButton)
        self.add_widget(headLayout)
        
        gapLayout = STableBoxLayout(size_hint=(1, None), height=2)
        self.add_widget(gapLayout)

        slview = STableScrollView()
        slview.size_hint = (1, .9)
        self.contentLayout = STableGridLayout(cols=headNum, 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'))
        
        stockData = gwResult.get("StockData")
        self.currStockDataList = stockData.split(";")
        self._addStockData()

        slview.add_widget(self.contentLayout)
        
        self.add_widget(slview)
Exemplo n.º 6
0
class STradeCost(BoxLayout):
    def __init__(self, paramDict, **kwargs):
        super(STradeCost, self).__init__(**kwargs)

        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)

        self.size_hint = (1, 1)
        self.orientation = "vertical"

        headLayout = STableGridLayout(cols=4,
                                      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=(.4, 1))
        headLabel.halign: 'center'
        headLabel.valign: 'middle'
        headLayout.add_widget(headLabel)
        headLabel = SHeadLabel(text="交易單位/契約乘數", size_hint=(.25, 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)
        self.add_widget(headLayout)

        gapLayout = STableBoxLayout(size_hint=(1, None), height=2)
        self.add_widget(gapLayout)

        self.maxIndex = 0
        self.def_ids = {}

        slview = STableScrollView()
        slview.size_hint = (1, None)
        slview.size = (540, 350)
        self.contentLayout = STableGridLayout(cols=4,
                                              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'))

        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "tradecost.ini")
        if not os.path.exists(filePath):
            with open(filePath, 'w'):
                pass

        alist = sutil.getListFromFile(filePath)
        for astr in alist:
            tmpList = astr.strip().split(",")
            if len(tmpList) < 3:
                continue
            self.addListRow(tmpList, False)
            self.maxIndex += 1

        self.addInsertRow(str(self.maxIndex))
        slview.add_widget(self.contentLayout)

        self.add_widget(slview)

        closeLayout = BoxLayout(size_hint=(1, None), height=36)
        self.closebtn_id = SButton(text="關閉", size_hint=(1, 1))
        closeLayout.add_widget(self.closebtn_id)
        self.add_widget(closeLayout)

    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 deleteRow(self, rowIndex):
        rowList = self.def_ids.get(rowIndex)
        for obj in rowList:
            self.contentLayout.remove_widget(obj)
        self.def_ids.pop(rowIndex)
        self.saveData()

    def saveData(self):
        keylist = self.def_ids.keys()
        keylist = sorted(keylist)
        listLen = len(keylist)
        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "tradecost.ini")
        with open(filePath, 'w', encoding='utf-8') as f:
            rowList = None
            for i in range(0, listLen - 1):
                rowList = self.def_ids.get(keylist[i])
                astr = rowList[1].text + "," + rowList[2].text + "," + rowList[
                    3].text + "\n"
                f.write(astr)

    def addInsertRow(self, strIndex):
        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 = SButton(text="新增", size_hint=(.8, 1))
        btn.halign = "center"
        btn.valign = "middle"
        btn.bind(on_release=self.addRecordPopup)
        funcLayout.add_widget(btn)
        funcLayout.add_widget(BoxLayout(size_hint=(.1, 1)))
        rowList.append(funcLayout)
        self.contentLayout.add_widget(funcLayout)
        contentLabel = SContentLabel(text="", size_hint=(.4, None), height=30)
        contentLabel.halign = "left"
        contentLabel.valign = "middle"
        rowList.append(contentLabel)
        self.contentLayout.add_widget(contentLabel)
        contentLabel = SContentLabel(text="", size_hint=(.25, None), height=30)
        contentLabel.halign = "right"
        contentLabel.valign = "middle"
        rowList.append(contentLabel)
        self.contentLayout.add_widget(contentLabel)
        contentLabel = SContentLabel(text="", size_hint=(.2, None), height=30)
        contentLabel.halign = "right"
        contentLabel.valign = "middle"
        rowList.append(contentLabel)
        self.contentLayout.add_widget(contentLabel)

        self.def_ids[int(strIndex)] = rowList

    def addRecordPopup(self, instance):
        refDict = {}
        for key in self.paramDict.keys():
            refDict[key] = self.paramDict.get(key)
        refDict['mode'] = "1"
        self.add_scsLayout = SCostSetting(refDict)
        self.add_popup = SPopup(title="新增規則",
                                content=self.add_scsLayout,
                                size_hint=(None, None),
                                size=(480, 360),
                                auto_dismiss=False)
        self.add_scsLayout.ensurebtn_id.bind(on_press=self.addRecordEvent)
        self.add_scsLayout.closebtn_id.bind(on_press=self.add_popup.dismiss)
        self.add_popup.title_font = CONSTS.FONT_NAME
        self.add_popup.open()

    def addRecordEvent(self, instance):
        ruleName = self.add_scsLayout.rule_id.text
        if ruleName == None or ruleName == "":
            self.app.showErrorView(True, CONSTS.ERR_RULE_IS_SPACE)
            return
        costStr = self.add_scsLayout.cost_id.text
        if costStr == None or costStr == "":
            self.app.showErrorView(True, CONSTS.ERR_COST_IS_SPACE)
            return
        dflag = False
        try:
            float(costStr)
        except:
            dflag = True
        if dflag:
            self.app.showErrorView(True, CONSTS.ERR_COST_MUST_NUMBER)
            return
        dflag = False
        for akey in self.def_ids.keys():
            rowList = self.def_ids.get(akey)
            if ruleName == rowList[1].text:
                dflag = True
                break
        if dflag:
            self.app.showErrorView(True, CONSTS.ERR_RULE_DUPLICATED)
            return

        tradeUnit = self.add_scsLayout.tradeunit_id.text
        alist = []
        alist.append(ruleName)
        alist.append(tradeUnit)
        alist.append(costStr)
        self.addListRow(alist, True)
        self.maxIndex += 1
        self.addInsertRow(str(self.maxIndex))
        self.saveData()
        self.add_popup.dismiss()

    def updateRecordPopup(self, instance):
        refDict = {}
        for key in self.paramDict.keys():
            refDict[key] = self.paramDict.get(key)
        refDict['mode'] = "2"
        self.update_scsLayout = SCostSetting(refDict)
        self.update_popup = SPopup(title="修改規則",
                                   content=self.update_scsLayout,
                                   size_hint=(None, None),
                                   size=(480, 360),
                                   auto_dismiss=False)
        self.update_scsLayout.ensurebtn_id.extra_info = instance.extra_info
        self.update_scsLayout.ensurebtn_id.bind(
            on_press=self.updateRecordEvent)
        self.update_scsLayout.closebtn_id.bind(
            on_press=self.update_popup.dismiss)
        self.update_popup.title_font = CONSTS.FONT_NAME
        rowList = self.def_ids.get(instance.extra_info)
        self.update_scsLayout.rule_id.text = rowList[1].text
        self.update_scsLayout.tradeunit_id.text = rowList[2].text
        self.update_scsLayout.cost_id.text = rowList[3].text
        if self.update_scsLayout.rule_id.text == "證券普通股" or self.update_scsLayout.rule_id.text == "台指期貨":
            self.update_scsLayout.tradeunit_id.disabled = True
        self.update_popup.open()

    def updateRecordEvent(self, instance):
        costStr = self.update_scsLayout.cost_id.text
        if costStr == None or costStr == "":
            self.app.showErrorView(True, CONSTS.ERR_COST_IS_SPACE)
            return
        dflag = False
        try:
            float(costStr)
        except:
            dflag = True
        if dflag:
            self.app.showErrorView(True, CONSTS.ERR_COST_MUST_NUMBER)
            return
        tradeUnit = self.update_scsLayout.tradeunit_id.text
        rowList = self.def_ids.get(instance.extra_info)
        rowList[2].text = tradeUnit
        rowList[3].text = costStr
        self.saveData()
        self.update_popup.dismiss()

    def deleteRecordPopup(self, instance):
        self.deleteConfirm = SRowConfirmLayout()
        self.del_popup = SPopup(title="刪除規則",
                                content=self.deleteConfirm,
                                size_hint=(None, None),
                                size=(240, 160),
                                auto_dismiss=False)
        self.deleteConfirm.yesbtn_id.extra_info = instance.extra_info
        self.deleteConfirm.yesbtn_id.bind(on_press=self.deleteRecordEvent)
        self.deleteConfirm.nobtn_id.bind(on_press=self.del_popup.dismiss)
        self.del_popup.title_font = CONSTS.FONT_NAME
        self.del_popup.open()

    def deleteRecordEvent(self, instance):
        self.deleteRow(instance.extra_info)
        self.del_popup.dismiss()
Exemplo n.º 7
0
class SStrategy(BoxLayout):
        
    def __init__(self, paramDict, **kwargs):
        super(SStrategy, self).__init__(**kwargs)
        
        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)        

        self.size_hint = (1, 1)
        self.orientation = "vertical"

        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=(.6, 1))
        headLabel.halign: 'center'
        headLabel.valign: 'middle'
        headLayout.add_widget(headLabel)
        headLabel = SHeadLabel(text="檔案名稱", size_hint=(.25, 1))
        headLabel.halign: 'center'
        headLabel.valign: 'middle'
        headLayout.add_widget(headLabel)
        self.add_widget(headLayout)
        
        gapLayout = STableBoxLayout(size_hint=(1, None), height=2)
        self.add_widget(gapLayout)
        
        self.maxIndex = 0
        self.def_ids = {}
        
        slview = STableScrollView()
        slview.size_hint = (1, None)
        slview.size = (540, 350)
        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'))
        
        filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "strategy.ini")
        if not os.path.exists(filePath):
            with open(filePath, 'w'): pass        
            
        alist = sutil.getListFromFile(filePath)
        for astr in alist:
            tmpList = astr.strip().split(",")
            if len(tmpList) < 2:
                continue
            self.addListRow(tmpList, False)
            self.maxIndex += 1            

        self.addInsertRow(str(self.maxIndex))
        slview.add_widget(self.contentLayout)
        
        self.add_widget(slview)
        
        closeLayout = BoxLayout(size_hint=(1, None), height=36)
        self.closebtn_id = SButton(text="關閉", size_hint=(1, 1))
        closeLayout.add_widget(self.closebtn_id)
        self.add_widget(closeLayout)

    def addListRow(self, alist, aflag):
        if aflag:
            self.deleteRow(self.maxIndex)
        
        rowList = []
        funcLayout = SBoxLayout(size_hint=(.25, None), height=30)
        funcLayout.orientation = "horizontal"
        funcLayout.padding = (1, 1, 1, 1)
        funcLayout.add_widget(BoxLayout(size_hint=(.06, 1)))
        btn = SInfoButton(extra_info=self.maxIndex, text="修", size_hint=(.14, 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=(.14, 1))
        btn.halign = "center"
        btn.valign = "middle"
        btn.bind(on_release=self.deleteRecordPopup)
        funcLayout.add_widget(btn)
        funcLayout.add_widget(BoxLayout(size_hint=(.02, 1)))        
        btn = SInfoButton(extra_info=self.maxIndex, text="編輯策略", size_hint=(.56, 1))
        btn.halign = "center"
        btn.valign = "middle"
        btn.bind(on_release=self.editContent)
        funcLayout.add_widget(btn)
        funcLayout.add_widget(BoxLayout(size_hint=(.06, 1)))
        rowList.append(funcLayout)
        self.contentLayout.add_widget(funcLayout)
        contentLabel = SContentLabel(text=alist[0], size_hint=(.5, 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 = "left"
        contentLabel.valign = "middle"
        rowList.append(contentLabel)
        self.contentLayout.add_widget(contentLabel)
        
        self.def_ids[self.maxIndex] = rowList

    def deleteRow(self, rowIndex):
        rowList = self.def_ids.get(rowIndex)
        for obj in rowList:
            self.contentLayout.remove_widget(obj)
        self.def_ids.pop(rowIndex)
        if rowList[2].text != "":
            filePath = os.path.abspath(os.path.join(save_dir, rowList[2].text))
            if os.path.exists(filePath):
                os.remove(filePath)
        self.saveData()

    def saveData(self):
        keylist = self.def_ids.keys()
        keylist = sorted(keylist)
        listLen = len(keylist)
        filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "strategy.ini")
        with open(filePath, 'w', encoding = 'utf-8') as f:
            rowList = None
            for i in range(0, listLen - 1):
                rowList = self.def_ids.get(keylist[i])
                astr = rowList[1].text + "," + rowList[2].text + "\n"
                f.write(astr)

    def addInsertRow(self, strIndex):
        rowList = []
        funcLayout = SBoxLayout(size_hint=(.25, None), height=30)
        funcLayout.orientation = "horizontal"
        funcLayout.padding = (1, 1, 1, 1)
        funcLayout.add_widget(BoxLayout(size_hint=(.1, 1)))
        btn = SButton(text="新增", size_hint=(.8, 1))
        btn.halign = "center"
        btn.valign = "middle"
        btn.bind(on_release=self.addRecordPopup)
        funcLayout.add_widget(btn)
        funcLayout.add_widget(BoxLayout(size_hint=(.1, 1)))
        rowList.append(funcLayout)
        self.contentLayout.add_widget(funcLayout)
        contentLabel = SContentLabel(text="", size_hint=(.5, None), height=30)
        contentLabel.halign = "left"
        contentLabel.valign = "middle"
        rowList.append(contentLabel)
        self.contentLayout.add_widget(contentLabel)
        contentLabel = SContentLabel(text="", size_hint=(.25, None), height=30)
        contentLabel.halign = "left"
        contentLabel.valign = "middle"
        rowList.append(contentLabel)
        self.contentLayout.add_widget(contentLabel)
        
        self.def_ids[int(strIndex)] = rowList

    def addRecordPopup(self, instance):
        refDict = {}
        for key in self.paramDict.keys():
            refDict[key] = self.paramDict.get(key)
        refDict['mode'] = "1"
        self.add_scsLayout = SStrategySetting(refDict)
        self.add_popup = SPopup(title="新增策略", content=self.add_scsLayout,
                size_hint=(None, None), size=(560, 440), auto_dismiss=False)
        self.add_scsLayout.ensurebtn_id.bind(on_press=self.addRecordEvent)
        self.add_scsLayout.closebtn_id.bind(on_press=self.add_popup.dismiss)
        self.add_popup.title_font = CONSTS.FONT_NAME
        self.add_popup.open()

    def addRecordEvent(self, instance):
        strategyName = self.add_scsLayout.strategy_id.text
        if strategyName == None or strategyName == "":
            self.app.showErrorView(True, CONSTS.ERR_STRATEGY_IS_SPACE)
            return
        
        dflag = False
        for akey in self.def_ids.keys():
            rowList = self.def_ids.get(akey)
            if strategyName == rowList[1].text:
                dflag = True
                break
        if dflag:
            self.app.showErrorView(True, CONSTS.ERR_STRATEGY_DUPLICATED)
            return
        
        fileName = self.add_scsLayout.filename_id.text
        alist = []
        alist.append(strategyName)
        alist.append(fileName)
        self.addListRow(alist, True)
        self.maxIndex += 1
        self.addInsertRow(str(self.maxIndex))
        self.saveData()
        self.add_popup.dismiss()
        self.filePathTmp = os.path.abspath(os.path.join(save_dir, fileName))
        open(self.filePathTmp, 'a').close()
        threading.Thread(target=self.openFile).start()

    def openFile(self):
        os.system(self.filePathTmp)

    def updateRecordPopup(self, instance):
        refDict = {}
        for key in self.paramDict.keys():
            refDict[key] = self.paramDict.get(key)
        refDict['mode'] = "2"
        self.update_scsLayout = SStrategySetting(refDict)
        self.update_popup = SPopup(title="修改策略", content=self.update_scsLayout,
                size_hint=(None, None), size=(560, 440), auto_dismiss=False)
        self.update_scsLayout.ensurebtn_id.extra_info = instance.extra_info
        self.update_scsLayout.ensurebtn_id.bind(on_press=self.updateRecordEvent)
        self.update_scsLayout.closebtn_id.bind(on_press=self.update_popup.dismiss)
        self.update_popup.title_font = CONSTS.FONT_NAME
        rowList = self.def_ids.get(instance.extra_info)
        self.update_scsLayout.strategy_id.text = rowList[1].text
        self.update_scsLayout.filename_id.text = rowList[2].text
        self.update_popup.open()

    def updateRecordEvent(self, instance):
        rowIndex = instance.extra_info
        strategyName = self.update_scsLayout.strategy_id.text
        if strategyName == None or strategyName == "":
            self.app.showErrorView(True, CONSTS.ERR_STRATEGY_IS_SPACE)
            return
        fileName = self.update_scsLayout.filename_id.text
        dflag = False
        for akey in self.def_ids.keys():
            if akey == rowIndex:
                continue
            rowList = self.def_ids.get(akey)
            if strategyName == rowList[1].text and fileName == rowList[2].text:
                dflag = True
                break
        if dflag:
            self.app.showErrorView(True, CONSTS.ERR_STRATEGY_DUPLICATED)
            return
        rowList = self.def_ids.get(rowIndex)
        rowList[1].text = strategyName
        self.saveData()
        self.update_popup.dismiss()
        self.filePathTmp = os.path.abspath(os.path.join(save_dir, fileName))
        threading.Thread(target=self.openFile).start()        

    def deleteRecordPopup(self, instance):
        self.deleteConfirm = SRowConfirmLayout()
        self.del_popup = SPopup(title="刪除策略", content=self.deleteConfirm,
                size_hint=(None, None), size=(240, 160), auto_dismiss=False)
        self.deleteConfirm.yesbtn_id.extra_info = instance.extra_info
        self.deleteConfirm.yesbtn_id.bind(on_press=self.deleteRecordEvent)
        self.deleteConfirm.nobtn_id.bind(on_press=self.del_popup.dismiss)
        self.del_popup.title_font = CONSTS.FONT_NAME
        self.del_popup.open()

    def deleteRecordEvent(self, instance):
        self.deleteRow(instance.extra_info)
        self.del_popup.dismiss()
    
    def editContent(self, instance):
        rowList = self.def_ids.get(int(instance.extra_info))
        filePath = os.path.join(save_dir, rowList[2].text)
        os.system(os.path.abspath(filePath))
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
class StkQuery(BoxLayout):

    queryStr_id = ObjectProperty(None)
    query_id = ObjectProperty(None)
    body_layout = ObjectProperty(None)
    content_layout = ObjectProperty(None)
    ensureBtn_id = ObjectProperty(None)
    cancelBtn_id = ObjectProperty(None)

    def __init__(self, paramDict, **kwargs):
        super(StkQuery, self).__init__(**kwargs)
        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)

        self.num_per_page = NUM_PER_PAGE
        self.page_num = 1
        self.max_page_num = 1

        self.resultIdNameList = []
        self.selectDict = {}
        self.selectIdNameList = []
        self.contentView = None
        self.pageLayout = None
        self.enterPageLayout = None
        self.nextPreLayout = None

    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 _calcPageInfo(self):
        stkListNum = len(self.resultIdNameList)

        self.max_page_num = int(stkListNum / self.num_per_page)
        tmpNum = stkListNum % self.num_per_page
        if tmpNum != 0:
            self.max_page_num += 1
        if self.page_num > self.max_page_num:
            self.page_num = self.max_page_num

        self.page_id.text = str(self.page_num)
        self.totalpage_id.text = str(self.max_page_num)

    def _on_page_id_enter(self, instance):
        topage_num = int(instance.text)
        pageNum = 0
        if topage_num < 1:
            pageNum = 1
        elif topage_num > self.max_page_num:
            pageNum = self.max_page_num
        else:
            pageNum = topage_num
        self.page_id.text = str(pageNum)
        if pageNum == self.page_num:
            return

        self.page_num = pageNum

        self._addContentData()

    def _onChangePage(self, instance):
        if instance.text == "下一頁":
            if self.page_num == self.max_page_num:
                self.page_num = 1
            else:
                self.page_num += 1
        elif instance.text == "上一頁":
            if self.page_num == 1:
                self.page_num = self.max_page_num
            else:
                self.page_num -= 1
        else:
            topage_num = int(changePage)
            if topage_num < 1:
                self.page_num = 1
            elif topage_num > self.max_page_num:
                self.page_num = self.max_page_num
            self.topage_txt = str(self.page_num)

        self.page_id.text = str(self.page_num)

        self._addContentData()

    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 _on_checkbox_active(self, acheckbox, value):

        if value:
            self.selectDict[acheckbox.idNameList[0]] = acheckbox.idNameList
        else:
            self.selectDict.pop(acheckbox.idNameList[0])

    def doSelectStk(self):
        if len(self.selectDict) == 0:
            return
        self.selectIdNameList.clear()
        aList = None
        for stkId in self.selectDict.keys():
            aList = self.selectDict.get(stkId)
            self.selectIdNameList.append(aList)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
class SelfStkSetting(BoxLayout):
    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 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 deleteRow(self, rowId):
        rowList = self.def_ids.get(rowId)
        for obj in rowList:
            self.contentLayout.remove_widget(obj)
        self.def_ids.pop(rowId)
        if rowId in self.selfStkList:
            self.selfStkList.remove(rowId)

    def saveData(self):
        stkListStr = ""
        for stkId in self.selfStkList:
            stkListStr += stkId + "|"
        if len(stkListStr) != 0:
            stkListStr = stkListStr[0:-1]

        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "self_stkquote.ini")
        alist = sutil.getListFromFile(filePath)
        with open(filePath, 'w', encoding='utf-8') as f:
            for tmpStr in alist:
                aList = tmpStr.split(",")
                if int(aList[0]) == self.selfgroup_index:
                    astr = str(
                        self.selfgroup_index
                    ) + "," + self.selfgroup_name_id.text + "," + stkListStr + "\n"
                else:
                    astr = tmpStr + "\n"
                f.write(astr)

    def addInsertRow(self):
        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=INSERT_ROW_ID,
                          text="新增",
                          size_hint=(.8, 1))
        btn.halign = "center"
        btn.valign = "middle"
        btn.bind(on_release=self.addRecordPopup)
        funcLayout.add_widget(btn)
        funcLayout.add_widget(BoxLayout(size_hint=(.1, 1)))
        rowList.append(funcLayout)
        self.contentLayout.add_widget(funcLayout)
        contentLabel = SContentLabel(text="", size_hint=(.2, None), height=30)
        contentLabel.halign = "center"
        contentLabel.valign = "middle"
        rowList.append(contentLabel)
        self.contentLayout.add_widget(contentLabel)
        contentLabel = SContentLabel(text="", size_hint=(.65, None), height=30)
        contentLabel.halign = "left"
        contentLabel.valign = "middle"
        rowList.append(contentLabel)
        self.contentLayout.add_widget(contentLabel)

        self.def_ids[INSERT_ROW_ID] = rowList

    def addRecordPopup(self, instance):
        refDict = {}
        for key in self.paramDict.keys():
            refDict[key] = self.paramDict.get(key)
        self.add_scsLayout = StkQuery(refDict)
        self.add_popup = SPopup(title="新增自選股票",
                                content=self.add_scsLayout,
                                size_hint=(None, None),
                                size=(480, 360),
                                auto_dismiss=False)
        self.add_scsLayout.ensureBtn_id.bind(on_press=self.addRecordEvent)
        self.add_scsLayout.cancelBtn_id.bind(on_press=self.add_popup.dismiss)
        self.add_popup.title_font = CONSTS.FONT_NAME
        self.add_popup.open()

    def addRecordEvent(self, instance):
        self.add_scsLayout.doSelectStk()

        if len(self.add_scsLayout.selectIdNameList) == 0:
            return

        duplicatedIds = []
        for aList in self.add_scsLayout.selectIdNameList:
            if aList[0] in self.selfStkList:
                duplicatedIds.append(aList[0][2:])
        if len(duplicatedIds) != 0:
            self.app.showErrorView(True, CONSTS.ERR_STKID_DUPLICATED,
                                   duplicatedIds)
            return

        self.deleteRow(INSERT_ROW_ID)

        for aList in self.add_scsLayout.selectIdNameList:
            self.addListRow(aList)
            self.selfStkList.append(aList[0])

        self.addInsertRow()

        self.add_popup.dismiss()

    def deleteRecordPopup(self, instance):
        self.deleteConfirm = SRowConfirmLayout()
        self.del_popup = SPopup(title="刪除自選股票",
                                content=self.deleteConfirm,
                                size_hint=(None, None),
                                size=(240, 160),
                                auto_dismiss=False)
        self.deleteConfirm.yesbtn_id.extra_info = instance.extra_info
        self.deleteConfirm.yesbtn_id.bind(on_press=self.deleteRecordEvent)
        self.deleteConfirm.nobtn_id.bind(on_press=self.del_popup.dismiss)
        self.del_popup.title_font = CONSTS.FONT_NAME
        self.del_popup.open()

    def deleteRecordEvent(self, instance):
        self.deleteRow(instance.extra_info)
        self.del_popup.dismiss()
Exemplo n.º 12
0
    def __init__(self, paramDict, **kwargs):
        super(StkQuote, self).__init__(**kwargs)
        
        self.lock = threading.RLock()

        self.size_hint = (1, 1)
        self.orientation = "vertical"

        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)
        self.dispIdName = self.paramDict.get("dispIdName", True)
        self.headDict = self.paramDict.get("headDict")
        self.headIdList = []
        self.headIdList.append("id")
        self.headIdList.append("name")
        
        for aKey in self.headDict.keys():
            if aKey == "id" or aKey == "name":
                continue
            else:
                self.headIdList.append(aKey)
        
        self.fieldIdList = [] #記錄資料的欄位列表(不包含id及name欄位)
        self.dispIdList = [] #記錄顯示的欄位列表
        """
        if self.dispIdName == True:
            self.dispIdList內容為 ['id','name','price','vol', ...]
        else:
            self.dispIdList內容為 ['id'(or 'name'),'price','vol', ...]
        """
        self.fieldMapping = {} #記錄資料欄位與顯示欄位的對應,''代表畫面不顯示此欄位
        """
        if self.dispIdName == True:
            {'id':'0', 'name':'1', 'price':'2', 'vol':'3', ...,}
        else:
            {'name':'0'(or 'id':'0'), 'price':'1', 'vol':'2', ...,}
        """
        self.dispFieldMapping = {} #記錄顯示欄位與資料欄位的對應
        """
        if self.dispIdName == True:
            {'0':'id', '1':'name', '2':'price', '3':'vol', ...}
        else:
            {'0':'name'(or '0':'id'), '1':'price', '2':'vol', ...}
        """
        # 1001-Begin: 以下將欄位訊息儲存至相關的變數中
        shiftIdx = 1
        self.fieldMapping["name"] = "0"
        if self.dispIdName == True:
            self.fieldMapping["id"] = "0"
            self.dispFieldMapping["0"] = "id"
            self.dispIdList.append("id")
            self.fieldMapping["name"] = "1"
            self.dispFieldMapping["1"] = "name"
            self.dispIdList.append("name")
            shiftIdx = 0
        else:
            self.dispIdList.append("name")
            self.fieldMapping["id"] = ""
            self.dispFieldMapping["0"] = "name"
        for idx in range(2, len(self.headIdList)):
            self.fieldIdList.append(self.headIdList[idx])
            if (idx - shiftIdx) >= COLUMN_NUM:
                self.fieldMapping[self.headIdList[idx]] = ""
            else:
                self.fieldMapping[self.headIdList[idx]] = str(idx - shiftIdx)
                self.dispFieldMapping[str(idx - shiftIdx)] = self.headIdList[idx]
                self.dispIdList.append(self.headIdList[idx])

        self.headButtonList = [] #記錄標題之Button List
        self.quoteBaseDict = {} #記錄股票基本資料之字典
        self.quoteDataDict = {} #記錄所有報價資料之字典
        """self.quoteDataDict資料格式如下所示:
           stkid: {'id': [stkId,fg_color,bg_color],'name': [stkName,fg_color,bg_color],'price': [priceValue,fg_color,bg_color], ...}
           example: 'T11101': {'id':['T11101','#000000','#FFFFFF'],'name':['台泥','#000000','#FFFFFF'],'price':[10.0,'#000000','#FFFFFF']}
        """
        self.dispDict = {} #記錄顯示物件的字典
        """self.dispDict資料格式如下所示:
        {stkid:{'0':Kivy Object, '1': Kivy Object, ....},stkid:{'0':Kivy Object, '1': Kivy Object, ....}}
        """

        headNum = len(self.dispFieldMapping) #取得畫面顯示的欄位數
        self.headLayout = STableGridLayout(cols=headNum, rows=1, spacing=2, size_hint=(1, 1))
        #1000-Start: 計算欄位寬度的size_hint
        if headNum < COLUMN_NUM: #如果欄位數比預設欄位數少
            self.idWidth_hint = 1.0 / headNum
            self.otherWidth_hint = self.idWidth_hint
        else:
            self.idWidth_hint = 0.1
            addWidth_hint = 0.1
            addField = 1
            if self.dispIdName == True:
                addWidth_hint += 0.1
                addField += 1
            self.otherWidth_hint = (1.0 - addWidth_hint) / (headNum - addField)
        #1000-End.
        for colIndexStr in self.dispFieldMapping.keys():
            headId = self.dispFieldMapping.get(colIndexStr)
            field = self.headDict.get(headId)
            if headId == "id" or headId == "name":
                headButton = SHeadSortedButton(headText = field, headIndex = headId, text = field, size_hint = (self.idWidth_hint, 1))
            else:
                headButton = SHeadSortedButton(headText = field, headIndex = headId, text = field, size_hint = (self.otherWidth_hint, 1))
            self.headLayout.add_widget(headButton)
            self.headButtonList.append(headButton)
        self.head_layout.add_widget(self.headLayout)

        self.contentLayout = STableGridLayout(cols=headNum, 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'))
        
        self.body_layout.add_widget(self.contentLayout)
Exemplo n.º 13
0
class StkQuote(BoxLayout):

    head_layout = ObjectProperty(None)
    body_layout = ObjectProperty(None)
    selfStkList = ObjectProperty(None)
    subscribeList = ObjectProperty(None)
        
    def __init__(self, paramDict, **kwargs):
        super(StkQuote, self).__init__(**kwargs)
        
        self.lock = threading.RLock()

        self.size_hint = (1, 1)
        self.orientation = "vertical"

        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)
        self.dispIdName = self.paramDict.get("dispIdName", True)
        self.headDict = self.paramDict.get("headDict")
        self.headIdList = []
        self.headIdList.append("id")
        self.headIdList.append("name")
        
        for aKey in self.headDict.keys():
            if aKey == "id" or aKey == "name":
                continue
            else:
                self.headIdList.append(aKey)
        
        self.fieldIdList = [] #記錄資料的欄位列表(不包含id及name欄位)
        self.dispIdList = [] #記錄顯示的欄位列表
        """
        if self.dispIdName == True:
            self.dispIdList內容為 ['id','name','price','vol', ...]
        else:
            self.dispIdList內容為 ['id'(or 'name'),'price','vol', ...]
        """
        self.fieldMapping = {} #記錄資料欄位與顯示欄位的對應,''代表畫面不顯示此欄位
        """
        if self.dispIdName == True:
            {'id':'0', 'name':'1', 'price':'2', 'vol':'3', ...,}
        else:
            {'name':'0'(or 'id':'0'), 'price':'1', 'vol':'2', ...,}
        """
        self.dispFieldMapping = {} #記錄顯示欄位與資料欄位的對應
        """
        if self.dispIdName == True:
            {'0':'id', '1':'name', '2':'price', '3':'vol', ...}
        else:
            {'0':'name'(or '0':'id'), '1':'price', '2':'vol', ...}
        """
        # 1001-Begin: 以下將欄位訊息儲存至相關的變數中
        shiftIdx = 1
        self.fieldMapping["name"] = "0"
        if self.dispIdName == True:
            self.fieldMapping["id"] = "0"
            self.dispFieldMapping["0"] = "id"
            self.dispIdList.append("id")
            self.fieldMapping["name"] = "1"
            self.dispFieldMapping["1"] = "name"
            self.dispIdList.append("name")
            shiftIdx = 0
        else:
            self.dispIdList.append("name")
            self.fieldMapping["id"] = ""
            self.dispFieldMapping["0"] = "name"
        for idx in range(2, len(self.headIdList)):
            self.fieldIdList.append(self.headIdList[idx])
            if (idx - shiftIdx) >= COLUMN_NUM:
                self.fieldMapping[self.headIdList[idx]] = ""
            else:
                self.fieldMapping[self.headIdList[idx]] = str(idx - shiftIdx)
                self.dispFieldMapping[str(idx - shiftIdx)] = self.headIdList[idx]
                self.dispIdList.append(self.headIdList[idx])

        self.headButtonList = [] #記錄標題之Button List
        self.quoteBaseDict = {} #記錄股票基本資料之字典
        self.quoteDataDict = {} #記錄所有報價資料之字典
        """self.quoteDataDict資料格式如下所示:
           stkid: {'id': [stkId,fg_color,bg_color],'name': [stkName,fg_color,bg_color],'price': [priceValue,fg_color,bg_color], ...}
           example: 'T11101': {'id':['T11101','#000000','#FFFFFF'],'name':['台泥','#000000','#FFFFFF'],'price':[10.0,'#000000','#FFFFFF']}
        """
        self.dispDict = {} #記錄顯示物件的字典
        """self.dispDict資料格式如下所示:
        {stkid:{'0':Kivy Object, '1': Kivy Object, ....},stkid:{'0':Kivy Object, '1': Kivy Object, ....}}
        """

        headNum = len(self.dispFieldMapping) #取得畫面顯示的欄位數
        self.headLayout = STableGridLayout(cols=headNum, rows=1, spacing=2, size_hint=(1, 1))
        #1000-Start: 計算欄位寬度的size_hint
        if headNum < COLUMN_NUM: #如果欄位數比預設欄位數少
            self.idWidth_hint = 1.0 / headNum
            self.otherWidth_hint = self.idWidth_hint
        else:
            self.idWidth_hint = 0.1
            addWidth_hint = 0.1
            addField = 1
            if self.dispIdName == True:
                addWidth_hint += 0.1
                addField += 1
            self.otherWidth_hint = (1.0 - addWidth_hint) / (headNum - addField)
        #1000-End.
        for colIndexStr in self.dispFieldMapping.keys():
            headId = self.dispFieldMapping.get(colIndexStr)
            field = self.headDict.get(headId)
            if headId == "id" or headId == "name":
                headButton = SHeadSortedButton(headText = field, headIndex = headId, text = field, size_hint = (self.idWidth_hint, 1))
            else:
                headButton = SHeadSortedButton(headText = field, headIndex = headId, text = field, size_hint = (self.otherWidth_hint, 1))
            self.headLayout.add_widget(headButton)
            self.headButtonList.append(headButton)
        self.head_layout.add_widget(self.headLayout)

        self.contentLayout = STableGridLayout(cols=headNum, 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'))
        
        self.body_layout.add_widget(self.contentLayout)

    def setStkList(self, selfStkList):
        self.selfStkList = selfStkList
    
    def setSubscribeList(self, subscribeList):
        self.subscribeList = subscribeList

    def setGroupName(self, groupName):
        self.groupName = groupName

    def _getDefaultDict(self):
        aDict = {}
        for headId in self.headIdList:
            aDict[headId] = ['', DEFAULT_FGCOLOR, DEFAULT_BGCOLOR]
        return aDict 

    @synchronized_with_attr("lock")
    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 _openOptionPopup(self):
        content = BoxLayout(size_hint=(1, 1), orientation="vertical")
        
        strendBtn = SButton(text="走勢圖", size_hint=(1, None), height=30)
        strendBtn.bind(on_press=self._openStrendChart)
        content.add_widget(strendBtn)
        
        content.add_widget(BoxLayout(size_hint=(1, None), height=1))
        
        stechBtn = SButton(text="技術分析", size_hint=(1, None), height=30)
        stechBtn.bind(on_press=self._openStechChart)
        content.add_widget(stechBtn)
        
        content.add_widget(BoxLayout(size_hint=(1, None), height=1))

        closeBtn = SButton(text="關閉", size_hint=(1, None), height=30)
        content.add_widget(closeBtn)

        titleName = self.oneStkDict.get("id") + " " + self.oneStkDict.get("name")
        self.option_popup = SPopup(title=titleName, content=content, title_font=CONSTS.FONT_NAME,
                        size_hint=(None, None), size=(240, 152), auto_dismiss=False)
        closeBtn.bind(on_press=self.option_popup.dismiss)
        self.option_popup.open()

    def _id_press(self, instance):
        self.oneStkDict = {}
        currIdx = -1
        for aKey in self.quoteBaseDict.keys():
            currIdx += 1
            if instance.text == aKey[2:]:
                self.oneStkDict = self.quoteBaseDict.get(aKey)
                break
        
        self.currIndex = currIdx
        self._openOptionPopup()

    def _name_press(self, instance):
        self.oneStkDict = {}
        currIdx = -1
        for aKey in self.quoteBaseDict.keys():
            currIdx += 1
            aDict = self.quoteBaseDict.get(aKey)
            if instance.text == aDict.get("name"):
                self.oneStkDict = aDict
                break

        self.currIndex = currIdx
        self._openOptionPopup()
    
    def _openStrendChart(self, instance):
        self.option_popup.dismiss()
        
        refParam = {}
        refParam[CONSTS.S_APP] = self.app
        refParam["ChartType"] = "1"
        refParam["GroupName"] = self.groupName
        refParam["SelfStkList"] = self.selfStkList
        refParam["SubscribeList"] = self.subscribeList
        refParam["QuoteBaseDict"] = self.quoteBaseDict
        refParam["OneStkDict"] = self.oneStkDict
      
        self.stcLayout = StkGroupView(refParam)
        self.strend_popup = SPopup(title="走勢圖&技術分析", content=self.stcLayout,
            size_hint=(None, None), size=(720, 540), auto_dismiss=False)
        self.stcLayout.closebtn_id.bind(on_press=self._strend_popup_dismiss)
        self.strend_popup.title_font = CONSTS.FONT_NAME
        self.strend_popup.open()

    def _strend_popup_dismiss(self, instance):
        self.strend_popup.dismiss()
        self.stcLayout.removeListener()    

    def _openStechChart(self, instance):
        self.option_popup.dismiss()
        
        refParam = {}
        refParam[CONSTS.S_APP] = self.app
        refParam["ChartType"] = "2"
        refParam["GroupName"] = self.groupName
        refParam["SelfStkList"] = self.selfStkList
        refParam["SubscribeList"] = self.subscribeList
        refParam["QuoteBaseDict"] = self.quoteBaseDict
        refParam["OneStkDict"] = self.oneStkDict

        self.sttLayout = StkGroupView(refParam)
        self.stech_popup = SPopup(title="走勢圖&技術分析", content=self.sttLayout,
            size_hint=(None, None), size=(720, 540), auto_dismiss=False)
        self.sttLayout.closebtn_id.bind(on_press=self._stech_popup_dismiss)
        self.stech_popup.title_font = CONSTS.FONT_NAME
        self.stech_popup.open()
    
    def _stech_popup_dismiss(self, instance):
        self.stech_popup.dismiss()
        self.sttLayout.removeListener()    

    @synchronized_with_attr("lock")
    def updateBaseQuote(self, baseList):
        for aDict in baseList:
            stkId = aDict.get("id")
            if stkId == None:
                continue
            else:
                existDict = self.quoteBaseDict.get(stkId)
                if existDict == None: #若無報價基本資料,創建一新的字典
                    existDict = {}
                tmpId = None
                for headId in aDict.keys():
                    existDict[headId] = aDict.get(headId)               
                self.quoteBaseDict[stkId] = existDict
        
    @synchronized_with_attr("lock")
    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
        #5001-End.

    @synchronized_with_attr("lock")
    def clearQuote(self):
        if self.contentLayout != None:
            self.contentLayout.clear_widgets()
        self.quoteBaseDict.clear()
        self.quoteDataDict.clear()
        self.dispDict.clear()

    @synchronized_with_attr("lock")
    def resetFieldsSeq(self, fieldIdList):
        self.fieldIdList = fieldIdList
        headIdIndex = -1
        for aObj in self.headButtonList:
            if aObj.headIndex == "id" or aObj.headIndex == "name":
                continue
            headIdIndex += 1
            headId = self.fieldIdList[headIdIndex]
            aObj.headIndex = headId
            aObj.text = self.headDict.get(headId)

        self._shiftDispField()        

    @synchronized_with_attr("lock")
    def nextField(self):
        removeId = self.fieldIdList.pop(0)
        self.fieldIdList.append(removeId)
        headIdIndex = -1
        for aObj in self.headButtonList:
            if aObj.headIndex == "id" or aObj.headIndex == "name":
                continue
            headIdIndex += 1
            headId = self.fieldIdList[headIdIndex]
            aObj.headIndex = headId
            aObj.text = self.headDict.get(headId)

        self._shiftDispField()
    
    @synchronized_with_attr("lock")
    def previousField(self):
        removeId = self.fieldIdList.pop(-1)
        self.fieldIdList.insert(0, removeId)
        headIdIndex = -1
        for aObj in self.headButtonList:
            if aObj.headIndex == "id" or aObj.headIndex == "name":
                continue
            headIdIndex += 1
            headId = self.fieldIdList[headIdIndex]
            aObj.headIndex = headId
            aObj.text = self.headDict.get(headId)
        
        self._shiftDispField()  

    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"
Exemplo n.º 14
0
class SSelectStock(BoxLayout):
        
    def __init__(self, paramDict, **kwargs):
        super(SSelectStock, self).__init__(**kwargs)
        
        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)
        self.fidList = self.paramDict.get("fidList")

        self.size_hint = (1, 1)
        self.orientation = "vertical"

        self.doSelectStock()

    def doSelectStock(self):
        userConf = sutil.getDictFromFile(os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "user.ini"))
        useridTxt = self.app.account
        if useridTxt.find("@") != -1:
            useridTxt = "1|" + useridTxt
        else:
            useridTxt = "2|" + useridTxt          
        gwParam = {}
        gwParam["Host"] = userConf.get("DOWNLOAD_URL").strip()
        gwParam["Port"] = int(userConf.get("DOWNLOAD_PORT").strip())
        gwParam["User"] = useridTxt
        gwParam["Password"] = self.app.pwd
        gwParam["ProductId"] = int(userConf.get("PRODUCT_ID").strip())
        gwParam["UserType"] = int(userConf.get("USER_TYPE").strip())
        gwParam["LoginType"] = int(userConf.get("TRADE_LOGIN_TYPE").strip())
        gwParam["Source"] = ""
        gwParam["StockCount"] = 0
        gwParam["Condition"] = self.fidList

        sysConfDict = self.app.confDict.get(CONSTS.SYS_CONF_DICT)
        
        refParam = {}
        refParam["CONSTS.S_APP"] = self.app
        refParam["TitleMsg"] = sysConfDict.get("MSG_TITLE")
        refParam["InfoMsg"] = "  資料讀取中..."
        refParam["PopupSize"] = (160, 120)
        refParam["GwParam"] = gwParam
        refParam["GwFunc"] = abxtoolkit.select_stock
        refParam["ResultFunc"] = self._finishedSelectStock

        sgwPopup = SGwPopup(refParam)
        sgwPopup.processEvent()

    def _finishedSelectStock(self, gwResult):

        self.result = gwResult
        dataFields = gwResult.get("DataFields")
        headNum = len(dataFields)
        
        self.currentHeadIndex = 0
        self.sortedDirection = 1
        self.headButtonList = []
        headLayout = STableGridLayout(cols=headNum, rows=1, spacing=2, size_hint=(1, None), height=30)
        headIndex = -1
        for field in dataFields:            
            headIndex += 1
            headButton = SHeadSortedButton(headText = field, headIndex = headIndex, text = field, size_hint = (1.0 / headNum, 1))
            if headIndex == 0:
                headButton.text = field + " ▼"
            headButton.bind(on_release=self._sortedData)
            headLayout.add_widget(headButton)
            self.headButtonList.append(headButton)
        self.add_widget(headLayout)
        
        gapLayout = STableBoxLayout(size_hint=(1, None), height=2)
        self.add_widget(gapLayout)

        slview = STableScrollView()
        slview.size_hint = (1, .9)
        self.contentLayout = STableGridLayout(cols=headNum, 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'))
        
        stockData = gwResult.get("StockData")
        self.currStockDataList = stockData.split(";")
        self._addStockData()

        slview.add_widget(self.contentLayout)
        
        self.add_widget(slview)

    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 _sortedData(self, instance):
        if instance.headIndex == self.currentHeadIndex:
            if self.sortedDirection == 1:
                self.sortedDirection = -1
                aBtn = self.headButtonList[self.currentHeadIndex]
                aBtn.text = aBtn.headText + " ▲"
            else:
                self.sortedDirection = 1
                aBtn = self.headButtonList[self.currentHeadIndex]
                aBtn.text = aBtn.headText + " ▼"                
            self.currStockDataList.reverse()
        else:
            aBtn = self.headButtonList[self.currentHeadIndex]
            aBtn.text = aBtn.headText            
            self.currentHeadIndex = instance.headIndex
            aBtn = self.headButtonList[self.currentHeadIndex]
            aBtn.text = aBtn.headText + " ▼"            
            self.sortedDirection = 1
            dataFields = self.result.get("DataFields")
            headNum = len(dataFields)              
            stockData = self.result.get("StockData")
            stockDataList = stockData.split(";")
            sortinfoList = []
            dataDict = {}
            for aData in stockDataList:
                if aData == "":
                    continue
                aFieldList = aData.split("|")
                stkId = ""
                num = -1
                for aField in aFieldList:
                    if aField == "":
                        continue
                    num += 1                   
                    if dataFields[num] == "ID":
                        stkId = aField
                        break
                aHeader = dataFields[self.currentHeadIndex]
                aValue = aFieldList[self.currentHeadIndex]
                if aHeader == "ID" or aHeader == "NAME":
                    sortinfoList.append(SortInfo(stkId, aValue))
                else:
                    sortinfoList.append(SortInfo(stkId, float(aValue)))
                dataDict[stkId] = aData
            sortList = sorted(sortinfoList)
            self.currStockDataList.clear()
            for aObj in sortList:
                self.currStockDataList.append(dataDict.get(aObj.pKey))
        self._addStockData()
                        
            
            
            
Exemplo n.º 15
0
class SOptionSelect(BoxLayout):

    contentLayout_id = ObjectProperty(None)
    ensurebtn_id = ObjectProperty(None)
    resetbtn_id = ObjectProperty(None)
    selectbtn_id = ObjectProperty(None)
    closebtn_id = ObjectProperty(None)
    sysConfDict = {}
    optionList = None
    kwargs = {}
    
    def __init__(self, refDict, **kwargs):
        super(SOptionSelect, self).__init__(**kwargs)

        self.app = refDict.get(CONSTS.S_APP)
        self.sysConfDict = self.app.confDict.get(CONSTS.SYS_CONF_DICT)
 
        slview = STableScrollView()
        slview.size_hint = (1, 1)
        self.stgLayout = STableGridLayout(cols=1, spacing=2, size_hint_y=None)
        # Make sure the height is such that there is something to scroll.
        self.stgLayout.bind(minimum_height=self.stgLayout.setter('height'))
        slview.add_widget(self.stgLayout)
        
        self.contentLayout_id.add_widget(slview)
        
        self._doQueryFormulaId()

    def _doQueryFormulaId(self):
        refParam = {}
        refParam["CONSTS.S_APP"] = self.app
        refParam["TitleMsg"] = self.sysConfDict.get("MSG_TITLE")
        refParam["InfoMsg"] = "  資料讀取中..."
        refParam["PopupSize"] = (160, 120)
        gwParam = {}
        userConf = sutil.getDictFromFile(os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "user.ini"))
        useridTxt = self.app.account
        if useridTxt.find("@") != -1:
            useridTxt = "1|" + useridTxt
        else:
            useridTxt = "2|" + useridTxt        
        gwParam["Host"] = userConf.get("DOWNLOAD_URL").strip()
        gwParam["Port"] = int(userConf.get("DOWNLOAD_PORT").strip())
        gwParam["User"] = useridTxt
        gwParam["Password"] = self.app.pwd
        gwParam["ProductId"] = int(userConf.get("PRODUCT_ID").strip())
        gwParam["UserType"] = int(userConf.get("USER_TYPE").strip())
        gwParam["LoginType"] = int(userConf.get("TRADE_LOGIN_TYPE").strip())
        gwParam["CateID"] = 8202000        
        refParam["GwParam"] = gwParam
        refParam["GwFunc"] = abxtoolkit.query_formulaid
        refParam["ResultFunc"] = self._finishedQueryFormulaId 

        sgwPopup = SGwPopup(refParam)
        sgwPopup.processEvent()
        
    def _finishedQueryFormulaId(self, gwResult):
        
        if self.optionList == None:
            self.optionList = []
        else:
            self.optionList.clear()

        formulaList = gwResult.get("FormulaList")

        aOption = None
        for adict in formulaList:
            aOption = SOptionElement({"OptionDict":adict})
            aOption.size_hint = (1, None)
            aOption.height = 32
            self.optionList.append(aOption)
            self.stgLayout.add_widget(aOption)
    
    def setToOptionDefault(self):
        if self.optionList == None:
            return
        for aObj in self.optionList:
            aObj.setToDefaultValue()
    
    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()