AppInventor Extension block with predefined value - app-inventor

I'm trying to create an extension with pre-defined value (for example string or int), which would be “sticked” to function in block menu, something like in picture bellow.
I have no idea how to write it in Java, or whether it is even possible.
Image
You can see that string is connected to main block in block menu.

Related

Python gui table whose cells are drop down lists with dynamic content based on the content of other drop-down-list-cells of the same gui-table

I am trying to port to Python 3.x a small gui application that I have written in Matlab.
The app contains a Matlab uitable, with which you can program bitfields of registers of a microcontroller. Actually you can create a panel which groups some register-bitfields that are important to you for debugging at a specific point in time (kind-of a watch window in a compiler IDE).
It looks like this:
Gui Table used to write to register bitfields of a microcontroller
So, each row of the table can be used to program a specific register bitfield.
There are 4 columns:
1. Register name (drop down list)
2. Bitfield name (drop down list)
3. Value to write (string)
4. Format (Hex or Dec drop down list, irrelevant here)
In order to use this application, one first clicks on the register name drop down list, where all registers are shown (detail: using a text box one can apply filters to narrow down the list size).
When the register is selected, the drop down list of the bitfield column updates automatically so that it contains only the bitfields of the chosen register. This happens with the help of a callback function.
Then, the user has to enter a value and a format, and only if all cells contain valid content, then a register write command is issued (via some debugger interface).
This worked OKish; sometimes the bitfields list was actually the one of the previous register added in the table, but this could be detected and have the entry cleared so that the user can try again. Also when the number of rows becomes very high and scroll bars appear, then if the user tries to enter a register at the bottom, every time they click on the drop down list, they can choose an entry and then the scroll bar position will automatically change showing the beginning of the table. This makes the process of entering registers quite cumbersome. As far as I know, the uitable of Matlab did not have accessible properties to control this behavior.
Since I am a hw engineer with limited sw technologies knowledge, I am wondering if there is a natural way to support this in Python 3.x, say with some structured (e.g. xml) data container that can naturally map to a gui component, without so much callback programming and data validation. The ideal behavior would be that the user starts to type directly at the register name drop down list (not possible in Matlab), and dynamically gets a filtered version of the register names list.
I am completely new to python, just installed Anaconda. I have found some interesting classes in PyQt:
QListView Class,
QListWidget Class,
QTableView Class,
QTableWidget Class.
However, I would like to have the combined functionality of the tableview with a listview, as is the case with the uitable in Matlab. Or even better, a text edit input that turns into a drop down list after typing a few letters.
The pyqtgraph.tablewidget seems to augment the functionality of QTableWidget, but I think this is still not what I need.
So, if the above is not possible, or would involve heavy programming, maybe all I need is to change approach and have a single separate search box with autocompletion, which looks into a "flattened" version of the registers database, and returns results in the form my_register_1.my_bitfield_1 (maybe allowing the user to search simultaneously at both register and bitfield names). When the user clicks on one item of the "autocompletion list", then the selected entry is mapped to the currently selected line in the tableview, adding both the register name and bitfield in read-only table cells. The "value to write" cell should still be editable, and when it gets valid data it should trigger register write command...
I would appreciate if you could guide me where to look. Thanks!
You should use the Qt model/view architecture. This allows you to have a representation of your data (the "model"), which is separate from how that data is represented (the "view"). So you set up a table of data, and then set up a view to represent that data. When you switch between different data sets, you tell the view to display the new data set. The tutorial I linked to explains this in some detail

Search for an NSView inside a NIB by string

I'm trying to write an application which should display some data. The data in question comes from a different module in our code (written in C, not ObjC), and for various reasons is identified by a string, not an integer or other form of constant. After the glue code, I have an incoming method on my AppDelegate like so:
-(void)newstringdata:(NSString*)data withLabel:(NSString*)label;
This method should always take the value of data and set it as the text for a particular label in the UI. The problem is, which label.
I could of course create an NSDictionary and fill it at run time with the possible values for the label parameter in the newstringdata:withLabel: method and references to outlets, but this seems somewhat ugly and inefficient; it requires me to maintain the outlets, the nib, and the NSDictionary-initializing code.
Instead, if possible, I would like to set a property in the interface designer somewhere, and then do a lookup in my newstringdata:withLabel: method based on the label which was passed which returns the NSLabel.
Is this possible? If so, how would I do it?
If the value of label will never include a slash (/), backslash (\), or colon (:), you can use the identifier property of NSView.
In the xib, enter each label string as the NSTextViews's identifier (in the Identity tab, 3rd tab from left).
Then in your code, loop through all views and:
if ([aView.identifier isEqualToString:label])
[aView setStringValue:data];

