Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Comparison
Message
From
19/04/2023 08:25:21
 
 
To
18/04/2023 18:53:39
General information
Forum:
Python
Category:
Other
Title:
Miscellaneous
Thread ID:
01686457
Message ID:
01686481
Views:
59
Likes (1)
Guessing that the produced Python code was indented to Python rules to loop:
That might be a better way to port between different GUI kits than manual coding.
Might even offer translation between screen layers in different computer languages,
plus a well defined start point for transporting more demanding pieces of code,
if trained well.


>Dragan, something quite interesting I have seen lately... chatGPT in action
>https://chat.openai.com/
>It will remember a conversation and expand upon previous information. Here a couple of questions to turn a fox sample into python: (or other languages as needed)
>
>can you write some sample code in vfp to iterate through a temp table and display the resulting list in a modal form?
>Sure, here's some sample Visual FoxPro code that iterates through a temp table and displays the resulting list in a modal form:
>
>sql
>Copy code
>LOCAL lcTempTable, lnRecno, lcField1, lcField2, lcField3
>lcTempTable = "TempTable" && Replace with the name of your temp table
>IF USED(lcTempTable)
> USE IN (lcTempTable)
>ENDIF
>SELECT 0
>USE (lcTempTable) ALIAS lcTempTable
>
>* Open the modal form
>DO FORM MyForm WITH "Title", .T.
>
>* Loop through the records in the temp table and add them to the list
>lnRecno = 1
>SCAN
> lcField1 = lcTempTable.Field1
> lcField2 = lcTempTable.Field2
> lcField3 = lcTempTable.Field3
> MyForm.lstResults.AddItem(lnRecno + " " + lcField1 + " " + lcField2 + " " + lcField3)
> lnRecno = lnRecno + 1
>ENDSCAN
>
>* Close the temp table and release resources
>USE IN (lcTempTable)
>In this example, MyForm is the name of the form that contains a listbox control named lstResults where the results will be displayed. You can modify the code to suit your specific needs.
>
>
>
>
>Stacy Violett
>now can you show that code using python instead please?
>Sure, here's an example of how to iterate through a temp table and display the results in a modal form using Python and the PyQt5 GUI framework:
>
>python
>Copy code
>from PyQt5.QtWidgets import QApplication, QDialog, QVBoxLayout, QListWidget, QListWidgetItem
>import pyodbc # Import the PyODBC library for database access
>
># Connect to the database and open the temp table
>conn = pyodbc.connect("Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;")
>cursor = conn.cursor()
>cursor.execute("SELECT * FROM TempTable")
>
># Create the modal dialog and list widget
>app = QApplication([])
>dialog = QDialog()
>layout = QVBoxLayout()
>list_widget = QListWidget()
>
># Loop through the records and add them to the list widget
>recno = 1
>for row in cursor.fetchall():
> field1 = row.Field1
> field2 = row.Field2
> field3 = row.Field3
> item = QListWidgetItem(f"{recno} {field1} {field2} {field3}")
> list_widget.addItem(item)
> recno += 1
>
># Add the list widget to the dialog layout and display the dialog
>layout.addWidget(list_widget)
>dialog.setLayout(layout)
>dialog.setWindowTitle("Results")
>dialog.setModal(True)
>dialog.exec_()
>
># Close the cursor and database connection
>cursor.close()
>conn.close()
>Note that you'll need to replace myServerAddress and myDataBase with the address of your SQL Server instance and the name of your database, respectively. You may also need to modify the SELECT statement to retrieve the correct columns from your temp table.
>
>
>
>
>
>
>>>Hi Rich,
>>>
>>>>Thank you so much for your detailed writeup on Python
>>>
>>>You're most welcome. This good old forum has been a helpful place for so many years. A pleasure to be useful here!
>>
>>BTW, my old padawan, Voja Cvejić, after wasting years learning .net (plus Angular, Ado.net and a few other tools out there) just in case it may land him next job, finally confesses he was wasting time, and wants to learn Python. He's lined up some „learn python in nn days“ thingies, but I guess these would mostly waste his time on learning stuff he already knows. Is there a crash course for an old fox?
>>
>>(unless, of course, someone here needs an old fox who knows a bunch of .net things and could do some work as a telecommuting assistant... but in that case this is the wrong neck of the forum)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform