Re: Free OCR package in Python and selecting appropriate widget for the GUI

2021-09-22 Thread Roland Mueller via Python-list
Hello,


ti 21. syysk. 2021 klo 16.53 Mohsen Owzar ([email protected])
kirjoitti:

> Hi Guys
> Long time ago I've written a program in Malab a GUI for solving Sudoku
> puzzles, which worked not so bad.
> Now I try to write this GUI with Python with PyQt5 or TKinter.
> First question is:
> Is there any free OCR software, packages or code in Python, which I can
> use to recognize the given digits and their positions in the puzzle square.
>

to my knowledge there is no Python package for OCR. Using a free OCR
package that has a command line interface one could integrate this into a
Python script that makes a call to this external OCR e.g. using Python
module subprocess.

BR,
Roland


> Second:
> Because, I can not attach a picture to this post, I try to describe my
> picture of my GUI.
> It is a 3x3 block / matrix (one third of the whole Sudoku 9x9 block).
> This block must be placed three times in row and columns.
> Each square of this 3x3 block has 3x3 digits from 1 to 9 at the
> initialization time. These digits are spread out in 3x3 equal distances.
> These are small fonts and black.
> The values given by the puzzle are red big fonts and not changeable
> The digits typed by the user are black big fonts and changeable
> If there is a big font from the Puzzle / User, these must be removed from
> the neighboring fields from the 3x3 matrix (1-9).
> Now my question is, actually a hint from your side:
> What should I take as widget for one of these small squares to have
> different content as I described above?
> I thought of a QLineEdit in PyQt5 or LineEdit in TKinter, because the user
> must type some values in there and therefore can not be labels. So again,
> for the sake of the clarity.
> •   When the fields are empty, each square has to show digits from 1
> to 9 with small fonts in 3x3 matrix order.
> •   Given values in the puzzle are big fonts and red.
> •   Digits which are typed by the user are big fonts and black.
> Now the question is, can I take only one LineEdit for all these tree
> situations, or I have to implement 9 small squares for small fonts and a
> big one for the big fonts?
> Any help and suggestion is welcome and appreciated.
>
> Best regards
> Mohsen
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: distlib 0.3.3 released on PyPI

2021-09-22 Thread Vinay Sajip via Python-list
I've recently released version 0.3.3 of distlib on PyPI [1]. For newcomers,
distlib is a library of packaging functionality which is intended to be
usable as the basis for third-party packaging tools.

The main changes in this release are as follows:

* Fixed #152: Removed splituser() function which wasn't used and is deprecated.

* Fixed #149: Handle version comparisons correctly in environment markers.

* Add ARM-64 launchers and support code to use them. Thanks to Niyas Sait and
  Adrian Vladu for their contributions.

* Fixed #148: Handle a single trailing comma following a version. Thanks to 
Blazej
  Floch for the report and suggested fix.

* Fixed #150: Fix incorrect handling of epochs.

* Reverted handling of tags for Python >= 3.10 (use 310 rather than 3_10). This 
is
  because PEP 641 was rejected.

* Added a GitHub Actions workflow to perform tests.

A more detailed change log is available at [2].

Please try it out, and if you find any problems or have any suggestions for 
improvements,
please give some feedback using the issue tracker! [3]

Regards,

Vinay Sajip

[1] https://pypi.org/project/distlib/0.3.3/
[2] https://distlib.readthedocs.io/en/0.3.3/
[3] https://bitbucket.org/pypa/distlib/issues/new
-- 
https://mail.python.org/mailman/listinfo/python-list


[Hint]: python simulator http

2021-09-22 Thread David Caul
Hi All,
Making any simulator http request , response base simulator with some UI on
browser , what are all things python package can support

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


Re: Free OCR package in Python and selecting appropriate widget for the GUI

2021-09-22 Thread DFS

On 9/21/2021 10:38 PM, Mohsen Owzar wrote:

