Beispiel #1
0
    def nui_skeleton_frame_ready(self, sender, e):
        skeletonFrame = e.SkeletonFrame
        self.skeleton.Children.Clear()

        for data in skeletonFrame.Skeletons:
            if SkeletonTrackingState.Tracked == data.TrackingState:
                for joint in data.Joints:
                    if joint.ID == JointID.Head:
                        jointPos = self.getDisplayPosition(joint)

                        self.lastX = jointPos.X
                        self.foundHead = True

        if self.foundHead:
            bubble = Image()
            #imageSource = System.Windows.Resources["think"]
            bubble.Source = self.thinkBubble
            bubble.SetValue(Canvas.TopProperty, self.lastY)
            bubble.SetValue(Canvas.LeftProperty, self.lastX)
            self.skeleton.Children.Add(bubble)

            text = TextBox()
            text.Text = "Hello World!"
            text.FontSize = 50
            text.FontWeight = FontWeights.Bold
            text.BorderThickness = Thickness(0)
            text.SetValue(Canvas.TopProperty, self.lastY + 120)
            text.SetValue(Canvas.LeftProperty, self.lastX + 60)
            self.skeleton.Children.Add(text)
Beispiel #2
0
    def populate_login_panel(self):
        button = Button()
        button.Content = '  Login  '
        button.FontSize = 16
        button.Margin = Thickness(5, 5, 5, 5)
        button.HorizontalAlignment = HorizontalAlignment.Stretch
        
        remember_me = CheckBox()
        remember_me.IsChecked = True
        remember_me.Margin = Thickness(5, 5, 5, 5)
        remember_me.Content = 'Remember'
        
        button_pane = StackPanel()
        button_pane.Children.Add(button)
        button_pane.Children.Add(remember_me)

        username = TextBox()
        username.FontSize = 16
        username.Width = 200
        username.Margin = Thickness(5, 5, 5, 5)

        password = PasswordBox()
        password.FontSize = 16
        password.Width = 200
        password.Margin = Thickness(5, 5, 5, 5)
        
        def HandleEnterKey(s, event):
            if event.Key == Key.Enter:
                event.Handled = True
                self.onLogin(None, None)
        
        password.KeyDown += HandleEnterKey
        if CheckStored():
            stored_username, stored_password = GetStored()
            username.Text = stored_username
            password.Password = stored_password

        entry_panel = StackPanel()
        entry_panel.HorizontalAlignment = HorizontalAlignment.Stretch
        entry_panel.Children.Add(username)
        entry_panel.Children.Add(password)

        self.bottom_panel.Children.Add(entry_panel)
        self.bottom_panel.Children.Add(button_pane)

        self.button = button
        self.remember_me = remember_me
        self.username_box = username
        self.password_box = password
        button.Click += self.onLogin
        
        self.msg = TextBlock()
        self.msg.Text = '      Login       '
        self.msg.FontSize = 16
        self.msg.HorizontalAlignment = HorizontalAlignment.Center
        self.msg.VerticalAlignment = VerticalAlignment.Center
        self.bottom_panel.Children.Add(self.msg)
Beispiel #3
0
 def _create_selector(self, default, hidden):
     if hidden:
         self._entry = PasswordBox()
         self._entry.Password = default if default else ''
     else:
         self._entry = TextBox()
         self._entry.Text = default if default else ''
     self._entry.SetValue(Grid.RowProperty, 1)
     self._entry.SetValue(Grid.ColumnSpanProperty, 2)
     self.Margin = Thickness(10)
     self._entry.Height = 30
     self._entry.Width = 150
     self._entry.SelectAll()
     return self._entry
Beispiel #4
0
    def setup_post_panel(self):
        self.bottom_panel.Children.Clear()
                
        entry_pane = TextBox()
        entry_pane.AcceptsReturn = True
        entry_pane.Width = 275
        entry_pane.Height = 75
        entry_pane.FontSize = 14
        entry_pane.Margin = Thickness(2)
        entry_pane.TextChanged += self.setCharsMsg
        entry_pane.TextWrapping = TextWrapping.Wrap
        
        self.entry_pane = entry_pane
        
        button = Button()
        button.Content = ' Post '
        self.bottom_panel.Children.Add(entry_pane)
        self.bottom_panel.Children.Add(button)

        self.button = button
        button.Click += self.onPost
        button.Margin = Thickness(2)

        self.msg = TextBlock()
        self.msg.FontSize = 14
        self.msg.HorizontalAlignment = HorizontalAlignment.Center
        self.msg.VerticalAlignment = VerticalAlignment.Center
        self.bottom_panel.Children.Add(self.msg)
        self.setCharsMsg(None, None)
