# Template - Import modules in pyde

**URL:** <https://discourse.processing.org/t/template-import-modules-in-pyde/16608>\
**Category:** Processing.py\
**Created:** [December 24, 2019, 11:56am UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608 "2019-12-24T11:56:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![benwall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/benwall/32/7566_2.png) [@benwall](https://discourse.processing.org/u/benwall)\
**Post date:** [December 24, 2019, 11:56am UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/1 "2019-12-24T11:56:17Z")

</div>

Hi,  
Here’s an import modules template I’ve been working on to work with Processing using any outside code editor.  
It allows users to launch the .pyde file with PDE, and simply clic the Play button to launch their sketch. Every real work on the .py files can be done elsewhere.

> **[scripts/template · master · BenWall / processing](https://gitlab.com/BenDewalle/processing/tree/master/scripts/template)**
>
> GitLab.com

- rename /template folder and template.pyde
- add modules & classes in /obj
- settings that need to be shared between classes are in the superclass settings.Settings
- objects are loaded in the canva in lib.world.World.populateWorld. As long as the object as a setup() or draw() method, it will be created.
- launch.py and template.pyde don’t need any change.

Please note that this has not been tested with controls inputs such as mousePressed.

Any comment appreciated 🙂

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [December 24, 2019, 6:43pm UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/2 "2019-12-24T18:43:20Z")

</div>

It looks like you’ve provided the wrong GitLab link 🙃

---

<div class="post-metadata">

**Author:** ![benwall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/benwall/32/7566_2.png) [@benwall](https://discourse.processing.org/u/benwall)\
**Post date:** [December 25, 2019, 2:15pm UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/3 "2019-12-25T14:15:41Z")

</div>

Fixed. The forum seems to convert the link when we post.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 26, 2019, 8:54am UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/4 "2019-12-26T08:54:53Z")

</div>

the link still not work,  
possibly as you have a private profile?  
[https://gitlab.com/BenDewalle/](https://gitlab.com/BenDewalle/) ?

and you made us registering there?

can you just post  
`template.pyde`  
here

* * *

also a template name should be  
`sketch.pyde`  
and the user has to copy it to

```auto
/../Processing/modes/PhytonMode/template/sketch.pyde

```

or

```auto
/../Processing/templates/python/sketch.pyde

```

* * *

---

<div class="post-metadata">

**Author:** ![benwall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/benwall/32/7566_2.png) [@benwall](https://discourse.processing.org/u/benwall)\
**Post date:** [December 26, 2019, 9:48am UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/5 "2019-12-26T09:48:58Z")

</div>

Should be ok by now. I switched to gitlab recently sorry about this.

> [@kll](#):
>
> also a template name should be `sketch.pyde`  
> and the user has to copy it to  
> `/../Processing/modes/PhytonMode/template/sketch.pyde`

On p3 this would give the error

```auto
The file 'sketch.pyde' needs to be inside a sketch folder named 'sketch'. Create this folder, move the file and continue?

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 26, 2019, 10:54am UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/6 "2019-12-26T10:54:01Z")

</div>

yes, if you want to work on it, and want use sketch.pyde it must be under /sketch/sketch.pyde,  
but i talked about use it as a template ( by using the PDE build in template system )  
here run Processing 3.5.3 64bit / on win 10 64bit /

```auto
\Documents\Processing\modes\PythonMode\template\sketch.pyde

```

with ( minimal template )

```auto
"""
sketch.pyde
"""

def setup():
    size(640, 360) # Size should be the first statement

def draw():
    background(0) # Set the background to black

def mousePressed():
 

```

works fine ( at any PDE start / switch to python mode , and at /file/new/ )

under what environment you tested that path ( for template ) i give you?

* * *

thanks, now i could download it.

you are aware that with PDE your files /lib/… can not be opened,  
so here a flat structure is preferred

---

<div class="post-metadata">

**Author:** ![benwall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/benwall/32/7566_2.png) [@benwall](https://discourse.processing.org/u/benwall)\
**Post date:** [December 28, 2019, 2:56pm UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/7 "2019-12-28T14:56:12Z")

</div>

> [@kll](#):
>
> you are aware that with PDE your files /lib/… can not be opened,  
> so here a flat structure is preferred

Maybe I’ve been misleading by using the word “template”, sorry.

I personnaly don’t like working in PDE, as it’s not a very good code editor next to, let’s say, VSCode. My solution’s purpose is to work in your prefered editor with a single instance of PDE opened next to your editor.  
With this setup, you just load the .pyde file in PDE, and clic on the “Play” button when you want to launch your sketch.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 29, 2019, 1:13am UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/8 "2019-12-29T01:13:26Z")

</div>

> [@benwall](#):
>
> I personnaly don’t like working in PDE, as it’s not a very good code editor

that is no problem…

* * *

and if you refer to it not as a template , more like a library  
it would be ok that most part of it is hidden,

but, if i want to work with the default PDE editor  
and can not reach the file

```auto
/template/lib/settings.py

```

to change the canvas X/Y,  
we can not use it.

so, please could you make a version for us?  
( flat structure, where the PDE sees all the files as TABs )

a good template should save lots of typing and give us a  
default sketch / or frame work /  
what shortens the way to our next own project.

* * *

if it is a template what works only for / with VSCode…  
please state that in the topic title.

---

<div class="post-metadata">

**Author:** ![benwall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/benwall/32/7566_2.png) [@benwall](https://discourse.processing.org/u/benwall)\
**Post date:** [December 29, 2019, 12:40pm UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/9 "2019-12-29T12:40:21Z")

</div>

I actually created this workflow because I have a lot of problems with PDE (it delete or rename files, don’t seem to reload modules, etc…). The PDE template system does not work for me, as you still have to edit code inside PDE for every new sketch, and I had problems while modifying a .py module in PDE and hiting save, the .py file was actually not really saved to disk.

I have not the time or the motivation to develop a workflow that will work with the convoluted ways of PDE when that’s exactly the opposite of what I want to do 🙂 You can however load .py files that are stored inside a /lib subdirectory (use Sketch \> Add Files or drag n drop in PDE)

My first post is definitly not clear enough about what I’m proposing and the terms I’m using, but I can’t seem to edit it (forum restriction?)

I’ll remove the /lib directory to comply on PDE way of saving files.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [January 6, 2020, 4:36pm UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/10 "2020-01-06T16:36:52Z")

</div>

> [@benwall](#):
>
> My first post is definitly not clear enough about what I’m proposing and the terms I’m using, but I can’t seem to edit it (forum restriction?)

That is right – post editing locks after 5 days for new users. I’ve just bumped things up for you if you would like to make any edits to your original post – thanks for sharing your project with the forum.

I agree that clarifying that this is meant to provide a VSCode project setup – and/or that it is explicitly _not_ for use with PDE – would help people understand when and how to use what you have created.

See also: [[TUTORIAL]Running Python Mode in VScode](https://discourse.processing.org/t/tutorial-running-python-mode-in-vscode/7716)

---

<div class="post-metadata">

**Author:** ![benwall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/benwall/32/7566_2.png) [@benwall](https://discourse.processing.org/u/benwall)\
**Post date:** [January 11, 2020, 10:25am UTC](https://discourse.processing.org/t/template-import-modules-in-pyde/16608/11 "2020-01-11T10:25:21Z")

</div>

Thanks @jeremydouglass, I edited my first post.
