how to change Tcl default font size - format

I am not very good at Tcl but I am using this code to visualize some systems. Can anyone help me with changing the default font of the produce of this code below?
I tried to put this to the top of the code but it didn't work:
font create myDefaultFont -family Helvetica -size 20
option add *font myDefaultFont
Here is the code:
proc DisplayModel2D { {ShapeType nill} {dAmp 5} {xLoc 10} {yLoc 10} {xPixels 512} {yPixels 384} {nEigen 1} } {
global TunitTXT
global ScreenResolutionX ScreenResolutionY
if { [info exists TunitTXT] != 1} {set TunitTXT ""}
if { [info exists ScreenResolutionX] != 1} {set ScreenResolutionX 1024}
if { [info exists ScreenResolutionY] != 1} {set ScreenResolutionY 768}
if {$xPixels == 0} {
set xPixels [expr int($ScreenResolutionX/2)];
set yPixels [expr int($ScreenResolutionY/2)];
set xLoc 10
set yLoc 10
}
if {$ShapeType == "nill"} {
puts ""; puts ""; puts "------------------"
puts "View the Model? (N)odes, (D)eformedShape, anyMode(1),(2),(#). Press enter for NO."
gets stdin answer
if {[llength $answer]>0 } {
if {$answer != "N" & $answer != "n"} {
puts "Modify View Scaling Factor=$dAmp? Type factor, or press enter for NO."
gets stdin answerdAmp
if {[llength $answerdAmp]>0 } {
set dAmp $answerdAmp
}
}
if {[string index $answer 0] == "N" || [string index $answer 0] == "n"} {
set ShapeType NodeNumbers
} elseif {[string index $answer 0] == "D" ||[string index $answer 0] == "d" } {
set ShapeType DeformedShape
} else {
set ShapeType ModeShape
set nEigen $answer
}
} else {
return
}
}
if {$ShapeType == "ModeShape" } {
set lambdaN [eigen $nEigen]; # perform eigenvalue analysis for ModeShape
set lambda [lindex $lambdaN [expr $nEigen-1]];
set omega [expr pow($lambda,0.5)]
set PI [expr 2*asin(1.0)]; # define constant
set Tperiod [expr 2*$PI/$omega]; # period (sec.)
set fmt1 "Mode Shape, Mode=%.1i Period=%.3f %s "
set windowTitle [format $fmt1 $nEigen $Tperiod $TunitTXT]
} elseif {$ShapeType == "NodeNumbers" } {
set windowTitle "Node Numbers"
} elseif {$ShapeType == "DeformedShape" } {
set windowTitle "Deformed Shape"
}
set viewPlane XY
recorder display $windowTitle $xLoc $yLoc $xPixels $yPixels -wipe ; # display recorder
DisplayPlane $ShapeType $dAmp $viewPlane $nEigen 0
}

font create myDefaultFont -family Helvetica -size 20
option add *font myDefaultFont
will indeed set the default font for all text added to widgets that have a -font option. It will not change the font of text printed on the console with puts. It's not clear from the code you've posted how your text is being displayed, but if you e.g. set the text of a label to the value of one of your variables it should be displayed with the font you've selected.

Related

Adding a feature to this Hangman Game

