Any PyQt developers here?

2022-10-25 Thread DFS

Having problems with removeRow() on a QTableView object.

After calling removeRow(), the screen isn't updating.  It's as if the 
model is read-only, but it's a QSqlTableModel() model, which is not 
read-only.


The underlying SQL is straightforward (one table) and all columns are 
editable.


None of the editStrategies are working either.

I tried everything I can think of, including changes to the 
EditTriggers, but no luck.  HELP!


FWIW, the same removeRow() code works fine with a QTableWidget.

---
object creation and data loading all works fine
---
#open db connection
qdb = QSqlDatabase.addDatabase("QSQLITE")
qdb.setDatabaseName(dbname)
qdb.open()

#prepare query and execute to return data
query = QSqlQuery()
query.prepare(cSQL)
query.exec_()

#set model type and query
model = QSqlTableModel()
model.setQuery(query)

#assign model to QTableView object
view = frm.tblPostsView
view.setModel(model)

#get all data
while(model.canFetchMore()): model.fetchMore()
datarows = model.rowCount()



---
iterate selected rows also works fine
SelectionMode is Extended.
identical code works for a QTableWidget
---
selected = tbl.selectionModel().selectedRows()
#reverse sort the selected items to delete from bottom up
selected = sorted(selected,reverse=True)
for i,val in enumerate(selected):
tbl.model().removeRow(selected[i].row())

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


Re: Any PyQt developers here?

2022-10-25 Thread Thomas Passin

On 10/25/2022 1:03 PM, DFS wrote:

Having problems with removeRow() on a QTableView object.