DFS schrieb am Dienstag, 21. September 2021 um 15:45:38 UTC+2:

On 9/21/2021 4:36 AM, Mohsen Owzar wrote:

Hi Guys
Long time ago I've written a program in Malab a GUI for solving Sudoku puzzles, 
which worked not so bad.
Now I try to write this GUI with Python with PyQt5 or TKinter.
First question is:
Is there any free OCR software, packages or code in Python, which I can use to 
recognize the given digits and their positions in the puzzle square.
Second:
Because, I can not attach a picture to this post, I try to describe my picture 
of my GUI.

Draw your GUI in PyQt designer or other graphics tool, then upload a
screenshot of it to imgur, then post the link to the picture.

Thanks, for your answer.
But, what is "imgur"?
I'm not so familiar with handling of pictures in this group.
How can I call "imgur" or how can I get there?

Regards
Mohsen



www.imgur.com

It's a website you can upload image files or screenshots to.  Then you 
can copy a link to your picture and post the link here.



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


Re: Polymorphic imports

2021-09-22 Thread Dennis Lee Bieber
On Tue, 21 Sep 2021 18:58:31 +, Travis Griggs 
declaimed the following:


>from lib import paths
>import paths.dynamic_client_module()
>
>But this seems to not work. Import can only take real modules? Not programatic 
>ones?

Consider "import" to be equivalent to a compile-time operation. 

https://docs.python.org/3/using/cmdline.html#environment-variables cf
PYTHONPATH

https://docs.python.org/3/library/sys.html#sys.path
"""
 sys.path

A list of strings that specifies the search path for modules.
Initialized from the environment variable PYTHONPATH, plus an
installation-dependent default.

As initialized upon program startup, the first item of this list,
path[0], is the directory containing the script that was used to invoke the
Python interpreter. If the script directory is not available (e.g. if the
interpreter is invoked interactively or if the script is read from standard
input), path[0] is the empty string, which directs Python to search modules
in the current directory first. Notice that the script directory is
inserted before the entries inserted as a result of PYTHONPATH.

A program is free to modify this list for its own purposes. Only
strings and bytes should be added to sys.path; all other data types are
ignored during import.
"""

So... Putting the module variants into separate directories, and
modifying the import path to reference the directory of a specific variant,
might do what you want -- as long as the module name itself remains fixed.

The other alternative may be
https://docs.python.org/3/library/functions.html#__import__


-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/

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


Re: Free OCR package in Python and selecting appropriate widget for the GUI

2021-09-22 Thread Mohsen Owzar
DFS schrieb am Mittwoch, 22. September 2021 um 05:10:30 UTC+2:
> On 9/21/2021 10:38 PM, Mohsen Owzar wrote: 
> > DFS schrieb am Dienstag, 21. September 2021 um 15:45:38 UTC+2: 
> >> On 9/21/2021 4:36 AM, Mohsen Owzar wrote: 
> >>> Hi Guys 
> >>> Long time ago I've written a program in Malab a GUI for solving Sudoku 
> >>> puzzles, which worked not so bad. 
> >>> Now I try to write this GUI with Python with PyQt5 or TKinter. 
> >>> First question is: 
> >>> Is there any free OCR software, packages or code in Python, which I can 
> >>> use to recognize the given digits and their positions in the puzzle 
> >>> square. 
> >>> Second: 
> >>> Because, I can not attach a picture to this post, I try to describe my 
> >>> picture of my GUI. 
> >> Draw your GUI in PyQt designer or other graphics tool, then upload a 
> >> screenshot of it to imgur, then post the link to the picture. 
> > Thanks, for your answer. 
> > But, what is "imgur"? 
> > I'm not so familiar with handling of pictures in this group. 
> > How can I call "imgur" or how can I get there? 
> > 
> > Regards 
> > Mohsen
> www.imgur.com 
> 
> It's a website you can upload image files or screenshots to. Then you 
> can copy a link to your picture and post the link here.
I have already posted the link, but I can not see it anywhere.
Now, I post it again:
https://imgur.com/a/Vh8P2TE
I hope that you can see my two images.
Regards
Mohsen
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Free OCR package in Python and selecting appropriate widget for the GUI