I have a hangman game and I am having trouble adding in a feature. I want to make it if the whole word is guessed, it will display "You guessed the word!!!", but I cant seem to find a spot to put it. This is the code
hangman's init()
script hangman
property stdin : missing value
property stdout : missing value
property dict : missing value
on init()
--starting up the game
set stdin to parent's hangmanStdin's alloc()'s init()
set stdout to parent's hangmanStdout's alloc()'s init()
set dict to parent's hangmanDictionary's alloc()'s init()
my mainLoop()
end init
on mainLoop()
repeat --endless
set option to stdin's getOptions("Lobby", "What would you like to do?", {"New Game", "Quit"})
if option is "New Game" then
set difficulty to stdin's getOptions("New Game", "Choose your difficulty", {"Normal", "Easy", "Hard"})
--replace this line with an automatic word generator
set x to parent's hangmanGame's alloc()'s initWithWordAndDifficulty(dict's getWord(), difficulty)
if x's startgame() is false then
return
else
stdout's printf("You've scored " & x's score & " points.")
end if
--game is over so clear it
set x to missing value
else
exit repeat
end if
end repeat
end mainLoop
on shouldTerminate()
return true
end shouldTerminate
on alloc()
copy me to x
return x
end alloc
end script
script hangmanGame
property parent : hangman
property wordToGuess : missing value
property maxFaults : missing value
property usedChars : missing value
property faults : missing value
property score : 0
on initWithWordAndDifficulty(theWord, theDifficulty)
if theDifficulty = "Hard" then
set my maxFaults to 5
else if theDifficulty = "Normal" then
set my maxFaults to 8
else --easy or any other value will be handled as easy
set my maxFaults to 10
end if
set my wordToGuess to theWord
set my usedChars to {}
set my faults to 0
set my score to 0
return me
end initWithWordAndDifficulty
on startgame()
repeat --endless
set __prompt to "Faults Left: " & maxFaults - faults & return & "The Word: " & my makeHiddenField()
set c to parent's stdin's getChar(__prompt)
if c = false then
return false
end if
--first check if getChar did give us any result
if length of c is not 0 then
--check if teh character is valid
if c is in "abcdefghijklmnopqrstuvwxyz" then
--check if we already checked this before
if c is not in my usedChars then
set end of my usedChars to c
--check if player guessed wrong character
if c is not in wordToGuess then
set faults to faults + 1
end if
end if
end if
end if
--check if player guessed all characters of word
if my wordGuessed() then
set my score to ((25 * (26 / (length of my usedChars))) as integer)
return true
end if
--check if player reached the max faults he's allowed to make
if my faults = my maxFaults then
display dialog "The word was " & quoted form of wordToGuess
return 0
end if
end repeat
end startgame
on wordGuessed()
repeat with aChar in every text item of my wordToGuess
if aChar is not in my usedChars then
return false
end if
end repeat
return true
end wordGuessed
on makeHiddenField()
set characterArray to {}
repeat with aChar in every text item of my wordToGuess
if aChar is in my usedChars then
set end of characterArray to aChar as string
else
set end of characterArray to "_"
end if
end repeat
set AppleScript's text item delimiters to space
set hiddenField to characterArray as string
set AppleScript's text item delimiters to ""
return hiddenField
end makeHiddenField
end script
script hangmanDictionary
property parent : hangman
property wordsPlayed : missing value
property allWords : missing value
on init()
set wordsPlayed to {}
--try to get more words from a file for example
set allWords to {"Hangman", "Police", "Officer", "Desktop", "Pencil", "Window", "Language", "Wealthy", "Trauma", "Spell", "Rival", "Tactical", "Thin", "Salty", "Bluish", "Falcon", "Distilery", "Ballistics", "Fumbling", "Limitless", "South", "Humble", "Foreign", "Affliction", "Retreat", "Agreeable", "Poisoner", "Flirt", "Fearsome", "Deepwater", "Bottom", "Twisted", "Morsel", "Filament", "Winter", "Contempt", "Drimys", "Grease", "Awesome", "Compulsive", "Crayon", "Prayer", "Blonde", "Backbone", "Dreamland", "Ballet", "Continuous", "Aerobatic", "Hideous", "Harmonic", "Lottery", "Encrypt", "Cable", "Aluminium", "Hunter", "National", "Hunter", "Mechanical", "Deadbeat", "Opposition", "Threat", "Decadent", "Gazelle", "Guild", "Authoritive", "Deliverance", "Severe", "Jerid", "Alarm", "Monochrome", "Cyanide", "External", "Potential", "Section", "Innocent", "Drifting", "Amnesia", "Domino", "Flimsy", "Flamethrowing", "Advocate", "Hirsute", "Brother", "Ephemeral", "Brutal", "Decade", "Drauma", "Dilemma", "Exquisite", "Glimmer", "Fugitive", "Digital", "Associate", "Ambivalent", "Ambulatory", "Apology", "Brawler", "Molecular", "Insurance", "Contractual", "Initial", "Calibration", "Heretical", "Disclosure", "Guerilla", "Dismember", "Minimal", "Altercation", "Eastern", "Integrate", "Femur", "Metallic", "Ambition", "Auxiliary", "Esoteric", "Converse", "Accepting", "Juvenile", "Efficacious", "Complex", "Imperil", "Division", "Onerous", "Astonish", "Scandalous", "Quaint", "Dominate", "Contrary", "Conspiracy", "Earthquake", "Embarrassment", "Exclude", "Ambiguous", "Captivate", "Compliance", "Migration", "Embryo", "Abandon", "Conservation", "Appreciate", "Applaud", "Pension", "Voyage", "Influence", "Consensus", "Incapable", "Economy", "Parameter", "Contrast", "Sensitive", "Meadow", "Chimney", "Familiar", "Serious", "Credibility", "Infrastructure", "Museum", "Relinquish", "Merit", "Coalition", "Retirement", "Transaction", "Official", "Composer", "Magnitude", "Committee", "Privilege", "Diamond", "Obligation", "Transition", "Jockey", "Reinforce", "Conflict", "Offensive", "Detective", "Effective", "Detector", "Abhorrent", "Fragile", "Feigned", "Addition", "Jealous", "Irritating", "Grotesque", "Hesitant", "Adaptable", "Highfalutin", "Defiant", "Ceaseless", "Aquatic", "Voracious", "Separate", "Phobic", "Scientific", "Cluttered", "Intelligent", "Garrulous", "Rhetorical", "Obtainable", "Bawdy", "Outstanding", "Synonymous", "Gleaming", "Ambitious", "Agonizing", "Fallacious", "Lamister", "Fugitive", "Individualism", "Archaic", "Paramount", "Pannose", "Pretermit", "Retorse", "Versability", "Demonomancy", "Vagile", "Reflation", "Foliate", "Guignol", "Agacerie", "Theopneustic", "Glumiferous", "Optative", "Scrivello", "Unifarious", "Ordonnance", "Dithyrambic", "Locative", "Locomotive", "Mirabilia", "Keyline", "Mellification", "Theomicrist", "Ireless", "Commonition", "Dragoon", "Webster", "Utinam", "Obumbrate", "Inceptive"}
return me
end init
on getWord()
set randomNr to (random number from 1 to (length of (my allWords))) as integer
--you could do somethinh here when a word is used again
return item randomNr of my allWords as string
end getWord
end script
script hangmanStdin
property parent : hangman
on init()
return me
end init
on getChar(__prompt)
set x to display dialog __prompt buttons {"Go", "Quit"} default button "Go" default answer ""
if button returned of x = "Quit" then
return false
end if
if length of x's text returned = 0 then
return ""
end if
return character 1 of x's text returned
end getChar
on getOptions(__title, __message, __options)
return button returned of (display alert __title message __message buttons __options default button 1)
end getOptions
end script
script hangmanStdout
property parent : hangman
on init()
return me
end init
on printf(__message)
display dialog __message buttons {"OK"} default button 1
end printf
end script
This is similar to your other topic, you just need to follow the flow of your script.
In the hangmanGame script’s startGame() handler, you are using the wordGuessed() handler to determine if the word was guessed, so the dialog can go where you are getting that result, for example:
if my wordGuessed() then
display dialog "You guessed the word!!!"
set my score to ((25 * (26 / (length of my usedChars))) as integer)
return true
end if

