How To Start A Well Organised Python Projects - Python MagicStick Text Editor - Part 1

Namaste Friends,




This Is our first part of Python MagicStick Text Editor Project and In this post, i will show you how to start and make a well organised python project structure that can deal with many rich features like Easy-To-Modify, Easy-To-Maintain and also have the ability of plug and play module.

But first, if you are a new visitor, Then I will suggest you to read our tutorial series number wise. because in this series i am showing how to use python tkinter module to create a real life application.

Links For Tutorials

MagicStick Text Editor Part 3
MagicStick Text Editor Part 4
MagicStick Text Editor Part 5
MagicStick Text Editor Part 6
MagicStick Text Editor Part 7
MagicStick Text Editor Part 8
MagicStick Text Editor Part 9
Or You Can Also Download Our Updated Example Codes Of Python MagicStick Text Editor Project For Understanding This Project More Clearly.

Check Here Our Github Repo




Now, let's focus to our main topic.

In Previous Tutorial, We created Some python empty scripts and folders To make our directory looks like this


MagicStick_Editor_Part_0
 |
 |---> About.txt  
 |
 |---> magicsticklibs
 |  |
 |  |---> __init__.py
 |  |     
 |  |---> Main.py
 |  |            
 |  |---> TextPad.py
 |  |
 |  |---> Graphics.py         
 |
 |
 |---> main.py


So, In Present Post, I am going to describe you about the plan behind this file and directory structure.

Friends, In Open Source project one of the most important factor is Additional plugin support or Addon Support. Here, Plugin or Addons Means a function facility that provide us a simple way to add our scripts with project Because with these types of features, other developers can easily design and write a plugin for our app and that can increase our apps features list and popularity.


Now, Our Main Question Is How Our Current Files Structure Satisfy Our Requirement.


In This Structure, To Run our app, we will simply run "main.py" script and then "main.py" script will import and run our other modules from "magicsticklibs".
Here, In "magicsticklibs" folder "Main.py" is our main controller that will control other script of "magicscticklibs" folder. "TextPad.py" is for Handling Tkinter Text Widget. "Graphic.py" is for handling our back-end library import function.
Because Their are some module names and functionality are different in python 2.x and python 3.x

For Example :

In Python 2.x, We import Tkinter Library Like This



import Tkinter

And In Python 3.x, like this.



import tkinter


For Handling these types of difference in module, I created a separate script called "Graphic.py"

Now, Let's Write Some Codes In These Files To Make This Structure Operational.


  •   "/main.py"


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## ################################################
## ###### Please Don't Remove Author Name #########
## ############# Thanks ###########################
## ################################################
##
##
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    http://bitforestinfo.blogspot.com/

    Note: We Feel Proud To Be Indian
######################################################
'''

import sys
from magicsticklibs import Main


root = Main.TextPad_Window(className = " MagicStick Text Editor")
root.mainloop()

  •   "/magicsticklibs/__init__.py"


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## ################################################
## ###### Please Don't Remove Author Name #########
## ############# Thanks ###########################
## ################################################
##
##
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    http://bitforestinfo.blogspot.com/

    Note: We Feel Proud To Be Indian
######################################################
'''
pass
  •  "/magicsticklibs/Main.py"


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## ################################################
## ###### Please Don't Remove Author Name #########
## ############# Thanks ###########################
## ################################################
##
##
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    http://bitforestinfo.blogspot.com/

    Note: We Feel Proud To Be Indian
######################################################
'''

from Graphics import Tkinter as tk
from TextPad import TextPad

class TextPad_Window(tk.Tk):
 def __init__(self, *args, **kwargs):
  tk.Tk.__init__(self, *args, **kwargs)
  self._text_pad_()


 def _text_pad_(self):
  TextPad(self).pack()
  return
  •  "/magicsticklibs/TextPad.py"


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
##
## ################################################
## ###### Please Don't Remove Author Name #########
## ############# Thanks ###########################
## ################################################
##
##
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    http://bitforestinfo.blogspot.com/

    Note: We Feel Proud To Be Indian
######################################################
'''

from Graphics import Tkinter

class TextPad(Tkinter.Text):
 def __init__(self, *args, **kwargs):
  Tkinter.Text.__init__(self, *args, **kwargs)
  self._pack()


 def _pack(self):
  self.pack(expand = True, fill = "both")
  return



if __name__ == '__main__':
 root = Tkinter.Tk(className = " Test TextPad")
 TextPad(root)
 root.mainloop()
  •  "/magicsticklibs/Graphics.py"



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
##
## ################################################
## ###### Please Don't Remove Author Name #########
## ############# Thanks ###########################
## ################################################
##
##
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    http://bitforestinfo.blogspot.com/

    Note: We Feel Proud To Be Indian
######################################################
'''

try:
 import Tkinter as Tkinter

except:
 import tkinter as Tkinter

Now, To Test This Application.

Just Run "main.py" Script.

Check Below my screenshot:



This Part Ends Here.

In Our Next Tutorial, we will continue this project.


Written By
              SSB

Share this

Related Posts

Previous
Next Post »