Can't reset TextArea length - textarea

I print socket output to textArea (it's in Service object), but after a while, my textArea gets filled and gives me exceptions, so I tried resetting it with textArea.setText(""); but textArea.getLength() doesn't reset to 0. Here's my code:
if(textArea.getLength() > 1000)
textArea.setText(""); // problem!
command = in.getText(); //command to sent to socket
out.println(command);
textField.setText(""); // just resetting textField (works)
Thanks!

Related

In TCL/TK Remove binding after widget destruction

I have a canvas located in a Sub window of my main application:
.dsm.nb.mdlbuild.canvas
additionally I have the following (one of several) proc helping me letting the user move stuff around on the canvas:
proc grab { xx yy } {
global currentx currenty
set currentx $xx
set currenty $yy
}
I use this binding:
.dsm.nb.mdlbuild.canvas bind $tagtomove <Button-1> {grab %x %y }
PROBLEM:
When the user closes the window (.dsm) the canvas gets distroyed to, but the binding seems to 'survive'.
When the user then subsequentually clicks somwhere he gets the error:
wrong args: should be "grab xx yy"
This because xx and yy is empty i suppose because the canvas is gone together with the parrent window...
I have tried to set the binding to nothing after the .dsm window is destroyed:
.dsm.nb.mdlbuild.canvas bind $tagtomove <Button-1> { }
and to use the "break" command, but with no success.
.dsm.nb.mdlbuild.canvas bind $tagtomove <Button-1> break
How can i remove the binding uppon closing the window (.dsm) in which the canvas is located so that this error does dissapear?
The problem is most likely that you used the name of a standard Tk command for your proc. The grab command is called from different places in the Tk library, but not always matching the number of arguments of your proc. This would cause the error. You can check this by dumping the value of $errorInfo after you received the error message.
So, just rename your proc to something other than grab (or any other built-in command).

Error Message Not Displayed Properly and Wrong Input gets selected

I am using jquery select2 method for multiple selections and for users to enter their own input it uses tags property.
Now I want to display the error message when a user enters wrong input.
Therefore, I am using formatResult property of select2 and checking regex for input.
When the input is correct; it returns the input else it returns error message from the function.
But this message is not coming in the format as it comes for select2 example "No matches found" and even when the error message is displayed, on clicking enter it takes the wrong input.
I want to display the message in correct format and not to select the wrong input on enter.
Please help. Below is my code:
$("#abc").select2({
minimumInputLength:1,
maximumInputLength:10,
formatResult: function(term){
if(term.text === 0)
return "Zero Not Allowed";
else return term.text;
}});
In this code, "zero not allowed" is not coming in the same format as "Please enter 1 or more characters" and when we press enter, zero gets selected.

PHP variable reverts back to last assigned after intensive curl operation

I'm querying one api and sending data to another. I'm also querying a mysql database. And doing all this about 40 times in one second. Then waiting a minute and repeating. I have a feeling I'm at the limit of what PHP can do.
My question is about two variables that will randomly revert back to their last value, from the previous loop. They only change their value after the call to self::apiCall() (below in the second function). Both $product and $productId will randomly change their value, about once every 40 loops or so.
I boosted PHP to 7.2, increased memory to 512, and assigned some variables to null to save memory. I'm not getting any official memory warnings, but watching the variables randomly go back to their last value is perplexing. Here's what the code looks like.
/**
* The initial create products loop which calls the secondary function where
* the variables can change.
**/
public static function createProducts() {
// Create connection
$conn = new mysqli(SERVERNAME, USERNAME, PASSWORD, DBNAME, PORT);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// This will go through each row and echo the id column
$productResults = mysqli_query($conn, "SELECT * FROM product_creation_queue");
if(mysqli_num_rows($productResults) > 0) {
$rowIndex = 0;
while($row = mysqli_fetch_assoc($productResults)){
self::createProduct($conn, $product);
}
}
}
/**
* The second function where I see both $product and $productId changing
* from time to time, which completely breaks the code. Their values
* only change after the call to self::createProduct() which is simply a
* curl function to hit an api endpoint.
**/
public static function createProduct($mysqlConnection, $product) {
// convert back to array from json
$productArray = json_decode($product, TRUE);
// here the value of $productId is one thing
$productId = $productArray['product']['id'];
// here is the curl call
$addProduct = self::api_call(TOKEN, SHOP, ENDPOINT, $product, 'POST');
// and randomly here it can revert to it's last value in a previous loop
echo $productId;
}
The problem was that the entire 40-query procedure took more than one minute to complete. And the cron job that started the procedure on the minute would start the next one before the first one had completed, thereby somehow re-assigning variables on the fly. The queries usually took less than one minute, but when it was longer, the conflicts appeared, thus leading to the appearance of randomness.
I reduced the number of queries per minute so now the process completes in less than 60 seconds and no variables are ever overwritten. I still don't understand how the variables would change if two php processes are happening at the same time--it seems like they would be siloed.

readByteSync - is this behavior correct?

stdin.readByteSync has recently been added to Dart.
Using stdin.readByteSync for data entry, I am attempting to allow a default value and if an entry is made by the operator, to clear the default value. If no entry is made and just enter is pressed, then the default is used.
What appears to be happening however is that no terminal output is sent to the terminal until a newline character is entered. Therefore when I do a print() or a stdout.write(), it is delayed until newline is entered.
Therefore, when operator enters first character to override default, the default is not cleared. IE. The default is "abc", data entered is "xx", however "xxc" is showing on screen after entry of "xx". The "problem" appears to be that no "writes" to the terminal are sent until newline is entered.
While I can find an alternative way of doing this, I would like to know if this is the way readByteSync should or must work. If so, I’ll find an alternative way of doing what I want.
// Example program //
import 'dart:io';
void main () {
int iInput;
List<int> lCharCodes = [];
print(""); print("");
String sDefault = "abc";
stdout.write ("Enter data : $sDefault\b\b\b");
while (iInput != 10) { // wait for newline
iInput = stdin.readByteSync();
if (iInput == 8 && lCharCodes.length > 0) { // bs
lCharCodes.removeLast();
} else if (iInput > 31) { // ascii printable char
lCharCodes.add(iInput);
if (lCharCodes.length == 1)
stdout.write (" \b\b\b\b chars cleared"); // clear line
print ("\nlCharCodes length = ${lCharCodes.length}");
}
}
print ("\nData entered = ${new String.fromCharCodes(lCharCodes).trim()}");
}
Results on Command screen are :
c:\Users\Brian\dart-dev1\test\bin>dart testsync001.dart
Enter data : xxc
chars cleared
lCharCodes length = 1
lCharCodes length = 2
Data entered = xx
c:\Users\Brian\dart-dev1\test\bin>
I recently added stdin.readByteSync and readLineSync, to easier create small scrips reading the stdin. However, two things are still missing, for this to be feature-complete.
1) Line mode vs Raw mode. This is basically what you are asking for, a way to get a char as soon as it's printed.
2) Echo on/off. This mode is useful for e.g. typing in passwords, so you can disable the default echo of the characters.
I hope to be able to implement and land these features rather soon.
You can star this bug to track the development of it!
This is common behavior for consoles. Try to flush the output with stdout.flush().
Edit: my mistake. I looked at a very old revision (dartlang-test). The current API does not provide any means to flush stdout. Feel free to file a bug.

