You are on page 1of 20

Notescri be

An In ter faced Text Editor m ade in Pyth on .


By Ar vind Sr inivasan

Page

Contents
1

Ack nowl edgement

. . . . . . . . . . . . . . . . . . . . 01

About Not escri be

. . . . . . . . . . . . . . . . . . . . 02

Program St ruct ure

. . . . . . . . . . . . . . . . . . . . 03

Source Code

. . . . . . . . . . . . . . . . . . . . 07

Out put

. . . . . . . . . . . . . . . . . . . . 12

Concl usi ons and


Bi bl i ography

. . . . . . . . . . . . . . . . . . . . 16

A ck now l edgement
Ever y wor k accom pl ish ed is a pl easu r e - a sen se of
satisfaction . H owever a n u m ber of peopl e m otivate, cr iticize
an d appr eciate a wor k with th eir objectives, ideas an d
opin ion s. H en ce, I tak e th is oppor tu n ity to th an k al l , wh o
h ave dir ectl y or in dir ectl y h el ped m e to accom pl ish th is
pr oject.
- Fir stl y, I wou l d l ik e to th an k m y com puter science
teacher , M r s Pa vi t hr a with ou t wh ose su ppor t th is
pr oject wou l d n ot h ave been com pl ete. Next, I wou l d l ik e
to th an k al l th e peopl e wh o gave th eir val u abl e tim e,
cooper ation an d feedback to th is pr oject. I wou l d al so l ik e
to th an k m y sch ool for pr ovidin g m e with th e r esou r ces
wh ich beyon d an y dou bt h ave h el ped m e.
- Secon dl y, I wou l d l ik e to sin cer el y th an k ou r Pr incipal
V.Thi a ga r a ja n an d Vice Pr incipal, M r s. La kshm i
K a nna n for th eir gu idan ce th r ou gh ou t.
- Th ir dl y, I th an k m y cl ass teach er, M r s M yth er ee for
h el pin g u s fin ish ou r pr oject in tim e.
Last bu t n ot th e l east, I wou l d wan t to th an k m y par en ts an d
oth er facu l ty m em ber s for stan din g beside m e to m ak e th is
pr oject a wh ol esom e on e.
1

Notescribe app

Working with text has


never been easier.

Open Source

Formattable

User Friendly
2

Program Structure
Sever al Pyth on con cepts h ave been u sed to cr eate th is pr oject.
Th ese pr im ar il y in cl u de th e fol l owin g:

Cl asses:
Tki nt er Cla ss:
Tk in ter su ppor ts 15 cor e widgets ou t of wh ich th e fol l owin g
few h ave been in str u m en tal in th e design of th e pr ogr am .
Th ey ar e:
- Bu t t on : u sed to execu te a com m an d or oth er oper ation .
- Can v as: Str u ctu r ed gr aph ics. Th is widget can be u sed to
dr aw gr aph s an d pl ots, cr eate gr aph ics editor s, an d to
im pl em en t cu stom widgets.
- En t r y : A text en tr y fiel d.
- Fr am e: A con tain er widget. Th e fr am e can h ave a bor der
an d a back gr ou n d, an d is u sed to gr ou p oth er widgets wh en
cr eatin g an appl ication or dial og l ayou t.
- L abel : Displ ays a text or an im age.
- M en u : A m en u pan e. Used to im pl em en t pu l l -down an d
pop-u p m en u s.
- M essage: Displ ay a text. Sim il ar to th e l abel widget, bu t can
au tom atical l y wr ap text to a given width or aspect r atio.
- Scal e: Al l ows you to set a n u m er ical val u e by dr aggin g a
3

?sl ider ?.
- Scr ol l bar : Stan dar d scr ol l bar s for u se with can vas, en tr y,
l istbox an d text widgets.
- Tex t : For m atted text displ ay. Al l ows you to displ ay an d edit
text with var iou s styl es an d attr ibu tes. Al so su ppor ts
em bedded im ages an d win dows.
- Pan ed W i n d ow : A con tain er widget th at or gan izes ch il d
widgets in r e-sizabl e pan es.