removeRow() isn't listed as being a method of a QTableView, not even an 
inherited method, so how are you calling removeRow() on it? (See 
https://doc.qt.io/qt-6/qtableview-members.html)


After calling removeRow(), the screen isn't updating.  It's as if the 
model is read-only, but it's a QSqlTableModel() model, which is not 
read-only.


The underlying SQL is straightforward (one table) and all columns are 
editable.


None of the editStrategies are working either.

I tried everything I can think of, including changes to the 
EditTriggers, but no luck.  HELP!


FWIW, the same removeRow() code works fine with a QTableWidget.

---
object creation and data loading all works fine
---
#open db connection
qdb = QSqlDatabase.addDatabase("QSQLITE")
qdb.setDatabaseName(dbname)
qdb.open()

#prepare query and execute to return data
query = QSqlQuery()
query.prepare(cSQL)
query.exec_()

#set model type and query
model = QSqlTableModel()
model.setQuery(query)

#assign model to QTableView object
view = frm.tblPostsView
view.setModel(model)

#get all data
while(model.canFetchMore()): model.fetchMore()
datarows = model.rowCount()



---
iterate selected rows also works fine
SelectionMode is Extended.
identical code works for a QTableWidget
---
selected = tbl.selectionModel().selectedRows()
#reverse sort the selected items to delete from bottom up
selected = sorted(selected,reverse=True)
for i,val in enumerate(selected):
 tbl.model().removeRow(selected[i].row())



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


Python 3.11 with Pygame

2022-10-25 Thread Joni Ekholm
Hi,

Does Pygame work with 3.11? with 3.10 no problems.

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


Re: Beautiful Soup - close tags more promptly?

2022-10-25 Thread Tim Delaney
On Mon, 24 Oct 2022 at 19:03, Chris Angelico  wrote:

>
> Ah, cool. Thanks. I'm not entirely sure of the various advantages and
> disadvantages of the different parsers; is there a tabulation
> anywhere, or at least a list of recommendations on choosing a suitable
> parser?
>

Coming to this a bit late, but from my experience with BeautifulSoup and
HTML produced by other people ...

lxml is easily the fastest, but also the least forgiving.
html.parer is middling on performance, but as you've seen sometimes makes
mistakes.
html5lib is the slowest, but is most forgiving of malformed input and edge
cases.

I use html5lib - it's fast enough for what I do, and the most likely to
return results matching what the author saw when they maybe tried it in a
single web browser.

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


Re: Beautiful Soup - close tags more promptly?

2022-10-25 Thread Chris Angelico
On Wed, 26 Oct 2022 at 04:59, Tim Delaney  wrote:
>
> On Mon, 24 Oct 2022 at 19:03, Chris Angelico  wrote:
>>
>>
>> Ah, cool. Thanks. I'm not entirely sure of the various advantages and
>> disadvantages of the different parsers; is there a tabulation
>> anywhere, or at least a list of recommendations on choosing a suitable
>> parser?
>
>
> Coming to this a bit late, but from my experience with BeautifulSoup and HTML 
> produced by other people ...
>
> lxml is easily the fastest, but also the least forgiving.
> html.parer is middling on performance, but as you've seen sometimes makes 
> mistakes.
> html5lib is the slowest, but is most forgiving of malformed input and edge 
> cases.
>
> I use html5lib - it's fast enough for what I do, and the most likely to 
> return results matching what the author saw when they maybe tried it in a 
> single web browser.

Cool cool. It sounds like html5lib should really be the recommended
parser for HTML, unless performance or dependency reduction is
important enough to change your plans. (But only for HTML. For XML,
lxml would still be the right choice.)

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


Re: Any PyQt developers here?

2022-10-25 Thread Barry Scott
There is an active PyQt mailing list that has lots of helpful and knowledgeable 
people on it.

https://www.riverbankcomputing.com/mailman/listinfo/pyqt

Barry


> On 25 Oct 2022, at 18:03, DFS  wrote:
> 
> Having problems with removeRow() on a QTableView object.
> 
> After calling removeRow(), the screen isn't updating.  It's as if the model 
> is read-only, but it's a QSqlTableModel() model, which is not read-only.
> 
> The underlying SQL is straightforward (one table) and all columns are 
> editable.
> 
> None of the editStrategies are working either.
> 
> I tried everything I can think of, including changes to the EditTriggers, but 
> no luck.  HELP!
> 
> FWIW, the same removeRow() code works fine with a QTableWidget.
> 
> ---
> object creation and data loading all works fine
> ---
> #open db connection
> qdb = QSqlDatabase.addDatabase("QSQLITE")
> qdb.setDatabaseName(dbname)
> qdb.open()
> 
> #prepare query and execute to return data
> query = QSqlQuery()
> query.prepare(cSQL)
> query.exec_()
> 
> #set model type and query
> model = QSqlTableModel()
> model.setQuery(query)
>   
> #assign model to QTableView object
> view = frm.tblPostsView
> view.setModel(model)
>   
> #get all data
> while(model.canFetchMore()): model.fetchMore()
> datarows = model.rowCount()
> 
> 
> 
> ---
> iterate selected rows also works fine
> SelectionMode is Extended.
> identical code works for a QTableWidget
> ---
> selected = tbl.selectionModel().selectedRows()
> #reverse sort the selected items to delete from bottom up
> selected = sorted(selected,reverse=True)
> for i,val in enumerate(selected):
>   tbl.model().removeRow(selected[i].row())
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: UTF-8 and latin1

2022-10-25 Thread Barry Scott


> On 25 Oct 2022, at 11:16, Stefan Ram  wrote:
> 
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> You can let Python guess the encoding of a file.
>> def encoding_of( name ):
>> path = pathlib.Path( name )
>> for encoding in( "utf_8", "cp1252", "latin_1" ):
>> try:
>> with path.open( encoding=encoding, errors="strict" )as file:
> 
>  I also read a book which claimed that the tkinter.Text
>  widget would accept bytes and guess whether these are
>  encoded in UTF-8 or "ISO 8859-1" and decode them 
>  accordingly. However, today I found that here it does 
>  accept bytes but it always guesses "ISO 8859-1".

The best you can do is assume that if the text cannot decode as utf-8 it may be 
8859-1.

Barry

> 
>  main.py
> 
> import tkinter
> 
> text = tkinter.Text()
> text.insert( tkinter.END, "AÄäÖöÜüß".encode( encoding='ISO 8859-1' ))
> text.insert( tkinter.END, "AÄäÖöÜüß".encode( encoding='UTF-8' ))
> text.pack()
> print( text.get( "1.0", "end" ))
> 
>  output
> 
> AÄäÖöÜüßAÄäÖöÜüß
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Python 3.11 with Pygame

2022-10-25 Thread Mats Wichmann

On 10/25/22 11:47, Joni Ekholm wrote:

Hi,

Does Pygame work with 3.11? with 3.10 no problems.

Br Joni


It often takes a while for projects with binary wheels to to catch up to 
new Python releases.  You can always go check:


https://pypi.org/project/pygame/#files

From that, it seems there aren't 3.11 wheels yet.


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


Re: UTF-8 and latin1

2022-10-25 Thread Chris Angelico
On Wed, 26 Oct 2022 at 05:09, Barry Scott  wrote:
>
>
>
> > On 25 Oct 2022, at 11:16, Stefan Ram  wrote:
> >
> > r...@zedat.fu-berlin.de (Stefan Ram) writes:
> >> You can let Python guess the encoding of a file.
> >> def encoding_of( name ):
> >> path = pathlib.Path( name )
> >> for encoding in( "utf_8", "cp1252", "latin_1" ):
> >> try:
> >> with path.open( encoding=encoding, errors="strict" )as file:
> >
> >  I also read a book which claimed that the tkinter.Text
> >  widget would accept bytes and guess whether these are
> >  encoded in UTF-8 or "ISO 8859-1" and decode them
> >  accordingly. However, today I found that here it does
> >  accept bytes but it always guesses "ISO 8859-1".
>
> The best you can do is assume that if the text cannot decode as utf-8 it may 
> be 8859-1.
>

Except when it's Windows-1252.

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