Forum › Forums › New users › New Users and General Questions › So many things about writing programs that were simple just got easier
- This topic has 11 replies, 4 voices, and was last updated May 11-12:01 am by BobC.
-
AuthorPosts
-
May 7, 2023 at 4:05 pm #106185Moderator
BobC
Seriously…
chatgpt
I’m not saying its smart or dumb, but it can be used as a programming reference, mentor, and fast keypuncher if you are able to write what you want in terms it will interpret correctly, and able to tweak the snippets of code it provides.
- This topic was modified 2 days, 2 hours ago by Brian Masinick.
May 7, 2023 at 6:40 pm #106201MemberRobin
::Be carefully with this. The generated code might fail horribly, or contain unnoticed (maybe hard to reveal) issues. To find them might be more difficult and time consuming than writing the code on your own 🙂
Be aware, ChatGPT is not able to deal with simple logical problems properly:(you can use Felipe PS traduzir-paginas-web for translating the text to your language)
All solutions ChatGPT presented were horribly illogical, even when making it aware of its errors multiple times.
Not the very best idea to let create it pieces of code to use…Windows is like a submarine. Open a window and serious problems will start.
May 7, 2023 at 6:52 pm #106207Member
Wallon
May 7, 2023 at 8:57 pm #106224ModeratorBobC
::LOL, *MY* code could fail horribly, and after many hours of effort! ChatGPT offered a solution within minutes.
I’m not expecting perfection, just possibilities…
The idea is to get snippets that might get me closer than searching myself.
May 7, 2023 at 9:24 pm #106227MemberRobin
::Bob, at least your code isn’t illogical at all. You have proven this already perfectly while working on antiXscreenshot2 ! Have you read what ChatGPT suggested as solutions to the simple logical question somebody has posed to it? I perfectly know you would never come forth with proposals for code like that…
ChatGPT will also translate all the texts in Transifex
This might work, since the ChatGPT is pretty good in forming grammatically proper sentences (at least in English language and some few other languages). Whether the content covers actually what you’d expect, this is another question. It is proven ChatGPT sometimes answers pure nonsense (or even worse: changing subtly the meaning, so it is hard to discover), disguised in a really convincing way of presentation in perfectly fine sentences.
Windows is like a submarine. Open a window and serious problems will start.
May 8, 2023 at 3:40 am #106241ModeratorBobC
::Ok Robin, you were right. The code it wrote was absolutely worthless.
It is always good to at least try new things. It doesn’t always work out, but sometimes, every once in a while, there can be pleasant surprises.
May 8, 2023 at 2:49 pm #106283Member
iznit
::ChatGPT, I have not attempted to use it for generating code. A few weeks ago I read comments in a slashdot.org discussion recommending that if you do use it to generate code, you should followup by pasting its proposed code back into chatbox and ask it to check this code for any bugs and or vulnerabilities. Supposedly this followup often results in further optimized code.
Hold on, maybe what I had read was in regard to “copilot” ((( github code generator ))) not vanilla ChatGPT.
May 9, 2023 at 1:40 pm #106321ModeratorBobC
::Ok, let’s see if anyone here is SMARTER THAN ChatGPT?
My program uses gdkdialog in a bash script.
I have a list of recent search strings in a text file named recent-searches.txt with one search string per line.
I want the screen to show “icewm manual” as the default in my search string comboboxentry. In my real program the default will be the first line of selected text on the screen, but lets just set SEARCHSTR=”icewm manual” for now to keep it simple.
I want my recent-searches.txt file lines selectable from the pulldown.
After I edit or change or select my search string and click the button to search I want the revised list saved in my recent-searches.txt file.
The name of my search string default field is SEARCHSTR.
What should the comboboxentry look like?
- This reply was modified 2 days, 7 hours ago by BobC.
- This reply was modified 2 days, 7 hours ago by BobC.
May 9, 2023 at 8:01 pm #106345MemberRobin
::Hello Bob,
you can use the comboboxentry widget in gtkdialog, just as we did together in multiple positions in antiXscreenshot2 already.Usage example (taken from antiXscreenshot2, lines 1054-1070):
<comboboxentry space-expand="false" space-fill="false" width-request="100" visible="'$THUMB'"> <variable>THUMB_EXT</variable> <default>'$THUMB_EXT'</default> <item>bmp</item> <item>gif</item> <item>jpg</item> <item>jp2</item> <item>lbm</item> <item>pam</item> <item>pcx</item> <item>png</item> <item>ppm</item> <item>tga</item> <item>tif</item> <item>webp</item> <item>xpm</item> </comboboxentry>Instead of <item>data</item> just use <input file>filename</input>, and use your bash string variable $SEARCHSTR as the default. The tag <output file>filename</output> should store the selected or entered search string within the file, but you may also take it from the shell output after the dialog was closed, it should appear in a string starting with the variable name used in the <variable>…</variable> tag, you can grep for it.
For details and further tags, attributes etc allowed in the comboboxentry widget please see:
https://web.archive.org/web/20160911043831/http://01micko.com/reference/comboboxentry.htmlDerived from this something like the following should do the trick:
Dialog=' ... <comboboxentry> <variable>SEARCHFOR</variable> <default>'$SEARCHSTR'</default> <input file>recent-searches.txt</input> <output file>searchfor.txt</output> </comboboxentry> ...'Keep in mind gtkdialog uses another shell (sh or dash) internally, but you are probably running the thing on bash. So you need to follow both syntax limitations when trying to add commands within the tags. Moreover the gtkdialog has its additional limitations for strings allowed within its tag patterns. All this goes in particular for the style of quoting, the usage of special characters and blanks, reserved characters, escaping of characters and piping of commands.
For adding the new search string to your existing searchstrings file you can use the file concatenation later on in your script, back from dialog execution on bash script level again:
echo "$(cat searchfor.txt recent-searches.txt)" > recent-searches.txtYou may want to exclude duplicate entries by e.g. using sort -u additionally.
Instead of processing all the aftermath in the bash script after dialog exit, gtkdialog provides the means to do this within the dialog already, so you can handle input errors without closing the dialog first. To achieve this make use of the action tags available within the combobox widget or also within the button widget. See https://web.archive.org/web/20160911043831/http://01micko.com/reference/button.html for details of the latter. But be warned, due to the three levels of shells you are coping with simultaneously (bash, dash and gtkdialog tag syntax), it might be really tricky to get it working. Best is to test the intended commands in a dash shell first (start sh in a console window); next, check what needs to be masked from bash, since the code needs to live in your bash script in the end. And finally find a way to mask any angle brackets > and < as well as quoting from gtkdialog, since it will break the respective tag line.
And no, I’m not going to compete ChatGPT; my hints are not readymade code working already; you’ll still have to experiment with this on your own to make it work in the end 🙂
But if any questions, just ask, I’ll help if I can.Kind regards
RobinWindows is like a submarine. Open a window and serious problems will start.
May 9, 2023 at 11:13 pm #106354ModeratorBobC
::Thanks for the very helpful reply. I had been hunting everywhere for a complete reference, so that link is greatly appreciated. I have most of the code right, but it might be that I am not creating a different file for output and didn’t know about the action.
Hopefully I will be able to get it working with a few more tries. I spent way too much time on it already.
May 10, 2023 at 4:17 pm #106446MemberRobin
::@bobc
You can use „functions” (enable, disable, show, hide…) within action tags for communication between the widgets. E.g. making a button widget store the recent content of the comboboxentry widget named SEARCHFOR by the <variable> tag into the file set by the <output file> tag present in the comboboxentry widget, just add the following tag to the button widget:<button> ... <action>if true save:SEARCHFOR</action> ... </button>You can study this method of communication across widgets within a gtkdialog script by reading the action tags present in antiXscreenshot2.
This way you can even execute shell commands directly by the action (or input) tags without any need of closing the dialog first to run the code on the bash level of your script. See line 534 and 1189 (<input> tags) in antiXscreenshot2 as examples. These lines are actually simple shell scripts, running on a separate dash/sh shell provided by gtkdialog internally. But as said already, making it work is pretty difficult due to the three levels of shells and their syntaxes mentioned you have to satisfy. Moreover the content of variables used in these internal shells is not consistent from one tag line to another: gtkdialog creates a fresh shell environment for each tag line, so you’ll need to use temp files as a workaround in case you actually need to transport a value from one tag line to another. But this workaround might fail, in case the file system writes the temp file not before another tag line tries to read from it already.
Windows is like a submarine. Open a window and serious problems will start.
May 11, 2023 at 12:01 am #106471ModeratorBobC
::tricky, Tricky, TRICKY!
My guess is that took 200 or 300 tries to get working.
Robin, thanks much for your suggestions. The most important ones were the link to the reference which is no longer on the web, and the magic feather. It is not perfect, but I think its pretty decent.
https://www.antixforum.com/forums/topic/antixforum-search-textbox/#post-106466
-
AuthorPosts
- You must be logged in to reply to this topic.