Qui t t er Cla ss:


Th is cl ass cal l s th e qu i t () fu n ction wh en th e qu it bu tton is
cl ick ed. Th e su b-fu n ction of th e m odu l e is design ed to ver ify
wh eth er th e u ser r eal l y wan ted to qu it.

Scr olledText Cla ss:


Th is cl ass does th e fu n ction of gen er atin g a GUI l ayer over
th e r oot l ayer. It is th e cl ass wh er e com m on m ajor fu n ction s
of th e text editor ar e added.
A few su b-fu n ction s ar e:
- __i n i t __(): In itiate Scr ol l edText cl ass. Fr am e Bu il din g an d
con figu r ation is don e u n der th is fu n ction wh ich cal l s
fr om its oth er fu n ction s.
- m ak ew i d get s(): A con tain er widget th at stor es text is
cr eated (Tex t ) wh ich is th en al ign ed an d assign ed th e
val u es th at wou l d be typed.
- set t ex t (): Th is fu n ction s is u sed to pin poin t th e l ocation of
th e text an d pr ovidin g basic fu n ction al ities of a text editor
l ik e del etin g an d in ser tin g ch ar acter s u sin g f ocu s() wh ich
en abl es pr oper poin ter position .
4

- get t ex t (): Retu r n s text fr om star t to fin ish u sin g tags.

Si m pleEdi t or Cla ss:


Th is cl ass is a der ived su b-cl ass fr om Scr ol l edText wh er e al l
th e m odification s an d cr eativen ess l ies. To m ak e th is GUI
m or e attr active an d appeal in g, Var iou s tech n iqu es an d tr ick s
h ad been fol l owed. Th is is al so th e pl ace for addin g a l ot m or e
fu n ction s, th u s in cr easin g th e over al l fu n ction al ity an d
u sabil ity.
Th is i nher i t a nce of cl asses can be con sider ed as bein g
M u l t i l ev el .

Scrol l edText

Simpl eEdit or

For m at t i n g Fu n ct i on s:
- on Sav e(): Ask s sav e_as_f i l en am e an d copies al l text
with ou t for m attin g an d wr ites th em to th e text fil e u sin g
w r i t e() fu n ction .
- on Cu t (): Sel ect r equ ir ed text u sin g tag in dexes an d del ete
th e sel ected text wh il e u sin g tk in ter to access cl ipboar d
an d appen d th e data sel ected fr om th e given text.

- on Past e(): Repeat sam e pr ocess as above bu t in stead of


del etin g, paste th e sel ection stor ed in th e cl ipboar d.
- on I t al i c(), on Bol d (), on St r i k e(), on Un d er l i n e(),
on H i gh l i gh t ():Sel ect an y given text u sin g tags on m ou se
poin ter s an d u se text.t ag_con f i g() to con figu r e as you
wan t, for m attin g th e sel ected text.

Ot h er u ses of con cep t s:


Text fi les:
Text fil e is a u ser r eadabl e fil e th at con tain s in for m ation in a
tr an sl ated for m at u n l ik e th e way it is h el d in m em or y. For
savin g of n otes an d oth er r eadil y avail abl e to r ead
docu m en ts, text fil es ar e u sed. fu n ction s l ik e wr ite() h ave
been u sed to som e exten t wh il e cr eatin g th is pr ogr am .

M od u l es u sed :
-

Tk in ter
os
sys
tk Sim pl eDial og
tk Fil eDial og
tk M essageBox

Program Code
# - * - c odi ng:

ut f - 8 - * -

f r om Tk i nt er i mpor t

f r om t k Si mpl eDi al og i mpor t

as k s t r i ng

f r om t k Fi l eDi al og

as k s av eas f i l ename

i mpor t

f r om t k Mes s ageBox i mpor t


r oot

as k ok c anc el

= Tk ( )

