def __Stage_2_ValidateBtnClick(self, event): self.stopwatch.Stop() panel = event.GetEventObject().GetParent() panelNumber = self.panelsNumbers[panel] answer = panel.FindWindow('AnswerField').GetValue() if self.__Stage_2_ValidateAnswer(answer): panel.FindWindow('AnswerField').Hide() panel.FindWindow('ValidateButton').Hide() panel.FindWindow('CancelButton').Hide() answerText = panel.FindWindow('AnswerText') answerText.SetLabel( textwrap.fill( structs.CurLang('Research', 'AnswerText') + ' : ' + answer, 40)) answerText.Show() qn = self.__Stage_2_CalculateQuestionNumber(panelNumber) if structs.GetSetting('score'): self.__Stage_2_ScoreRecalc(panelNumber, qn, answer) if self.questionsAnswered == structs.GetSetting('groups_number'): panel.GetParent().FindWindow('NextRoundButton').Enable() UpdateAll(panel.GetParent()) self.answers.append( structs.NewAnswer(self.questions[qn], answer, self.stopwatch.GetTime())) else: self.stopwatch.Start()
def __StartBtnClick(self, event): if not structs.ImportQuestions( files.OpenJSON( structs.GetSetting('questions_pack'), True, True, structs.CurLang('Files', 'QuestionsPackFileName'))): ErrMsg( structs.CurLang('Files', 'LoadingErrorTitle'), structs.CurLang('Files', 'LoadingError') + ' ' + structs.CurLang('Files', 'QuestionsPackFileName', False), self) return if not (structs.GetQuestionsNumber() % structs.GetSetting('groups_number') == 0): ErrMsg(structs.CurLang('Settings', 'WrongGroupsNumberTitle'), structs.CurLang('Settings', 'WrongGroupsNumber'), self) return if structs.GetSetting('image'): images = [] for i in range(1, structs.GetSetting('groups_number') + 1): img = str(i) + '.png' if files.CheckExisting(img): images.append(wx.Bitmap(img)) else: ErrMsg( structs.CurLang('Files', 'LoadingErrorTitle'), structs.CurLang('Files', 'LoadingError') + ' ' + structs.CurLang('Files', 'ImageFileName', False), self) return structs.ImportImagePack(images) OpenFrame(newResearchFrame, self, True)
def __Stage_2_SetLayoutG(self, panel): if structs.GetSetting('additional_label'): wx.StaticText(panel, name='AdditionalLabel', style=wx.ALIGN_CENTRE_HORIZONTAL) if structs.GetSetting('image'): wx.StaticBitmap(panel, name='Image') if structs.GetSetting('score'): wx.StaticText(panel, name='Score', style=wx.ALIGN_CENTRE_HORIZONTAL) wx.StaticText(panel, name='QuestionText', style=wx.ALIGN_CENTRE_HORIZONTAL) wx.TextCtrl(panel, name='AnswerField', style=wx.TE_MULTILINE) wx.Button(panel, name='AnswerButton') wx.Button(panel, name='ValidateButton') wx.Button(panel, name='CancelButton') wx.StaticText(panel, name='AnswerText', style=wx.ALIGN_CENTRE_HORIZONTAL) topSizer = wx.BoxSizer(wx.VERTICAL) style = { 'topSizer': { 'flag': wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER | wx.EXPAND, 'border': 3 } } for elem in panel.GetChildren(): topSizer.Add(elem, **style['topSizer']) panel.SetSizer(topSizer)
def NewResearch(person): global Research Research = {} Research['Person'] = person Research['Date'] = str(datetime.date.today()) Research['Settings'] = { 'AdditionalLabel' : structs.GetSetting('additional_label'), 'Images' : structs.GetSetting('image'), 'Score' : structs.GetSetting('score') } Research['QPack'] = structs.GetPackName() Research['Stage_1'] = { 'Conform' : structs.GetConform(), 'Confidence' : [0] * structs.GetQuestionsNumber() } Research['Stage_2'] = { 'Rounds' : [] }
def __SetContents(self, panel): self.__QuestionsFile(self.panel) panel.FindWindow('AdditionalLabelSetting').SetValue( structs.GetSetting('additional_label')) panel.FindWindow('ImageSetting').SetValue(structs.GetSetting('image')) panel.FindWindow('ScoreSetting').SetValue(structs.GetSetting('score')) panel.FindWindow('GroupsNumberSpiner').SetValue( structs.GetSetting('groups_number')) panel.FindWindow('GroupsNumberSpiner').SetRange(3, 12) langCtrl = panel.FindWindow('LanguageChoice') for lang in structs.GetAvailableLangs(): langCtrl.Append(lang[1]) if lang[0] == structs.GetSetting('lang'): sel = langCtrl.GetCount() - 1 langCtrl.SetSelection(sel) panel.FindWindow('AcceptButton').Disable()
def __init__(self, parent): wx.Frame.__init__(self, parent=parent, style=wx.CLOSE_BOX | wx.CAPTION) self.SetIcon(structs.GetIcon()) self.stage = 1 self.questionNumber = 0 self.confidenceTime = structs.GetSetting('confidence_time') self.confidenceTimer = wx.Timer(self) self.roundNumber = 0 self.roundsNubmer = structs.GetQuestionsNumber() // structs.GetSetting( 'groups_number') self.questionsAnswered = 0 self.questions = [] self.answers = [] self.scores = [0] * structs.GetSetting('groups_number') self.stopwatch = log.Stopwatch() self.mainPanel = wx.Panel(self) self.stagesPanels = [ wx.Panel(self.mainPanel), wx.Panel(self.mainPanel) ] self.groupPanels = [] self.panelsNumbers = {} self.sortRounds = [4, 7, 10] self.__SetLayout(self.mainPanel, self.stagesPanels) self.__SetBinding(self.mainPanel, self.stagesPanels) InfMsg( structs.CurLang('Research', 'Title')[self.stage - 1], structs.CurLang('Research', 'InformationText')[self.stage - 1], self) self.stagesPanels[1].Hide() self.__Stage_1_Restart(self.stagesPanels[0])
def __Stage_1_Restart(self, panel): self.questionNumber += 1 if self.questionNumber <= structs.GetQuestionsNumber(): self.confidenceTime = structs.GetSetting('confidence_time') self.__Stage_1_SetContents(panel) self.__Stage_1_SetText(panel, True) self.confidenceTimer.Start(1000) else: self.stage += 1 self.Hide() InfMsg( structs.CurLang('Research', 'Title')[self.stage - 1], structs.CurLang('Research', 'InformationText')[self.stage - 1], self) self.questions = [0] + structs.GetQuestionsConfident( log.GetConfidences()) self.__SetText(self.mainPanel) self.stagesPanels[0].Hide() self.stagesPanels[1].Show() self.Show() self.__Stage_2_Round(self.stagesPanels[1], self.groupPanels)
def __Stage_2_SetLayout(self, panel): wx.StaticText(panel, name='RoundNumber', style=wx.ALIGN_CENTER_HORIZONTAL) wx.Button(panel, name='NextRoundButton') uppSizer = wx.BoxSizer(wx.HORIZONTAL) lowSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer = wx.BoxSizer(wx.VERTICAL) style = { 'rndSizer': { 'flag': wx.ALL | wx.ALIGN_CENTER_VERTICAL, 'border': 3 }, 'uppSizer': { 'flag': wx.ALL | wx.ALIGN_CENTER, 'border': 3 }, 'lowSizer': { 'flag': wx.ALL | wx.EXPAND, 'border': 3 }, 'topSizer': { 'flag': wx.ALL | wx.EXPAND, 'border': 3 }, 'grpSizer': [{ 'flag': wx.TOP | wx.EXPAND, 'border': 60 }, { 'flag': wx.TOP | wx.EXPAND, 'border': 25 }, { 'flag': wx.TOP | wx.EXPAND, 'border': 0 }, { 'flag': wx.TOP | wx.EXPAND, 'border': 25 }, { 'flag': wx.TOP | wx.EXPAND, 'border': 60 }] } gN = structs.GetSetting('groups_number') for groupNumber in range(gN): p = wx.Panel(panel) self.groupPanels.append(p) self.panelsNumbers[p] = groupNumber self.__Stage_2_SetLayoutG(p) lowSizer.Add(p, **style['grpSizer'][groupNumber]) if groupNumber != gN - 1: lowSizer.Add(wx.StaticLine(panel, style=wx.LI_VERTICAL), **style['lowSizer']) uppSizer.Add(panel.FindWindow('RoundNumber'), **style['rndSizer']) uppSizer.Add(panel.FindWindow('NextRoundButton'), **style['topSizer']) topSizer.Add(uppSizer, **style['uppSizer']) topSizer.Add(wx.StaticLine(panel), **style['topSizer']) topSizer.Add(lowSizer, **style['topSizer']) panel.SetSizer(topSizer)
def __SetLayout(self, panel): wx.CheckBox(panel, name='AdditionalLabelSetting') wx.CheckBox(panel, name='ImageSetting') wx.CheckBox(panel, name='ScoreSetting') wx.StaticText(panel, name='QuestionsPackFileLabel', style=wx.ALIGN_RIGHT) wx.StaticText(panel, name='QuestionsPackFile', style=wx.ALIGN_LEFT) wx.StaticText(panel, name='QuestionsPackNone', style=wx.ALIGN_LEFT) BrowseButton(panel, name='QuestionsBrowseButton', extension=files.ext.JSON, defaultFilePath=structs.GetSetting('questions_pack')) wx.StaticText(panel, name='GroupsNumberLabel', style=wx.ALIGN_RIGHT) wx.SpinCtrl(panel, name='GroupsNumberSpiner') wx.Choice(panel, name='LanguageChoice') wx.StaticText(panel, name='LanguageSettingLabel', style=wx.ALIGN_RIGHT) wx.Button(panel, name='OkButton') wx.Button(panel, name='CancelButton') wx.Button(panel, name='AcceptButton') wx.StaticBox(panel, name='ResearchBox') wx.StaticBox(panel, name='ApplicationBox') lowSizer1 = wx.StaticBoxSizer(panel.FindWindow('ResearchBox'), wx.VERTICAL) lowSizer2 = wx.StaticBoxSizer(panel.FindWindow('ApplicationBox'), wx.VERTICAL) quesPackSizer = wx.BoxSizer(wx.HORIZONTAL) groupsNumberSizer = wx.BoxSizer(wx.HORIZONTAL) langSizer = wx.BoxSizer(wx.HORIZONTAL) lowSizer3 = wx.BoxSizer(wx.HORIZONTAL) topSizer = wx.BoxSizer(wx.VERTICAL) baseSizer = wx.BoxSizer(wx.VERTICAL) style = { 'lowSizer': { 'flag': wx.ALL | wx.EXPAND, 'border': 3 }, 'topSizer': { 'flag': wx.ALL | wx.EXPAND, 'border': 3 }, 'buttonsSizer': { 'proportion': 1, 'flag': wx.ALL | wx.EXPAND, 'border': 3 }, 'grNumSizer': { 'flag': wx.ALL | wx.ALIGN_CENTER_VERTICAL, 'border': 3 }, 'quesSizer': { 'flag': wx.ALL | wx.ALIGN_CENTER_VERTICAL, 'border': 3 }, 'langSizer': { 'flag': wx.ALL | wx.ALIGN_CENTER_VERTICAL, 'border': 3 }, 'baseSizer': { 'flag': wx.ALL, 'border': 3 } } quesPackSizer.Add(panel.FindWindow('QuestionsPackFileLabel'), **style['quesSizer']) quesPackSizer.Add(panel.FindWindow('QuestionsPackFile'), **style['quesSizer']) quesPackSizer.Add(panel.FindWindow('QuestionsPackNone'), **style['quesSizer']) quesPackSizer.Add(panel.FindWindow('QuestionsBrowseButton'), **style['quesSizer']) groupsNumberSizer.Add(panel.FindWindow('GroupsNumberLabel'), **style['grNumSizer']) groupsNumberSizer.Add(panel.FindWindow('GroupsNumberSpiner'), **style['grNumSizer']) lowSizer1.Add(quesPackSizer, **style['lowSizer']) lowSizer1.Add(groupsNumberSizer, **style['lowSizer']) lowSizer1.Add(panel.FindWindow('AdditionalLabelSetting'), **style['lowSizer']) lowSizer1.Add(panel.FindWindow('ImageSetting'), **style['lowSizer']) lowSizer1.Add(panel.FindWindow('ScoreSetting'), **style['lowSizer']) langSizer.Add(panel.FindWindow('LanguageSettingLabel'), **style['langSizer']) langSizer.Add(panel.FindWindow('LanguageChoice'), **style['langSizer']) lowSizer2.Add(langSizer, **style['lowSizer']) lowSizer3.Add(panel.FindWindow('OkButton'), **style['buttonsSizer']) lowSizer3.Add(panel.FindWindow('CancelButton'), **style['buttonsSizer']) lowSizer3.Add(panel.FindWindow('AcceptButton'), **style['buttonsSizer']) topSizer.Add(lowSizer1, **style['topSizer']) topSizer.Add(lowSizer2, **style['topSizer']) topSizer.Add(wx.StaticLine(panel), **style['topSizer']) topSizer.Add(lowSizer3, **style['topSizer']) baseSizer.Add(topSizer, **style['baseSizer']) panel.SetSizer(baseSizer)