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 _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 _method(self): root.Children.Clear() main = StackPanel() t = TextBlock(Text=" Examples ") t.FontSize = 32 t.Foreground = SolidColorBrush(Colors.Magenta) main.Children.Add(t) b = Button('Browser DOM') b.Click += lambda: SetExample('browserDOM') main.Children.Add(b) b = Button('HTML Events') b.Click += lambda: SetExample('inputEvents') main.Children.Add(b) b = Button('Video Player') b.Click += lambda: SetExample('videoExample') main.Children.Add(b) b = Button('Open File Dialog') b.Click += lambda: SetExample('openFileDialog') main.Children.Add(b) b = Button('Local Storage') b.Click += lambda: SetExample('isolatedStorageFile') main.Children.Add(b) b = Button('Loading XAML') b.Click += lambda: SetExample('loadingXaml') main.Children.Add(b) b = Button('Using Controls') b.Click += lambda: SetExample('controls') main.Children.Add(b) b = Button('WebClient') b.Click += lambda: SetExample('webClient') main.Children.Add(b) b = Button('Threading') b.Click += lambda: SetExample('threading') main.Children.Add(b) b = Button('Read from a File') b.Click += lambda: SetExample('openFile') main.Children.Add(b) b = Button('Setting Position') b.Click += lambda: SetExample('position') main.Children.Add(b) b = Button('Animation') b.Click += lambda: SetExample('animation') main.Children.Add(b) root.Children.Add(main)
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 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 _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 createTextBlockAndHyperlink(self, grid): textblock = TextBlock() textblock.TextWrapping = TextWrapping.Wrap textblock.Background = Brushes.AntiqueWhite textblock.TextAlignment = TextAlignment.Center textblock.Inlines.Add(Bold(Run("TextBlock"))) textblock.Inlines.Add(Run(" is designed to be ")) textblock.Inlines.Add(Italic(Run("lightweight"))) textblock.Inlines.Add(Run(", and is geared specifically at integrating ")) textblock.Inlines.Add(Italic(Run("small"))) textblock.Inlines.Add(Run(" portions of flow content into a UI. ")) link = Hyperlink(Run("A Hyperlink - Click Me")) def action(s, e): self.label.Content = "Hyperlink Clicked" link.Click += action textblock.Inlines.Add(link) SetGridChild(grid, textblock, 2, 2, "TextBlock")
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 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 __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)
def populateList(self): files = glob.glob(self.path + '*.dcm') self.patsort = Patients(files) self.patsort.ReadFiles() defpatlistsorted = self.patsort.SortDicomInfo() #sort on id in listbox for id, patlist in defpatlistsorted: list_item = ListBoxItem() list_item.FontFamily = TextBlock.FontFamily("Courier New") list_item.FontSize = 14 list_item.Content = id.strip() #add to listbox self.listBoxPatients.Items.Add(list_item)
def _getTextBlock(rss): result = TextBlock() for item in rss: run = Run(item.Title) hlink = Hyperlink(run) hlink.NavigateUri = Uri(item.Url) hlink.Foreground = harriet.Setting.ChatWindowColor.Foreground hlink.RequestNavigate += _OnRequestNavigate result.Inlines.Add(hlink) result.Inlines.Add(LineBreak()) result.Inlines.Add(LineBreak()) return result
def setUp(self): self.new_ctl = Document.CreateElement('foo') self.new_ctl.SetAttribute("id", "newctl") self.utf8_string = "aBc 西-雅-图的冬天AbC-123" # htmlElement tagName casing varies by browser if (BrowserInformation.Name == 'Microsoft Internet Explorer'): self.tag = "<B>%s</B>" else: self.tag = "<b>%s</b>" self.new_value = self.tag % self.utf8_string self.new_ctl.innerHTML = self.new_value body = Document.Body body.AppendChild(self.new_ctl) app.RootVisual = Canvas() self.tb = TextBlock() app.RootVisual.Children.Add(self.tb)
##################################################################################### # # 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 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()
##################################################################################### # # 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):
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
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()
from System import TimeSpan 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, 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 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)