r oot . t i t l e( " NOTESCRI BE" )


TI TLE=' NOTESCRI BE'
r oot . c onf i g( bac k gr ound=" #FFFFFF" )
r oot . wm_s t at e( " z oomed" )
m1 = PanedWi ndow( )
m1. c onf i g( bd=10,

bg=" #FFFFFF" , wi dt h=200)

m1. pac k ( f i l l =BOTH,

ex pand=1)

t op = Label ( m1, t ex t =" Wel c ome t o NOTESCRI BE A di s t r ac t i on- f r ee


t ex t edi t or
Pr ogr am by Ar v i ndc heenu. " , f ont =( " Hel v et i c a Neue" ,
20, ' bol d' ) , f or egr ound=' bl ac k ' , bac k gr ound=' whi t e' )
m1. add( t op)
c l as s Qui t t er ( Fr ame) :
def

__i ni t __( s el f ,

par ent =None) :

Fr ame. __i ni t __( s el f ,

par ent )

s el f . pac k ( )
def

qui t ( s el f ) :
ans = as k ok c anc el ( ' Ver i f y ex i t ' ,
i f

ans :

" Real l y qui t ?" )

Fr ame. qui t ( s el f )
7

c l as s Sc r ol l edTex t ( Fr ame) :
def

__i ni t __( s el f ,

par ent =None,

Fr ame. __i ni t __( s el f ,

t ex t =' ' ,

f i l e=None) :

par ent )

s el f . pac k ( ex pand=YES,

f i l l =BOTH)

s el f . c onf i g( bac k gr ound=' #FFFFFF' )


s el f . mak ewi dget s ( )
s el f . s et t ex t ( t ex t ,
def

f i l e)

mak ewi dget s ( s el f ) :


t ex t

= Tex t ( s el f ,

r el i ef =SUNKEN)

t ex t . pac k ( s i de=LEFT,
s el f . t ex t
def

f i l l =BOTH)

= t ex t

s et t ex t ( s el f ,
i f

ex pand=YES,

t ex t =' ' ,

f i l e=None) :

f i l e:
t ex t

= open( f i l e,

' r ' ) . r ead( )

s el f . t ex t . del et e( ' 1. 0' ,

END)

s el f . t ex t . i ns er t ( ' 1. 0' ,

t ex t )

s el f . t ex t . mar k _s et ( I NSERT,

' 1. 0' )

s el f . t ex t . f oc us ( )
def

get t ex t ( s el f ) :
r et ur n s el f . t ex t . get ( ' 1. 0' ,

END+' - 1c ' )

s av e= Phot oI mage( f i l e=" s av e. gi f " )


c ut

= Phot oI mage( f i l e=" c ut . gi f " )

pas t e = Phot oI mage( f i l e=" pas t e. gi f " )


bol d = Phot oI mage( f i l e=" bol d. gi f " )
i t al i c = Phot oI mage( f i l e=" i t al i c . gi f " )
s t r i k e = Phot oI mage( f i l e=" s t r i k e. gi f " )
hi ghl i ght = Phot oI mage( f i l e=" quot e. gi f " )
under l i ne = Phot oI mage( f i l e=" under l i ne. gi f " )
c l as s Si mpl eEdi t or ( Sc r ol l edTex t ) :

def

__i ni t __( s el f ,

par ent =None,

f i l e=None) :

f r m = Fr ame( par ent )


