Re: tksheet - Copy and Paste with headers

2023-04-16 Thread aapost

On 4/14/23 14:33, angela vales wrote:

I have recently created a tkinter app and need the ability to copy and paste 
data from tksheet table into an Excel file. I do have a button for export, but 
it will be beneficial to also allow the user to simply copy,paste.

I have enabled the appropriate bindings but cannot find a solution to also
copy the header information during the copy and paste.


the csv export code runs through a different path than the ctrl_c code, 
one operating on the sheet level, one on the main table level (I didn't 
dig in to the depths but my assumptions would be that main table doesn't 
mathematically consider the headers in the same way).


def yield_sheet_rows in _tksheet.py vs def ctrl_c in _tksheet_main_table.py

Comparing how the each path functions, without a larger redesign of 
tksheet, you could create a custom button press combo binding to 
something other than ctrl-c utilizing the yield_sheet_rows (or - 
disallow all other ctrl-c functionality in favor of ONLY a csv style 
everything dump when using ctrl-c):


Import these:
import csv as csv_module
import io

This would be your custom binding functionality:
rows = self.sheet.yield_sheet_rows(get_header = True, get_index = False)

s = io.StringIO()
writer = csv_module.writer(s, dialect = csv_module.excel_tab, 
lineterminator = "\n")

for row in rows:
writer.writerow(row)
self.clipboard_clear()
self.clipboard_append(s.getvalue())

It would need something deeper if you wanted to integrate it to ctrl-c 
and keep the existing ctrl-c functionality



--
https://mail.python.org/mailman/listinfo/python-list


Re: tksheet - Copy and Paste with headers

2023-04-16 Thread Thomas Passin

On 4/16/2023 9:01 AM, Alan Gauld wrote:



在 2023/4/15 2:33, angela vales 写道:

I have recently created a tkinter app and need the ability to copy and

paste data from tksheet table into an Excel file.


First thanks for drawing my attention to tksheet. I've long
been desiring a decent table widget in tkinter and was on the
verge of trying to create one of my own. tksheet looks like
it will do all I need.

As to copy/paste I couldn't see any explicit mention but
it does say the underlying data is in a Tk Canvas so it may
be that copy/paste will just work, did you try it? What
happened if you paste into a text editor in the first
instance? And Excel in the second?

If all else fails you can probably write handlers and bind
to Ctrl-C and Ctrl-V to do something yourself that mimics
cut/paste.


I have not used tksheet, but in its documentation at 
https://github.com/ragardner/tksheet/wiki#14-getting-selected-cells, 
there is the method


get_currently_selected()

Returns namedtuple of (row, column, type_) e.g. (0, 0, "column")
type_ can be "row", "column" or "cell"

There are companion methods for rows, columns, etc.  That would be a 
good starting point.

--
https://mail.python.org/mailman/listinfo/python-list


Re: tksheet - Copy and Paste with headers

2023-04-16 Thread Alan Gauld

> 在 2023/4/15 2:33, angela vales 写道:
>> I have recently created a tkinter app and need the ability to copy and 
> paste data from tksheet table into an Excel file. 

First thanks for drawing my attention to tksheet. I've long
been desiring a decent table widget in tkinter and was on the
verge of trying to create one of my own. tksheet looks like
it will do all I need.

As to copy/paste I couldn't see any explicit mention but
it does say the underlying data is in a Tk Canvas so it may
be that copy/paste will just work, did you try it? What
happened if you paste into a text editor in the first
instance? And Excel in the second?

If all else fails you can probably write handlers and bind
to Ctrl-C and Ctrl-V to do something yourself that mimics
cut/paste.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tksheet - Copy and Paste with headers

2023-04-16 Thread Jason Wang

在 2023/4/15 2:33, angela vales 写道:

Hello All,

I found this small group in a google search, so not sure if it is still active 
but giving it a try nonetheless.

I have recently created a tkinter app and need the ability to copy and paste 
data from tksheet table into an Excel file. I do have a button for export, but 
it will be beneficial to also allow the user to simply copy,paste.

I have enabled the appropriate bindings but cannot find a solution to also
copy the header information during the copy and paste.

