def __init__(self, h): self.ctrl = CheckBox() self.ctrl.VerticalAlignment = VerticalAlignment.Center self.ctrl.VerticalContentAlignment = VerticalAlignment.Center self.Initialize(h) if h.get('label'): self.ctrl.Content = h['label'] if h.get('fontsize'): self.SetFontSize(h['fontsize']) if h.get('handler'): self.ctrl.Click += h['handler']
def __init__(self, model): """ Display the GUI using data in the model class """ self.model = model stream = StreamReader( os.path.join(os.path.dirname(__file__), GUI_XAML_FILE)) self.window = XamlReader.Load(stream.BaseStream) self.window.Title = self.model.title self.lblPrompt = LogicalTreeHelper.FindLogicalNode( self.window, "lblPrompt") self.lblPrompt.Content = self.model.prompt self.choicesGrid = LogicalTreeHelper.FindLogicalNode( self.window, "choicesGrid") self.choicesChk = System.Array.CreateInstance( CheckBox, len(self.model.choiceList)) self.choicesLabels = System.Array.CreateInstance( Label, len(self.model.choiceList)) for ii, choiceName in enumerate(self.model.choiceList): self.choicesGrid.RowDefinitions.Add(RowDefinition()) self.choicesLabels[ii] = Label() self.choicesLabels[ii].Content = choiceName self.choicesLabels[ii].SetValue(Grid.RowProperty, ii) self.choicesLabels[ii].SetValue(Grid.ColumnProperty, 0) if self.model.alignChoices.lower() == 'left': self.choicesLabels[ ii].HorizontalAlignment = HorizontalAlignment.Left else: self.choicesLabels[ ii].HorizontalAlignment = HorizontalAlignment.Right self.choicesGrid.Children.Add(self.choicesLabels[ii]) self.choicesChk[ii] = CheckBox() self.choicesChk[ii].Margin = Thickness(7.0, 7.0, 2.0, 2.0) self.choicesChk[ii].SetValue(Grid.RowProperty, ii) self.choicesChk[ii].SetValue(Grid.ColumnProperty, 1) self.choicesChk[ii].HorizontalAlignment = HorizontalAlignment.Left self.choicesGrid.Children.Add(self.choicesChk[ii]) self.btCancel = LogicalTreeHelper.FindLogicalNode( self.window, "btCancel") self.btCancel.Click += self.cancel_clicked self.btOK = LogicalTreeHelper.FindLogicalNode(self.window, "btOK") self.btOK.Click += self.ok_clicked self.window.Show() self.window.Closed += lambda s, e: self.window.Dispatcher.InvokeShutdown( ) System.Windows.Threading.Dispatcher.Run()