Try to use ContextAmbient.current.resources.updateConfiguration but it doesn't reflect the changes. Also, tried the re-assign context using createConfigurationContext.
val context = ContextAmbient.current
val config = context.resources.configuration
val locale = Locale("en")
config.setLocale(locale)
context = context.createConfigurationContext(config)
Related
This is from a TextField composable
When to use "Default Copy"? Does it matter?
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Text
)
// vs //
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Text
)
if you want to keep same instance and want to update one of the properties and preserve other ones you can use .copy().
Consider this example with a data class Person
data class Person(
val name: String = "",
val age: Int = 1
)
and some use-case like this
val johnPerson = Person("John", 21)
val unknownPerson = Person(age = 23)
I can simply copy unknownPerson and keep the age 23 and finally set the person's name like this
val knownPerson = unknownPerson.copy(name = "Mr. Kebab")
prints
Person(name=Mr. Kebab, age=23)
It does not matter. They both end up doing the same thing. KeyboardOptions class is not a data class, and even if it were, the copy() method would still create a new instance.
I'm trying to load all these images at once. Their all in the same directory so is there a way to load them all at once without being this repetitive?
bg = pygame.image.load('Desktop/Files/Dungeon Minigame/background.png')
f_zombie = pygame.image.load('Desktop/Files/Dungeon Minigame/f_zombie.png')
f_knight = pygame.image.load('Desktop/Files/Dungeon Minigame/f_knight.png')
b_knight = pygame.image.load('Desktop/Files/Dungeon Minigame/b_knight.png')
r_knight = pygame.image.load('Desktop/Files/Dungeon Minigame/r_knight.png')
heart = pygame.image.load('Desktop/Files/Dungeon Minigame/heart.png')
empty_heart = pygame.image.load('Desktop/Files/Dungeon Minigame/empty_heart.png')
Get a list of all the files in the directory (see os) and create a dictionary with the loaded files:
import os
path = 'Desktop/Files/Dungeon Minigame/'
filenames = [f for f in os.listdir(path) if f.endswith('.png')]
images = {}
for name in filenames:
imagename = os.path.splitext(name)[0]
images[imagename] = pygame.image.load(os.path.join(path, name)).convert_alpha()
You can access the images in the dictionary by its name:
screen.blit(images['background'], (0, 0))
Alternatively you can add variables to global namespace, using globals():
path = 'Desktop/Files/Dungeon Minigame/'
filenames = [f for f in os.listdir(path) if f.endswith('.png')]
for name in filenames:
imagename = os.path.splitext(name)[0]
globals()[imagename] = pygame.image.load(os.path.join(path, name)).convert_alpha()
screen.blit(background, (0, 0))
I'm attempting to build a ROM-based Window function using DSPComplex and FixedPoint types, but seem to keep running into the following error:
chisel3.core.Binding$ExpectedHardwareException: vec element 'dsptools.numbers.DspComplex#32' must be hardware, not a bare Chisel type
The source code for my attempt at this looks like the following:
class TaylorWindow(len: Int, window: Seq[FixedPoint]) extends Module {
val io = IO(new Bundle {
val d_valid_in = Input(Bool())
val sample = Input(DspComplex(FixedPoint(16.W, 8.BP), FixedPoint(16.W, 8.BP)))
val windowed_sample = Output(DspComplex(FixedPoint(24.W, 8.BP), FixedPoint(24.W, 8.BP)))
val d_valid_out = Output(Bool())
})
val win_coeff = Vec(window.map(x=>DspComplex(x, FixedPoint(0, 16.W, 8.BP))).toSeq) // ROM storing our coefficients.
io.d_valid_out := io.d_valid_in
val counter = Reg(UInt(10.W))
// Implicit reset
io.windowed_sample:= io.sample * win_coeff(counter)
when(io.d_valid_in) {
counter := counter + 1.U
}
}
println(getVerilog(new TaylorWindow(1024, fp_seq)))
I'm actually reading the coefficients in from a file (this particular window has a complex generation function that I'm doing in Python elsewhere) with the following sequence of steps
val filename = "../generated/taylor_coeffs"
val coeff_file = Source.fromFile(filename).getLines
val double_coeffs = coeff_file.map(x => x.toDouble)
val fp_coeffs = double_coeffs.map(x => FixedPoint.fromDouble(x, 16.W, 8.BP))
val fp_seq = fp_coeffs.toSeq
Does this mean the DSPComplex type isn't able to be translated to Verilog?
Commenting out the win_coeff line seems to make the whole thing generate (but clearly doesn't do what I want it to do)
I think you should try using
val win_coeff = VecInit(window.map(x=>DspComplex.wire(x, FixedPoint.fromDouble(0.0, 16.W, 8.BP))).toSeq) // ROM storing our coefficients.
which will create hardware values like you want. The Vec just creates a Vec of the type specfied
Now if I have .env file like
USE_DOCKER=yes
POSTGRES_DB=kbackend
USER=root
DB_URL=$USER:$POSTGRES_DB
when I use env('DB_URL') it returns to me $USER:$POSTGRES_DB
I want to return root:kbackend
I use django-environ
My original incorrect answer:
DB_URL=${USER}:${POSTGRES_DB}
Updated answer: Currently, django-environ does not support this. The relevant code:
logger.debug('Read environment variables from: {0}'.format(env_file))
for line in content.splitlines():
m1 = re.match(r'\A([A-Za-z_0-9]+)=(.*)\Z', line)
if m1:
key, val = m1.group(1), m1.group(2)
m2 = re.match(r"\A'(.*)'\Z", val)
if m2:
val = m2.group(1)
m3 = re.match(r'\A"(.*)"\Z', val)
if m3:
val = re.sub(r'\\(.)', r'\1', m3.group(1))
cls.ENVIRON.setdefault(key, str(val))
For example:
Config.groovy:
// ...
grails.variable1 = "a"
grails.varibale2 = "${grails.variable1}bc"
//...
UPDATE 1
Way shown above works with grails 2.2.3. For older versions of grails please use solution #tim_yates suggested
You need to declare a variable:
def rootVar = 'a'
grails.variable1 = rootVar
grails.varibale2 = "${rootVar}bc"
Or you might be able to do it via a closure (not tested):
grails.variable1 = 'a'
grails.varibale2 = { -> "${grails.variable1}bc" }()