Beispiel #1
0
 def __init__(self, h):
     self.ctrl = Label()
     self.Initialize(h)
     self.image = Image()
     self.image.HorizontalAlignment = HorizontalAlignment.Center
     self.image.VerticalAlignment = VerticalAlignment.Center
     if h.get('image'):
         self.image.Source = BitmapImage(
             System.Uri(h['image'], System.UriKind.Relative))
     if h.get('stretch'): self.Stretch(h['stretch'])
     else: self.StretchUniform()
     if h.get('size'):
         self.image.Height = float(h['size'])
         self.image.Width = float(h['size'])
     if h.get('scroll') and h['scroll']:
         scroll = ScrollViewer()
         scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto
         scroll.Content = self.image
         self.ctrl.Content = scroll
     elif h.get('multiple') and h['multiple']:
         stack = StackPanel()
         stack.Orientation = Orientation.Horizontal
         stack.Children.Add(self.image)
         self.ctrl.Content = stack
     else:
         self.ctrl.Content = self.image
Beispiel #2
0
    def button_Click(self, sender, e):
        print('clicked', sender.Content, e, self)

        msg = Label(Content='Welcome to IronPython!', FontSize=26)

        for c in self.LogicalChildren:
            if isinstance(c, StackPanel) and c.Name == "stackPanel":
                print(c)
                c.AddChild(msg)
Beispiel #3
0
    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()
Beispiel #4
0
 def _create_body(self, message, value, **extra):
     _label = Label()
     textblock = TextBlock()
     textblock.Text = message
     textblock.TextWrapping = TextWrapping.Wrap
     _label.Content = textblock
     _label.Margin = Thickness(10)
     _label.SetValue(Grid.ColumnSpanProperty, 2)
     _label.SetValue(Grid.RowProperty, 0)
     self.Content.AddChild(_label)
     selector = self._create_selector(value, **extra)
     if selector:
         self.Content.AddChild(selector)
         selector.Focus()
Beispiel #5
0
 def onClick(self, sender, event):
     message = Label()
     message.FontSize = 36
     message.Content = 'Welcome to IronPython!'
     self.stackPanel.Children.Add(message)
