Best way to display MySql data in Tkinter GUI - mysql

Just wondering if there is a better way to display MySql data to users of my app.
Basically I store look-up data then put it in a pop-up window for viewing:
for row in all_reinforcement_data:
r_total = ("Total number of reinforcement entries", mycursor.rowcount)
r_id = ("\n\nId", row[0])
messagebox.showinfo("Reinforcement Data Results", r_total + r_id)
Which doesn't look too polished but gives me what I want:
Is there any other ways of showing the user the data. In some form they could copy and paste from, ideally an excell spreadsheet or something similar.

In a messagebox I don't believe you could do it. You could attempt to do it in a normal window with an entry that you could only copy out of, similarly to this question.
For example, you could do this to show the rows in a simple window:
from tkinter import *
row_info = Tk()
row_info.title("Reinforcement Data Results")
title = Label(text="Total number of reinforcement entries:")
title.pack()
data = Entry(row_info, borderwidth=0, justify='center')
data.insert(END, mycursor.row_count)
data.pack()
data.configure(state="readonly")
close = Button(row_info, text="Ok", command=row_info.destroy)
close.pack()
row_info.mainloop()

Related

Import txt file into ms access m:m table

I'm quite new to MS Access. I just set up a new Access database to be used with our schematics tool. Our tool can access the database, so this works fine. At the end of our schematics capturing process, we generate a bill of material (BOM), listing every part that is in the design.
I want to be able to evaluate which part (each has a unique part ID "TUPID") is used on which board (unique board-ID "UBRID") - so I set up a Many-to-Many-table. First tests entering some data there by hand look good, importing text-files containing "UBRID", "TUPID" works fine too.
Now I want to be able to import the generated BOM, which is plain text containing only the "TUPID" - the "UBRID" is not known by the schematics tool. I know, I can manipulate the text file before I run a query, but I would rather not. I want to start the import operation from a form, which lists all boards (thus getting the "UBRID" by selecting the relevant board) then I want to start the import - but how is this done? Do I have to run a query for each line of the text file, or what is the best way to achieve my goal?
Looking forward for any tips!
Assuming import is for one UBRID set at a time - import records then run UPDATE action to populate those records with UBRID. Something like:
CurrentDb.Execute "UPDATE tablename SET UBRID = '" & Me.UBRID & "' WHERE UBRID IS NUll"

Online user input into R script

I am an R programmer who unfortunately has no experience in web development or anything related, so this could be a very basic question.
I would like to know whether it's possible to create a website where user input triggers some piece of R code to run. Let's use a trivial example:
I have a .txt file on my local device.
If a user visited my website, he would be able to input a number and click a "send" button.
The user should receive the sum of his input and the number stored on my text file. Then, the number in the text file should be replaced by the user's input. This means, something like this should run:
my_number <- read.txt(my_file.txt)
write.txt(user_input, file="my_file.txt")
output <- my_number + user_input
My question is, how can I tell R what the desired value for user_input is, and how can I let my website print the output.
NOTE: I tried to use the title "Can a website trigger R code execution?", but for some reason that is an inappropriate title!

How can I move to subsequent web pages after POST (ing) a html form in R?

A happy and a prosperous New Year, 2016 to everyone.
Here, I am using NCDC website to download weather data from say 01-Jan-2015 to 31-Mar-2015 for a state in the US say Connecticut. The link is mentioned below in the script. From filling details on this webpage to page in which you click on submit after entering your email id, there are intermediate pages that require some inputs before continuing on to a next page. My goal is to write a R script that automatically triggers download (submit order) for different states for different time periods after providing required inputs.
For purpose of ease, I am putting steps that one need to follow to download data for Connecticut. These steps are (please go through 2 snapshots attached):
Step-1 : Here, you select a dataset, State name, and time period-
4 values that would go in the form on landing page are Daily Summaries, 2015-01-01 to 2015-03-31, States, and Connecticut.
library(httr)
url <- "http://www.ncdc.noaa.gov/cdo-web/search?datasetid=GHCND"
fd <- list(
submit = "Search",
searchStartDate = "2015-01-01",
searchEndDate = "2015-03-31",
resultType = "States",
searchString = "Connecticut"
)
resp<-POST(url, body=fd, encode="form")
Step-2 : Here, you would need to click first on ADD TO CART and then on View All Items under Cart. This would be possible, if we operate on resp from above step. I am not able to figure out a way to do this operation.
Step-3 : Here, you need to select 2nd option under "Select the Output Format" before clicking on CONTINUE.
Step-4 : Here, you have to select many options as highlighted in the image before clicking on CONTINUE.
Step-5: Finally, you enter the email id and click on "SUBMIT ORDER".
If you need any other input from my end, do let me know.
Thanks

Is HTML5 localstorage appropriate to store input field values?

