Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
inovisao
pynovisao
Commits
56c1db36
Commit
56c1db36
authored
Aug 27, 2016
by
Alessandro dos Santos Ferreira
Browse files
PEP 8 -- Style Guide for Python Code
parent
5baa60fe
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
662 additions
and
419 deletions
+662
-419
src/interface/__init__.py
src/interface/__init__.py
+5
-1
src/interface/interface.py
src/interface/interface.py
+5
-4
src/interface/tk/__init__.py
src/interface/tk/__init__.py
+17
-1
src/interface/tk/tk_canvas.py
src/interface/tk/tk_canvas.py
+18
-22
src/interface/tk/tk_config.py
src/interface/tk/tk_config.py
+8
-9
src/interface/tk/tk_customdialog.py
src/interface/tk/tk_customdialog.py
+137
-0
src/interface/tk/tk_customframe.py
src/interface/tk/tk_customframe.py
+11
-10
src/interface/tk/tk_itemmenu.py
src/interface/tk/tk_itemmenu.py
+4
-4
src/interface/tk/tk_logger.py
src/interface/tk/tk_logger.py
+46
-0
src/interface/tk/tk_menu.py
src/interface/tk/tk_menu.py
+11
-11
src/interface/tk/tk_utils.py
src/interface/tk/tk_utils.py
+4
-4
src/interface/tk_interface.py
src/interface/tk_interface.py
+233
-0
src/main.py
src/main.py
+10
-9
src/pynovisao.py
src/pynovisao.py
+71
-57
src/segmentation/__init__.py
src/segmentation/__init__.py
+21
-1
src/segmentation/segmenter.py
src/segmentation/segmenter.py
+6
-5
src/segmentation/slic.py
src/segmentation/slic.py
+37
-34
src/util/X11Colors.py
src/util/X11Colors.py
+0
-235
src/util/__init__.py
src/util/__init__.py
+9
-1
src/util/config.py
src/util/config.py
+9
-11
No files found.
src/interface/__init__.py
View file @
56c1db36
__all__
=
[
"Interface"
,
"TkInterface"
]
\ No newline at end of file
from
interface
import
Interface
,
InterfaceException
from
tk_interface
import
TkInterface
__all__
=
[
"interface"
,
"tk_interface"
]
\ No newline at end of file
src/interface/
I
nterface.py
→
src/interface/
i
nterface.py
View file @
56c1db36
...
...
@@ -2,11 +2,12 @@
# -*- coding: utf-8 -*-
#
"""
Nome: I
nterface.
py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: Classe abstrata para os modulos de interface.
Abstract class for graphical i
nterface.
Name: interface.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
traceback
from
abc
import
ABCMeta
,
abstractmethod
...
...
src/interface/tk/__init__.py
View file @
56c1db36
__all__
=
[
"TkCanvas"
,
"TkConfig"
,
"TkCustomDialog"
,
"TkCustomFrame"
,
"TkLogger"
,
"TkMenu"
,
"TkItemMenu"
,
"TkUtils"
]
\ No newline at end of file
from
tk_canvas
import
Image
from
tk_config
import
TkConfig
from
tk_customdialog
import
SimpleDialog
,
ConfigDialog
,
ChooseOneDialog
from
tk_customframe
import
CustomGrid
from
tk_logger
import
Log
from
tk_menu
import
Menu
from
tk_itemmenu
import
ItemMenu
,
Command
,
Separator
,
CheckButton
from
tk_utils
import
Utils
__all__
=
[
"tk_canvas"
,
"tk_config"
,
"tk_customdialog"
,
"tk_customframe"
,
"tk_logger"
,
"tk_menu"
,
"tk_itemmenu"
,
"tk_utils"
]
src/interface/tk/
TkC
anvas.py
→
src/interface/tk/
tk_c
anvas.py
View file @
56c1db36
...
...
@@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
#
"""
Nome: TkCanvas.py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: TODO
Provides structured graphics interface from Tkinter package.
Name: tk_canvas.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
sys
...
...
@@ -22,10 +22,6 @@ from matplotlib import pylab as plt
class
Image
(
object
):
parent
=
None
__im
=
None
__canvas
=
None
def
__init__
(
self
,
parent
,
image
,
onclick
=
None
):
self
.
parent
=
parent
...
...
@@ -33,36 +29,36 @@ class Image(object):
self
.
parent
.
image
=
image
fig
=
plt
.
figure
(
facecolor
=
'white'
,
edgecolor
=
'black'
,
linewidth
=
1
)
self
.
_
_
im
=
plt
.
imshow
(
self
.
parent
.
image
)
# later use a.set_data(new_data)
self
.
_im
=
plt
.
imshow
(
self
.
parent
.
image
)
# later use a.set_data(new_data)
#ax = plt.gca()
#ax.set_xticklabels([])
#ax.set_yticklabels([])
# a tk.DrawingArea
self
.
_
_
canvas
=
FigureCanvasTkAgg
(
fig
,
master
=
self
.
parent
)
self
.
_
_
canvas
.
show
()
self
.
_
_
canvas
.
get_tk_widget
().
pack
(
side
=
Tk
.
TOP
,
fill
=
Tk
.
BOTH
,
expand
=
1
)
self
.
_canvas
=
FigureCanvasTkAgg
(
fig
,
master
=
self
.
parent
)
self
.
_canvas
.
show
()
self
.
_canvas
.
get_tk_widget
().
pack
(
side
=
Tk
.
TOP
,
fill
=
Tk
.
BOTH
,
expand
=
1
)
if
onclick
is
not
None
:
fig
.
canvas
.
mpl_connect
(
'button_press_event'
,
func
=
onclick
)
def
refresh
(
self
,
image
):
if
self
.
_
_
canvas
is
not
None
:
if
self
.
_canvas
is
not
None
:
self
.
parent
.
image
=
image
self
.
_
_
im
.
set_data
(
self
.
parent
.
image
)
self
.
_
_
canvas
.
draw
()
self
.
_im
.
set_data
(
self
.
parent
.
image
)
self
.
_canvas
.
draw
()
def
close
(
self
):
if
self
.
_
_
canvas
is
not
None
:
if
self
.
_canvas
is
not
None
:
self
.
parent
.
image
=
None
#self._
_
im.set_data(np.zeros((0,0,3), float))
#self._
_
canvas.draw()
self
.
_
_
canvas
.
get_tk_widget
().
pack_forget
();
self
.
_
_
canvas
.
get_tk_widget
().
destroy
();
#self._im.set_data(np.zeros((0,0,3), float))
#self._canvas.draw()
self
.
_canvas
.
get_tk_widget
().
pack_forget
();
self
.
_canvas
.
get_tk_widget
().
destroy
();
self
.
_
_
im
=
None
self
.
_
_
canvas
=
None
self
.
_im
=
None
self
.
_canvas
=
None
return
True
return
False
src/interface/tk/
TkC
onfig.py
→
src/interface/tk/
tk_c
onfig.py
View file @
56c1db36
...
...
@@ -2,20 +2,19 @@
# -*- coding: utf-8 -*-
#
"""
Nome: TkConfig.py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: TODO
Extends util.config.Config with tk_entry field.
Name: tk_config.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
from
util.
C
onfig
import
Config
from
util.
c
onfig
import
Config
class
TkConfig
(
Config
):
tk_entry
=
None
def
__init__
(
self
,
label
,
value
,
c_type
,
tk_entry
=
None
,
hidden
=
False
,
min_value
=
None
,
max_value
=
None
):
super
(
self
.
__class__
,
self
).
__init__
(
label
,
value
,
c_type
,
hidden
,
min_value
,
max_value
)
def
__init__
(
self
,
label
,
value
,
c_type
,
tk_entry
=
None
,
hidden
=
False
,
meta
=
None
):
super
(
self
.
__class__
,
self
).
__init__
(
label
,
value
,
c_type
,
hidden
,
meta
)
self
.
tk_entry
=
tk_entry
def
get_entry_val
(
self
):
...
...
src/interface/tk/
TkC
ustom
D
ialog.py
→
src/interface/tk/
tk_c
ustom
d
ialog.py
View file @
56c1db36
...
...
@@ -2,11 +2,12 @@
# -*- coding: utf-8 -*-
#
"""
Nome: TkCustomDialog.py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: Classe que customiza as janelas de dialogo da biblioteca TkInter.
Provides customized dialogs extending Tkinter.Toplevel.
Name: tk_customdialog.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
sys
if
sys
.
version_info
[
0
]
<
3
:
import
Tkinter
as
Tk
...
...
@@ -15,12 +16,11 @@ else:
from
collections
import
OrderedDict
from
TkC
onfig
import
TkConfig
from
tk_c
onfig
import
TkConfig
class
SimpleDialog
(
Tk
.
Toplevel
):
parent
=
None
def
__init__
(
self
,
parent
,
title
=
None
,
command_ok
=
None
):
self
.
parent
=
parent
...
...
@@ -40,18 +40,18 @@ class SimpleDialog(Tk.Toplevel):
class
ConfigDialog
(
SimpleDialog
):
__configs
=
None
def
__init__
(
self
,
parent
,
title
=
None
,
configs
=
None
,
command_ok
=
None
):
SimpleDialog
.
__init__
(
self
,
parent
,
title
,
command_ok
)
self
.
_configs
=
None
if
configs
is
not
None
:
self
.
add_configs
(
configs
,
command_ok
)
def
add_configs
(
self
,
configs
,
command_ok
):
row
=
0
self
.
_
_
configs
=
OrderedDict
()
self
.
_configs
=
OrderedDict
()
for
key
in
configs
:
if
configs
[
key
].
hidden
==
False
:
Tk
.
Label
(
self
,
text
=
configs
[
key
].
label
).
grid
(
row
=
row
,
padx
=
4
,
pady
=
4
,
sticky
=
Tk
.
W
)
...
...
@@ -63,9 +63,9 @@ class ConfigDialog(SimpleDialog):
entry
.
focus_set
()
row
+=
1
self
.
_
_
configs
[
key
]
=
TkConfig
(
configs
[
key
].
label
,
configs
[
key
].
value
,
c_type
=
configs
[
key
].
c_type
,
tk_entry
=
entry
,
hidden
=
configs
[
key
].
hidden
)
self
.
_configs
[
key
]
=
TkConfig
(
configs
[
key
].
label
,
configs
[
key
].
value
,
c_type
=
configs
[
key
].
c_type
,
tk_entry
=
entry
,
hidden
=
configs
[
key
].
hidden
,
meta
=
configs
[
key
].
meta
)
else
:
self
.
_
_
configs
[
key
]
=
TkConfig
(
configs
[
key
].
label
,
configs
[
key
].
value
,
c_type
=
configs
[
key
].
c_type
,
hidden
=
configs
[
key
].
hidden
)
self
.
_configs
[
key
]
=
TkConfig
(
configs
[
key
].
label
,
configs
[
key
].
value
,
c_type
=
configs
[
key
].
c_type
,
hidden
=
configs
[
key
].
hidden
,
meta
=
configs
[
key
].
meta
)
B1
=
Tk
.
Button
(
self
,
text
=
"Ok"
,
width
=
5
,
command
=
command_ok
)
B1
.
grid
(
row
=
row
,
padx
=
6
,
pady
=
6
,
sticky
=
Tk
.
W
)
...
...
@@ -79,8 +79,59 @@ class ConfigDialog(SimpleDialog):
def
update_and_validate_configs
(
self
):
for
key
in
self
.
__configs
:
self
.
__configs
[
key
].
value
=
self
.
__configs
[
key
].
get_entry_val
()
for
key
in
self
.
_configs
:
self
.
_configs
[
key
].
value
=
self
.
_configs
[
key
].
get_entry_val
()
def
get_configs
(
self
):
return
self
.
_configs
class
ChooseOneDialog
(
SimpleDialog
):
def
__init__
(
self
,
parent
,
title
=
None
,
configs
=
None
,
command_ok
=
None
):
SimpleDialog
.
__init__
(
self
,
parent
,
title
,
command_ok
)
self
.
v
=
Tk
.
StringVar
()
self
.
_configs
=
None
if
configs
is
not
None
:
self
.
add_configs
(
configs
,
command_ok
)
def
add_configs
(
self
,
configs
,
command_ok
):
row
=
0
self
.
_configs
=
OrderedDict
()
for
key
in
configs
:
if
configs
[
key
].
hidden
==
False
:
Tk
.
Label
(
self
,
text
=
configs
[
key
].
label
).
grid
(
row
=
row
,
padx
=
4
,
pady
=
4
,
sticky
=
Tk
.
W
)
radio
=
Tk
.
Radiobutton
(
self
,
text
=
configs
[
key
].
label
,
value
=
key
,
variable
=
self
.
v
,
width
=
25
,
bg
=
'white'
,
fg
=
'black'
,
padx
=
4
,
pady
=
4
,
indicatoron
=
1
,
anchor
=
Tk
.
W
,
activebackground
=
'white'
,
activeforeground
=
'black'
,
highlightbackground
=
'white'
)
radio
.
grid
(
row
=
row
,
padx
=
4
,
pady
=
4
,
sticky
=
Tk
.
W
)
if
configs
[
key
].
value
==
True
:
radio
.
select
()
row
+=
1
self
.
_configs
[
key
]
=
TkConfig
(
configs
[
key
].
label
,
configs
[
key
].
value
,
c_type
=
configs
[
key
].
c_type
,
tk_entry
=
radio
,
hidden
=
configs
[
key
].
hidden
,
meta
=
configs
[
key
].
meta
)
else
:
self
.
_configs
[
key
]
=
TkConfig
(
configs
[
key
].
label
,
configs
[
key
].
value
,
c_type
=
configs
[
key
].
c_type
,
hidden
=
configs
[
key
].
hidden
,
meta
=
configs
[
key
].
meta
)
B1
=
Tk
.
Button
(
self
,
text
=
"Ok"
,
width
=
5
,
command
=
command_ok
)
B1
.
grid
(
row
=
row
,
padx
=
6
,
pady
=
6
,
sticky
=
Tk
.
W
+
Tk
.
E
)
self
.
bind
(
"<Return>"
,
command_ok
)
#B2 = Tk.Button(self, text="Cancel", width=5, command = self.destroy)
#B2.grid(row=row+1, column=0, padx=6, pady=6, sticky=Tk.W)
self
.
bind
(
"<Escape>"
,
lambda
*
_
:
self
.
destroy
())
def
update_and_validate_configs
(
self
):
for
key
in
self
.
_configs
:
self
.
_configs
[
key
].
value
=
False
self
.
_configs
[
self
.
v
.
get
()].
value
=
True
def
get_configs
(
self
):
return
self
.
_
_
configs
return
self
.
_configs
src/interface/tk/
TkC
ustom
F
rame.py
→
src/interface/tk/
tk_c
ustom
f
rame.py
View file @
56c1db36
...
...
@@ -2,25 +2,23 @@
# -*- coding: utf-8 -*-
#
"""
Nome: TkCustom
Frame.
py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: TODO.
Provides customized grids extending Tkinter.
Frame.
Name: tk_customframe.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
sys
if
sys
.
version_info
[
0
]
<
3
:
import
Tkinter
as
Tk
else
:
import
tkinter
as
Tk
from
TkUtils
import
Utils
from
util.X11Colors
import
Colors
from
tk_utils
import
Utils
from
util.x11_colors
import
X11Colors
class
CustomGrid
(
Tk
.
Frame
):
parent
=
None
v
=
None
def
__init__
(
self
,
parent
,
width
=
0
,
height
=
0
,
bg
=
'white'
):
self
.
parent
=
parent
...
...
@@ -30,18 +28,21 @@ class CustomGrid(Tk.Frame):
Tk
.
Frame
.
__init__
(
self
,
self
.
parent
,
width
=
width
,
height
=
height
,
bg
=
bg
)
def
add_cell_label
(
self
,
text
,
row
,
column
,
width
=
0
,
height
=
0
,
bg
=
'white'
,
fg
=
"black"
):
Tk
.
Label
(
self
,
text
=
text
,
width
=
width
,
height
=
height
,
bg
=
bg
,
fg
=
fg
,
padx
=
4
,
pady
=
4
).
grid
(
row
=
row
,
column
=
column
)
def
add_cell_button_color
(
self
,
text
,
row
,
column
,
width
=
0
,
height
=
0
,
bg
=
'white'
,
fg
=
"black"
,
command
=
None
,
command_args
=
None
):
bg_color
=
Colors
.
get_color_hex
(
bg
)
bg_color
=
X11
Colors
.
get_color_hex
(
bg
)
bt
=
Tk
.
Button
(
self
,
text
=
text
,
width
=
width
,
height
=
height
,
bg
=
bg_color
,
fg
=
fg
,
padx
=
0
,
pady
=
0
,
cursor
=
"hand1"
,
command
=
lambda
*
_
:
command
(
command_args
))
bt
.
grid
(
row
=
row
,
column
=
column
)
def
add_cell_radio_button
(
self
,
text
,
value
,
row
,
column
,
width
=
0
,
height
=
0
,
bg
=
'white'
,
fg
=
"black"
,
selected
=
False
,
command
=
None
,
command_args
=
None
):
radio
=
Tk
.
Radiobutton
(
self
,
text
=
text
,
variable
=
self
.
v
,
value
=
value
,
...
...
src/interface/tk/
TkI
tem
M
enu.py
→
src/interface/tk/
tk_i
tem
m
enu.py
View file @
56c1db36
...
...
@@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
#
"""
Nome:
ItemMenu.
py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: TODO
Implements all items from menu inheriting from abstract class
ItemMenu.
Name: main.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
sys
if
sys
.
version_info
[
0
]
<
3
:
...
...
src/interface/tk/
TkL
ogger.py
→
src/interface/tk/
tk_l
ogger.py
View file @
56c1db36
...
...
@@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
#
"""
Nome: Logger.py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: TODO
Creates a log on bottom of window using a Tkinter.Text.
Name: tk_logger.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
sys
...
...
@@ -14,18 +14,15 @@ if sys.version_info[0] < 3:
else
:
import
tkinter
as
Tk
class
Logger
(
object
):
parent
=
None
class
Log
(
object
):
__body
=
None
def
__init__
(
self
,
parent
):
self
.
parent
=
parent
self
.
_
_
body
=
Tk
.
Text
(
self
.
parent
,
width
=
0
,
height
=
10
,
bg
=
"white"
,
fg
=
"black"
,
padx
=
5
,
pady
=
5
)
self
.
_
_
body
.
insert
(
Tk
.
INSERT
,
"$ Pynovisao is ready to use!
\n
"
)
self
.
_
_
body
.
config
(
state
=
Tk
.
DISABLED
)
self
.
_
_
body
.
pack
(
side
=
Tk
.
BOTTOM
,
fill
=
Tk
.
X
,
expand
=
False
)
self
.
_body
=
Tk
.
Text
(
self
.
parent
,
width
=
0
,
height
=
10
,
bg
=
"white"
,
fg
=
"black"
,
padx
=
5
,
pady
=
5
)
self
.
_body
.
insert
(
Tk
.
INSERT
,
"$ Pynovisao is ready to use!
\n
"
)
self
.
_body
.
config
(
state
=
Tk
.
DISABLED
)
self
.
_body
.
pack
(
side
=
Tk
.
BOTTOM
,
fill
=
Tk
.
X
,
expand
=
False
)
def
write_logger
(
self
,
fmt
,
*
args
):
...
...
@@ -33,17 +30,17 @@ class Logger(object):
self
.
append_logger
(
fmt
%
args
)
def
append_logger
(
self
,
fmt
,
*
args
):
self
.
_
_
body
.
config
(
state
=
Tk
.
NORMAL
)
self
.
_
_
body
.
insert
(
Tk
.
END
,
fmt
%
args
)
self
.
_
_
body
.
insert
(
Tk
.
END
,
'
\n
'
)
self
.
_
_
body
.
config
(
state
=
Tk
.
DISABLED
)
self
.
_body
.
config
(
state
=
Tk
.
NORMAL
)
self
.
_body
.
insert
(
Tk
.
END
,
fmt
%
args
)
self
.
_body
.
insert
(
Tk
.
END
,
'
\n
'
)
self
.
_body
.
config
(
state
=
Tk
.
DISABLED
)
def
clear_logger
(
self
):
self
.
_
_
body
.
config
(
state
=
Tk
.
NORMAL
)
self
.
_
_
body
.
delete
(
'1.0'
,
Tk
.
END
)
self
.
_
_
body
.
insert
(
'1.0'
,
'$ '
)
self
.
_
_
body
.
config
(
state
=
Tk
.
DISABLED
)
self
.
_body
.
config
(
state
=
Tk
.
NORMAL
)
self
.
_body
.
delete
(
'1.0'
,
Tk
.
END
)
self
.
_body
.
insert
(
'1.0'
,
'$ '
)
self
.
_body
.
config
(
state
=
Tk
.
DISABLED
)
def
destroy_logger
(
self
):
self
.
_
_
body
.
pack_forget
();
self
.
_
_
body
.
destroy
();
self
.
_body
.
pack_forget
();
self
.
_body
.
destroy
();
src/interface/tk/
TkM
enu.py
→
src/interface/tk/
tk_m
enu.py
View file @
56c1db36
...
...
@@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
#
"""
Nome: Menu.py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: TODO
Provides menu structure functionalities.
Name: tk_menu.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
sys
...
...
@@ -14,33 +14,33 @@ if sys.version_info[0] < 3:
else
:
import
tkinter
as
Tk
from
TkI
tem
M
enu
import
*
from
tk_i
tem
m
enu
import
*
class
Menu
(
object
):
parent
=
None
label
=
None
_
_items_menu
=
None
_items_menu
=
None
def
__init__
(
self
,
parent
,
label
):
self
.
parent
=
parent
self
.
label
=
label
self
.
_
_
items_menu
=
[]
self
.
_items_menu
=
[]
def
add_command
(
self
,
label
,
action
,
shortcut
):
self
.
_
_
items_menu
.
append
(
Command
(
self
,
label
,
action
,
shortcut
)
)
self
.
_items_menu
.
append
(
Command
(
self
,
label
,
action
,
shortcut
)
)
def
add_separator
(
self
):
self
.
_
_
items_menu
.
append
(
Separator
(
self
)
)
self
.
_items_menu
.
append
(
Separator
(
self
)
)
def
add_check_button
(
self
,
label
,
action
,
shortcut
):
self
.
_
_
items_menu
.
append
(
CheckButton
(
self
,
label
,
action
,
shortcut
)
)
self
.
_items_menu
.
append
(
CheckButton
(
self
,
label
,
action
,
shortcut
)
)
def
render
(
self
,
menubar
):
menu
=
Tk
.
Menu
(
menubar
,
tearoff
=
0
)
for
item
in
self
.
_
_
items_menu
:
for
item
in
self
.
_items_menu
:
item
.
render
(
menu
)
if
item
.
shortcut
is
not
None
:
...
...
src/interface/tk/
TkU
tils.py
→
src/interface/tk/
tk_u
tils.py
View file @
56c1db36
...
...
@@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
#
"""
Nome: TkUtils.py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: TODO
Provides static method utilities from Tkinter package.
Name: tk_utils.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
os
import
tkMessageBox
,
Tkconstants
,
tkFileDialog
...
...
src/interface/
TkI
nterface.py
→
src/interface/
tk_i
nterface.py
View file @
56c1db36
...
...
@@ -2,11 +2,12 @@
# -*- coding: utf-8 -*-
#
"""
Nome:
Tk
I
nter
face.py
Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
Descricão: Classe que implementa os modulos de interface utilizando a biblioteca TkInter.
Implements graphical interface using
Tk
i
nter
package modules.
Name: main.py
Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
import
sys
if
sys
.
version_info
[
0
]
<
3
:
import
Tkinter
as
Tk
...
...
@@ -14,138 +15,135 @@ else:
import
tkinter
as
Tk
import
tkMessageBox
from
Interface
import
Interface
,
InterfaceException
as
IException
from
tk
import
*
import
tk
as
tk_local
from
interface
import
Interface
,
InterfaceException
as
IException
class
TkInterface
(
Interface
):
MAX_CLASSES
=
20
utils
=
TkUtils
.
Utils
title
=
None
__root
=
None
__menus
=
None
__image
=
None
__grid
=
None
__logger
=
None
utils
=
tk_local
.
Utils
def
__init__
(
self
,
title
):
self
.
title
=
title
self
.
_
_
root
=
Tk
.
Tk
()
self
.
_
_
root
.
wm_title
(
self
.
title
)
self
.
_
_
root
.
geometry
(
'%dx%d+%d+%d'
%
(
800
,
600
,
0
,
0
))
self
.
_root
=
Tk
.
Tk
()
self
.
_root
.
wm_title
(
self
.
title
)
self
.
_root
.
geometry
(
'%dx%d+%d+%d'
%
(
800
,
600
,
0
,
0
))
self
.
__menus
=
[]
self
.
_menus
=
[]
self
.
_image
=
None
self
.
_grid
=
None
self
.
_logger
=
None
self
.
_conf_dialog
=
None
def
set_subtitle
(
self
,
subtitle
):
self
.
_
_
root
.
wm_title
(
self
.
title
+
' - '
+
subtitle
)
self
.
_root
.
wm_title
(
self
.
title
+
' - '
+
subtitle
)
def
add_menu
(
self
,
label
):
self
.
_
_
menus
.
append
(
TkMenu
.
Menu
(
self
.
_
_
root
,
label
)
)
self
.
_menus
.
append
(
tk_local
.
Menu
(
self
.
_root
,
label
)
)
def
add_command
(
self
,
label
,
action
,
shortcut
=
None
):
self
.
_
_
menus
[
-
1
].
add_command
(
label
=
label
,
action
=
lambda
*
_
:
self
.
_
_
apply
(
action
),
shortcut
=
shortcut
)
self
.
_menus
[
-
1
].
add_command
(
label
=
label
,
action
=
lambda
*
_
:
self
.
_apply
(
action
),
shortcut
=
shortcut
)
def
add_separator
(
self
):
self
.
_
_
menus
[
-
1
].
add_separator
(
)
self
.
_menus
[
-
1
].
add_separator
(
)
def
add_check_button
(
self
,
label
,
action
,
shortcut
=
None
):
self
.
_
_
menus
[
-
1
].
add_check_button
(
label
=
label
,
action
=
lambda
*
_
:
self
.
_
_
apply
(
action
),
shortcut
=
shortcut
)
self
.
_menus
[
-
1
].
add_check_button
(
label
=
label
,
action
=
lambda
*
_
:
self
.
_apply
(
action
),
shortcut
=
shortcut
)
def
render_menu
(
self
):
menubar
=
Tk
.
Menu
(
self
.
_
_
root
)
menubar
=
Tk
.
Menu
(
self
.
_root
)
for
menu
in
self
.
_
_
menus
:
for
menu
in
self
.
_menus
:
menu
.
render
(
menubar
)
self
.
_
_
root
.
config
(
menu
=
menubar
)
self
.
_root
.
config
(
menu
=
menubar
)
def
add_image
(
self
,
image
,
title
=
None
,
onclick
=
None
):
if
self
.
_
_
image
is
not
None
:
self
.
_
_
image
.
close
()
if
self
.
_image
is
not
None
:
self
.
_image
.
close
()
self
.
_
_
image
=
TkCanvas
.
Image
(
self
.
_
_
root
,
image
,
lambda
event
,
*
_
:
self
.
_
_
apply
(
onclick
,
event
))
self
.
_image
=
tk_local
.
Image
(
self
.
_root
,
image
,
lambda
event
,
*
_
:
self
.
_apply
(
onclick
,
event
))
if
title
is
not
None
:
self
.
set_subtitle
(
title
)
def
refresh_image
(
self
,
image
,
title
=
None
):
if
self
.
_
_
image
is
not
None
:
self
.
_
_
image
.
refresh
(
image
)
if
self
.
_image
is
not
None
:
self
.
_image
.
refresh
(
image
)