2021-09-22 Thread DFS

On 9/22/2021 1:54 AM, Mohsen Owzar wrote:

DFS schrieb am Mittwoch, 22. September 2021 um 05:10:30 UTC+2:

On 9/21/2021 10:38 PM, Mohsen Owzar wrote:

DFS schrieb am Dienstag, 21. September 2021 um 15:45:38 UTC+2:

On 9/21/2021 4:36 AM, Mohsen Owzar wrote:

Hi Guys
Long time ago I've written a program in Malab a GUI for solving Sudoku puzzles, 
which worked not so bad.
Now I try to write this GUI with Python with PyQt5 or TKinter.
First question is:
Is there any free OCR software, packages or code in Python, which I can use to 
recognize the given digits and their positions in the puzzle square.
Second:
Because, I can not attach a picture to this post, I try to describe my picture 
of my GUI.

Draw your GUI in PyQt designer or other graphics tool, then upload a
screenshot of it to imgur, then post the link to the picture.

Thanks, for your answer.
But, what is "imgur"?
I'm not so familiar with handling of pictures in this group.
How can I call "imgur" or how can I get there?

Regards
Mohsen

www.imgur.com

It's a website you can upload image files or screenshots to. Then you
can copy a link to your picture and post the link here.

I have already posted the link, but I can not see it anywhere.
Now, I post it again:
https://imgur.com/a/Vh8P2TE
I hope that you can see my two images.
Regards
Mohsen



Got it.

I haven't used tkinter.  In PyQt5 designer I think you should use one 
QTextEdit control for each square.



Each square with the small black font can be initially populated with

1  2  3
4  5  6
7  8  9



https://imgur.com/lTcEiML



some starter python code  (maybe save as sudoku.py)

=
from PyQt5 import Qt, QtCore, QtGui, QtWidgets, uic
from PyQt5.Qt import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

#objects
app = QtWidgets.QApplication([])
frm  = uic.loadUi("sudoku.ui")


#grid = a collection of squares
grids = 1

#squares = number of squares per grid
squares = 9

#fill the squares with 1-9
def populateSquares():
for i in range(grids,grids+1):
for j in range(1,squares+1):
widget = frm.findChild(QtWidgets.QTextEdit, 
"txt{}_{}".format(i,j))
widget.setText("1  2  3  4  5  6  7  8  9")

#read data from squares
def readSquares():
for i in range(grids,grids+1):
for j in range(1,squares+1):
			print("txt%d_%d contains: %s" % 
(i,j,frm.findChild(QtWidgets.QTextEdit, 
"txt{}_{}".format(i,j)).toPlainText()))



#connect pushbuttons to code
frm.btnPopulate.clicked.connect(populateSquares)
frm.btnReadContents.clicked.connect(readSquares)

#show main form
frm.show()

#initiate application
app.exec()
=





.ui file (ie save as sudoku.ui)
=



 MainWindow
 
  
   
0
0
325
288
   
  
  
   Sudoku
  
  
   

 
  32
  22
  83
  65
 


 
  Courier
  12
  50
  false
 


 false


 color: rgb(0, 0, 127);
background-color: rgb(255, 255, 127);


 QFrame::StyledPanel


 QFrame::Sunken


 Qt::ScrollBarAlwaysOff


 true

   
   

 
  114
  22
  83
  65
 


 
  Courier
  12
  50
  false
 


 false


 color: rgb(0, 0, 127);
background-color: rgb(255, 255, 127);


 QFrame::StyledPanel


 QFrame::Sunken


 Qt::ScrollBarAlwaysOff


 true

   
   

 
  196
  22
  83
  65
 


 
  Courier
  12
  50
  false
 


 false


 color: rgb(0, 0, 127);