How to add new features to my Hangman game?

I am working on a game, Hangman. I have the code down, I just want to display the word if you lose. How can I do that?
hangman's init()--by Londres on Stack Overflow
script hangman
property stdin : missing value
property stdout : missing value
property dict : missing value
on init()
--starting up the game
set stdin to parent's hangmanStdin's alloc()'s init()
set stdout to parent's hangmanStdout's alloc()'s init()
set dict to parent's hangmanDictionary's alloc()'s init()
my mainLoop()
end init
on mainLoop()
repeat --endless
set option to stdin's getOptions("Lobby", "What would you like to do?", {"New Game", "Quit"})
if option is "New Game" then
set difficulty to stdin's getOptions("New Game", "Choose your difficulty", {"Normal", "Easy", "Hard"})
--replace this line with an automatic word generator
set x to parent's hangmanGame's alloc()'s initWithWordAndDifficulty(dict's getWord(), difficulty)
if x's startgame() is false then
return
else
stdout's printf("You've scored " & x's score & " points.")
end if
--game is over so clear it
set x to missing value
else
exit repeat
end if
end repeat
end mainLoop
on shouldTerminate()
return true
end shouldTerminate
on alloc()
copy me to x
return x
end alloc
end script
script hangmanGame
property parent : hangman
property wordToGuess : missing value
property maxFaults : missing value
property usedChars : missing value
property faults : missing value
property score : 0
on initWithWordAndDifficulty(theWord, theDifficulty)
if theDifficulty = "Hard" then
set my maxFaults to 5
else if theDifficulty = "Normal" then
set my maxFaults to 8
else --easy or any other value will be handled as easy
set my maxFaults to 12
end if
set my wordToGuess to theWord
set my usedChars to {}
set my faults to 0
set my score to 0
return me
end initWithWordAndDifficulty
on startgame()
repeat --endless
set __prompt to "Faults Left: " & maxFaults - faults & return & "The Word: " & my makeHiddenField()
set c to parent's stdin's getChar(__prompt)
if c = false then
return false
end if
--first check if getChar did give us any result
if length of c is not 0 then
--check if teh character is valid
if c is in "abcdefghijklmnopqrstuvwxyz" then
--check if we already checked this before
if c is not in my usedChars then
set end of my usedChars to c
--check if player guessed wrong character
if c is not in wordToGuess then
set faults to faults + 1
end if
end if
end if
end if
--check if player guessed all characters of word
if my wordGuessed() then
set my score to ((25 * (26 / (length of my usedChars))) as integer)
return true
end if
--check if player reached the max faults he's allowed to make
if my faults = my maxFaults then
return 0
end if
end repeat
end startgame
on wordGuessed()
repeat with aChar in every text item of my wordToGuess
if aChar is not in my usedChars then
return false
end if
end repeat
return true
end wordGuessed
on makeHiddenField()
set characterArray to {}
repeat with aChar in every text item of my wordToGuess
if aChar is in my usedChars then
set end of characterArray to aChar as string
else
set end of characterArray to "_"
end if
end repeat
set AppleScript's text item delimiters to space
set hiddenField to characterArray as string
set AppleScript's text item delimiters to ""
return hiddenField
end makeHiddenField
end script
script hangmanDictionary
property parent : hangman
property wordsPlayed : missing value
property allWords : missing value
on init()
set wordsPlayed to {}
--try to get more words from a file for example
set allWords to {"Hangman", "Police", "Officer", "Desktop", "Pencil", "Window", "Language", "Wealthy", "Trauma", "Spell", "Rival", "Tactical", "Thin", "Salty", "Bluish", "Falcon", "Distilery", "Ballistics", "Fumbling", "Limitless", "South", "Humble", "Foreign", "Affliction", "Retreat", "Agreeable", "Poisoner", "Flirt", "Fearsome", "Deepwater", "Bottom", "Twisted", "Morsel", "Filament", "Winter", "Contempt", "Drimys", "Grease", "Awesome", "Compulsive", "Crayon", "Prayer", "Blonde", "Backbone", "Dreamland", "Ballet", "Continuous", "Aerobatic", "Hideous", "Harmonic", "Lottery", "Encrypt", "Cable", "Aluminium", "Hunter", "National", "Hunter", "Mechanical", "Deadbeat", "Opposition", "Threat", "Decadent", "Gazelle", "Guild", "Authoritive", "Deliverance", "Severe", "Jerid", "Alarm", "Monochrome", "Cyanide", "External", "Potential", "Section", "Innocent", "Drifting", "Amnesia", "Domino", "Flimsy", "Flamethrowing", "Advocate", "Hirsute", "Brother", "Ephemeral", "Brutal", "Decade", "Drauma", "Dilemma", "Exquisite", "Glimmer", "Fugitive", "Digital", "Associate", "Ambivalent", "Ambulatory", "Apology", "Brawler", "Molecular", "Insurance", "Contractual", "Initial", "Calibration", "Heretical", "Disclosure", "Guerilla", "Dismember", "Minimal", "Altercation", "Eastern", "Integrate", "Femur", "Metallic", "Ambition", "Auxiliary", "Esoteric", "Converse", "Accepting", "Juvenile", "Efficacious", "Complex", "Imperil", "Division", "Onerous", "Astonish", "Scandalous", "Quaint", "Dominate", "Contrary", "Conspiracy", "Earthquake", "Embarrassment", "Exclude", "Ambiguous", "Captivate", "Compliance", "Migration", "Embryo", "Abandon", "Conservation", "Appreciate", "Applaud", "Pension", "Voyage", "Influence", "Consensus", "Incapable", "Economy", "Parameter", "Contrast", "Sensitive", "Meadow", "Chimney", "Familiar", "Serious", "Credibility", "Infrastructure", "Museum", "Relinquish", "Merit", "Coalition", "Retirement", "Transaction", "Official", "Composer", "Magnitude", "Committee", "Privilege", "Diamond", "Obligation", "Transition", "Jockey", "Reinforce", "Conflict", "Offensive", "Detective", "Effective", "Detector"}
return me
end init
on getWord()
set randomNr to (random number from 1 to (length of (my allWords))) as integer
--you could do somethinh here when a word is used again
return item randomNr of my allWords as string
end getWord
end script
script hangmanStdin
property parent : hangman
on init()
return me
end init
on getChar(__prompt)
set x to display dialog __prompt buttons {"Go", "Quit"} default button "Go" default answer ""
if button returned of x = "Quit" then
return false
end if
if length of x's text returned = 0 then
return ""
end if
return character 1 of x's text returned
end getChar
on getOptions(__title, __message, __options)
return button returned of (display alert __title message __message buttons __options default button 1)
end getOptions
end script
script hangmanStdout
property parent : hangman
on init()
return me
end init
on printf(__message)
display dialog __message buttons {"OK"} default button 1
end printf
end script
How can I make it so if you lose the game, not only does it say the you got 0 points but also say the word that they missed. I'm trying my best to get this done. It's a project that I'm doing to get the basics of coding. Took me awhile.
You are only checking the return result from hangmanGame’s startGame() handler for false or otherwise, but the handler returns 0 if all the faults are used. You could add an additional check in there, but the easiest way would probably be to add a dialog in the startGame() comparison, for example:
if my faults = my maxFaults then
display dialog "The word was " & quoted form of wordToGuess
return 0
end if

