How can I set the same parameters/options for multiple objects? - manim

I started to learn how to use manin and found the following problem.
Suppose that I want the text in my video with font="Calibri" and font_size=72.
Then I have to write the following code:
Text("Text 1",font="Calibri",font_size=72)
After that, if I want to use the same style of text again, I have to write again the parameters/options of the function Text():
Text("Text 2",font="Calibri",font_size=72)
So my question is, is it possible to define a variable with the parameters/options for Text() so I won't have to copy and paste them every time?
Something like this:
options={font="Calibri",font_size=72}
Text("Text 1",options)
Text("Text 2",options)
that would simply things.

I figured it out! I just have to def a function:
def font_1(text):
new_text=Text(text,font="Calibri",font_size=72)
return new_text
Then to writte "Text 1" and "Text 2" with the same formate I just use the code
font_1("Text 1")
font_1("Text 2")

Related

Index Out Of Range When Using .onDelete -SwiftUI

When executing the .onDelete function, I am getting an index out of range. I have successfully used onDelete elsewhere in my app, deleting data directly from core data. This version is to only delete from a list not stored in core data.
I created some temporary lists for testing, and using this .onDelete was successful. The successful test cases were with arrays that already had data in them and did not need to be initialized. The array used in the code below is one that is initialized when the user lands on this page - could this be why it is failing?
There is lots of code inside this struct, but the relevant parts are below:
#State var recipeStep: [String]
More code, eventually reaching the ForEach causing the problems
List {
ForEach(0..<recipeStep.count, id: \.self) { index in
HStack {
Text(String(stepNumber[index]) + ".").bold()
TextField("", text: $recipeStep[index]).multilineTextAlignment(.leading).padding(.leading)
}
}.onDelete { (indexSet) in
recipeStep.remove(atOffsets: indexSet)}
Any thoughts as to why I am getting an index out of range error?
You loop with recipeStep in
ForEach(0..<recipeStep.count, id: \.self) { index in
While you use both $recipeStep[index] and stepNumber[index]
So recipeStep and stepNumber should be of same size to avoid crashes or better union them in 1 model
I was able to get this to work by modifying my textfield to work the following way:
EditorView(container: self.$recipeStep, index: index, text: recipeStep[index])
The solution was found here, posted by Asperi: https://stackoverflow.com/a/58911168/12299030
I had to modify his solution a bit to fit my forEach, but overall it works perfectly!

modifing the function to capitalize every word of the given string and return the results

I think I get how to capitalize the string ('how do you do')by possibly using the caps method or title method. but how would I return it ? im confused by that.
would I do return('How Do You Do')[0].lower('How Do You Do') ?
im new to learning the stuff I watched didn't really help explain it to me
I suppose you are using Python. You just have to use .lower() to the string.
print('How Do You Do'.lower())
Result:
how do you do
Alternately, you can make them all caps using .upper()
text = "How Do You Do"
text.upper()
Result:
HOW DO YOU DO
And capitalize only the first letter of each word using .title()
text.title()
Result
How Do You Do
EDIT
def convert_to_title(text):
return text.title()
print(convert_to_title('how do you do?'))
Result:
How Do You Do?

iOS: Localise multi-line string literals

Since a recent swift version, multi line string literals are available that allow to format the appearance of a multi line string easily.
I'm looking for a way, though, to localise such a string.
Here is an example of the text of a pre-configured mail, that users can send:
mailComposerVC.setMessageBody("""
Hi,
I would like to share the following feedback:
""",
isHTML: false)
It seems there is no way to properly transform this into the localisable .strings file.
As a workaround, I came up with the solution to individually localise each part of the message and use interpolation:
let localisedGreeting = NSLocalizedString("Hi", comment: "")
let localisedMessage = NSLocalizedString("I would like to share the following feedback: ", comment: "")
mailComposerVC.setMessageBody("""
\(localisedGreeting),
\(localisedMessage)
""",
isHTML: false)
The .strings file looks like this:
"Hi" = "Hallo";
"I would like to share the following feedback: " = "ich möchte folgendes Feedback geben: ";
Is there a better/more concise way to do this?
Both keys and values in the Localizable.strings file can be multi-line.
With
"Hi,
I would like to share the following feedback:
" = "Hallo,
ich möchte folgendes Feedback geben:
";
the call
let localizedMessage = NSLocalizedString("""
Hi,
I would like to share the following feedback:
""", comment: "")
expands as intended.
This might however not work with localization tools, and also does not
display with the correct syntax coloring in the Localizable.strings, which
might be confusing.
I would use a short (single-line) key instead, and localize that for all
languages (including the default language english).
For me this layout of text and quotes worked (Swift 5.3, Xcode 12)
Localizable.strings
"First Line
Second Line" = "Erste Linie
Zweite Linie";
Implementation
let lines = NSLocalizedString("""
First Line
Second Line
""", comment: "")

kivy buttons don't work inside accordion?

When I bind a function to a button inside an accordion nothing happens upon clicking it. I have no idea what i'm doing wrong. :( Any thoughts?
def printTest():
print "The button worked!"
accord = Accordion(anim_duration=1.5, orientation='vertical')
specialButton = Button(text="click me", font_size='20sp', text_size=(1100, None), halign="center")
specialButton.bind(on_press=printTest():
item = AccordionItem(title="Hello World")
item.add_widget(specialButton)
accord.add_widget(item)
specialButton.bind(on_press=printTest():
This isn't valid syntax, is the colon a typo?
Either way, the problem is that you are calling printTest, not passing it as an argument.
Instead try
def printTest(*args):
print "The button worked!"
...and...
specialButton.bind(on_press=printTest)
The *args is important because the binding automatically passes some arguments.
I covered this in more detail here.

Nokogiri/Ruby array question

I have a quick question. I am currently writing a Nokogiri/Ruby script and have the following code:
fullId = doc.xpath("/success/data/annotatorResultBean/annotations/annotationBean/concept/fullId")
fullId.each do |e|
e = e.to_s()
g.write(e + "\n")
end
This spits out the following text:
<fullId>D001792</fullId>
<fullId>D001792</fullId>
<fullId>D001792</fullId>
<fullId>D008715</fullId>
I wanted the just the numbers text in between the "< fullid>" saved, without the < fullId>,< /fullId> markup. What am I missing?
Bobby
I think you want to use the text() accessor (which returns the child text values), rather than to_s() (which serializes the entire node, as you see here).
I'm not sure what the g object you're calling write on is, but the following code should give you an array containing all of the text in the fullId nodes:
doc.xpath(your_xpath).map {|e| e.text}

Resources