f r m. pac k ( f i l l =X, s i de=' r i ght ' )
f r m. c onf i g( bac k gr ound=" #FFFFFF" )
But t on( f r m, t ex t =' Sav e' , i mage= s av e,
c ommand=s el f . onSav e, hi ghl i ght bac k gr ound=' #FFFFFF' , bg=' #FFFFFF' ,
f g=' bl ac k ' , r el i ef =' f l at ' ) . pac k ( s i de=BOTTOM, pady =5, padx =10)
But t on( f r m, t ex t =' Cut ' , i mage= c ut ,
c ommand=s el f . onCut , hi ghl i ght bac k gr ound=' #FFFFFF' , bg=' #FFFFFF' ,
f g=' bl ac k ' , r el i ef =' f l at ' ) . pac k ( s i de=BOTTOM, pady =5, padx =10)
But t on( f r m, t ex t =' Pas t e' , i mage= pas t e,
c ommand=s el f . onPas t e, hi ghl i ght bac k gr ound=' #FFFFFF' , bg=' #FFFFFF' ,
f g=' bl ac k ' , r el i ef =' f l at ' ) . pac k ( s i de=BOTTOM, pady =5, padx =10)
But t on( f r m, t ex t =' I t al i c ' , i mage= i t al i c ,
c ommand=s el f . onI t al i c , hi ghl i ght bac k gr ound=' #FFFFFF' , bg=' #FFFFFF' ,
f g=' bl ac k ' , r el i ef =' f l at ' ) . pac k ( s i de=BOTTOM, pady =5, padx =10)
But t on( f r m, t ex t =' Bol d' , i mage= bol d,
c ommand=s el f . onBol d, hi ghl i ght bac k gr ound=' #FFFFFF' , bg=' #FFFFFF' ,
f g=' bl ac k ' , r el i ef =' f l at ' ) . pac k ( s i de=BOTTOM, pady =5, padx =10)
But t on( f r m, t ex t =' St r i k et hr ough' , i mage= s t r i k e,
c ommand=s el f . onSt r i k e, hi ghl i ght bac k gr ound=' ' #FFFFFF' , bg=' #FFFFFF' ' ,
f g=' bl ac k ' , r el i ef =' f l at ' ) . pac k ( s i de=BOTTOM, pady =5, padx =10)
But t on( f r m, t ex t =' Under l i ne' , i mage= under l i ne,
c ommand=s el f . onUnder l i ne, hi ghl i ght bac k gr ound=' #FFFFFF' , bg=' #FFFFFF' ,
f g=' bl ac k ' , r el i ef =' f l at ' ) . pac k ( s i de=BOTTOM, pady =5, padx =10)
But t on( f r m, t ex t =' Hi ghl i ght ' , i mage= hi ghl i ght ,
c ommand=s el f . onHi ghl i ght , hi ghl i ght bac k gr ound=' #FFFFFF' , bg=' #FFFFFF' ' ,
f g=' bl ac k ' , r el i ef =' f l at ' ) . pac k ( s i de=BOTTOM, pady =5, padx =10]
Sc r ol l edTex t . __i ni t __( s el f ,

par ent ,

f i l e=f i l e)

s el f . t ex t . c onf i g(
bor der wi dt h=0,
f ont =" { Hel v et i c a Neue} 40" ,
f or egr ound=" #000000" ,
bac k gr ound=" #FFFFFF" ,

i ns er t bac k gr ound=" bl ac k " ,

# c ur s or

s el ec t f or egr ound=" whi t e" ,

# s el ec t i on

hi ghl i ght t hi c k nes s =0,


s el ec t bac k gr ound=" bl ac k " ,
wr ap= WORD,

# us e wor d wr appi ng

undo=Tr ue,
wi dt h=64, )
def

onSav e( s el f ) :
f i l ename = as k s av eas f i l ename( )
i f

f i l ename:
al l t ex t

= s el f . get t ex t ( )

open( f i l ename,
def

' w' ) . wr i t e( al l t ex t )

onCut ( s el f ) :
t ex t

= s el f . t ex t . get ( SEL_FI RST,

s el f . t ex t . del et e( SEL_FI RST,

SEL_LAST)

SEL_LAST)

s el f . c l i pboar d_c l ear ( )


s el f . c l i pboar d_append( t ex t )
def

onPas t e( s el f ) :
t r y:
t ex t

= s el f . s el ec t i on_get ( s el ec t i on=' CLI PBOARD' )

s el f . t ex t . i ns er t ( I NSERT,
ex c ept

t ex t )

Tc l Er r or :