background-color: rgb(255, 255, 127);


 QFrame::StyledPanel


 QFrame::Sunken


 Qt::ScrollBarAlwaysOff


 true

   
   

 
  32
  86
  83
  65
 


 
  Courier
  12
  50
  false
 


 false


 color: rgb(0, 0, 127);
background-color: rgb(255, 255, 127);


 QFrame::StyledPanel


 QFrame::Sunken


 Qt::ScrollBarAlwaysOff


 true

   
   

 
  114
  86
  83
  65
 


 
  Courier
  12
  50
  false
 


 false


 color: rgb(0, 0, 127);
background-color: rgb(255, 255, 127);


 QFrame::StyledPanel


 QFrame::Sunken


 Qt::ScrollBarAlwaysOff


 true

   
   

 
  196
  86
  83
  65
 


 
  Courier
  12
  50
  false
 


 false


 color: rgb(0, 0, 127);
background-color: rgb(255, 255, 127);

Re: XML Considered Harmful

2021-09-22 Thread Pete Forman
Jon Ribbens  writes:

> On 2021-09-21, Pete Forman  wrote:
>> CSV is quite good as a lowest common denominator exchange format. I
>> say quite because I would characterize it by 8 attributes and you
>> need to pick a dialect such as MS Excel which sets out what those
>> are. XML and JSON are controlled much better. You can easily verify
>> that you conform to those and guarantee that *any* conformant parser
>> can read your content. XML is more powerful in that repect than JSON
>> in that you can define and enforce schemas. In your case the fuel
>> name, UOM, etc. can be validated with standard tools. In JSON all
>> that checking is entirely handled by the consuming program(s).
>
> That's not true. You can use "JSON Schema" to create a schema for
> validating JSON files, and there appear to be at least four
> implementations in Python.

Fair point. It has been a while since I looked at JSON schemas and they
were rather less mature then.

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


Re: XML Considered Harmful

2021-09-22 Thread Michael F. Stemper

On 21/09/2021 16.21, Pete Forman wrote:

"Michael F. Stemper"  writes:

On 21/09/2021 13.49, alister wrote:

On Tue, 21 Sep 2021 13:12:10 -0500, Michael F. Stemper wrote:

It's my own research, so I can give myself the data in any format that I
like.


as far as I can see the main issue with XML is bloat, it tries to do
too many things & is a very verbose format, often the quantity of
mark-up can easily exceed the data contained within it. other formats
such a JSON & csv have far less overhead, although again not always
suitable.


I've heard of JSON, but never done anything with it.


Then you should certainly try to get a basic understanding of it. One
thing JSON shares with XML is that it is best left to machines to
produce and consume. Because both can be viewed in a text editor there
is a common misconception that they are easy to edit. Not so, commas are
a common bugbear in JSON and non-trivial edits in (XML unaware) text
editors are tricky.


Okay, after playing around with the example in Lubanovic's book[1]
I've managed to create a dict of dicts of dicts and write it to a
json file. It seems to me that this is how json handles hierarchical
data. Is that understanding correct?

Is this then the process that I would use to create a *.json file
to provide data to my various programs? Copy and paste the current
hard-coded assignment statements into REPL, use json.dump(dict,fp)
to write it to a file, and then read the file into each program
with json.load(fp)? (Actually, I'd write a function to do that,
just as I would with XML.)


Consider what overhead you should worry about. If you are concerned
about file sizes then XML, JSON and CSV should all compress to a similar
size.


Not a concern at all for my current application.


How does CSV handle hierarchical data? For instance, I have
generators[1], each of which has a name, a fuel and one or more
incremental heat rate curves. Each fuel has a name, UOM, heat content,
and price. Each incremental cost curve has a name, and a series of
ordered pairs (representing a piecewise linear curve).