ZPL print Italic Bold and Underline

I need to print ZPL with dynamic content.
I Need your help. I am dynamic content , please help me.
is this word possible to print. Note the content is dynamic.
ZPL Code please.
If you want to type bold you can use this
^FO340,128^FDbold^FS
^FO339,128^FDbold^FS
Another option (External fonts usage for underline, italic and bold)
http://labelary.com/docs.html
There is no simple way to bold or italicize text withing ZPL. The fonts the printer has are very basic and can't be changed like that.
Complex font settings (italic, bold, serif ) are actually sent as compressed images to ZPL printers (you can check this with ZebraDesigner).
The format is called Z64, which is based on LZ77.
These two pages contain interesting code in Java to write a converter :
http://www.jcgonzalez.com/img-to-zpl-online
https://gist.github.com/trevarj/1255e5cbc08fb3f79c3f255e25989a18
...still I'm not sure whether the CRC part of the conversion will remain the same in the future, as this is probably vendor-dependent.
Here is a Python port of the first script :
import cv2
import base64
import matplotlib.pyplot as plt
import io
import numpy
blacklimit=int(50* 768/100)
compress=False
total=0
width_byte=0
mapCode = dict()
LOCAL_PATH="C://DEV//printer//zebra_debug.txt"
'''
class StringBuilder(object):
def __init__(self):
self._stringio = io.StringIO()
def __str__(self):
return self._stringio.getvalue()
def getvalue(self):
return self._stringio.getvalue()
def append(self, *objects, sep=' ', end=''):
print(*objects, sep=sep, end=end, file=self._stringio)
'''
def init_map_code():
global mapCode
mapCode[1] = "G"
mapCode[2] = "H"
mapCode[3] = "I"
mapCode[4] = "J"
mapCode[5] = "K"
mapCode[6] = "L"
mapCode[7] = "M"
mapCode[8] = "N"
mapCode[9] = "O"
mapCode[10] = "P"
mapCode[11] = "Q"
mapCode[12] = "R"
mapCode[13] = "S"
mapCode[14] = "T"
mapCode[15] = "U"
mapCode[16] = "V"
mapCode[17] = "W"
mapCode[18] = "X"
mapCode[19] = "Y"
mapCode[20] = "g"
mapCode[40] = "h"
mapCode[60] = "i"
mapCode[80] = "j"
mapCode[100] = "k"
mapCode[120] = "l"
mapCode[140] = "m"
mapCode[160] = "n"
mapCode[180] = "o"
mapCode[200] = "p"
mapCode[220] = "q"
mapCode[240] = "r"
mapCode[260] = "s"
mapCode[280] = "t"
mapCode[300] = "u"
mapCode[320] = "v"
mapCode[340] = "w"
mapCode[360] = "x"
mapCode[380] = "y"
mapCode[400] = "z"
def numberToBase(n, b):
if n == 0:
return [0]
digits = []
while n:
digits.append(int(n % b))
n //= b
return digits[::-1]
def four_byte_binary(binary_str):
decimal=int(binary_str, 2)
if decimal>15:
returned=hex(decimal).upper()
returned=returned[2:]
else:
#returned=hex(decimal).upper()+"0"
returned=hex(decimal).upper()
if binary_str!="00000000":
print("cut="+returned)
returned=returned[2:]
returned="0"+returned
if binary_str!="00000000":
print("low10="+returned)
#
if binary_str!="00000000":
print(binary_str+"\t"+str(decimal)+"\t"+returned+"\t")
return returned
def createBody(img):
global blacklimit
global width_byte
global total
height, width, colmap = img.shape
print(height)
print(width)
print(colmap)
rgb = 0
index=0
aux_binary_char=['0', '0', '0', '0', '0', '0', '0', '0']
sb=[]
if(width%8>0):
width_byte=int((width/8)+1)
else:
width_byte=width/8
total=width_byte*height
print(height)
print("\n")
print(width)
print("\n")
i=0
for h in range(0, height):
for w in range(0, width):
color = img[h,w]
#print(color)
#print(w)
blue=color[0]
green=color[1]
red=color[2]
blue=blue & 0xFF
green=green & 0xFF
red=red & 0xFF
"""
blue=np.uint8(blue)
green=np.unit8(green)
red=np.unit8(red)
"""
#print(bin(blue))
auxchar='1'
total_color=red+green+blue
if(total_color> blacklimit):
#print('above_black_limit')
auxchar='0'
aux_binary_char[index]=auxchar
index=index+1
if(index==8 or w==(width-1)):
if "".join(aux_binary_char) !="00000000":
print(i)
sb.append(four_byte_binary("".join(aux_binary_char)))
i=i+1
aux_binary_char=['0', '0', '0', '0', '0', '0', '0', '0']
index=0
#print(h)
sb.append("\n")
#print(sb)
print(blacklimit)
return ''.join(sb)
def encode_hex_ascii(code):
global width_byte
global mapCode
max_linea=width_byte*2
sb_code=[]
sb_linea=[]
previous_line=1
counter=1
aux = code[0]
first_char=False
for i in range(1, len(code)):
if(first_char):
aux=code[i]
first_char=False
continue
if(code[i]=="\n"):
if(counter>= max_linea and aux=='0'):
sb_linea.append(",")
elif(counter>= max_linea and aux=='F'):
sb_linea.append("!")
elif(counter>20):
multi20=int((counter/20))*20
resto20=counter%20
sb_linea.append(mapCode[multi20])
if(resto20!=0):
sb_linea.append(mapCode[resto20] +aux)
else:
sb_linea.append(aux)
else:
sb_linea.append(mapCode[counter] +aux)
counter=1
first_char=True
if(''.join(sb_linea)==previous_line):
sb_code.append(":")
else:
sb_code.append(''.join(sb_linea))
previous_line=''.join(sb_linea)
sb_linea=[]
continue
if aux==code[i]:
counter=counter+1
else:
if counter>20:
multi20=int((counter/20))*20
resto20=counter%20
sb_linea.append(mapCode[multi20])
if resto20!=0:
sb_linea.append(mapCode[resto20] + aux)
else:
sb_linea.append(aux)
else:
sb_linea.append(mapCode[counter] + aux)
counter=1
aux=code[i]
return ''.join(sb_code)
def head_doc():
global total
global width_byte
return "^XA " + "^FO0,0^GFA,"+ str(int(total)) + ","+ str(int(total)) + "," + str(int(width_byte)) +", "
def foot_doc():
return "^FS"+ "^XZ"
def process(img):
global compress
init_map_code()
cuerpo=createBody(img)
print("CUERPO\n")
print(cuerpo)
print("\n")
if compress:
cuerpo=encode_hex_ascii(cuerpo)
print("COMPRESS\n")
print(cuerpo)
print("\n")
return head_doc() + cuerpo + foot_doc()
img = cv2.imread("C:\\Users\\ftheeten\\Pictures\\out.jpg", cv2.IMREAD_COLOR )
compress=True
blacklimit ==int(50* 768/100)
test=process(img)
file=open(LOCAL_PATH, 'w')
file.write(test)
file.close()

