コード例 #1
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()
コード例 #2
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()
コード例 #3
0
    def onFocus(self, instance, value):
        if value:
            content = BoxLayout(size_hint=(1, 1), orientation="vertical")
            self.datePicker = SDatePicker(self.startdate_id.text)
            self.datePicker.size_hint = (1, .8)
            content.add_widget(self.datePicker)

            bottomLayout = BoxLayout(size_hint=(1, .1),
                                     orientation="horizontal")
            ensurebtn = SButton(text="確定", size_hint=(.49, .8))
            bottomLayout.add_widget(ensurebtn)
            bottomLayout.add_widget(BoxLayout(size_hint=(.02, 1)))
            closebtn = SButton(text="關閉", size_hint=(.49, .8))
            bottomLayout.add_widget(closebtn)
            content.add_widget(bottomLayout)

            self._popup = SPopup(title="日期選擇",
                                 content=content,
                                 title_font=CONSTS.FONT_NAME,
                                 size_hint=(None, None),
                                 size=(250, 330),
                                 auto_dismiss=False)
            ensurebtn.bind(on_press=self.datePickerEvent)
            closebtn.bind(on_press=self._popup.dismiss)
            self._popup.open()
コード例 #4
0
ファイル: sstrategy.py プロジェクト: haojiehuang/syt_backtest
    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)
コード例 #5
0
 def __init__(self, paramDict, **kwargs):
     super(SExecTrade, self).__init__(**kwargs)
     
     self.paramDict = paramDict
     self.app = self.paramDict.get(CONSTS.S_APP)
     self.sysConfDict = self.app.confDict.get(CONSTS.SYS_CONF_DICT)
     self.strategyDict = {}
     
     self.rowdata_id.bind(focus=self.onRowdataFocus)
     
     self.strategyDropDown = SStrategyDropDown()
     firstRecord = True
     strategyList = None
     filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "strategy.ini")
     alist = sutil.getListFromFile(filePath)
     for astr in alist:
         strategyList = astr.strip().split(",")
         if len(strategyList) < 2:
             continue
         if firstRecord:
             firstRecord = False
             self.strategy_id.text = strategyList[0]
         self.strategyDict[strategyList[0]] = strategyList
         abtn = SButton(text=strategyList[0])
         abtn.size_hint_y = None
         abtn.height = 30
         abtn.bind(on_release=self.strategyDropDown.select)
         self.strategyDropDown.add_widget(abtn)
         
     self.strategy_id.bind(on_release=self.strategyDropDown.open)
     self.strategyDropDown.bind(on_select=self.strategySelect)
     
     self.savefile_id.bind(focus=self.onSavefileFocus)
コード例 #6
0
    def showExplain(self):
        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "trade_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, .9))
        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 = STableBoxLayout(size_hint=(1, .1))
        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),
                       pos_hint={
                           'x': 0.1,
                           'y': 0.1
                       },
                       pos=(100.0, 100.0),
                       auto_dismiss=False)
        closebtn_id.bind(on_press=popup.dismiss)
        popup.title_font = CONSTS.FONT_NAME
        popup.open()
コード例 #7
0
    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
コード例 #8
0
    def __init__(self, paramDict, **kwargs):
        super(SDownload, self).__init__(**kwargs)

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

        self.datatype_dropdown = DatatypeDropDown()
        self.datatypebtn_id.bind(on_release=self.datatype_dropdown.open)
        self.datatype_dropdown.bind(on_select=self.datatypeSelect)

        self.accountIDDropDown = SAccountIDDropDown()
        firstRecord = True
        accountIdList = self.app.accountIdList
        for astr in accountIdList:
            if firstRecord == True:
                firstRecord = False
                self.account_id.text = astr
            abtn = SButton(text=astr)
            abtn.size_hint_y = None
            abtn.height = 30
            abtn.bind(on_release=self.accountIDDropDown.select)
            self.accountIDDropDown.add_widget(abtn)

        self.account_id.bind(on_release=self.accountIDDropDown.open)
        self.accountIDDropDown.bind(on_select=self.accountSelect)

        self.startdate_id.bind(focus=self.onFocus)

        self.initial_data()
コード例 #9
0
    def finishedPopup(self):
        content = BoxLayout(size_hint=(1, 1), orientation="vertical")

        content.add_widget(BoxLayout(size_hint=(1, .4)))

        bottomLayout = BoxLayout(size_hint=(1, .2), orientation="horizontal")
        bottomLayout.add_widget(BoxLayout(size_hint=(.1, 1)))
        ensurebtn = SButton(text="確定", size_hint=(.8, .8))
        bottomLayout.add_widget(ensurebtn)
        bottomLayout.add_widget(BoxLayout(size_hint=(.1, 1)))
        content.add_widget(bottomLayout)

        content.add_widget(BoxLayout(size_hint=(1, .4)))

        self.fin_popup = SPopup(title="執行完成",
                                content=content,
                                title_font=CONSTS.FONT_NAME,
                                size_hint=(None, None),
                                size=(200, 100),
                                auto_dismiss=False)
        ensurebtn.bind(on_press=self.fin_popup.dismiss)
        self.fin_popup.open()
