[Tutor] Python 3.7 Grids

2019-06-29 Thread David Merrick
Hi Looking for a way to use the determine the position of a card in a grid
using the mouse click event in Python. Code is attached. There are no
viruses.

Unfortunately using Tinkter grids / frames can't determine between the two
demo cards.

Any suggestions are welcome

-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

Cell 027 3089 169
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] path

2019-06-29 Thread ingo
A user has to type a path in the commandline on Win 10, so just a
string. This has to become a path / directory in the file system. Later
in the process subdirectories and files are 'appended' by the script. In
these files there are also paths, derived from the input path and they
have to use forward slashes. The tool that uses these files requires that.

# create structure:
# /---fullpath  <-- input() cmd
# |
# /--- data
# /--- db
# |+--- basename.db3<-- pathlib.Path(...).touch()
# |+--- basename.read   <-- forward slashes inside
# /--- ddl
# /--- doc
# /--- sql
# +--- basename.sublime-project <-- forward slashes inside (json)
# +--- _FOSSIL_


And here the misery begins...

A short excerpt:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64
bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> inp = "c:\test\drive\this"
>>> import pathlib
>>> p=pathlib.PurePath(inp)
>>> p
PureWindowsPath('c:\test/drive\this')
>>> print(pathlib.PurePosixPath(p))
c:/ est/drive his
>>> inp
'c:\test\\drive\this'
>>> import os
>>> print(os.path.normpath(inp))
c:  est\drive his
>>> print(pathlib.Path(inp))
c:  est\drive his
>>>

how to go from a string to a path, how to append to a path (os.path.join
or / with Path), how to turn it into 'posix'

TIA,

Ingo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.7 Grids

2019-06-29 Thread Bob Gailer
On Jun 29, 2019 3:01 AM, "David Merrick"  wrote:
>
> Hi Looking for a way to use the determine the position of a card in a grid
> using the mouse click event in Python. Code is attached.

Unfortunately this list does not forward attachments. Either give us a link
to the code or even better if it's not terribly complicated paste it into
the reply. be sure to reply all so everyone on the tutor list will see your
reply.

> There are no viruses.

That's kind of like a Salesman saying "trust me".

Bob Gailer
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-Help] Writing hello world

2019-06-29 Thread Bob Gailer
On Jun 28, 2019 9:26 AM, "Erastus muriithi" 
wrote:
>
> Iam a student..iam interested in learning python,,I don't know how to
study this python.kindly help me how to go about it..Thankyou

First make sure you have python installed on your computer. If you need
help with that let us know what kind of computer and operating system you
are using.

At the python. Org website you will find links to tutorials. Try some of
these out.

Direct future emails to tutor@python.org.
Always reply all so a copy goes back to the list.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path

2019-06-29 Thread Mats Wichmann
On 6/29/19 6:46 AM, ingo wrote:
> A user has to type a path in the commandline on Win 10, so just a
> string.
> A short excerpt:
> 
> Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64
> bit (AMD64)] on win32
> Type "copyright", "credits" or "license()" for more information.
 inp = "c:\test\drive\this"
 import pathlib
 p=pathlib.PurePath(inp)
 p
> PureWindowsPath('c:\test/drive\this')
 print(pathlib.PurePosixPath(p))
> c:/ est/drive his
 inp
> 'c:\test\\drive\this'
 import os
 print(os.path.normpath(inp))
> c:  est\drive his
 print(pathlib.Path(inp))
> c:  est\drive his

> 
> how to go from a string to a path, how to append to a path (os.path.join
> or / with Path), how to turn it into 'posix'

Most people don't use pathlib, and that's kind of sad, since it tries to
mitigate the kinds of questions you just asked. Kudos for trying.

For your example, when you define inp as a string, it needs to be a raw
string because otherwise Python will interpret the backslash sequences.
\t means tab, which is why the the results look mangled.

inp = "c:\test\drive\this"

If you're going to use pathlib, then may as well use the / operator for
joining,

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path

