Tcl: Difference between revisions

Content deleted Content added
m not sure this is an issue of spelling
Why TCL needs a XAML API built in….because xaml is better than tk
Tags: Reverted possible vandalism Mobile edit Mobile web edit
Line 1:
 
package require Tclx
 
proc parse_xaml {xaml_file output_file} {
set input [open $xaml_file r]
set output [open $output_file w]
 
set in_grid 0
set row 0
set column 0
set sticky "nw"
 
while {[gets $input line] >= 0} {
if {[regexp {<Grid} $line]} {
set in_grid 1
puts $output "# Load the Tk Package"
puts $output "package require Tk"
puts $output "# Main Frame"
puts $output "frame .main -borderwidth 1 -relief solid -padx 10 -pady 10"
} elseif {[regexp {</Grid>} $line]} {
set in_grid 0
puts $output "# Pack Command"
puts $output "pack .main"
} elseif {$in_grid} {
if {[regexp {<TextBox} $line]} {
set width [lindex [regexp -inline {Width="(\d+)"} $line] 1]
puts $output "entry .main.e$row.$column -width $width"
puts $output "grid .main.e$row.$column -row $row -column $column -sticky $sticky"
incr column
} elseif {[regexp {<Label} $line]} {
set text [lindex [regexp -inline {Content="(.+?)"} $line] 1]
puts $output "label .main.l$row.$column -text \"$text\""
puts $output "grid .main.l$row.$column -row $row -column $column -sticky $sticky"
incr column
} elseif {[regexp {<Button} $line]} {
set text [lindex [regexp -inline {Content="(.+?)"} $line] 1]
set width [lindex [regexp -inline {Width="(\d+)"} $line] 1]
puts $output "button .main.b$row.$column -text \"$text\" -width $width"
puts $output "grid .main.b$row.$column -row $row -column $column -sticky $sticky"
incr column
} elseif {[regexp {</Grid.Row>} $line]} {
set column 0
incr row
}
}
}
 
close $input
close $output
}
 
# Usage example:
# parse_xaml "input.xaml" "output.tcl"
 
 
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Tcl/Tk to XAML Conversion" Width="600" Height="400">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Column="0" Grid.Row="0" Width="200"/>
<TextBox Grid.Column="1" Grid.Row="0" Width="200"/>
<Label Grid.Column="0" Grid.Row="1" Content="First Name"/>
<Label Grid.Column="1" Grid.Row="1" Content="Last Name"/>
<TextBox Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3" Width="300"/>
<Label Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" Content="Address"/>
<TextBox Grid.Column="0" Grid.Row="4" Width="200"/>
<TextBox Grid.Column="1" Grid.Row="4" Width="50"/>
<TextBox Grid.Column="2" Grid.Row="4" Width="100"/>
<Label Grid.Column="0" Grid.Row="5" Content="City"/>
<Label Grid.Column="1" Grid.Row="5" Content="ST"/>
<Label Grid.Column="2" Grid.Row="5" Content="Zip"/>
<TextBox Grid.Column="0" Grid.Row="6" Grid.ColumnSpan="2" Width="200"/>
<Label Grid.Column="0" Grid.Row="7" Grid.ColumnSpan="2" Content="Phone"/>
<Label Grid.Column="3" Grid.Row="0" Grid.RowSpan="7" Width="120" Height="160" BorderThickness="3" Background="Black"/>
<Label Grid.Column="3" Grid.Row="7" Width="120" Content="Photo"/>
 
<Button Grid.Column="0" Grid.Row="8" Content="Previous" Width="100" HorizontalAlignment="Right"/>
<Button Grid.Column="2" Grid.Row="8" Content="Next" Width="100" HorizontalAlignment="Left"/>
<Button Grid.Column="0" Grid.Row="9" Content="Add" Width="100" HorizontalAlignment="Right"/>
<Button Grid.Column="1" Grid.Row="9" Content="Save" Width="100" HorizontalAlignment="Left"/>
<Button Grid.Column="2" Grid.Row="9" Content="Delete" Width="100" HorizontalAlignment="Left"/>
<Button Grid.Column="3" Grid.Row="9" Content="Exit" Width="100" HorizontalAlignment="Left" Click="ExitButton_Click"/>
</Grid>
</Window>
 
 
 
{{short description|High-level programming language}}
{{About||the Chinese electronics company|TCL Technology|other uses|}}