My table is generated after a query is run. Here is a small snippet.

  df = pd.read_sql_query(query, conn)
 results_table.set_sheet_data(df.values.tolist())
 results_table.headers(df.columns.tolist())
 results_table.enable_bindings(
"drag_select",
"select_all",
"column_drag_and_drop",
"row_drag_and_drop",
"column_select",
"row_select",
"arrowkeys",
"right_click_popup_menu",
"copy",
"paste",
"undo"
)

best
Angela Vales
I am not sure how to solve your problem. The newsgroup may not be able 
to wait for an answer, so I suggest that you go to Stack Overflow to ask 
questions after conducting a thorough Google search. Of course, you can 
also wait for someone who knows the answer to come and answer:D

--
https://mail.python.org/mailman/listinfo/python-list


Re: TkSheet

2022-10-08 Thread Michael F. Stemper

On 08/10/2022 07.58, Benny Rieger wrote:

What a great work;-)

I need a solution for save my tabel as csv. How to do that? Has someone a 
solution for that?


Is this what you're seeking?



--
Michael F. Stemper
No animals were harmed in the composition of this message.
--
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-17 Thread Rich Shepard

On Thu, 17 Jun 2021, Dennis Lee Bieber wrote:


FreePascal/Lazarus is supposed to be similar to Delphi, and does
have Linux installs -- but I don't know what it provides for database
linkages. I do have it installed on my Windows box (the Linux install is
HUGE; takes up over 1/4 of the space on BeagleBone Black so I didn't
install it there).


Dennis,

In the 1980s I looked closely at Pascal. More recently I did so again
because the local linux/UNIX group had a presentation on its use. Decided
another language was not for me.

Thanks,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-17 Thread Rich Shepard

On Thu, 17 Jun 2021, Alan Gauld via Python-list wrote:


Sounds like a job for a database view. Can you modify the database schema?
Could you create a view - even a temporary one just while your app is
running?


Alan,

Yes, created views work well with postgres. Building one for complex,
multitable queries is always a good idea.

Thanks,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-17 Thread Rich Shepard

On Thu, 17 Jun 2021, Dennis Lee Bieber wrote:


My naive idea is to use two queries, one selects * from the company table
ordered by nunber, the other by name. The UI offers two radiobuttons when
viewing the results, one for each sort column.


Presuming all the data fits in memory, it may be faster to just define
the key structure for Python's internal sort() function than to go back out
to the database server, wait for it to gather the desired fields and sort
them, then transfer all the data back to your script.


Dennis,

That's a possibility.

Thanks,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-17 Thread Alan Gauld via Python-list
On 17/06/2021 00:15, Rich Shepard wrote:

> When I view my contacts table it needs to includes attributes from the
> company, people, and contacts tables so I can view all prior contacts with
> that person.

Sounds like a job for a database view.
Can you modify the database schema? Could you create a
view - even a temporary one just while your app is running?

Alternatively, and I've done this trick myself, create an
in-memory SqlLite database with a table that holds all the
columns you want then fetch the data from the master and
manipulate/view it from Sqlite - this makes sorting by
different columns fast and simple.

The downside is you have to refresh it periodically or
you will miss all changes in the master.

> Many years ago I used wxPython. For several reasons I decided to learn and
> use tkinter from now one. One reason is that the application for my clients
> will run mostly on windows hosts and I want to limit the software they need
> to install and maintain in order to run it.

Sure, that's the main reason I use tkinter too.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-16 Thread Rich Shepard

On Wed, 16 Jun 2021, Alan Gauld via Python-list wrote:


But there is nothing I know of for Tkinter that provides views of database
tables in the way that Delphi or VB or C# do, for example.


Alan,

These are all Microsoft tools. I run linux only.


You have to extract the data using SQL and populate the table and manage
all changes (of both view and data) yourself.



From an incomplete reading of the tksheet() doc it looks to be the best way

to display tables returned by a SQL query. PyQt5 has a QTableView() that
does the job, and it works great for a single table, but apparently not so
well with complex joins on multiple tables.

When I view my contacts table it needs to includes attributes from the
company, people, and contacts tables so I can view all prior contacts with
that person.


If you do a lot of that kind of desktop apps then you could look at Dabo
which is built on wxPython but has links to databases. Unfortunately it
looks like work ground to a halt about 5 years ago.


Many years ago I used wxPython. For several reasons I decided to learn and
use tkinter from now one. One reason is that the application for my clients
will run mostly on windows hosts and I want to limit the software they need
to install and maintain in order to run it.