Beispiel #6
0
def onOpened(s, e):
    global menuItem

    menuItem.Items.Clear()

    def onSignInClick(source, rea):
        config = None
        directory = Path.Combine(
            Environment.GetFolderPath(
                Environment.SpecialFolder.ApplicationData),
            Assembly.GetEntryAssembly().GetName().Name)
        backgroundBrush = None
        textColor = SystemColors.ControlTextBrush

        if Directory.Exists(directory):
            fileName1 = Path.GetFileName(Assembly.GetEntryAssembly().Location)

            for fileName2 in Directory.EnumerateFiles(directory, "*.config"):
                if fileName1.Equals(
                        Path.GetFileNameWithoutExtension(fileName2)):
                    exeConfigurationFileMap = ExeConfigurationFileMap()
                    exeConfigurationFileMap.ExeConfigFilename = fileName2
                    config = ConfigurationManager.OpenMappedExeConfiguration(
                        exeConfigurationFileMap, ConfigurationUserLevel.None)

        if config is None:
            config = ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None)
            directory = None

        if config.AppSettings.Settings["BackgroundImage"] is not None:
            fileName = config.AppSettings.Settings[
                "BackgroundImage"].Value if directory is None else Path.Combine(
                    directory,
                    config.AppSettings.Settings["BackgroundImage"].Value)
            fs = None
            bi = BitmapImage()

            try:
                fs = FileStream(fileName, FileMode.Open, FileAccess.Read,
                                FileShare.Read)

                bi.BeginInit()
                bi.StreamSource = fs
                bi.CacheOption = BitmapCacheOption.OnLoad
                bi.CreateOptions = BitmapCreateOptions.None
                bi.EndInit()

            finally:
                if fs is not None:
                    fs.Close()

            backgroundBrush = ImageBrush(bi)
            backgroundBrush.TileMode = TileMode.Tile
            backgroundBrush.ViewportUnits = BrushMappingMode.Absolute
            backgroundBrush.Viewport = Rect(0, 0, bi.Width, bi.Height)
            backgroundBrush.Stretch = Stretch.None

            if backgroundBrush.CanFreeze:
                backgroundBrush.Freeze()

        if backgroundBrush is None and config.AppSettings.Settings[
                "BackgroundColor"] is not None:
            if config.AppSettings.Settings["BackgroundColor"].Value.Length > 0:
                backgroundBrush = SolidColorBrush(
                    ColorConverter.ConvertFromString(
                        config.AppSettings.Settings["BackgroundColor"].Value))

                if backgroundBrush.CanFreeze:
                    backgroundBrush.Freeze()

        if config.AppSettings.Settings["TextColor"] is not None:
            if config.AppSettings.Settings["TextColor"].Value.Length > 0:
                textColor = ColorConverter.ConvertFromString(
                    config.AppSettings.Settings["TextColor"].Value)

        textBrush = SolidColorBrush(textColor)

        if textBrush.CanFreeze:
            textBrush.Freeze()

        window = Window()

        def onClick(source, args):
            global username, password

            if not String.IsNullOrEmpty(
                    usernameTextBox.Text) and not String.IsNullOrEmpty(
                        passwordBox.Password):
                username = usernameTextBox.Text
                password = passwordBox.Password

                def onSave():
                    try:
                        fs = None
                        sr = None
                        sw = None

                        try:
                            fs = FileStream(__file__, FileMode.Open,
                                            FileAccess.ReadWrite,
                                            FileShare.Read)
                            encoding = UTF8Encoding(False)
                            sr = StreamReader(fs, encoding, True)
                            lines = Regex.Replace(
                                Regex.Replace(
                                    sr.ReadToEnd(), "username\\s*=\\s*\"\"",
                                    String.Format("username = \"{0}\"",
                                                  username),
                                    RegexOptions.CultureInvariant),
                                "password\\s*=\\s*\"\"",
                                String.Format("password = \"{0}\"", password),
                                RegexOptions.CultureInvariant)
                            fs.SetLength(0)
                            sw = StreamWriter(fs, encoding)
                            sw.Write(lines)

                        finally:
                            if sw is not None:
                                sw.Close()

                            if sr is not None:
                                sr.Close()

                            if fs is not None:
                                fs.Close()

                    except Exception, e:
                        Trace.WriteLine(e.clsException.Message)
                        Trace.WriteLine(e.clsException.StackTrace)

                def onCompleted(task):
                    global menuItem

                    for window in Application.Current.Windows:
                        if window is Application.Current.MainWindow and window.ContextMenu is not None:
                            if window.ContextMenu.Items.Contains(menuItem):
                                window.ContextMenu.Items.Remove(menuItem)
                                window.ContextMenu.Opened -= onOpened

                                if window.ContextMenu.Items[10].GetType(
                                ).IsInstanceOfType(window.ContextMenu.Items[
                                        window.ContextMenu.Items.Count - 4]):
                                    window.ContextMenu.Items.RemoveAt(10)

                    menuItem = None

                Task.Factory.StartNew(
                    onSave, TaskCreationOptions.LongRunning).ContinueWith(
                        onCompleted,
                        TaskScheduler.FromCurrentSynchronizationContext())

            window.Close()

        window.Owner = Application.Current.MainWindow
        window.Title = Application.Current.MainWindow.Title
        window.WindowStartupLocation = WindowStartupLocation.CenterScreen
        window.ResizeMode = ResizeMode.NoResize
        window.SizeToContent = SizeToContent.WidthAndHeight
        window.Background = SystemColors.ControlBrush

        stackPanel1 = StackPanel()
        stackPanel1.UseLayoutRounding = True
        stackPanel1.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel1.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel1.Orientation = Orientation.Vertical

        window.Content = stackPanel1

        stackPanel2 = StackPanel()
        stackPanel2.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel2.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel2.Orientation = Orientation.Vertical
        stackPanel2.Background = SystemColors.ControlBrush if backgroundBrush is None else backgroundBrush

        stackPanel1.Children.Add(stackPanel2)

        gradientStopCollection = GradientStopCollection()
        gradientStopCollection.Add(GradientStop(Color.FromArgb(0, 0, 0, 0), 0))
        gradientStopCollection.Add(
            GradientStop(Color.FromArgb(Byte.MaxValue, 0, 0, 0), 1))

        linearGradientBrush = LinearGradientBrush(gradientStopCollection,
                                                  Point(0.5, 0), Point(0.5, 1))
        linearGradientBrush.Opacity = 0.1

        if linearGradientBrush.CanFreeze:
            linearGradientBrush.Freeze()

        stackPanel3 = StackPanel()
        stackPanel3.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel3.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel3.Orientation = Orientation.Vertical
        stackPanel3.Background = linearGradientBrush

        stackPanel2.Children.Add(stackPanel3)

        solidColorBrush1 = SolidColorBrush(Colors.Black)
        solidColorBrush1.Opacity = 0.25

        if solidColorBrush1.CanFreeze:
            solidColorBrush1.Freeze()

        border1 = Border()
        border1.HorizontalAlignment = HorizontalAlignment.Stretch
        border1.VerticalAlignment = VerticalAlignment.Stretch
        border1.BorderThickness = Thickness(0, 0, 0, 1)
        border1.BorderBrush = solidColorBrush1

        stackPanel3.Children.Add(border1)

        stackPanel4 = StackPanel()
        stackPanel4.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel4.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel4.Orientation = Orientation.Vertical
        stackPanel4.Margin = Thickness(10, 10, 10, 20)

        border1.Child = stackPanel4

        stackPanel5 = StackPanel()
        stackPanel5.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel5.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel5.Orientation = Orientation.Vertical

        dropShadowEffect1 = DropShadowEffect()
        dropShadowEffect1.BlurRadius = 1
        dropShadowEffect1.Color = Colors.Black if Math.Max(
            Math.Max(textColor.R, textColor.G),
            textColor.B) > Byte.MaxValue / 2 else Colors.White
        dropShadowEffect1.Direction = 270
        dropShadowEffect1.Opacity = 0.5
        dropShadowEffect1.ShadowDepth = 1

        if dropShadowEffect1.CanFreeze:
            dropShadowEffect1.Freeze()

        stackPanel5.Effect = dropShadowEffect1

        stackPanel4.Children.Add(stackPanel5)

        usernameLabel = Label()
        usernameLabel.Foreground = textBrush

        if CultureInfo.CurrentCulture.Equals(
                CultureInfo.GetCultureInfo("ja-JP")):
            usernameLabel.Content = "ユーザ名"
        else:
            usernameLabel.Content = "Username"

        RenderOptions.SetClearTypeHint(usernameLabel, ClearTypeHint.Enabled)

        stackPanel5.Children.Add(usernameLabel)

        usernameTextBox = TextBox()
        usernameTextBox.Width = 240

        stackPanel4.Children.Add(usernameTextBox)

        dropShadowEffect2 = DropShadowEffect()
        dropShadowEffect2.BlurRadius = 1
        dropShadowEffect2.Color = Colors.Black if Math.Max(
            Math.Max(textColor.R, textColor.G),
            textColor.B) > Byte.MaxValue / 2 else Colors.White
        dropShadowEffect2.Direction = 270
        dropShadowEffect2.Opacity = 0.5
        dropShadowEffect2.ShadowDepth = 1

        if dropShadowEffect2.CanFreeze:
            dropShadowEffect2.Freeze()

        stackPanel6 = StackPanel()
        stackPanel6.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel6.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel6.Orientation = Orientation.Vertical
        stackPanel6.Effect = dropShadowEffect2

        stackPanel4.Children.Add(stackPanel6)

        passwordLabel = Label()
        passwordLabel.Foreground = textBrush

        if CultureInfo.CurrentCulture.Equals(
                CultureInfo.GetCultureInfo("ja-JP")):
            passwordLabel.Content = "パスワード"
        else:
            passwordLabel.Content = "Password"

        RenderOptions.SetClearTypeHint(passwordLabel, ClearTypeHint.Enabled)

        stackPanel6.Children.Add(passwordLabel)

        passwordBox = PasswordBox()
        passwordBox.Width = 240

        stackPanel4.Children.Add(passwordBox)

        solidColorBrush2 = SolidColorBrush(Colors.White)
        solidColorBrush2.Opacity = 0.5

        if solidColorBrush2.CanFreeze:
            solidColorBrush2.Freeze()

        border2 = Border()
        border2.HorizontalAlignment = HorizontalAlignment.Stretch
        border2.VerticalAlignment = VerticalAlignment.Stretch
        border2.BorderThickness = Thickness(0, 1, 0, 0)
        border2.BorderBrush = solidColorBrush2

        stackPanel1.Children.Add(border2)

        signInButton = Button()
        signInButton.HorizontalAlignment = HorizontalAlignment.Right
        signInButton.VerticalAlignment = VerticalAlignment.Center
        signInButton.Margin = Thickness(10, 10, 10, 10)
        signInButton.Padding = Thickness(10, 2, 10, 2)
        signInButton.IsDefault = True

        if CultureInfo.CurrentCulture.Equals(
                CultureInfo.GetCultureInfo("ja-JP")):
            signInButton.Content = "サインイン"
        else:
            signInButton.Content = "Sign in"

        signInButton.Click += onClick

        border2.Child = signInButton

        usernameTextBox.Focus()
        window.Show()