I have a question, on how to best store local values of some form fields.
In my website, users use the keypad to keep a tally count of items. They can enter a label for the items they count. The problem is that each user apply different labels for their needs - and, each time they visit the labels are blank.
My sites are running through site44.com, which does not allow the use of server side php. So, in my research, I think using HTML5 localstorage may allow a user to keep the label after the exit the site?
Is this a correct interpretation?
Can someone give me a guide if I have, say 3 inputs - with different ids - how to set up the script?
you can use the local storage like this :
var fn = document.getElementById("firstname").value;
localStorage.setItem("firstname", fn);
var ln = document.getElementById("lastname").value;
localStorage.setItem("lastname", ln);
var em = document.getElementById("email").value;
localStorage.setItem("email", em);
thus the clients browser will have these items set in their local storage.
Now if a user visits the website afterwards. you can check for the value of localStorage and find the items of your need.
Suppose on users' next visit you want to send him a greet message ( he has not logged in ofcourse ) you can use a script like this below:
var name = localStorage.getItem("firstname");
alert("Hello"+name);

PowerBuilder pasting in tabbed data window

I recently started a new job with a company and my first task is to update some quite old software for them.
There is a big back story but basically the software was written in PB8 (around 1997) and no one within the company (including me) has had any experience with PowerBuilder before and as the newbie I have been tasked to update and maintain it until a replacement has been approved and can be developed.
We have the license for PowerBuilder 12.5 so I am using PB12.5 Classic to do everything. The original developer cannot be contacted for support and no documentation exists.
One thing I am trying to understand, that will be a huge help in the future, is how to determine where functions are defined and where variables get their values..
The example I am working on at the moment is the following scenario.
There is a data window with tabs, named tab_detail each tab displays different whatever little orange men are in the tree list.
One of these are called dw_detail which allows pasting of data. None of the other tabs allow pasting of data, but I would like them to. dw_detail has an event rbuttondown() with the following code in it:
Window w_parentwin
If ib_add_mode Or ib_chg_mode Then
w_parentwin = Parent.GetParent().GetParent()
m_dwpaste m_pop_paste
m_pop_paste = CREATE m_dwpaste
m_pop_paste.idw_data = This
If ii_agent_code > 0 And Not IsNull(id_period) And Clipboard() <> "" Then
m_pop_paste.m_popup.m_paste.Enabled = TRUE
Else
m_pop_paste.m_popup.m_paste.Enabled = FALSE
End If
m_pop_paste.m_popup.PopMenu(w_parentwin.PointerX(), w_parentwin.PointerY())
DESTROY(m_pop_paste)
End If
When I add that code to the rbuttondown() event of tab number 2 (dw_adjustment) tab 2 now allows paste when I right click within the dw_adjustment data window but the data gets pasted to the fields within the dw_detail tab not the fields on the dw_adjustment tab.
I have tried debugging and stepping through the code but there are thousands of values in the variable window and without the ability to search I cannot find the variables used above and what their values are or why data gets pasted to the dw_detail tab instead of the dw_adjustment tab when I paste into the dw_adjustment tab.
Basically I am looking for any helpful tips on where to look or what the above is doing and why everything pastes to tab 1 instead of the tab I clicked paste in.
If more detail is needed from code from a different location or more information is needed I am happy to provide it.
As suggested by Seki I found the m_popup when double clicked it came up with wf_pastereturn():
Integer li_idx, li_rows, li_dwrows, li_comm, li_seqno
String ls_approval_type
If tab_detail.tabpage_details.dw_detail.RowCount() > 0 Then
li_idx = 1
li_dwrows = tab_detail.tabpage_details.dw_detail.RowCount()
Do Until li_idx > li_dwrows
ls_approval_type = tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx]
If IsNull(ls_approval_type) or ls_approval_type = "" Then
tab_detail.tabpage_details.dw_detail.DeleteRow(li_idx)
Else
li_idx++
End If
li_dwrows = tab_detail.tabpage_details.dw_detail.RowCount()
Loop
End If
If li_dwrows > 0 Then
li_seqno = Long(tab_detail.tabpage_details.dw_detail.Object.seq_no [li_dwrows])
End If
li_seqno += 10
If Clipboard() <> "" Then
If tab_detail.tabpage_details.dw_detail.ImportClipboard(1, li_rows, 1, 4, 3) <= 0 Then
MessageBox("Invalid Data", "Unable to paste!", StopSign!)
Return -1
End If
li_rows = tab_detail.tabpage_details.dw_detail.RowCount()
li_dwrows++
For li_idx = li_dwrows To li_rows
tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx] = trim(tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx])
tab_detail.tabpage_details.dw_detail.Object.approval_no [li_idx] = trim(tab_detail.tabpage_details.dw_detail.Object.approval_no [li_idx])
tab_detail.tabpage_details.dw_detail.Object.agent_code [li_idx] = ii_agent_code
tab_detail.tabpage_details.dw_detail.Object.period [li_idx] = id_period
li_comm = f_new_commission(Long(tab_detail.tabpage_details.dw_detail.Object.value_of_work[li_idx]), id_period)
tab_detail.tabpage_details.dw_detail.Object.levy_payable[li_idx]= &
inv_rate.of_CalculateLevyPayable (Long(tab_detail.tabpage_details.dw_detail.Object.value_of_work[li_idx]), id_period)
tab_detail.tabpage_details.dw_detail.Object.comm_deductable [li_idx] = li_comm
tab_detail.tabpage_details.dw_detail.Object.commission [li_idx] = li_comm
tab_detail.tabpage_details.dw_detail.Object.seq_no [li_idx] = li_seqno
li_seqno += 10
tab_detail.tabpage_details.dw_detail.Object.agent_return_detail_create_date[li_idx] = Today()
tab_detail.tabpage_details.dw_detail.Object.agent_return_detail_create_user[li_idx] = SQLCA.Logid
Next
Clipboard("")
Return 0
Else
Return -1
End If
I modified the function to use the windows SelectedTab property. Data will now paste into the tab but in the wrong input fields. I looked further and the data columns for the ImportClipboard function do not line up.
How is the best way to change the order of the selected database columns?
Here is a screenshot of what I mean by tabs:
So within the main program window, there are the above tabs, within each tab (where the input fields are) there is a data window labelled with the dw_ prefix.
Thanks heaps for your help.
I think first you should do some short tutorials. Please check out these:
PowerBuilder Classic 12/12.5 guide/tutorials
These are short and useful.
On the other side you are able to select specific variables in your own "watch variable" list, so you do not have to search over the several variables. You can right click on the variable name and do a Quickwatch or you can Insert the variable name in the Watch window.
Br. Gábor
The action with a contextual menu is in 2 times :
handle the mouse right click to display a contextual menu
perform an action among the one or several actions provided by the popup menu
You shown the pbscript that is displaying the menu with PopMenu() if there is something in the clipboard (Clipboard() <> "") and maybe you did not noticed that the pasting action is somewhere else.
Look in m_popup: there must be some code inside that may be hard-coded to paste in dw_detail. If so, maybe that you could store in the window instance variables a reference to the currently processed dw for the contextual menu.
Something like :
datawindow idw_current in the instance variables
then in the rbuttondown() event idw_current = this (this being the datawindow the rbuttondown() event belongs to)
and finally in the menu reuse the id_current instead of a hardcoded dw_detail
Concerning your question about where the variables are modified: what you can do is searching the variables by their name (right click on the target or a single pbl or object then 'search'), and put a breakpoint on the lines where they are affected. If you run in debug mode (CtrlDCtrlT instead of CtrlR) you will be able to trace when a variable is modified.
Paste Problem
Pass 1
It's hard to tell for sure, but I'd look at the code of m_dwpaste.m_popup.m_paste.Clicked. The worse case scenario is that dw_detail is hard coded into that script; the slightly better case is that it has a more flexible routine in there, but somehow dw_adjustment doesn't fit into that algorithm.
Pass 2
With the new information, we can see that the code of wf_pastereturn() (I'm not sure how you got to this script, but this looks like the culprit) is not simply pasting, but doing a lot more that involves specific fields. In fact, it's not just pasting, it's importing the data, which means that it's assuming the contents of the clipboard are not only in a specific format, but match the data set of the DataWindow (see the Columns pane in the DW painter, and be careful not to confuse the data set part of the DataWindow with the UI part). The question is, do you want:
"Pasting" like copying text from Notepad into a browser form; just putting text into the current field?
"Pasting" exactly like the other DataWindow, including assumptions that all the same columns mentioned in the script are in both DataWindows?
"Pasting" something like this script, but customized for the data set in the new DataWindow?
These all require somewhat different solutions, combined with the differences I asked about in my comment about tabs vs. DataWindows.
Finding Stuff
I'm going to give an unapologetically biased point of view, because I'm the author of a tool that, among other things, helps you search PowerBuilder code called PBL Peeper.
If you're looking at code in the Browse tab, and you want to see other mentions of the variable, you can select it, right click, and either
search forward or back within the script
search for the object name in the tree on the left (it'll make more sense when you see it)
search either the rest of the object or the rest of the application
Finding where a variable is assigned is more difficult than it sounds, because of the multiple syntaxes that could be involved.
// assigns a value on instantiation
int i = 1
// assigns a value when executed
i = 1
// does not assign a value
IF i = 1 THEN
// assigns a value possibly if the parameter is passed by reference (kind of like a pointer to the variable)
f_foo (i)
Finding the setting of a variable can be helped by understanding variable scope. If the variable is local, you only need to search the script. If the scope is instance or shared, you need to search the object (as above, pretty easy) and its descendants (easy to go to a given descendant with an RMB on the treeview, harder to search on a set of descendants). If the scope is global, you want to search the entire app.
Finding where a selected function is declared is possible, but you need to know a little secret (or RTFM). The Find on the RMB menu uses the parameters from the Find page, so you need to set Portion Type to All, not just Scripts, to find where functions are declared. Alternatively, you can use the Lists / Scripts pages and find the script using the functions on that page (Find, QuickFind, Filter, etc...).
The tool has a plethora of functionalities that let you find, filter and sift through code to get at what you're after. The above is just a quick introduction.
Good luck,
Terry.