Text with multiple colors in PsychoPy - python

I am messing around in PsychoPy now, trying to modify the Sternberg demo for a class project. I want the stimulus text—the number set—to display in a variety of colors: say, one digit is red, the next blue, the next brown, etc. A variety within the same stimulus.
I can only find how to change the color of the entire set. I was wondering if I could add another variable to the spreadsheet accompanying the experiment and have the values in the cells be comma separated (red,blue,brown…). Is this possible?

No, that isn't possible right now. There's an experimental new stimulus class called TextBox that will allow it, but you'd have to write code to use that (not available yet from the Builder interface). Or just create some tif images of your stimuli and use those?

The current way to implement this is to have a separate text stimulus for each digit, each with the desired colour.
If the text representation of the number is contained in a variable called, say, stimulusText then in the Text field for the first text component put "$stimulusText[0]" so that it contains just the first digit. In the next text component , use "$stimulusText[1]", and so on.
The colour of each text component can be either fixed or vary according to separate column variables specified in a conditions file.

Related

QTableView - how to highlight only text with color (not entire cell)

I would like to for some of the columns in my QTableView give color highlight to the text without filling the rest of the cell with color. This image shows exactly what I want:
What is the best way to do this? One option is to create each text value as an image externally and then set it as an icon (I know how to do that from other SO posts). But is there a better way?
I will do this for quite many tables / columns with many different values so I would need to create many images if I use icons. So it would be great if there is a way to instead write the text in the QTableView and somehow apply the color background so that it covers the text only.
Is it possible to e.g. paint that background using an item delegate somehow? Has someone done something similar with item delegates before and that can share an example of how it's done? I'm very new to Qt.
I'm using PyQt6.

pptx-python: find table height dynamically after adding text

I want to find the height of the table dynamically, so that whenever the table's height reaches a specific number, I can create another slide and split the table. Because number of text in cell varies, the height will be different for each time the code is run.
Is it possible to do it in pptx-python?
No. "Stretched" table cell heights and the resulting overall table height turns out to be a rendering concern and those values are not recorded in the .pptx file.
A row or cell can have a minimum height that is set in the file, but once the cell gets more text than it can display it will automatically grow beyond that minimum and the PowerPoint renderer is the one to do that. It does not record the value it ends up with.
One way to approximate the rendered dimensions of a table cell is to render the the text yourself in some sort of graphical environment and see how big it gets. That value will depend on the font type-face and point-size, so you'll need to know those. Any way you go about it will be approximate; there are a lot of small complicating factors and even one renderer like OpenOffice might not always render exactly like another, say PowerPoint or Google Docs. For example, there may also be column width adjustment rules that PowerPoint uses to help accommodate a heavily populated cell, not just making the cell taller.
I've heard of at least one developer having reasonable results using wxPython as a rendering environment in which to approximate PowerPoint's rendering behavior, but I believe that was for a single textbox. Doing the same for a table is potentially much more complex.
Another route might be to use VBA to drive an actually running instance of PowerPoint. That may give access to the rendered size of the table.

How to change image position and text wrapping using python-docx?

After adding the image using add_method(), I want to change the image position and text wrapping properties.
I want to change the text-wrapping: in front of text
I want to change the properties as
horizontal
alignment : right , relative to : margin
vertical
absolute position: 2.15 cm , below: Page
This is how I change it manually in word, but I want to do it using python-docx
Is there any way to get it done?
The short answer is "No."
There are two ways images can be placed in Word, inline images and floating images.
An inline image is placed in a run and is essentially treated as a big character. The height of the line it appears on is adjusted upward to fit the image and the paragraph it is in flows between pages depending on the text before it, just like any other paragraph.
A floating image lies on the drawing layer, like a clear plastic sheet above the document layer where the text lives. It is given an absolute position and in general does not flow with the text (although it can be anchored to part of the text). Text can be set to wrap around the image, wherever it ends up on the page.
python-docx currently only supports inline images. There is no existing API support for floating images (and the text wrapping they allow).

How to show 2 scene side by side in asciimatics

I'm try to use asciimatics for a TUI, which will be the front end for a test frame work. The TUI should have some parameters that are constant and are common for all tests, and another section where there are parameters based on the selected test.
I'm pretty sure I can get this to work if I create a main frame for the common parameters, and frames for each individual test, then, based on the selected test open the specific test frame when the user clicks a button to edit test parameters.
However, I would much rather have the test parameters shown along side the common ones. I was thinking about putting the second frame inside a layout, and swapping it on the fly when the selected test is changed. Is this possible to do with asciimatics?
Thanks,
o
As documented in https://asciimatics.readthedocs.io/en/stable/widgets.html#layouts-in-more-detail, a Layout belongs inside a Frame. You can't put a Frame in side a Layout.
However, there is no reason you can't just use two Frames next to each other. Simply create them with the right size and locations to be side by side.

Alternate row coloring in Scintilla

I'm using wxStyledTextCtrl from wxPython, a wrapper around the Scintilla component.
Is there any way to get alternate row coloring on it (odd rows in one background color and even rows in another color)?
I'm using the builtin python styler to highlight keywords.
The background of lines can be changed, for example by markers (which is used for stuff like bookmarks or breakpoints, current execution point and the like in IDEs), but there is no built-in mode for changing the background colour of every other line.
You could simulate this by setting a special marker with a background colour for all odd or even line numbers (MarkerSetBackground() and MarkerAdd()). This would probably consume a lot of cycles, and each editing operation that splits or joins, inserts or deletes lines would need the markers to be reset. Still, it may be worth looking into, given that there seems to be no other way.

Categories

Resources