Expand passed arguments before printing with puts to virtual server

I am having trouble with an expect script not evaluating arguments. Everything in the puts ${file_id} block (simplified obviously) gets placed onto a virtual machine and is later used to for configuration. The block you see puts the same code into a local directory for me to see if things are working properly.
global env
set env(os1) [lindex $argv 0]
set env(scratch_repo) /tmp/yum.repo_[pid]
set file_id [ open ${env(scratch_repo)} "w"]
puts ${file_id} {
root_image=node-${env(os1)}
if {[string first r ${env(os1)}] == 0} {
create_node_byid 1 [string range ${env(os1)} 0 4]-64
} else {
create_node_byid 1 [string range ${env(os1)} 0 5]-64
}
}
Unfortunately, the log file looks exactly as above. The arguments are not being substituted properly and I can't figure out why. I've tried using regular variables, different syntax for referencing local and global variables but have had no luck getting this to work. Any thoughts?
As Etan Reisner pointed use double quotes in the puts command instead of braces, so that it will get replaced.
puts ${file_id} "
root_image=node-${env(os1)}
if {[string first r ${env(os1)}] == 0} {
create_node_byid 1 [string range ${env(os1)} 0 4]-64
} else {
create_node_byid 1 [string range ${env(os1)} 0 5]-64
}
"
Assuming env(os1) as Ubuntu, will produce the following content in the file
root_image=node-Ubuntu
if {-1 == 0} {
create_node_byid 1 Ubunt-64
} else {
create_node_byid 1 Ubuntu-64
}
Note : This will only do variable substitutions not evaluation of code as such. i.e. if-else commands won't be evaluated.