pas s
def

onI t al i c ( s el f ) :
s el f . t ex t . t ag_add( " y es wher e" ,

40,

SEL_FI RST, SEL_LAST)

i f s el f . t ex t . t ag_c onf i g( ' her e' , f ont =( ' Hel v et i c a Neue' ,


' bol d' ) , f or egr ound=" bl ac k " ) :

Neue' ,

40,

s el f . t ex t . t ag_c onf i g( ' y es wher e' , f ont =( ' Hel v et i c a


' bol d i t al i c ' ) , f or egr ound=" bl ac k " )

el s e:
10

Neue' ,

40,

def

s el f . t ex t . t ag_c onf i g( ' y es wher e' , f ont =( ' Hel v et i c a


' i t al i c ' ) , f or egr ound=" bl ac k " )

onBol d( s el f ) :
s el f . t ex t . t ag_add( " her e" ,

SEL_FI RST, SEL_LAST)

s el f . t ex t . t ag_c onf i g( ' her e' , f ont =( ' Hel v et i c a Neue' , 40,
' bol d' ) , f or egr ound=" bl ac k " )
def

onSt r i k e( s el f ] :
s el f . t ex t . t ag_add( " nowher e" ,

SEL_FI RST, SEL_LAST)

s el f . t ex t . t ag_c onf i g( ' nowher e' , f or egr ound=" bl ac k " ,


ov er s t r i k e=1)
def

onUnder l i ne( s el f ) :
s el f . t ex t . t ag_add( " t her e" , SEL_FI RST, SEL_LAST)

s el f . t ex t . t ag_c onf i g( " t her e" , f or egr ound=' bl ac k ' ,


under l i ne=1)
def

onHi ghl i ght ( s el f ) :


s el f . t ex t . t ag_add( " wher e" , SEL_FI RST, SEL_LAST)

s el f . t ex t . t ag_c onf i g( " wher e" ,


f or egr ound=" bl ac k " )
i f

bac k gr ound=" y el l ow" ,

__name__ == ' __mai n__' :


t r y:
Si mpl eEdi t or ( f i l e=s y s . ar gv [ 1] ) . mai nl oop( )
ex c ept

I ndex Er r or :

Si mpl eEdi t or ( ) . mai nl oop( )

11

Output Screens
Th e com p l et e Tex t w i d get :

#1

12

Qu ot e:

#2

Un d er l i n e:

#3

St r i k e t h r ou gh :

#4
13

I t al i c:

#5

Cu t an d Past e:

#6

14

Sav e Tex t d ocu m en t :

#7

15

Concl usi on
H en ce, th e a pyth on pr ogr am was wr itten to dem on str ate a
pr oject with th e u se of fil es, cl asses an d fu n ction s. Th is
pr ogr am featu r es th e car bon copy of a sim pl e text editor th at
en abl es easy an d fu n fil l ed wr itin g.
I th an k th e sch ool m an agem en t for givin g u s th e gol den
oppor tu n ity to wor k on a pr ogr am th at is r eal istic an d fil l ed
with fu n . I th an k ou r com pu ter scien ce teach er, M r s.Pavitr a
wh o h el ped u s an d su ppor ted u s in m ak in g th is pr oject a
gr eat su ccess. I fin al l y th an k th e m an agem en t for givin g u s
th e per m ission to wor k in ou r l abs an d ou r par en ts wh o h ave
su ppor ted u s an d h ave been in th e m ost ter r ibl e m om en ts of
ou r l ife an gu ided u s!

Bi bl i ograph y
-

Ncer t Pyth on Lab M an u al


Googl e an d W ik ipedia.
u sin gpyth on .com
on l in epyth on tu tor.com
codeacadem y.com
Cou r ser a cou r ses fr om Rice Un iver sity.
Im ages fr om googl e.

Th ank You.
Pr ogr am m er : Ar vin d Sr in ivasan
Cl ass: 12 A
Sch ool : Ar sh a Vidya M an dir

You might also like