コード例 #10
0
    def _finishedDownload(self, gwResult):
        fileName = gwResult.get("FileName")
        fileLen = gwResult.get("FileLen")

        content = BoxLayout(size_hint=(1, 1), orientation="vertical")
        content.add_widget(BoxLayout(size_hint=(1, .05)))

        fileLayout = GridLayout(cols=2, spacing=2, size_hint=(1, None))
        fileLayout.bind(minimum_height=fileLayout.setter('height'))
        fileLayout.add_widget(
            SLabel(text="檔案目錄:", size_hint=(.22, None), height=30))
        fileLayout.add_widget(
            SLabel(text=download_path, size_hint=(.78, None), height=30))
        fileLayout.add_widget(
            SLabel(text="檔案名稱:", size_hint=(.22, None), height=30))
        fileLayout.add_widget(
            SLabel(text=fileName, size_hint=(.78, None), height=30))
        fileLayout.add_widget(
            SLabel(text="檔案長度:", size_hint=(.22, None), height=30))
        fileLayout.add_widget(
            SLabel(text=str(fileLen), size_hint=(.78, None), height=30))
        content.add_widget(fileLayout)

        content.add_widget(BoxLayout(size_hint=(1, .05)))

        bottomLayout = BoxLayout(size_hint=(1, .1), orientation="horizontal")
        ensurebtn = SButton(text="確定", size_hint=(1, .8))
        bottomLayout.add_widget(ensurebtn)
        content.add_widget(bottomLayout)

        self.fin_popup = Popup(title="下載完成",
                               content=content,
                               title_font=CONSTS.FONT_NAME,
                               size_hint=(None, None),
                               size=(360, 200),
                               auto_dismiss=False)
        ensurebtn.bind(on_press=self.fin_popup.dismiss)
        self.fin_popup.open()
コード例 #11
0
    def showErrMsg(self, errList):
        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "err_explain.ini")
        with open(filePath, 'r', encoding='utf-8-sig') as f:
            lineList = f.readlines()
        explainStr = ""
        for astr in lineList:
            explainStr += astr
        explainStr += "\n\n"
        for astr in errList:
            explainStr += astr + "\n"

        contentLayout = BoxLayout(size_hint=(1, 1), orientation="vertical")
        slview = ScrollView(size_hint=(1, .92))
        contentLayout.add_widget(slview)
        explainLayout = BoxLayout(size_hint=(1, None))
        explainLayout.bind(minimum_height=explainLayout.setter('height'))
        explainLabel = SLabel(text=explainStr, size_hint=(1, None))
        explainLabel.halign = "center"
        explainLabel.font_name = CONSTS.FONT_NAME
        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 = Popup(title="錯誤格式說明",
                      content=contentLayout,
                      size_hint=(None, None),
                      size=(680, 400),
                      auto_dismiss=False)
        closebtn_id.bind(on_press=popup.dismiss)
        popup.title_font = CONSTS.FONT_NAME
        popup.open()
コード例 #12
0
ファイル: sbtmenu.py プロジェクト: haojiehuang/syt_backtest
    def __init__(self, paramDict, **kwargs):
        super(SBTMenu, self).__init__(**kwargs)

        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)
        
        userConf = sutil.getDictFromFile(os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "user.ini"))
        bt_file = userConf.get("BACKTEST_FILE")
        if bt_file != None and bt_file != "":
            self.fileList = bt_file.split(",")
            aflag = False
            for afile in self.fileList:
                afilePath = os.path.join(bk_file_dir, afile)
                if not os.path.exists(afilePath):
                    aflag = True
                    break
            if not aflag:
                if self.body_layout != None:
                    self.remove_widget(self.body_layout)
                refDict = {}
                for key in self.paramDict.keys():
                    refDict[key] = self.paramDict[key]
                refDict["fileDir"] = bk_file_dir
                refDict["fileList"] = self.fileList
                refDict[CONSTS.S_BTMENU] = self
                self.sbacktest = SBacktest(refDict)
                self.body_layout = self.sbacktest
                self.body_layout.size_hint = (1, .95)
                self.body_layout.pos_hint = {'x':0,'y':0}
                self.add_widget(self.body_layout, index=0)
        
        subMenu = self.paramDict.get("SUBMENU")
        if subMenu != None:
            if subMenu == False:
                exitBtn = SButton(text="離開", size_hint=(1, 1))
                exitBtn.halign = "center"
                exitBtn.valign = "middle"
                exitBtn.bind(on_release=self.closeWindows)
                self.exitLayout_id.add_widget(exitBtn)
コード例 #13
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)
コード例 #14
0
 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
コード例 #15
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)
コード例 #16
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)
コード例 #17
0
    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()