Viewing enum names in vcs ucli

I am working in VCS UCLI (ie, the command line interface) and am having trouble getting VCS to display various state variables, of a typedef'd enum type, value as the name rather than the number. For example, I have some SystemVerilog like this:
typedef enum logic [1:0] {A, B, C} state_t;
state_t s;
...
Now in ucli, I want to see the value of s (say its in state A) so I type something like:
ucli% get s
0
ucli% get s -radix symbolic
0
ucli% show s -value
s 0
ucli% show s -value -radix symbolic
s 0
ucli% show s -value -type
s 0 { ENUM state_t { {A 0} {B 1} {C 2} } }
(Or something like that). I have read the ucli user guide, and it seems like symbolic radix, the only one I know of that might possibly be close, just uses the raw value from the enum, not the enum name. I have tried calling the .name() method for variable s using the call command in ucli (ucli% call {$display("%s", s.name())}), but it doesnt seem to be supported. I know VCS has the capacity to print the enum name, it certainly can in DVE, but I am having trouble coming up with ways to get to show me in the ucli.
Does anyone know how to get the ucli to print the enum name instead of the number when queried? Is enum-type radix somehow (user-defined like in DVE?), use some SystemVerilog system call to get the name, anything like that?
(Note, I understand I could just use the DVE, but I am trying to use the ucli to simply the interface for potential users, this is for educational purposes and I want to mask alot of the ucli interface (and VCS interface in general) to not overwhelm students and get some variables easily; Im turning the vcs ucli into a simple processor simulator)
++++++++++++ UPDATE ++++++++++++
I came up with a very hacky solution but I would really like a better approach. I quickly wrote my own wrapper for show (called eshow) whish ill replace any -value with the enum name if -radix enum is set:
#
# An extension of show to include "-radix enum"
#
# Borrowed from http://wiki.tcl.tk/17342
# Credit to Richard Suchenwirth (12-8-2006)
proc getopt {_argv name {_var ""} {default ""}} {
upvar 1 $_argv argv $_var var
set pos [lsearch -regexp $argv ^$name]
if {$pos>=0} {
set to $pos
if {$_var ne ""} {
set var [lindex $argv [incr to]]
}
set argv [lreplace $argv $pos $to]
return 1
} else {
if {[llength [info level 0]] == 5} {set var $default}
return 0
}
}
proc eshow {args} {
set argv $args
# If radix is not specified or value is not specified, then dont bother doing anything but regular show
if { 0 == [getopt argv -radix radix] } {
return [eval show $args]
}
if { 0 == [getopt argv -value] } {
return [eval show $args]
}
# If radix isnt enum, just pass off to regular show
if { 0 == [string equal -nocase $radix "enum"] } {
return [eval show $args]
}
# Now get the signal, its value and its type
set var [lindex [eval show $argv] 0]
set val [lindex [show $var -value] 1]
set typ [lindex [show $var -type] 1]
# If the type isnt an enum, error
if { 0 == [string equal -nocase [lindex $typ 0] "ENUM"] } {
return "The type of variable $var is not an enumerated type"
}
# Process the enumerations
set enuml [lindex $typ 2]
# Find the value name
foreach v $enuml {
if { $val == [lindex $v 1] } {
set enumname [lindex $v 0]
break
}
}
# If could not be found....
if { 0 == [info exists enumname] } {
return "The variabel $var has a value which does not map"
}
# Get rid of radix from args
getopt args -radix trashcan
# Replace all values with the name
set retval [eval show $args]
set retshow $retval
foreach v [lsearch -all $retval $val] {
set retshow [lreplace $retshow $v $v $enumname]
}
return $retshow
}
Thus, if I type any other non-radix enum eshow commands, it will pass to show, but otherwise, it will replace all values with thier names and return the same thing show would with the replacement. As I said, I REALLY want a better solution, but in case anyone wants to use my function, here it is.

Resources