Regards,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-16 Thread Rich Shepard

On Thu, 17 Jun 2021, dn via Python-list wrote:


Use the DBMS by retrieving the data in the desired sequence?


dn,

Yep. That's what I thought would be the best approach.

Thanks,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-16 Thread Rich Shepard

On Wed, 16 Jun 2021, Dennis Lee Bieber wrote:


Scroll further down to "bindings"... rc_insert_row -- a 
menu binding


Dennis,

Yes, I saw that one, too.


As for sorting, I don't see anything that allows one to add custom
events to the bindings... best I can come up with is that if a header
column is selected you sort the data and reload the table.


My naive idea is to use two queries, one selects * from the company table
ordered by nunber, the other by name. The UI offers two radiobuttons when
viewing the results, one for each sort column.

Thanks,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-16 Thread Alan Gauld via Python-list
On 16/06/2021 21:45, Rich Shepard wrote:

> The two applications I'm building are both database applications. If
> tksheet() is not the most appropriate widget to display database tables what
> alternative would be better?

I've not used tksheet but it sounds like it might be worth investigating.

There is a grid in Tix but its quite hard to use and Tix is now
deprecated. It was also a bit unreliable when used from
Python (that's euphemistic for "I couldn't get it to work!" :-)

But there is nothing I know of for Tkinter that provides views
of database tables in the way that Delphi or VB or C# do, for
example. You have to extract the data using SQL and populate
the table and manage all changes (of both view and data) yourself.

A good grid component would be a huge boon for tkinter, its one
of the most commonly used widgets in VB/Delphi etc

A DB-API linked grid would be the height of luxury...

If you do a lot of that kind of desktop apps then you could
look at Dabo which is built on wxPython but has links to databases.
Unfortunately it looks like work ground to a halt about 5 years ago.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-16 Thread dn via Python-list
On 17/06/2021 08.45, Rich Shepard wrote:
> On Wed, 16 Jun 2021, Terry Reedy wrote:
> 
>> Somewhat sparse doc at
>> https://github.com/ragardner/tksheet/blob/master/DOCUMENTATION.md#5-modifying-table-data
>>
>> insert_row()
> 
> Terry,
> 
> I'm reading this now and saw that.
> 
>> and change the column used for sorting (e.g.,
>>> sorting by company number or company name).
>>
>> I did not see anything about sorting.  tksheet is generic 'table', not
>> a database viewer
> 
> The two applications I'm building are both database applications. If
> tksheet() is not the most appropriate widget to display database tables
> what
> alternative would be better?

Use the DBMS by retrieving the data in the desired sequence?
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-16 Thread Rich Shepard

On Wed, 16 Jun 2021, Terry Reedy wrote:


Somewhat sparse doc at
https://github.com/ragardner/tksheet/blob/master/DOCUMENTATION.md#5-modifying-table-data
insert_row()


Terry,

I'm reading this now and saw that.


and change the column used for sorting (e.g.,

sorting by company number or company name).


I did not see anything about sorting.  tksheet is generic 'table', not a 
database viewer


The two applications I'm building are both database applications. If
tksheet() is not the most appropriate widget to display database tables what
alternative would be better?

Thanks,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: tksheet

2021-06-16 Thread Terry Reedy

On 6/16/2021 12:31 PM, Rich Shepard wrote:

Reading the doc for tksheet tells me that it allows me to modify cells (or
entire rows) as well as display them. What I don't see is whether I can add
a new row using tksheet


Somewhat sparse doc at
https://github.com/ragardner/tksheet/blob/master/DOCUMENTATION.md#5-modifying-table-data

insert_row()

 and change the column used for sorting (e.g.,

sorting by company number or company name).


I did not see anything about sorting.  tksheet is generic 'table', not a 
database viewer


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


tkinter: tksheet

2021-06-16 Thread Rich Shepard

Reading the doc for tksheet tells me that it allows me to modify cells (or
entire rows) as well as display them. What I don't see is whether I can add
a new row using tksheet and change the column used for sorting (e.g.,
sorting by company number or company name).

If you have experience with tksheet perhaps you can answer my questions
about it's capabilities.

Rich
--
https://mail.python.org/mailman/listinfo/python-list