def __init__(self, parent, msg): wpf.LoadComponent(self, 'WizardDialog.xaml') self.Title = "Error" self.SizeToContent = SizeToContent.WidthAndHeight #self.WindowStartupLocation = WindowStartupLocation.Manual self.Left = parent.Left + parent.ActualWidth / 4 self.Top = parent.Top + parent.ActualHeight / 4 stack = Controls.StackPanel() stack.Orientation = Controls.Orientation.Horizontal stack.HorizontalAlignment = HorizontalAlignment.Center stack.Margin = Thickness(10.0, 6.0, 10.0, 6.0) errorImage = Controls.Image() errorImage.Margin = Thickness(6.0, 6.0, 0.0, 10.0) errorImage.Source = ImageAwesome.CreateImageSource( FontAwesomeIcon.ExclamationCircle, Media.Brushes.Red) errorImage.Width = 14 errorImage.Height = 18 stack.Children.Add(errorImage) label = Controls.Label() #label.Style = self.FindResource("ctrl") #label.FontSize = 16 label.Content = msg label.Margin = Thickness(0.0, 6.0, 0.0, 10.0) stack.Children.Add(label) self.Base.Children.Add(stack) self.button = Controls.Button() #self.button.Style = self.FindResource("wzdbtn") self.button.Click += self.buttonClick self.button.Content = "OK" self.button.Width = 70 self.button.Height = 30 self.button.Margin = Thickness(0.0, 6.0, 0.0, 12.0) self.Base.Children.Add(self.button) self.ShowDialog()
def on_click_options(self, sender, event): """ toggle dock options displayed on the left """ if self.ui_roots_options.Visibility == Visibility.Collapsed: self.ui_options_api.BorderThickness = Thickness(1) self.ui_roots_options.Visibility = Visibility.Visible else: self.ui_options_api.BorderThickness = Thickness(0) self.ui_roots_options.Visibility = Visibility.Collapsed
def __init__(self, printer, context, root): self._input_data = [] self.original_context = context self.printer = printer self.prompt = root.prompt self.root = root self.done_first_run = False self._sync = ManualResetEvent(False) self.ff3 = False self.FontSize = 15 self.Margin = Thickness(0) self.FontFamily = FontFamily( "Consolas, Monaco, Lucida Console, Global Monospace") self.AcceptsReturn = True self.BorderThickness = Thickness(0) self.VerticalScrollBarVisibility = ScrollBarVisibility.Auto self.MinWidth = 300 def reset(): "Clear the console, its history and the execution context." self._reset_needed = True return 'resetting' def input(prompt='Input:'): 'input([prompt]) -> value\n\nEquivalent to eval(raw_input(prompt)).' return eval(self.context['raw_input'](prompt), self.context, self.context) self.original_context['reset'] = reset self.original_context['gohome'] = gohome self.original_context['exit'] = 'There is no escape...' self.original_context['raw_input'] = self.raw_input self.original_context['input'] = input # for debugging only! self.original_context['root'] = root self.context = {} self.history = None self._reset_needed = False self._thread = None self._thread_reset = None self._raw_input_text = '' self._temp_context = None self.engine = Python.CreateEngine() self.scope = self.engine.CreateScope() self._original_caret = None if hasattr(self, 'CaretBrush'): self._original_caret = self.CaretBrush self._disabled = SolidColorBrush(Colors.White) self.KeyDown += self.handle_key self.TextChanged += self.text_changed
def __init__(self): self.ctrl = Border() self.ctrl.HorizontalAlignment = HorizontalAlignment.Left self.ctrl.VerticalAlignment = VerticalAlignment.Top self.ctrl.Background = Brushes.SkyBlue self.ctrl.BorderBrush = Brushes.Black self.ctrl.BorderThickness = Thickness(1)
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)
def get_console_block(): block = TextBlock() block.FontSize = 15 block.Margin = Thickness(0, 0, 0, 0) block.TextWrapping = TextWrapping.Wrap block.FontFamily = FontFamily("Consolas, Global Monospace") return block
def image(*args, **kwargs): """ Create a false-colour image plot of the specified 2D array (matrix) (or overwite current plot if hold is set). Plot2DImage image(image): image is a 2D array (matrix) Plot2DImage image(x, y, image): image is a 2D array (matrix); x and y are arrays. Max and min of x and y provide the ranges for the axes. """ if PlotContext.CurrentWindowIndex == None: PlotContext.OpenNextWindow() if (PlotContext.CurrentPlot == None) or (PlotContext.HoldState == False): # New plot or overwite plot plot = Plot2D() PlotContext.AddPlot(plot) else: # Add to current plot plot = PlotContext.CurrentPlot if len(args) == 1: dims = getsize(args[0]) if len(dims) == 2: image = plot.AddFalseColourImage(args[0]) plot.Margin = Thickness(10) setprops(image, **kwargs) elif len(args) == 3 and (type(args[0]) == type(args[1]) == type(args[2])): dims0 = getsize(args[0]) dims1 = getsize(args[1]) dims2 = getsize(args[2]) if len(dims2) == 2: image = plot.AddFalseColourImage(args[0], args[1], args[2]) setprops(image, **kwargs) return plot
def plot(*args, **kwargs): """ Create a line plot (or overwite current plot if hold is set) Plot2DCurve plot(x, y): x and y are vectors of the same length Plot2DCurve plot(y): x vector will be created Also support PyLab-like line properties, e.g.: plot(x1, y1, '-or', x2, y2, '--sb') Line types are '-', '--', ':' , '-.' Marker types are 's', 'o', '^' Colours are 'r', 'g', 'b', 'y', 'c', 'm', 'k', 'w' Can also specify properties of the Curves to change, e.g.: plot(x1, y1, '-or', StrokeThickness = 2) """ if PlotContext.CurrentWindowIndex == None: PlotContext.OpenNextWindow() if (PlotContext.CurrentPlot == None) or (PlotContext.HoldState == False): # New plot or overwite plot curves = Plotting.Plot2D(*args) plot = curves[0].Plot plot.Padding = Thickness(10) PlotContext.AddPlot(plot) else: # Add to current plot curves = Plotting.Plot2D(PlotContext.CurrentPlot, *args) # Apply kwargs for curve in curves: setprops(curve, **kwargs) if (curves.Count > 1): return curves elif (curves.Count == 1): return curves[0]
def _create_selector(self, values): self._listbox = ListBox() self._listbox.SetValue(Grid.RowProperty, 1) self._listbox.SetValue(Grid.ColumnSpanProperty, 2) self._listbox.Margin = Thickness(10) for item in values: self._listbox.Items.Add(item) return self._listbox
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()
def _create_button(self, content, callback): if content: button = Button() button.Margin = Thickness(10) button.MaxHeight = 50 button.MaxWidth = 150 button.SetValue(Grid.RowProperty, 2) button.Content = content button.Click += callback return button
def __init__(self, h): self.box = EzHBox() self.ctrl = self.box.ctrl self.ctrl.Margin = Thickness(1) items = h.get('items') width = [1, 1] if h.get('first'): width[0] = float(h['first']) * 10 width[1] = 10 - width[0] self.box.AddItem(EzLayout(items[0]), width[0], expand=True) self.box.AddSplitter() self.box.AddItem(EzLayout(items[1]), width[1], expand=True)
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()
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 add_stackpanel(document, items): panel = StackPanel() document.Children.Add(panel) panel.Margin = Thickness(10) for i, item in enumerate(items): item_panel = StackPanel() item_panel.Margin = Thickness(2) item_panel.Orientation = Orientation.Horizontal panel.Children.Add(item_panel) text = _get_text_block(u'\u2022\u00a0') item_panel.Children.Add(text) def goto_page(s, e, page=i + 1): _debug('goto', page) if topComboBoxPart.SelectedIndex == 0: topComboBoxPart.SelectedIndex = page else: topComboBoxPage.SelectedIndex = page button = HyperlinkButton() item_panel.Children.Add(button) button.Content = _get_text_block(item) button.Click += goto_page
def __init__(self, parent): wpf.LoadComponent(self, 'WizardDialog.xaml') f = open('OpenSourceLicenseTerms.txt') opl = f.read() f.close() self.Title = "About" self.SizeToContent = SizeToContent.WidthAndHeight #self.WindowStartupLocation = WindowStartupLocation.Manual self.Left = parent.Left + parent.ActualWidth / 4 self.Top = parent.Top + parent.ActualHeight / 4 stack = Controls.StackPanel() sv = Controls.ScrollViewer() sv.Width = 500 sv.Height = 300 tb = Controls.TextBlock() #tb.FontSize = 16 tb.TextWrapping = TextWrapping.Wrap r = Documents.Run(gVersionStr + '\n') r.Foreground = Media.Brushes.Blue tb.Inlines.Add(r) r = Documents.Run( 'This software is created by JunHyeok Heo ([email protected])\n' ) r.Foreground = Media.Brushes.Blue tb.Inlines.Add(r) r = Documents.Run('under MIT License.\n') r.Foreground = Media.Brushes.Blue tb.Inlines.Add(r) tb.Inlines.Add(opl) sv.AddChild(tb) stack.AddChild(sv) btn = Controls.Button() btn.Click += self.buttonClick btn.Content = "Close" btn.Width = 70 btn.Height = 30 btn.Margin = Thickness(0.0, 6.0, 0.0, 12.0) stack.AddChild(btn) self.Base.AddChild(stack) self.ShowDialog()
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)
def onCompleted(task): window = Window() stackPanel3 = StackPanel() def onLoaded(sender, args): stackPanel3.Width = Math.Ceiling(stackPanel3.ActualWidth) def onCloseClick(sender, args): window.Close() window.Owner = Application.Current.MainWindow if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): window.Title = "バリデータ" else: window.Title = "Validator" window.WindowStartupLocation = WindowStartupLocation.CenterOwner window.ResizeMode = ResizeMode.NoResize window.SizeToContent = SizeToContent.WidthAndHeight window.Background = SystemColors.ControlBrush window.Loaded += onLoaded 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.WindowBrush stackPanel1.Children.Add(stackPanel2) stackPanel3.HorizontalAlignment = HorizontalAlignment.Stretch stackPanel3.VerticalAlignment = VerticalAlignment.Stretch stackPanel3.Orientation = Orientation.Vertical if errorList.Count == 0: if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): attachStackPanel(stackPanel3, Brushes.Lime, "有効なスクリプトです。") else: attachStackPanel(stackPanel3, Brushes.Lime, "Valid.") for warning in warningList: attachStackPanel(stackPanel3, Brushes.Yellow, warning) for error in errorList: attachStackPanel(stackPanel3, Brushes.Red, error) stackPanel2.Children.Add(stackPanel3) solidColorBrush = SolidColorBrush(Colors.White) solidColorBrush.Opacity = 0.5 if solidColorBrush.CanFreeze: solidColorBrush.Freeze() border = Border() border.HorizontalAlignment = HorizontalAlignment.Stretch border.VerticalAlignment = VerticalAlignment.Stretch border.BorderThickness = Thickness(0, 1, 0, 0) border.BorderBrush = solidColorBrush stackPanel1.Children.Add(border) closeButton = Button() closeButton.HorizontalAlignment = HorizontalAlignment.Right closeButton.VerticalAlignment = VerticalAlignment.Center closeButton.Margin = Thickness(10, 10, 10, 10) closeButton.Padding = Thickness(10, 2, 10, 2) closeButton.IsDefault = True if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): closeButton.Content = "閉じる" else: closeButton.Content = "Close" closeButton.Click += onCloseClick border.Child = closeButton window.Show()
import clr clr.AddReference("PresentationFramework", "PresentationCore") from System.Windows import (Application, SizeToContent, Thickness, Window) from System.Windows.Controls import (Button, Label, StackPanel) from System.Windows.Media.Effects import DropShadowBitmapEffect win = Window(Title="Welcome to IronPython", Width=450) win.SizeToContent = SizeToContent.Height stack = StackPanel() stack.Margin = Thickness(15) win.Content = stack button = Button(Content="Push Me", FontSize=24, BitmapEffect=DropShadowBitmapEffect()) def onClick(sender, event): msg = Label() msg.FontSize = 36 msg.Content = 'Welcome to IronPython!' stack.Children.Add(msg) button.Click += onClick stack.Children.Add(button)
def __init__(self): self.ctrl = Grid() self.ctrl.Margin = Thickness(1) self.cols = 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
def Initialize(self, h): if h.get('key'): _window__ctrl_table[h['key']] = self if h.get('tooltip'): self.SetToolTip(h['tooltip']) self.ctrl.Margin = Thickness(5) self.ctrl.Padding = Thickness(1)
def __init__(self): self.ctrl = StackPanel() self.ctrl.Margin = Thickness(15)
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()
def onCompleted(task): global maxWidth, maxHeight window = Window() contentControl = ContentControl() grid1 = Grid() tickTimer = DispatcherTimer(DispatcherPriority.Normal) closeTimer = DispatcherTimer(DispatcherPriority.Background) def onLoaded(sender, args): global rectList, digits storyboard = Storyboard() def onCurrentStateInvalidated(sender, args): if sender.CurrentState == ClockState.Filling: for element in grid1.Children: element.Opacity = 1 storyboard.Remove(contentControl) if not grid1.Tag: closeTimer.Start() storyboard.CurrentStateInvalidated += onCurrentStateInvalidated r = Random(Environment.TickCount) dateTime = DateTime.Now digits[0] = dateTime.Hour / 10 digits[1] = dateTime.Hour % 10 digits[2] = dateTime.Minute / 10 digits[3] = dateTime.Minute % 10 digits[4] = dateTime.Second / 10 digits[5] = dateTime.Second % 10 for i in range(digits.Length): beginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds( r.Next(500))) for element1 in grid1.Children: if Grid.GetColumn(element1) == i: doubleAnimation = DoubleAnimation( element1.Opacity, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation.BeginTime = beginTime sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseOut doubleAnimation.EasingFunction = sineEase storyboard.Children.Add(doubleAnimation) Storyboard.SetTarget(doubleAnimation, element1) Storyboard.SetTargetProperty( doubleAnimation, PropertyPath(UIElement.OpacityProperty)) if Grid.GetRow(element1) == 0: scale1 = Math.Max( element1.ActualWidth / maxWidth, element1.ActualHeight / maxHeight) if rectList[digits[Grid.GetColumn( element1 )]].Width > maxWidth and rectList[digits[ Grid.GetColumn( element1)]].Height > maxHeight: translateX = Math.Round( -(rectList[digits[Grid.GetColumn( element1)]].X + (rectList[digits[Grid.GetColumn( element1)]].Width - maxWidth) / 2.0)) translateY = Math.Round( -(rectList[digits[Grid.GetColumn( element1)]].Y + (rectList[digits[Grid.GetColumn( element1)]].Height - maxHeight) / 2.0)) elif rectList[digits[Grid.GetColumn( element1)]].Width > maxWidth: translateX = Math.Round( -(rectList[digits[Grid.GetColumn( element1)]].X + (rectList[digits[Grid.GetColumn( element1)]].Width - maxWidth) / 2.0)) translateY = Math.Round(-rectList[digits[ Grid.GetColumn(element1)]].Y) elif rectList[digits[Grid.GetColumn( element1)]].Height > maxHeight: translateX = Math.Round(-rectList[digits[ Grid.GetColumn(element1)]].X) translateY = Math.Round( -(rectList[digits[Grid.GetColumn( element1)]].Y + (rectList[digits[Grid.GetColumn( element1)]].Height - maxHeight) / 2.0)) else: translateX = Math.Round(-rectList[digits[ Grid.GetColumn(element1)]].X) translateY = Math.Round(-rectList[digits[ Grid.GetColumn(element1)]].Y) scale2 = Math.Max( maxWidth / rectList[digits[Grid.GetColumn( element1)]].Width, maxHeight / rectList[digits[Grid.GetColumn( element1)]].Height) if scale2 > 1: scale2 = 1 for element2 in element1.Child.Children: transformGroup1 = TransformGroup() transformGroup1.Children.Add( TranslateTransform( (element2.ActualWidth - maxWidth) / 2, (element2.ActualHeight - maxHeight) / 2)) transformGroup1.Children.Add( ScaleTransform( scale1, scale1, element2.ActualWidth / 2, element2.ActualHeight / 2)) element2.RenderTransform = transformGroup1 for element3 in element2.Children: transformGroup2 = TransformGroup() transformGroup2.Children.Add( TranslateTransform( translateX, translateY)) transformGroup2.Children.Add( ScaleTransform( scale2, scale2, maxWidth / 2, maxHeight / 2)) element3.RenderTransform = transformGroup2 contentControl.BeginStoryboard( storyboard, HandoffBehavior.SnapshotAndReplace, True) tickTimer.Start() def onWindowMouseEnter(sender, args): closeTimer.Stop() grid1.Tag = True def onWindowMouseLeave(sender, args): if closeTimer.Tag: closeTimer.Start() grid1.Tag = False def onTick(sender, args): global rectList, digits if rectList.Count > 0: dateTime = DateTime.Now for element1 in grid1.Children: if Grid.GetRow(element1) == 0: if Grid.GetColumn(element1) == 0: digit = dateTime.Hour / 10 elif Grid.GetColumn(element1) == 1: digit = dateTime.Hour % 10 elif Grid.GetColumn(element1) == 2: digit = dateTime.Minute / 10 elif Grid.GetColumn(element1) == 3: digit = dateTime.Minute % 10 elif Grid.GetColumn(element1) == 4: digit = dateTime.Second / 10 else: digit = dateTime.Second % 10 if digit != digits[Grid.GetColumn(element1)]: for element2 in element1.Child.Children: for element3 in element2.Children: storyboard = Storyboard() for transform in element3.RenderTransform.Children: if clr.GetClrType( TranslateTransform ).IsInstanceOfType(transform): if rectList[ digit].Width > maxWidth and rectList[ digit].Height > maxHeight: translateX = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].X + (rectList[digit].X + (rectList[digit].Width - maxWidth) / 2.0 - rectList[digits[ Grid.GetColumn( element1)]].X) )) translateY = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].Y + (rectList[digit].Y + (rectList[digit]. Height - maxHeight) / 2.0 - rectList[digits[ Grid.GetColumn( element1)]].Y) )) elif rectList[ digit].Width > maxWidth: translateX = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].X + (rectList[digit].X + (rectList[digit].Width - maxWidth) / 2.0 - rectList[digits[ Grid.GetColumn( element1)]].X) )) translateY = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].Y + (rectList[digit].Y - rectList[digits[ Grid.GetColumn( element1)]].Y) )) elif rectList[ digit].Height > maxHeight: translateX = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].X + (rectList[digit].X - rectList[digits[ Grid.GetColumn( element1)]].X) )) translateY = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].Y + (rectList[digit].Y + (rectList[digit]. Height - maxHeight) / 2.0 - rectList[digits[ Grid.GetColumn( element1)]].Y) )) else: translateX = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].X + (rectList[digit].X - rectList[digits[ Grid.GetColumn( element1)]].X) )) translateY = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].Y + (rectList[digit].Y - rectList[digits[ Grid.GetColumn( element1)]].Y) )) doubleAnimation1 = DoubleAnimation( translateX, TimeSpan.FromMilliseconds( 500)) doubleAnimation2 = DoubleAnimation( translateY, TimeSpan.FromMilliseconds( 500)) sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseInOut doubleAnimation1.EasingFunction = sineEase doubleAnimation2.EasingFunction = sineEase storyboard.Children.Add( doubleAnimation1) storyboard.Children.Add( doubleAnimation2) Storyboard.SetTarget( doubleAnimation1, element3) Storyboard.SetTarget( doubleAnimation2, element3) Storyboard.SetTargetProperty( doubleAnimation1, PropertyPath( "(0).(1)[0].(2)", Canvas. RenderTransformProperty, TransformGroup. ChildrenProperty, TranslateTransform. XProperty)) Storyboard.SetTargetProperty( doubleAnimation2, PropertyPath( "(0).(1)[0].(2)", Canvas. RenderTransformProperty, TransformGroup. ChildrenProperty, TranslateTransform. YProperty)) else: scale1 = Math.Max( maxWidth / rectList[digits[ Grid.GetColumn( element1)]].Width, maxHeight / rectList[ digits[Grid.GetColumn( element1)]].Height) scale2 = Math.Max( maxWidth / rectList[digit].Width, maxHeight / rectList[digit].Height) if scale1 > 1: scale1 = 1 if scale2 > 1: scale2 = 1 transform.ScaleX = transform.ScaleY = scale1 + ( scale2 - scale1) doubleAnimation1 = DoubleAnimation( scale1 + (scale2 - scale1), TimeSpan.FromMilliseconds( 500)) doubleAnimation2 = DoubleAnimation( scale1 + (scale2 - scale1), TimeSpan.FromMilliseconds( 500)) sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseInOut doubleAnimation1.EasingFunction = sineEase doubleAnimation2.EasingFunction = sineEase storyboard.Children.Add( doubleAnimation1) storyboard.Children.Add( doubleAnimation2) Storyboard.SetTarget( doubleAnimation1, element3) Storyboard.SetTarget( doubleAnimation2, element3) Storyboard.SetTargetProperty( doubleAnimation1, PropertyPath( "(0).(1)[1].(2)", Canvas. RenderTransformProperty, TransformGroup. ChildrenProperty, ScaleTransform. ScaleXProperty)) Storyboard.SetTargetProperty( doubleAnimation2, PropertyPath( "(0).(1)[1].(2)", Canvas. RenderTransformProperty, TransformGroup. ChildrenProperty, ScaleTransform. ScaleYProperty)) element3.BeginStoryboard( storyboard, HandoffBehavior.SnapshotAndReplace) digits[Grid.GetColumn(element1)] = digit def onClose(sender, args): global digits closeTimer.Stop() storyboard = Storyboard() def onCurrentStateInvalidated(sender, args): if sender.CurrentState == ClockState.Filling: for element in grid1.Children: element.Opacity = 0 storyboard.Remove(contentControl) tickTimer.Stop() window.Close() storyboard.CurrentStateInvalidated += onCurrentStateInvalidated r = Random(Environment.TickCount) for i in range(digits.Length): beginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds( r.Next(500))) for element in grid1.Children: if Grid.GetColumn(element) == i: doubleAnimation = DoubleAnimation( element.Opacity, 0, TimeSpan.FromMilliseconds(500)) doubleAnimation.BeginTime = beginTime sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseIn doubleAnimation.EasingFunction = sineEase storyboard.Children.Add(doubleAnimation) Storyboard.SetTarget(doubleAnimation, element) Storyboard.SetTargetProperty( doubleAnimation, PropertyPath(UIElement.OpacityProperty)) contentControl.BeginStoryboard( storyboard, HandoffBehavior.SnapshotAndReplace, True) closeTimer.Tag = False tickTimer.Tick += onTick tickTimer.Interval = TimeSpan.FromMilliseconds(100) closeTimer.Tick += onClose closeTimer.Interval = TimeSpan.FromSeconds(3) closeTimer.Tag = True window.Owner = Application.Current.MainWindow window.Title = Application.Current.MainWindow.Title window.WindowStartupLocation = WindowStartupLocation.CenterScreen window.AllowsTransparency = True window.WindowStyle = WindowStyle.None window.ResizeMode = ResizeMode.NoResize window.ShowActivated = False window.ShowInTaskbar = Application.Current.MainWindow.ContextMenu.Items[ 5].IsChecked window.Topmost = True window.SizeToContent = SizeToContent.WidthAndHeight window.Background = Brushes.Transparent window.Loaded += onLoaded window.MouseEnter += onWindowMouseEnter window.MouseLeave += onWindowMouseLeave contentControl.UseLayoutRounding = True contentControl.HorizontalAlignment = HorizontalAlignment.Stretch contentControl.VerticalAlignment = VerticalAlignment.Stretch window.Content = contentControl grid1.HorizontalAlignment = HorizontalAlignment.Center grid1.VerticalAlignment = VerticalAlignment.Center grid1.Background = Brushes.Transparent grid1.Tag = False contentControl.Content = grid1 bitmapImageList1 = List[BitmapImage]() bitmapImageList2 = List[BitmapImage]() width = 0 height = 0 for stream in task.Result.Key: try: bitmapImage = BitmapImage() bitmapImage.BeginInit() bitmapImage.StreamSource = stream bitmapImage.CacheOption = BitmapCacheOption.OnLoad bitmapImage.CreateOptions = BitmapCreateOptions.None bitmapImage.EndInit() width += bitmapImage.PixelWidth if bitmapImage.PixelHeight > height: height = bitmapImage.PixelHeight bitmapImageList1.Add(bitmapImage) finally: stream.Close() for stream in task.Result.Value: try: bitmapImage = BitmapImage() bitmapImage.BeginInit() bitmapImage.StreamSource = stream bitmapImage.CacheOption = BitmapCacheOption.OnLoad bitmapImage.CreateOptions = BitmapCreateOptions.None bitmapImage.EndInit() bitmapImageList2.Add(bitmapImage) finally: stream.Close() x = 0 kvpList = List[KeyValuePair[Point, BitmapImage]]() for bitmapImage in bitmapImageList1: rect = Rect(x, (height - bitmapImage.PixelHeight) / 2, bitmapImage.PixelWidth, bitmapImage.PixelHeight) rectList.Add(rect) kvpList.Add(KeyValuePair[Point, BitmapImage](rect.Location, bitmapImage)) x += bitmapImage.PixelWidth rowDefinition1 = RowDefinition() rowDefinition1.Height = GridLength(1, GridUnitType.Auto) grid1.RowDefinitions.Add(rowDefinition1) for i in range(digits.Length): columnDefinition = ColumnDefinition() columnDefinition.Width = GridLength(1, GridUnitType.Star) grid1.ColumnDefinitions.Add(columnDefinition) border = Border() border.HorizontalAlignment = HorizontalAlignment.Stretch border.VerticalAlignment = VerticalAlignment.Stretch border.Margin = Thickness(4) border.BorderBrush = Brushes.Black border.BorderThickness = Thickness(1) border.Padding = Thickness(0) border.Width = 160 border.Height = 480 border.Background = Brushes.White border.Opacity = 0 grid1.Children.Add(border) Grid.SetColumn(border, i) Grid.SetRow(border, 0) grid2 = Grid() grid2.HorizontalAlignment = HorizontalAlignment.Stretch grid2.VerticalAlignment = VerticalAlignment.Stretch grid2.Background = Brushes.Transparent grid2.ClipToBounds = True border.Child = grid2 grid3 = Grid() grid3.HorizontalAlignment = HorizontalAlignment.Left grid3.VerticalAlignment = VerticalAlignment.Top grid3.Width = 160 grid3.Height = 480 grid3.Background = Brushes.Transparent grid2.Children.Add(grid3) canvas = Canvas() canvas.HorizontalAlignment = HorizontalAlignment.Left canvas.VerticalAlignment = VerticalAlignment.Top canvas.Width = width canvas.Height = maxHeight canvas.Background = Brushes.Transparent grid3.Children.Add(canvas) for kvp in kvpList: image = Image() image.HorizontalAlignment = HorizontalAlignment.Left image.VerticalAlignment = VerticalAlignment.Top image.Source = kvp.Value image.Width = kvp.Value.PixelWidth image.Height = kvp.Value.PixelHeight image.Stretch = Stretch.Fill canvas.Children.Add(image) Canvas.SetLeft(image, kvp.Key.X) Canvas.SetTop(image, kvp.Key.Y) column = 1 rowDefinition2 = RowDefinition() rowDefinition2.Height = GridLength(1, GridUnitType.Auto) grid1.RowDefinitions.Add(rowDefinition2) for bitmapImage in bitmapImageList2: image = Image() image.HorizontalAlignment = HorizontalAlignment.Right image.VerticalAlignment = VerticalAlignment.Top image.Margin = Thickness(0, 0, 8, 0) image.Source = bitmapImage image.Width = bitmapImage.PixelWidth / 2 image.Height = bitmapImage.PixelHeight / 2 image.Stretch = Stretch.Fill grid1.Children.Add(image) Grid.SetColumn(image, column) Grid.SetRow(image, 1) column += 2 window.Show()