2019-06-29 Thread Mats Wichmann
Sigh... something dropped my raw string, so that was a really bad sample :(

inp = r"c:\test\drive\this"


On Sat, Jun 29, 2019, at 07:44, Mats Wichmann wrote:
> 
> For your example, when you define inp as a string, it needs to be a raw
> string because otherwise Python will interpret the backslash sequences.
> \t means tab, which is why the the results look mangled.
> 
> inp = "c:\test\drive\this"
> 
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path

2019-06-29 Thread ingo
On 29-6-2019 15:52, Mats Wichmann wrote:
> Sigh... something dropped my raw string, so that was a really bad sample :(
> 
> inp = r"c:\test\drive\this"
> 
> 
> On Sat, Jun 29, 2019, at 07:44, Mats Wichmann wrote:
>>
>> For your example, when you define inp as a string, it needs to be a raw
>> string because otherwise Python will interpret the backslash sequences.
>> \t means tab, which is why the the results look mangled.
>>
>> inp = "c:\test\drive\this"
>>


import pathlib
print('input')
a=input()
b=r"{}".format(a) #does this make sense to create a r'string'?
wa = pathlib.PureWindowsPath(a)
wb = pathlib.PureWindowsPath(b)
pa = pathlib.PurePosixPath(a)
pb = pathlib.PurePosixPath(b)
ppa = pathlib.PurePosixPath(wa)
ppb = pathlib.PurePosixPath(wb)


input
c:\test\this\path\
>>> print(a)
c:\test\this\path\
>>> print(b)
c:\test\this\path\
>>> print(wa)
c:\test\this\path
>>> print(wb)
c:\test\this\path
>>> print(pa)
c:\test\this\path\
>>> print(pb)
c:\test\this\path\
>>> print(ppa)
c:\/test/this/path
>>> print(ppb)
c:\/test/this/path

What I'm looking for is c:/test/this/path
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path

2019-06-29 Thread ingo



On 29-6-2019 16:33, ingo wrote:

> 
> What I'm looking for is c:/test/this/path


After further testing, the other tools in the chain accept paths like
c:\\test\\dir
c:\/test/dir
c:/test/dir

anything except standard windows, the top two I can generate.

Ingo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.7 Grids

2019-06-29 Thread boB Stepp
On Sat, Jun 29, 2019 at 2:02 AM David Merrick  wrote:
>
> Hi Looking for a way to use the determine the position of a card in a grid
> using the mouse click event in Python. Code is attached. There are no
> viruses.
>
> Unfortunately using Tinkter grids / frames can't determine between the two
> demo cards.

As Bob Gailer mentioned this is a text only list which does not allow
attachments, so I cannot see what you are actually attempting with
your code.  But with what you said, two thoughts come to my mind:

1) You can embed each card image on a button widget and if such a
button is clicked have the button's callback function respond
accordingly.

2) tkinter allows you to know the size of your window and can report
back what the cursor's current position is.  If you ensure that your
cards take up a known coordinate space in the window, when a mouse
click event happens you can write code to determine if the cursor fell
within either card's known coordinate space.

Hope this gives you some idea of how to tackle your problem.

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path

2019-06-29 Thread ingo



On 29-6-2019 15:42, Mats Wichmann wrote:
> 
> Most people don't use pathlib, and that's kind of sad, since it tries to
> mitigate the kinds of questions you just asked. Kudos for trying.

In the end, it works,

Ingo

---%<--%<--%<---
# set up some default directories and files
# for starting a new project with SQLite
# using Sublime + SQLTools.
#
# /---fullpath
# |
# /--- data
# /--- db
# |+--- basename.db3
# |+--- basename.read
# /--- ddl
# /--- doc
# /--- sql
# +--- basename.sublime-project
# +--- _FOSSIL_

import pathlib
import sys

# the last bit of the full path is used as the name for the database
# c:\newdatabase\test will create the databse
# c:\newdatabase\test\db\test.db3
print('enter full path for new db:')
fp = pathlib.Path(input())
fn = fp.name  # = os.path.basename()

dirs = {}
for sub in ['', 'data', 'db', 'ddl', 'doc', 'sql']:
dirs[sub] = fp / sub
try:
dirs[sub].mkdir(parents=False, exist_ok=False)
except FileExistsError:
print(f'Directory already exists: {dirs[sub]}')
sys.exit(1)

fdb = dirs['db'] / (fn+'.db3')
fdb.touch()

fr = dirs['db'] / (fn+'.read')
fr.write_text(f"""
-- template to build db from tables etc
-- using dot commands

PRAGMA foreign_keys = OFF;
--DROP TABLE IF EXISTS sometable;

BEGIN TRANSACTION;
--.read {(dirs['ddl'] / 'someddl.ddl').as_posix()}
COMMIT;

PRAGMA temp_store   = 2;
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = WAL;

BEGIN TRANSACTION;
--.read {(dirs['sql'] / 'somequery.sql').as_posix()}
COMMIT;
"""
)

fsub = dirs[''] / (fn+'.sublime-project')
fsub.write_text(f'''
{{
  "folders":[
{{
  "path": "."
}}
  ],
  "connections":{{
"Connection SQLite":{{
  "database": "{fdb.as_posix()}",
  "encoding": "utf-8",
  "type": "sqlite"
}}
  }},
  "default": "Connection SQLite"
}}'''
)

# TODO set up fossil in the fp dir


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor