def _get_text_block(text): block = TextBlock() block.FontSize = 15 block.FontFamily = FontFamily( "Verdana,Tahoma,Geneva,Lucida Grande,Trebuchet MS,Helvetica,Arial,Serif" ) block.Text = text return block
def create_headline(self): headline = TextBlock() headline.Margin = Thickness(5, 5, 5, 5) headline.FontSize = 16 headline.Text = 'Twitter on Silverlight for IronPython in Action' headline.Foreground = SolidColorBrush(Colors.White) self.Children.Add(headline) self.headline = headline
def get_text(self, text): tb = TextBlock() tb.Text = text tb.Width = self.canvas.ActualWidth tb.Height = 40 tb.FontSize = 30 tb.Background = SolidColorBrush(Colors.Black) tb.Foreground = SolidColorBrush(Colors.White) tb.TextAlignment = TextAlignment.Center return tb
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 populate_tweets(self, data): statuses = TwitterStatusReader().read(data) if not statuses: self.msg.Text = 'No tweets found!' return grid = Grid() grid.ShowGridLines = True self.top_panel.Content = grid first_column = ColumnDefinition() first_column.Width = GridLength(115.0) grid.ColumnDefinitions.Add(first_column) grid.ColumnDefinitions.Add(ColumnDefinition()) for i in range(len(statuses)): grid.RowDefinitions.Add(RowDefinition()) def configure_block(block, col, row): block.FontSize = 14 block.Margin = Thickness(5) block.HorizontalAlignment = HorizontalAlignment.Left block.VerticalAlignment = VerticalAlignment.Center grid.SetRow(block, row) grid.SetColumn(block, col) for row, status in enumerate(statuses): name = status['name'] text = status['text'] block1 = HyperlinkButton() block1.Content = name block1.NavigateUri = Uri('http://twitter.com/%s' % name) # this should open the link in a new window # but causes link to not function at all on Safari # It works for IE though #block1.TargetName = '_blank' block1.FontWeight = FontWeights.Bold configure_block(block1, 0, row) block2 = TextBlock() block2.Text = text block2.TextWrapping = TextWrapping.Wrap configure_block(block2, 1, row) grid.Children.Add(block1) grid.Children.Add(block2)
def createScrollViewer(self, grid): scroll = ScrollViewer() scroll.Height = 200 scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto scroll.HorizontalAlignment = HorizontalAlignment.Stretch scroll.VerticalAlignment = VerticalAlignment.Stretch panel = StackPanel() text = TextBlock() text.TextWrapping = TextWrapping.Wrap text.Margin = Thickness(0, 0, 0, 20) text.Text = "A ScrollViewer.\r\n\r\nScrollbars appear as and when they are needed...\r\n" rect = Rectangle() rect.Fill = GetLinearGradientBrush() rect.Width = 500 rect.Height = 500 panel.Children.Add(text) panel.Children.Add(rect) scroll.Content = panel; SetGridChild(grid, scroll, 1, 2, "ScrollViewer")
def onClickTarget(self, sender, event): # Check to see if content was already set if sender.Content == None: # Insert an Ellipse in the target label grid = Grid() ellipse = Shapes.Ellipse() ellipse.Style = Application.Current.Windows[0].Resources["TargetStyle"] grid.Children.Add(ellipse) sender.Content = grid text = TextBlock() text.Style = Application.Current.Windows[0].Resources["TextBlockStyle"] text.Text = str(len(self.path)+1) grid.Children.Add(text) ellipse.Visibility = Visibility.Visible # Update moveMatrix position rowCol = sender.Name.split("and") lastRowCol = [int(rowCol[1]), int(rowCol[2])] self.path.append([lastRowCol[0], lastRowCol[1]])
def __init__(self, h): self.ctrl = Button() self.Initialize(h) if h.get('fontsize'): self.SetFontSize(h['fontsize']) if h.get('handler'): self.ctrl.Click += h['handler'] stack = StackPanel() stack.Orientation = Orientation.Vertical #Horizontal self.ctrl.Content = stack if h.get('image'): image = Image() image.Source = BitmapImage( System.Uri(h['image'], System.UriKind.Relative)) image.VerticalAlignment = VerticalAlignment.Center image.Stretch = Stretch.Fill #Stretch.None if h.get('size'): image.Height = float(h['size']) image.Width = float(h['size']) stack.Children.Add(image) if h.get('label'): text = TextBlock() text.Text = h['label'] text.TextAlignment = TextAlignment.Center stack.Children.Add(text)
from System.Windows import Application from System.Windows.Controls import Canvas, TextBlock from System.Threading import Thread, ThreadStart root = Canvas() Application.Current.RootVisual = root text = TextBlock() thread_id = Thread.CurrentThread.ManagedThreadId text.Text = "Created on thread %s" % thread_id text.FontSize = 24 root.Children.Add(text) def wait(): Thread.Sleep(3000) thread_id = Thread.CurrentThread.ManagedThreadId def SetText(): text.Text = 'Hello from thread %s' % thread_id text.Dispatcher.BeginInvoke(SetText) t = Thread(ThreadStart(wait)) t.Start()
def _get_text_block(text): block = TextBlock() block.FontSize = 15 block.FontFamily = FontFamily("Verdana,Tahoma,Geneva,Lucida Grande,Trebuchet MS,Helvetica,Arial,Serif") block.Text = text return block
##################################################################################### # # Copyright (c) Microsoft Corporation. All rights reserved. # # This source code is subject to terms and conditions of the Apache License, Version 2.0. A # copy of the license can be found in the License.html file at the root of this distribution. If # you cannot locate the Apache License, Version 2.0, please send an email to # [email protected]. By using this source code in any fashion, you are agreeing to be bound # by the terms of the Apache License, Version 2.0. # # You must not remove this notice, or any other, from this software. # # ##################################################################################### """ Bare-bones application used to ensure the 'Silverlight3Release' build configuration of IronPython is OK. """ from System.Windows import Application from System.Windows.Controls import TextBlock tb = TextBlock() tb.Text = "Hello World" Application.Current.RootVisual = tb
from System.Windows import Application, Thickness from System.Windows.Controls import ( Button, Orientation, TextBlock, StackPanel, TextBox ) from System.Windows.Input import Key root = StackPanel() 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):
from System.Windows import Application from System.Windows.Controls import Canvas, TextBlock from System.Windows.Threading import DispatcherTimer from System import TimeSpan root = Canvas() Application.Current.RootVisual = root text = TextBlock() text.Text = "Nothing yet" text.FontSize = 24 root.Children.Add(text) counter = 0 def callback(sender, event): global counter counter += 1 text.Text = 'Tick %s' % counter timer = DispatcherTimer() timer.Tick += callback timer.Interval = TimeSpan.FromSeconds(2) timer.Start()
##################################################################################### # # Copyright (c) Microsoft Corporation. All rights reserved. # # This source code is subject to terms and conditions of the Microsoft Public License. A # copy of the license can be found in the License.html file at the root of this distribution. If # you cannot locate the Microsoft Public License, please send an email to # [email protected]. By using this source code in any fashion, you are agreeing to be bound # by the terms of the Microsoft Public License. # # You must not remove this notice, or any other, from this software. # # ##################################################################################### """ Bare-bones application used to ensure the 'Silverlight Release' build configuration of IronPython is OK. """ from System.Windows import Application from System.Windows.Controls import TextBlock tb = TextBlock() tb.Text = "Hello World" Application.Current.RootVisual = tb
from System.Windows import Application from System.Windows.Controls import Canvas, TextBlock, MediaElement from System.Windows.Media import VideoBrush, Stretch root = Canvas() video = MediaElement() source = Uri('../SomeVideo.wmv', UriKind.Relative) video.Source = source video.Opacity = 0.0 video.IsMuted = True def restart(s, e): video.Position = TimeSpan(0) video.Play() video.MediaEnded += restart brush = VideoBrush() brush.Stretch = Stretch.UniformToFill brush.SetSource(video) t = TextBlock() t.Text = 'Video' t.FontSize = 120 t.Foreground = brush root.Children.Add(t) root.Children.Add(video) Application.Current.RootVisual = root
from System.Windows import Application, Duration, PropertyPath from System.Windows.Controls import Canvas, TextBlock from System.Windows.Media.Animation import ( DoubleAnimation, Storyboard ) root = Canvas() Application.Current.RootVisual = root root.Children.Clear() root.Resources.Clear() t = TextBlock() t.FontSize = 20 t.Text = 'Move the Mouse Over Me' root.Children.Add(t) sb = Storyboard() duration = Duration(TimeSpan.FromSeconds(0.25)) a = DoubleAnimation() a.Duration = duration sb.Duration = duration sb.AutoReverse = True sb.Children.Add(a) Storyboard.SetTarget(a, t) Storyboard.SetTargetProperty(a, PropertyPath('FontSize')) a.From = 20 a.To = 30
from System.Windows import Application from System.Windows.Controls import Canvas, TextBlock canvas = Canvas() textblock = TextBlock() textblock.FontSize = 24 textblock.Text = 'Hello World from IronPython' canvas.Children.Add(textblock) Application.Current.RootVisual = canvas
def PrintText(t): tb = TextBlock() tb.Text = t console.Children.Add(tb)