Beispiel #7
0
def onClick(sender, event):
    msg = Label()
    msg.FontSize = 36
    msg.Content = 'Welcome to IronPython!'

    stack.Children.Add(msg)
Beispiel #8
0
 def on_click(self, sender, event):
     msg = Label(FontSize=36, Content='Welcome to IronPython!')
     self.stackPanel.Children.Add(msg)
Beispiel #9
0
def attachStackPanel(stackPanel, brush, text):
    stackPanel1 = StackPanel()
    stackPanel1.HorizontalAlignment = HorizontalAlignment.Stretch
    stackPanel1.VerticalAlignment = VerticalAlignment.Stretch
    stackPanel1.Orientation = Orientation.Vertical
    stackPanel1.Background = brush

    stackPanel.Children.Add(stackPanel1)

    gradientStopCollection = GradientStopCollection()
    gradientStopCollection.Add(GradientStop(Color.FromArgb(0, 0, 0, 0), 0))
    gradientStopCollection.Add(
        GradientStop(Color.FromArgb(Byte.MaxValue, 0, 0, 0), 1))

    linearGradientBrush = LinearGradientBrush(gradientStopCollection,
                                              Point(0.5, 0), Point(0.5, 1))
    linearGradientBrush.Opacity = 0.1

    if linearGradientBrush.CanFreeze:
        linearGradientBrush.Freeze()

    stackPanel2 = StackPanel()
    stackPanel2.HorizontalAlignment = HorizontalAlignment.Stretch
    stackPanel2.VerticalAlignment = VerticalAlignment.Stretch
    stackPanel2.Orientation = Orientation.Vertical
    stackPanel2.Background = linearGradientBrush

    stackPanel1.Children.Add(stackPanel2)

    solidColorBrush1 = SolidColorBrush(Colors.White)
    solidColorBrush1.Opacity = 0.5

    if solidColorBrush1.CanFreeze:
        solidColorBrush1.Freeze()

    border1 = Border()
    border1.HorizontalAlignment = HorizontalAlignment.Stretch
    border1.VerticalAlignment = VerticalAlignment.Stretch
    border1.Padding = Thickness(0)
    border1.BorderThickness = Thickness(0, 1, 0, 0)
    border1.BorderBrush = solidColorBrush1

    solidColorBrush2 = SolidColorBrush(Colors.Black)
    solidColorBrush2.Opacity = 0.25

    if solidColorBrush2.CanFreeze:
        solidColorBrush2.Freeze()

    stackPanel2.Children.Add(border1)

    border2 = Border()
    border2.HorizontalAlignment = HorizontalAlignment.Stretch
    border2.VerticalAlignment = VerticalAlignment.Stretch
    border2.Padding = Thickness(10, 5, 10, 5)
    border2.BorderThickness = Thickness(0, 0, 0, 1)
    border2.BorderBrush = solidColorBrush2

    border1.Child = border2

    dropShadowEffect = DropShadowEffect()
    dropShadowEffect.BlurRadius = 1
    dropShadowEffect.Color = Colors.Black if Math.Max(
        Math.Max(SystemColors.ControlTextColor.R,
                 SystemColors.ControlTextColor.G),
        SystemColors.ControlTextColor.B) > Byte.MaxValue / 2 else Colors.White
    dropShadowEffect.Direction = 270
    dropShadowEffect.Opacity = 0.5
    dropShadowEffect.ShadowDepth = 1

    if dropShadowEffect.CanFreeze:
        dropShadowEffect.Freeze()

    border3 = Border()
    border3.HorizontalAlignment = HorizontalAlignment.Stretch
    border3.VerticalAlignment = VerticalAlignment.Stretch
    border3.Padding = Thickness(0)
    border3.Effect = dropShadowEffect

    border2.Child = border3

    label = Label()
    label.Foreground = SystemColors.ControlTextBrush
    label.Content = text

    RenderOptions.SetClearTypeHint(label, ClearTypeHint.Enabled)

    border3.Child = label
Beispiel #10
0
 def __init__(self, h):
     self.ctrl = Label()
     self.Initialize(h)
     if h.get('label'): self.SetValue(h['label'])
     if h.get('fontsize'): self.SetFontSize(h['fontsize'])