Can CSV files model this sort of situation?


The short answer is no. CSV files represent spreadsheet row-column
values with nothing fancier such as formulas or other redirections.


Okay, that was what I suspected.


CSV is quite good as a lowest common denominator exchange format. I say
quite because I would characterize it by 8 attributes and you need to
pick a dialect such as MS Excel which sets out what those are. XML and
JSON are controlled much better. You can easily verify that you conform
to those and guarantee that *any* conformant parser can read your
content. XML is more powerful in that repect than JSON in that you can
define and enforce schemas. In your case the fuel name, UOM, etc. can be
validated with standard tools.


Yeah, validating against a DTD is pretty easy, since lxml.etree does all
of the work.


  In JSON all that checking is entirely
handled by the consuming program(s).

Well, the consumer's (almost) always going to need to do *some*
validation. For instance, as far as I can tell, a DTD can't specify
that there must be at least two of a particular item.

The designers of DTD seem to have taken the advice of MacLennan[2]:
  "The only reasonable numbers are zero, one, or infinity."

Which is great until you need to make sure that you have enough
points to define at least one line segment.


As in all such cases it is a matter of choosing the most apropriate tool
for the job in hand.


Naturally. That's what I'm exploring.


You might also like to consider HDF5. It is targeted at large volumes of
scientific data and its capabilities are well above what you need.


Yeah, I won't be looking at more than five or ten generators at most. A
small number is enough to confirm or refute the behavior that I'm
testing.


[1] _Introducing Python: Modern Computing in Simple Packages_,
Second Release, (c) 2015, Bill Lubanovic, O'Reilly Media, Inc.
[2] _Principles of Programming Languages: Design, Evaluation,
and Implementation_, Second Edition, (c) 1987, Bruce J. MacLennan,
Holt, Rinehart, & Winston
--
Michael F. Stemper
No animals were harmed in the composition of this message.
--
https://mail.python.org/mailman/listinfo/python-list


Re: XML Considered Harmful

2021-09-22 Thread Michael F. Stemper

On 21/09/2021 19.30, Eli the Bearded wrote:

In comp.lang.python, Michael F. Stemper  wrote:

I've heard of JSON, but never done anything with it.


You probably have used it inadvertantly on a regular basis over the
past few years. Websites live on it.


I used to use javascript when I was running Windows (up until 2009),
since it was the only programming language to which I had ready
access. Then I got a linux box and quickly discovered python. I
dropped javascript like a hot potato.


How does CSV handle hierarchical data? For instance, I have
generators[1], each of which has a name, a fuel and one or more
incremental heat rate curves. Each fuel has a name, UOM, heat content,
and price. Each incremental cost curve has a name, and a series of
ordered pairs (representing a piecewise linear curve).

Can CSV files model this sort of situation?


Can a string of ones and zeros encode the sounds of Bach, the images
of his sheet music, the details to reproduce his bust in melted plastic
extruded from nozzle under the control of machines?

Yes, CSV files can model that. But it would not be my first choice of
data format. (Neither would JSON.) I'd probably use XML.


Okay. 'Go not to the elves for counsel, for they will say both no
and yes.' (I'm not actually surprised to find differences of opinion.)


[1] The kind made of tons of iron and copper, filled with oil, and
rotating at 1800 rpm.


Those are rather hard to model in CSV, too, but I'm sure it could be
done.



for bonus round, use punched holes in paper to encode the ones and zeros


I've done cardboard.


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


Re: XML Considered Harmful

2021-09-22 Thread Dennis Lee Bieber
On Tue, 21 Sep 2021 13:12:10 -0500, "Michael F. Stemper"
 declaimed the following:

>On the prolog thread, somebody posted a link to:
>
>
>One thing that it tangentially says is "XML is not the answer."
>
>I read this page right when I was about to write an XML parser
>to get data into the code for a research project I'm working on.
>It seems to me that XML is the right approach for this sort of
>thing, especially since the data is hierarchical in nature.
>
>Does the advice on that page mean that I should find some other
>way to get data into my programs, or does it refer to some kind
>of misuse/abuse of XML for something that it wasn't designed
>for?