Mysterious output from Lua after modifying a control

I am using Lua with wxLua to build a GUI. Normally when I exit the app, I get no output from Lua.
However I just added a function to a wxListView (called myListView) like this
myListView.foo = bar
function bar (self)
-- do something with the wxListView
end
Whether or not I ever called foo(), when I exit the app, I get the following output from Lua:
~wxLuaObject -2 1 0
If I comment out the assignment, I get no output when exiting the app. If instead, I nil out foo later on in the code:
myListView.foo = nil
I get the same output immediately when that line is executed and then again on program exit.
What does the output mean? What am I doing wrong? How do I fix it?
Thanks!
This seems to be an internal diagnostic for the case when wxLuaObject is destroyed and m_reference == LUA_NOREF (-2 as it is in your case) and Lua state object is not in closing state (0 as reported in your case):
// this is from modules/wxlua/src/wxlbind.cpp (starts on line 83 in my version)
wxLuaObject::~wxLuaObject()
{
if ((m_reference != LUA_NOREF) && m_wxlState->Ok() && !m_wxlState->IsClosing())
{
m_wxlState->wxluaR_Unref(m_reference, &wxlua_lreg_refs_key);
m_reference = LUA_NOREF;
}
//else if (!m_wxlState->IsClosing())
// wxPrintf(wxT("~wxLuaObject %d %d %d\n"), (int)m_reference, (int)m_wxlState->Ok(), (int)m_wxlState->IsClosing());
I have this message commented out in my wxlua code (2.8.12.1), but you may want to check your version and upgrade as needed. This is the only place where ~wxLuaObject message appears in the source code. It seems to be harmless, but it can potentially point to other issues with what you are doing.

Resources