Building a GUI in Netbeans, which should I use?

I am building a GUI in Netbeans - it is for a simple little application - a converter program. Basically, user types whatever it is they want to convert into a text field, selects the conversion from a number of radio buttons (say lbs to kg) and then clicks "Convert".
The thing is, I want the "Convert" button and the radio buttons to behave like this:
Radio buttons and "Convert" button are disabled when program loads.
Radio buttons and "Convert" button will become enabled if user types a number (and only a number) into the text field.
If used deletes what they have typed, everything will be disabled again until they type in another number.
I have managed to set the Radio buttons and "Convert" button up so they are disabled, by unchecking the "enabled" box in the properties for each component. I have also been able to use a simple if statement and the keyTyped event to enable/disable as follows:
private void txtUsrInputKeyTyped(java.awt.event.KeyEvent evt)
{
if (!txtUsrInput.getText().equals(""))
{
btnCalculate.setEnabled(true);
}
else
{
btnCalculate.setEnabled(false);
}
}
I want to extend my code so that if the user accidentally types a letter or symbol into the text field (don't ask me why they'd do that, when they know they must only type a number) then the program will either ignore what they typed, or display an error. The exception to this is, of course, typing a period (.) because they might want to indicate a decimal number.
Any thoughts on how I might do this? Hope what I wrote makes sense!
Your GUI
If you do not already know swing, then learn it. Knowing how all of the components work is always a huge advantage for any developer, and if anything goes wrong, you know exactly how to fix it (or at least have a much better chance). Take a look at this stuff, for some help on getting started.
Checking for a decimal
This looks like a job for regular expressions. What you can do is specify a number [0-9], and a period, \.. Then ensure that either a number or a decimal is typed a certain amount of times. The important thing to note here though, is that the user can only type one decimal, which winds up being:
([0-9]+(\.[0-9]+))
This will allow values like 9, 0.9, 1.9302. It will not allow values like .901. If you wish to allow that, simple swap the first + for a *.:
([0-9]*(\.[0-9]+))
Using it
Because a text box contains a string, you can compare it with your regex. Simply:
if(textBox1.getText().matches("([0-9]+(\.[0-9]+))")) {
// Run some code in here.
}
Well, if GUI is simple, DO NOT use GUI Builder, but code from scratch. Following harder path, you will learn about layouts, actionlisteners and so on ...

How to display information taken from text area in netbeans (for a GUI)?

I have taken information from a text area (on a JFrame) and saved it as a variable, but now I would like to display the string thats stored in that variable in a different JFrame (which already have created). how do i go about doing this?
Example:
one frame says: enter your name (store this value in a variable)
click proceed
closes first frame
second frame is open now and I want to display the name of the player (variable) in the top corner of the JFrame.
Any ideas on what to use from the swing palette?
Save the value in a static variable so that you can use it anywhere.

How to get touch pointer inside a specific Grid

I have a layout like the following:
grid-1
grid-2
grid-3
...
one nested inside of another.
Within Grid-3, there are 10x10 matrix of images. What I'd like to know is how do I know a touch is within grid-3 and which image is touched? I read the example from eBook and code:
primaryTouchPoint.TouchDevice.DirectlyOver == txtblk
I tries to use it with my grid-3 name, the touch pointer only at the very top line of grid-3. And I don't want to write 100 line of if-else statement for each image. And also when I use
grid-3.Width, actualWidth, these method all return 0. How do I know the size of this grid-3 on screen?
-Henry
One way would be to wrap each image inside a control that has a click event, like a button. Point all the click event handlers to a single method and grab the child image from this.

Resources