There are some that try to use XML as a /live/ data /storage/ format
(such as http://www.drivehq.com/web/brana/pandora.htm which has to parse
XML files for all configuration data and filter definitions on start-up,
and update those files on any changes).

If you control both the data generation and the data consumption,
finding some format with less overhead than XML is probably to be
recommended. XML is more a self-documented (in theory) means of packaging
data for transport between widely disparate applications, which are likely
written by different teams, if not different companies, who only interface
via the definition of the data as seen by XML.

>
>If XML is not the way to package data, what is the recommended
>approach?

Again, if you control both generation and consumption... I'd probably
use an RDBM. SQLite tends to be packaged with Python [Windows] or, at the
least, the DB-API adapter [Linux tends to expect SQLite as a standard
installed item]. SQLite is a "file server" model (as is the JET engine used
by M$ Access) -- each application (instance) is directly accessing the
database file; there is no server process mediating access.

Hierarchical (since you mention that in later posts) would be
represented by relations (terminology from relational theory -- a "table"
to most) linked by foreign keys.


-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/

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


Re: Polymorphic imports

2021-09-22 Thread Chris Angelico
On Thu, Sep 23, 2021 at 4:20 AM Dennis Lee Bieber  wrote:
>
> The other alternative may be
> https://docs.python.org/3/library/functions.html#__import__
>

I wouldn't recommend calling a dunder. If you just want to pass a text
string and get back a module, importlib is a better choice.

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


Re: XML Considered Harmful

2021-09-22 Thread Dennis Lee Bieber
On Wed, 22 Sep 2021 09:52:59 -0500, "Michael F. Stemper"
 declaimed the following:

>On 21/09/2021 19.30, Eli the Bearded wrote:
>> In comp.lang.python, Michael F. Stemper  wrote:
>>> How does CSV handle hierarchical data? For instance, I have
>>> generators[1], each of which has a name, a fuel and one or more
>>> incremental heat rate curves. Each fuel has a name, UOM, heat content,
>>> and price. Each incremental cost curve has a name, and a series of
>>> ordered pairs (representing a piecewise linear curve).
>>>
>>> Can CSV files model this sort of situation?
>> 
 
>> Yes, CSV files can model that. But it would not be my first choice of
>> data format. (Neither would JSON.) I'd probably use XML.
>
>Okay. 'Go not to the elves for counsel, for they will say both no
>and yes.' (I'm not actually surprised to find differences of opinion.)
>
You'd have to include a "level" (and/or data type if multiple objects
can be at the same level) field (as the first field) in CSV which
identifies how to parse the rest of the CSV data (well, technically, the
CSV module has "parsed" it -- in terms of splitting at commas, handling
quoted strings (which may contain commas which are not split points, etc.).

1-generator, name
2-fuel, name, UOM, heat-content, price
2-curve, name
3-point, X, Y
3-point, X, Y
...
2-curve, name
3-point, X, Y
3-point, X, Y
...

You extract objects at each level; if the level is the same or "lower"
(numerically -- higher in hierarchy) you attach the "previously" extracted
object to the parent object... Whether list or dictionary, or class
instance(s):

class Point():
#Point may be overkill, easier to just use a tuple (X, Y)
def __init__(self, X, Y):
self.X = X
self.Y = Y

class Curve():
def __init__(self, name):
self.name = name
self.points = []

#use as aCurve.points.append(currentPoint)

class Fuel():
def __init__(self, name, ..., price):
self.name = name
...
self.price = price

class Generator():
def __init__(self, name):
self.name = name
self.fuel = None
self.curves = []

#aGenerator.fuel = currentCurve
#aGenerator.curves.append(currentCurve)



-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/

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