Beispiel #5
0
    def nui_skeleton_frame_ready(self, sender, e):
        skeletonFrame = e.SkeletonFrame
        self.skeleton.Children.Clear()

        for data in skeletonFrame.Skeletons:
            if SkeletonTrackingState.Tracked == data.TrackingState:
                for joint in data.Joints:
                    if joint.ID == JointID.Head:
                        jointPos = self.getDisplayPosition(joint)

                        self.lastX = jointPos.X
                        self.foundHead = True

        if self.foundHead:
            bubble = Image()
            #imageSource = System.Windows.Resources["think"]
            bubble.Source = self.thinkBubble
            bubble.SetValue(Canvas.TopProperty, self.lastY)
            bubble.SetValue(Canvas.LeftProperty, self.lastX)
            self.skeleton.Children.Add(bubble)

            text = TextBox()
            text.Text = "Hello World!"
            text.FontSize = 50
            text.FontWeight = FontWeights.Bold
            text.BorderThickness = Thickness(0)
            text.SetValue(Canvas.TopProperty, self.lastY + 120)
            text.SetValue(Canvas.LeftProperty, self.lastX + 60)
            self.skeleton.Children.Add(text)
Beispiel #6
0
 def __init__(self, h):
     self.ctrl = TextBox()
     self.Initialize(h)
     if h.get('width'): self.SetWidth(h['width'])
     if h.get('fontsize'): self.SetFontSize(h['fontsize'])
     if h.get('multiline'):
         self.ctrl.AcceptsReturn = True
         self.ctrl.AcceptsTab = True
         self.ctrl.TextWrapping = TextWrapping.Wrap
Beispiel #7
0
    def on_loaded(self, s, e):
        bubble = Image()
        bubble.Name = "Bubble"
        #imageSource = System.Windows.Resources["think"]
        bubble.Source = self.thinkBubble
        bubble.SetValue(Canvas.TopProperty, self.currentY)
        bubble.SetValue(Canvas.LeftProperty, self.currentX)
        self.mainPanel.Children.Add(bubble)

        text = TextBox()
        text.Text = "???"
        text.FontSize = 65
        text.FontWeight = FontWeights.Bold
        text.BorderThickness = Thickness(0)
        text.SetValue(Canvas.TopProperty, self.currentY + 35)
        text.SetValue(Canvas.LeftProperty, self.currentX + 55)
        self.mainPanel.Children.Add(text)

        myDoubleAnimation = DoubleAnimation()
        myDoubleAnimation.From = 770.0;
        myDoubleAnimation.To = 250.0;

        myDoubleAnimation.Duration = Duration(TimeSpan.FromSeconds(3))

        myDoubleAnimationText = DoubleAnimation()
        myDoubleAnimationText.From = 770.0 + 35.0;
        myDoubleAnimationText.To = 250.0 + 35.0;

        myDoubleAnimationText.Duration = Duration(TimeSpan.FromSeconds(3))

        #myStoryboard = Storyboard()
        #myStoryboard.Children.Add(myDoubleAnimation)
        #Storyboard.SetTargetName(myDoubleAnimation, bubble.Name)
        #Storyboard.SetTargetProperty(myDoubleAnimation, PropertyPath(Canvas.TopProperty))

        #myStoryboard.Begin(self);

        bubble.BeginAnimation(Canvas.TopProperty, myDoubleAnimation)
        text.BeginAnimation(Canvas.TopProperty, myDoubleAnimationText)
Beispiel #8
0
class InputDialog(_WpfDialog):
    def __init__(self, message, default='', hidden=False):
        _WpfDialog.__init__(self, message, default, hidden=hidden)

    def _create_selector(self, default, hidden):
        if hidden:
            self._entry = PasswordBox()
            self._entry.Password = default if default else ''
        else:
            self._entry = TextBox()
            self._entry.Text = default if default else ''
        self._entry.SetValue(Grid.RowProperty, 1)
        self._entry.SetValue(Grid.ColumnSpanProperty, 2)
        self.Margin = Thickness(10)
        self._entry.Height = 30
        self._entry.Width = 150
        self._entry.SelectAll()
        return self._entry

    def _get_value(self):
        try:
            return self._entry.Text
        except AttributeError:
            return self._entry.Password
Beispiel #9
0
    def on_loaded(self, s, e):
        bubble = Image()
        bubble.Name = "Bubble"
        #imageSource = System.Windows.Resources["think"]
        bubble.Source = self.thinkBubble
        bubble.SetValue(Canvas.TopProperty, self.currentY)
        bubble.SetValue(Canvas.LeftProperty, self.currentX)
        self.mainPanel.Children.Add(bubble)

        text = TextBox()
        text.Text = "???"
        text.FontSize = 65
        text.FontWeight = FontWeights.Bold
        text.BorderThickness = Thickness(0)
        text.SetValue(Canvas.TopProperty, self.currentY + 35)
        text.SetValue(Canvas.LeftProperty, self.currentX + 55)
        self.mainPanel.Children.Add(text)

        myDoubleAnimation = DoubleAnimation()
        myDoubleAnimation.From = 770.0
        myDoubleAnimation.To = 250.0

        myDoubleAnimation.Duration = Duration(TimeSpan.FromSeconds(3))

        myDoubleAnimationText = DoubleAnimation()
        myDoubleAnimationText.From = 770.0 + 35.0
        myDoubleAnimationText.To = 250.0 + 35.0

        myDoubleAnimationText.Duration = Duration(TimeSpan.FromSeconds(3))

        #myStoryboard = Storyboard()
        #myStoryboard.Children.Add(myDoubleAnimation)
        #Storyboard.SetTargetName(myDoubleAnimation, bubble.Name)
        #Storyboard.SetTargetProperty(myDoubleAnimation, PropertyPath(Canvas.TopProperty))

        #myStoryboard.Begin(self);

        bubble.BeginAnimation(Canvas.TopProperty, myDoubleAnimation)
        text.BeginAnimation(Canvas.TopProperty, myDoubleAnimationText)
Beispiel #10
0
 def __new__(cls, printer, context, root):
     return TextBox.__new__(cls)
Beispiel #11
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 #12
0
 def __new__(cls, printer, context, root):
     return TextBox.__new__(cls)
Beispiel #13
0
    def handle_key(self, sender, event):
        # Mac Safari uses '\r' for newlines in Silverlight TextBox??
        contents = self.Text.replace('\r\n', '\n').replace('\r', '\n')
        key = event.Key
        start = self.SelectionStart
        end = start + self.SelectionLength

        modifiers = Keyboard.Modifiers
        control = (modifiers & ModifierKeys.Control) or (modifiers
                                                         & ModifierKeys.Apple)
        if key == Key.C and control:
            event.Handled = True
            self.keyboard_interrupt()
            return

        if self._thread is not None:
            # ignore key events (we have already checked for Ctrl-C)
            event.Handled = True
            return

        if key != Key.Enter:
            if key == Key.Up:
                if self.on_first_line(contents):
                    event.Handled = True
                    previous = self.history.back(contents)
                    if previous is not None:
                        self.Text = previous
                        self.SelectionStart = len(previous)
                    return

            elif key == Key.Down:
                if self.on_last_line(contents):
                    event.Handled = True
                    next = self.history.forward(contents)
                    if next is not None:
                        self.Text = next
                        self.SelectionStart = len(next)
                    return

            elif key == Key.Tab:
                event.Handled = True
                self.Text = self.Text[:start] + '    ' + self.Text[end:]
                self.SelectionStart = start + 4
                return

            if key == key.Add and self.ff3:
                if not (modifiers & ModifierKeys.Shift):
                    event.Handled = True
                    self.Text = self.Text[:start] + '=' + self.Text[end:]
                    self.SelectionStart = start + 1
                    return

            TextBox.OnKeyDown(self, event)
            return

        event.Handled = True
        if empty_or_comment_only(contents):
            # needed or we get a SyntaxError
            self.Text = ''
            self.printer.print_lines(contents)
            self.printer.scroll()
            return

        # manual handling unfortunately
        # means things like trailing comments break
        # these functions; so not ideal
        stripped = contents.rstrip()
        if stripped == 'gohome':
            gohome()
        elif stripped == 'reset':
            contents = 'reset()'
        elif stripped == 'import this':
            # import hook so that importing *worked*
            # would be a better solution...
            self.printer.print_lines(stripped)
            self.Text = ''
            self.history.append(contents)
            import this
            self.context['this'] = this
            self.printer.set_prompt()
            self.printer.scroll()
            return

        if not self.is_complete(contents, start):
            self.do_indent(start)
        else:
            self.execute(contents)
Beispiel #14
0
textblock = TextBlock()
textblock.Margin = Thickness(20)
textblock.FontSize = 18
textblock.Text = 'Stuff goes here'
root.Children.Add(textblock)

panel = StackPanel()
panel.Margin = Thickness(20)
panel.Orientation = Orientation.Horizontal

button = Button()
button.Content = 'Push Me'
button.FontSize = 18
button.Margin = Thickness(10)

textbox = TextBox()
textbox.Text = "Type stuff here..."
textbox.FontSize = 18
textbox.Margin = Thickness(10)
textbox.Width = 200
#textbox.Watermark = 'Type Something Here'

def onClick(s, e):
    textblock.Text = textbox.Text
    textbox.Text = ""
	
def onKeyDown(sender, e):
    if e.Key == Key.Enter:
        e.Handled = True
        onClick(None, None)
	
Beispiel #15
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()