Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pyMKcam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
pyMKcam
Commits
31c4d85e
Commit
31c4d85e
authored
Jun 18, 2012
by
Lars Kruse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify UI related lists (ListPluginBase)
* duplicate code removed * marked as gtk-specific
parent
2f58933a
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
136 additions
and
211 deletions
+136
-211
Bounds.py
pycam/Plugins/Bounds.py
+15
-38
Models.py
pycam/Plugins/Models.py
+8
-25
Processes.py
pycam/Plugins/Processes.py
+10
-34
Tasks.py
pycam/Plugins/Tasks.py
+7
-37
Toolpaths.py
pycam/Plugins/Toolpaths.py
+4
-20
Tools.py
pycam/Plugins/Tools.py
+11
-36
__init__.py
pycam/Plugins/__init__.py
+65
-9
bounds.ui
share/ui/bounds.ui
+2
-2
models.ui
share/ui/models.ui
+2
-2
processes.ui
share/ui/processes.ui
+5
-3
tasks.ui
share/ui/tasks.ui
+5
-3
tools.ui
share/ui/tools.ui
+2
-2
No files found.
pycam/Plugins/Bounds.py
View file @
31c4d85e
...
@@ -34,7 +34,6 @@ class Bounds(pycam.Plugins.ListPluginBase):
...
@@ -34,7 +34,6 @@ class Bounds(pycam.Plugins.ListPluginBase):
UI_FILE
=
"bounds.ui"
UI_FILE
=
"bounds.ui"
DEPENDS
=
[
"Models"
]
DEPENDS
=
[
"Models"
]
CATEGORIES
=
[
"Bounds"
]
CATEGORIES
=
[
"Bounds"
]
COLUMN_REF
=
0
# mapping of boundary types and GUI control elements
# mapping of boundary types and GUI control elements
BOUNDARY_TYPES
=
{
BOUNDARY_TYPES
=
{
...
@@ -57,29 +56,19 @@ class Bounds(pycam.Plugins.ListPluginBase):
...
@@ -57,29 +56,19 @@ class Bounds(pycam.Plugins.ListPluginBase):
bounds_box
.
unparent
()
bounds_box
.
unparent
()
self
.
core
.
register_ui
(
"main"
,
"Bounds"
,
bounds_box
,
30
)
self
.
core
.
register_ui
(
"main"
,
"Bounds"
,
bounds_box
,
30
)
self
.
_boundsview
=
self
.
gui
.
get_object
(
"BoundsTable"
)
self
.
_boundsview
=
self
.
gui
.
get_object
(
"BoundsTable"
)
self
.
_gtk_handlers
=
[]
self
.
set_gtk_modelview
(
self
.
_boundsview
)
self
.
_gtk_handlers
.
append
((
self
.
_boundsview
.
get_selection
(),
self
.
register_model_update
(
lambda
:
"changed"
,
"bounds-selection-changed"
))
self
.
core
.
emit_event
(
"bounds-list-changed"
))
self
.
_treemodel
=
self
.
_boundsview
.
get_model
()
self
.
_treemodel
.
clear
()
def
update_model
():
if
not
hasattr
(
self
,
"_model_cache"
):
self
.
_model_cache
=
{}
cache
=
self
.
_model_cache
for
row
in
self
.
_treemodel
:
cache
[
row
[
self
.
COLUMN_REF
]]
=
list
(
row
)
self
.
_treemodel
.
clear
()
for
index
,
item
in
enumerate
(
self
):
if
not
id
(
item
)
in
cache
:
cache
[
id
(
item
)]
=
[
id
(
item
)]
self
.
_treemodel
.
append
(
cache
[
id
(
item
)])
self
.
core
.
emit_event
(
"bounds-list-changed"
)
self
.
register_model_update
(
update_model
)
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"BoundsMoveUp"
),
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"BoundsMoveUp"
),
(
self
.
ACTION_DOWN
,
"BoundsMoveDown"
),
(
self
.
ACTION_DOWN
,
"BoundsMoveDown"
),
(
self
.
ACTION_DELETE
,
"BoundsDelete"
)):
(
self
.
ACTION_DELETE
,
"BoundsDelete"
)):
self
.
register_list_action_button
(
action
,
self
.
_boundsview
,
self
.
register_list_action_button
(
action
,
self
.
gui
.
get_object
(
obj_name
))
self
.
gui
.
get_object
(
obj_name
))
self
.
_treemodel
=
self
.
_boundsview
.
get_model
()
self
.
_treemodel
.
clear
()
self
.
_gtk_handlers
=
[]
self
.
_gtk_handlers
.
append
((
self
.
_boundsview
.
get_selection
(),
"changed"
,
"bounds-selection-changed"
))
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"BoundsNew"
),
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"BoundsNew"
),
"clicked"
,
self
.
_bounds_new
))
"clicked"
,
self
.
_bounds_new
))
# model selector
# model selector
...
@@ -159,16 +148,6 @@ class Bounds(pycam.Plugins.ListPluginBase):
...
@@ -159,16 +148,6 @@ class Bounds(pycam.Plugins.ListPluginBase):
while
len
(
self
)
>
0
:
while
len
(
self
)
>
0
:
self
.
pop
()
self
.
pop
()
def
get_selected
(
self
,
index
=
False
):
return
self
.
_get_selected
(
self
.
_boundsview
,
index
=
index
)
def
select
(
self
,
bounds
):
if
bounds
in
self
:
selection
=
self
.
_boundsview
.
get_selection
()
index
=
[
id
(
b
)
for
b
in
self
]
.
index
(
id
(
bounds
))
selection
.
unselect_all
()
selection
.
select_path
((
index
,))
def
get_selected_models
(
self
,
index
=
False
):
def
get_selected_models
(
self
,
index
=
False
):
return
self
.
models_control
.
get_value
()
return
self
.
models_control
.
get_value
()
...
@@ -176,8 +155,9 @@ class Bounds(pycam.Plugins.ListPluginBase):
...
@@ -176,8 +155,9 @@ class Bounds(pycam.Plugins.ListPluginBase):
self
.
models_control
.
set_value
(
models
)
self
.
models_control
.
set_value
(
models
)
def
_render_bounds_size
(
self
,
column
,
cell
,
model
,
m_iter
):
def
_render_bounds_size
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
bounds
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
bounds
=
self
[
path
[
0
]]
if
not
bounds
:
return
low
,
high
=
bounds
.
get_absolute_limits
()
low
,
high
=
bounds
.
get_absolute_limits
()
if
None
in
low
or
None
in
high
:
if
None
in
low
or
None
in
high
:
text
=
""
text
=
""
...
@@ -186,8 +166,7 @@ class Bounds(pycam.Plugins.ListPluginBase):
...
@@ -186,8 +166,7 @@ class Bounds(pycam.Plugins.ListPluginBase):
cell
.
set_property
(
"text"
,
text
)
cell
.
set_property
(
"text"
,
text
)
def
_render_bounds_name
(
self
,
column
,
cell
,
model
,
m_iter
):
def
_render_bounds_name
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
bounds
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
bounds
=
self
[
path
[
0
]]
cell
.
set_property
(
"text"
,
bounds
[
"name"
])
cell
.
set_property
(
"text"
,
bounds
[
"name"
])
def
_trigger_table_update
(
self
):
def
_trigger_table_update
(
self
):
...
@@ -392,10 +371,8 @@ class Bounds(pycam.Plugins.ListPluginBase):
...
@@ -392,10 +371,8 @@ class Bounds(pycam.Plugins.ListPluginBase):
self
.
select
(
new_bounds
)
self
.
select
(
new_bounds
)
def
_edit_bounds_name
(
self
,
cell
,
path
,
new_text
):
def
_edit_bounds_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
bounds
=
self
.
get_by_path
(
path
)
bounds_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
if
bounds
and
(
new_text
!=
bounds
[
"name"
])
and
new_text
:
bounds
=
[
bound
for
bound
in
self
if
id
(
bound
)
==
bounds_ref
]
if
(
new_text
!=
bounds
[
"name"
])
and
new_text
:
bounds
[
"name"
]
=
new_text
bounds
[
"name"
]
=
new_text
...
...
pycam/Plugins/Models.py
View file @
31c4d85e
...
@@ -33,7 +33,6 @@ class Models(pycam.Plugins.ListPluginBase):
...
@@ -33,7 +33,6 @@ class Models(pycam.Plugins.ListPluginBase):
UI_FILE
=
"models.ui"
UI_FILE
=
"models.ui"
CATEGORIES
=
[
"Model"
]
CATEGORIES
=
[
"Model"
]
COLUMN_REF
=
0
ICONS
=
{
"visible"
:
"visible.svg"
,
"hidden"
:
"visible_off.svg"
}
ICONS
=
{
"visible"
:
"visible.svg"
,
"hidden"
:
"visible_off.svg"
}
FALLBACK_COLOR
=
{
"red"
:
0.5
,
"green"
:
0.5
,
"blue"
:
1.0
,
"alpha"
:
1.0
}
FALLBACK_COLOR
=
{
"red"
:
0.5
,
"green"
:
0.5
,
"blue"
:
1.0
,
"alpha"
:
1.0
}
...
@@ -53,11 +52,14 @@ class Models(pycam.Plugins.ListPluginBase):
...
@@ -53,11 +52,14 @@ class Models(pycam.Plugins.ListPluginBase):
self
.
core
.
register_ui_section
(
"model_handling"
,
self
.
core
.
register_ui_section
(
"model_handling"
,
add_model_handling_item
,
clear_model_handling_obj
)
add_model_handling_item
,
clear_model_handling_obj
)
self
.
_modelview
=
self
.
gui
.
get_object
(
"ModelView"
)
self
.
_modelview
=
self
.
gui
.
get_object
(
"ModelView"
)
self
.
set_gtk_modelview
(
self
.
_modelview
)
self
.
register_model_update
(
lambda
:
self
.
core
.
emit_event
(
"model-list-changed"
))
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ModelMoveUp"
),
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ModelMoveUp"
),
(
self
.
ACTION_DOWN
,
"ModelMoveDown"
),
(
self
.
ACTION_DOWN
,
"ModelMoveDown"
),
(
self
.
ACTION_DELETE
,
"ModelDelete"
),
(
self
.
ACTION_DELETE
,
"ModelDelete"
),
(
self
.
ACTION_CLEAR
,
"ModelDeleteAll"
)):
(
self
.
ACTION_CLEAR
,
"ModelDeleteAll"
)):
self
.
register_list_action_button
(
action
,
self
.
_modelview
,
self
.
register_list_action_button
(
action
,
self
.
gui
.
get_object
(
obj_name
))
self
.
gui
.
get_object
(
obj_name
))
self
.
_gtk_handlers
=
[]
self
.
_gtk_handlers
=
[]
self
.
_gtk_handlers
.
extend
((
self
.
_gtk_handlers
.
extend
((
...
@@ -68,18 +70,6 @@ class Models(pycam.Plugins.ListPluginBase):
...
@@ -68,18 +70,6 @@ class Models(pycam.Plugins.ListPluginBase):
self
.
_edit_model_name
)))
self
.
_edit_model_name
)))
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ModelList"
)
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ModelList"
)
self
.
_treemodel
.
clear
()
self
.
_treemodel
.
clear
()
def
update_model
():
if
not
hasattr
(
self
,
"_model_cache"
):
self
.
_model_cache
=
{}
cache
=
self
.
_model_cache
for
row
in
self
.
_treemodel
:
cache
[
row
[
self
.
COLUMN_REF
]]
=
list
(
row
)
self
.
_treemodel
.
clear
()
for
index
,
item
in
enumerate
(
self
):
if
not
id
(
item
)
in
cache
:
cache
[
id
(
item
)]
=
[
id
(
item
)]
self
.
_treemodel
.
append
(
cache
[
id
(
item
)])
self
.
core
.
emit_event
(
"model-list-changed"
)
selection
=
self
.
_modelview
.
get_selection
()
selection
=
self
.
_modelview
.
get_selection
()
selection
.
set_mode
(
self
.
_gtk
.
SELECTION_MULTIPLE
)
selection
.
set_mode
(
self
.
_gtk
.
SELECTION_MULTIPLE
)
self
.
_gtk_handlers
.
append
((
selection
,
"changed"
,
self
.
_gtk_handlers
.
append
((
selection
,
"changed"
,
...
@@ -90,7 +80,6 @@ class Models(pycam.Plugins.ListPluginBase):
...
@@ -90,7 +80,6 @@ class Models(pycam.Plugins.ListPluginBase):
self
.
register_gtk_handlers
(
self
.
_gtk_handlers
)
self
.
register_gtk_handlers
(
self
.
_gtk_handlers
)
self
.
register_event_handlers
(
self
.
_event_handlers
)
self
.
register_event_handlers
(
self
.
_event_handlers
)
self
.
_get_colors_of_selected_models
()
self
.
_get_colors_of_selected_models
()
self
.
register_model_update
(
update_model
)
# update the model list
# update the model list
self
.
core
.
emit_event
(
"model-list-changed"
)
self
.
core
.
emit_event
(
"model-list-changed"
)
self
.
core
.
register_namespace
(
"models"
,
self
.
core
.
register_namespace
(
"models"
,
...
@@ -145,16 +134,13 @@ class Models(pycam.Plugins.ListPluginBase):
...
@@ -145,16 +134,13 @@ class Models(pycam.Plugins.ListPluginBase):
self
.
_visualize_visible_state
)
self
.
_visualize_visible_state
)
def
_edit_model_name
(
self
,
cell
,
path
,
new_text
):
def
_edit_model_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
model
=
self
.
get_by_path
(
path
)
model_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
if
model
and
(
new_text
!=
model
[
"name"
])
and
new_text
:
model
=
[
m
for
m
in
self
if
id
(
m
)
==
model_ref
][
0
]
if
(
new_text
!=
model
[
"name"
])
and
new_text
:
model
[
"name"
]
=
new_text
model
[
"name"
]
=
new_text
def
_render_model_name
(
self
,
column
,
cell
,
model
,
m_iter
):
def
_render_model_name
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
model_obj
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
model_dict
=
self
[
path
[
0
]]
cell
.
set_property
(
"text"
,
model_obj
[
"name"
])
cell
.
set_property
(
"text"
,
model_dict
[
"name"
])
def
_visualize_visible_state
(
self
,
column
,
cell
,
model
,
m_iter
):
def
_visualize_visible_state
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
path
=
model
.
get_path
(
m_iter
)
...
@@ -175,9 +161,6 @@ class Models(pycam.Plugins.ListPluginBase):
...
@@ -175,9 +161,6 @@ class Models(pycam.Plugins.ListPluginBase):
model
[
"visible"
]
=
not
model
[
"visible"
]
model
[
"visible"
]
=
not
model
[
"visible"
]
self
.
core
.
emit_event
(
"visual-item-updated"
)
self
.
core
.
emit_event
(
"visual-item-updated"
)
def
get_selected
(
self
):
return
self
.
_get_selected
(
self
.
_modelview
,
force_list
=
True
)
def
get_visible
(
self
):
def
get_visible
(
self
):
return
[
model
for
model
in
self
if
model
[
"visible"
]]
return
[
model
for
model
in
self
if
model
[
"visible"
]]
...
...
pycam/Plugins/Processes.py
View file @
31c4d85e
...
@@ -28,7 +28,6 @@ class Processes(pycam.Plugins.ListPluginBase):
...
@@ -28,7 +28,6 @@ class Processes(pycam.Plugins.ListPluginBase):
DEPENDS
=
[
"ParameterGroupManager"
]
DEPENDS
=
[
"ParameterGroupManager"
]
CATEGORIES
=
[
"Process"
]
CATEGORIES
=
[
"Process"
]
UI_FILE
=
"processes.ui"
UI_FILE
=
"processes.ui"
COLUMN_REF
=
0
def
setup
(
self
):
def
setup
(
self
):
self
.
core
.
set
(
"processes"
,
self
)
self
.
core
.
set
(
"processes"
,
self
)
...
@@ -40,10 +39,13 @@ class Processes(pycam.Plugins.ListPluginBase):
...
@@ -40,10 +39,13 @@ class Processes(pycam.Plugins.ListPluginBase):
self
.
_gtk_handlers
=
[]
self
.
_gtk_handlers
=
[]
self
.
core
.
register_ui
(
"main"
,
"Processes"
,
process_frame
,
weight
=
20
)
self
.
core
.
register_ui
(
"main"
,
"Processes"
,
process_frame
,
weight
=
20
)
self
.
_modelview
=
self
.
gui
.
get_object
(
"ProcessEditorTable"
)
self
.
_modelview
=
self
.
gui
.
get_object
(
"ProcessEditorTable"
)
self
.
set_gtk_modelview
(
self
.
_modelview
)
self
.
register_model_update
(
lambda
:
self
.
core
.
emit_event
(
"process-list-changed"
))
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ProcessMoveUp"
),
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ProcessMoveUp"
),
(
self
.
ACTION_DOWN
,
"ProcessMoveDown"
),
(
self
.
ACTION_DOWN
,
"ProcessMoveDown"
),
(
self
.
ACTION_DELETE
,
"ProcessDelete"
)):
(
self
.
ACTION_DELETE
,
"ProcessDelete"
)):
self
.
register_list_action_button
(
action
,
self
.
_modelview
,
self
.
register_list_action_button
(
action
,
self
.
gui
.
get_object
(
obj_name
))
self
.
gui
.
get_object
(
obj_name
))
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"ProcessNew"
),
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"ProcessNew"
),
"clicked"
,
self
.
_process_new
))
"clicked"
,
self
.
_process_new
))
...
@@ -84,23 +86,11 @@ class Processes(pycam.Plugins.ListPluginBase):
...
@@ -84,23 +86,11 @@ class Processes(pycam.Plugins.ListPluginBase):
"edited"
,
self
.
_edit_process_name
))
"edited"
,
self
.
_edit_process_name
))
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ProcessList"
)
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ProcessList"
)
self
.
_treemodel
.
clear
()
self
.
_treemodel
.
clear
()
def
update_model
():
if
not
hasattr
(
self
,
"_model_cache"
):
self
.
_model_cache
=
{}
cache
=
self
.
_model_cache
for
row
in
self
.
_treemodel
:
cache
[
row
[
self
.
COLUMN_REF
]]
=
list
(
row
)
self
.
_treemodel
.
clear
()
for
index
,
item
in
enumerate
(
self
):
if
not
id
(
item
)
in
cache
:
cache
[
id
(
item
)]
=
[
id
(
item
)]
self
.
_treemodel
.
append
(
cache
[
id
(
item
)])
self
.
core
.
emit_event
(
"process-list-changed"
)
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"StrategySelector"
),
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"StrategySelector"
),
"changed"
,
"process-strategy-changed"
))
"changed"
,
"process-strategy-changed"
))
self
.
register_model_update
(
update_model
)
self
.
_event_handlers
=
(
self
.
_event_handlers
=
(
(
"process-strategy-list-changed"
,
self
.
_update_widgets
),
(
"process-strategy-list-changed"
,
self
.
_update_widgets
),
(
"process-list-changed"
,
self
.
_trigger_table_update
),
(
"process-selection-changed"
,
self
.
_process_switch
),
(
"process-selection-changed"
,
self
.
_process_switch
),
(
"process-changed"
,
self
.
_store_process_settings
),
(
"process-changed"
,
self
.
_store_process_settings
),
(
"process-strategy-changed"
,
self
.
_store_process_settings
))
(
"process-strategy-changed"
,
self
.
_store_process_settings
))
...
@@ -127,33 +117,19 @@ class Processes(pycam.Plugins.ListPluginBase):
...
@@ -127,33 +117,19 @@ class Processes(pycam.Plugins.ListPluginBase):
self
.
pop
()
self
.
pop
()
return
True
return
True
def
get_selected
(
self
,
index
=
False
):
return
self
.
_get_selected
(
self
.
_modelview
,
index
=
index
)
def
select
(
self
,
process
):
if
process
in
self
:
selection
=
self
.
_modelview
.
get_selection
()
index
=
[
id
(
p
)
for
p
in
self
]
.
index
(
id
(
p
))
selection
.
unselect_all
()
selection
.
select_path
((
index
,))
def
_render_process_description
(
self
,
column
,
cell
,
model
,
m_iter
):
def
_render_process_description
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
process
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
data
=
self
[
path
[
0
]]
# TODO: describe the strategy
# TODO: describe the strategy
text
=
"TODO"
text
=
"TODO"
cell
.
set_property
(
"text"
,
text
)
cell
.
set_property
(
"text"
,
text
)
def
_render_process_name
(
self
,
column
,
cell
,
model
,
m_iter
):
def
_render_process_name
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
process
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
data
=
self
[
path
[
0
]]
cell
.
set_property
(
"text"
,
process
[
"name"
])
cell
.
set_property
(
"text"
,
data
[
"name"
])
def
_edit_process_name
(
self
,
cell
,
path
,
new_text
):
def
_edit_process_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
process
=
self
.
get_by_path
(
path
)
process_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
if
process
and
(
new_text
!=
process
[
"name"
])
and
new_text
:
process
=
[
p
for
p
in
self
if
id
(
p
)
==
process_ref
][
0
]
if
(
new_text
!=
process
[
"name"
])
and
new_text
:
process
[
"name"
]
=
new_text
process
[
"name"
]
=
new_text
def
_trigger_table_update
(
self
):
def
_trigger_table_update
(
self
):
...
...
pycam/Plugins/Tasks.py
View file @
31c4d85e
...
@@ -31,7 +31,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
...
@@ -31,7 +31,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
UI_FILE
=
"tasks.ui"
UI_FILE
=
"tasks.ui"
CATEGORIES
=
[
"Task"
]
CATEGORIES
=
[
"Task"
]
COLUMN_REF
=
0
DEPENDS
=
[
"Models"
,
"Tools"
,
"Processes"
,
"Bounds"
,
"Toolpaths"
]
DEPENDS
=
[
"Models"
,
"Tools"
,
"Processes"
,
"Bounds"
,
"Toolpaths"
]
def
setup
(
self
):
def
setup
(
self
):
...
@@ -43,10 +42,13 @@ class Tasks(pycam.Plugins.ListPluginBase):
...
@@ -43,10 +42,13 @@ class Tasks(pycam.Plugins.ListPluginBase):
task_frame
.
unparent
()
task_frame
.
unparent
()
self
.
core
.
register_ui
(
"main"
,
"Tasks"
,
task_frame
,
weight
=
40
)
self
.
core
.
register_ui
(
"main"
,
"Tasks"
,
task_frame
,
weight
=
40
)
self
.
_taskview
=
self
.
gui
.
get_object
(
"TaskView"
)
self
.
_taskview
=
self
.
gui
.
get_object
(
"TaskView"
)
self
.
set_gtk_modelview
(
self
.
_taskview
)
self
.
register_model_update
(
lambda
:
self
.
core
.
emit_event
(
"task-list-changed"
))
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"TaskMoveUp"
),
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"TaskMoveUp"
),
(
self
.
ACTION_DOWN
,
"TaskMoveDown"
),
(
self
.
ACTION_DOWN
,
"TaskMoveDown"
),
(
self
.
ACTION_DELETE
,
"TaskDelete"
)):
(
self
.
ACTION_DELETE
,
"TaskDelete"
)):
self
.
register_list_action_button
(
action
,
self
.
_taskview
,
self
.
register_list_action_button
(
action
,
self
.
gui
.
get_object
(
obj_name
))
self
.
gui
.
get_object
(
obj_name
))
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"TaskNew"
),
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"TaskNew"
),
"clicked"
,
self
.
_task_new
))
"clicked"
,
self
.
_task_new
))
...
@@ -102,19 +104,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
...
@@ -102,19 +104,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
self
.
_generate_selected_toolpaths
),
self
.
_generate_selected_toolpaths
),
(
self
.
gui
.
get_object
(
"GenerateAllToolPathsButton"
),
"clicked"
,
(
self
.
gui
.
get_object
(
"GenerateAllToolPathsButton"
),
"clicked"
,
self
.
_generate_all_toolpaths
)))
self
.
_generate_all_toolpaths
)))
# manage the treemodel
def
update_model
():
if
not
hasattr
(
self
,
"_model_cache"
):
self
.
_model_cache
=
{}
cache
=
self
.
_model_cache
for
row
in
self
.
_treemodel
:
cache
[
row
[
self
.
COLUMN_REF
]]
=
list
(
row
)
self
.
_treemodel
.
clear
()
for
index
,
item
in
enumerate
(
self
):
if
not
id
(
item
)
in
cache
:
cache
[
id
(
item
)]
=
[
id
(
item
)]
self
.
_treemodel
.
append
(
cache
[
id
(
item
)])
self
.
core
.
emit_event
(
"task-list-changed"
)
# shape selector
# shape selector
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"TaskTypeSelector"
),
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"TaskTypeSelector"
),
"changed"
,
"task-type-changed"
))
"changed"
,
"task-type-changed"
))
...
@@ -126,7 +115,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
...
@@ -126,7 +115,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
(
"task-type-changed"
,
self
.
_store_task
),
(
"task-type-changed"
,
self
.
_store_task
),
(
"task-selection-changed"
,
self
.
_update_widgets
),
(
"task-selection-changed"
,
self
.
_update_widgets
),
(
"task-list-changed"
,
self
.
_update_widgets
))
(
"task-list-changed"
,
self
.
_update_widgets
))
self
.
register_model_update
(
update_model
)
self
.
register_gtk_handlers
(
self
.
_gtk_handlers
)
self
.
register_gtk_handlers
(
self
.
_gtk_handlers
)
self
.
register_event_handlers
(
self
.
_event_handlers
)
self
.
register_event_handlers
(
self
.
_event_handlers
)
self
.
_update_widgets
()
self
.
_update_widgets
()
...
@@ -152,26 +140,9 @@ class Tasks(pycam.Plugins.ListPluginBase):
...
@@ -152,26 +140,9 @@ class Tasks(pycam.Plugins.ListPluginBase):
while
len
(
self
)
>
0
:
while
len
(
self
)
>
0
:
self
.
pop
()
self
.
pop
()
def
get_selected
(
self
,
index
=
False
):
return
self
.
_get_selected
(
self
.
_taskview
,
index
=
index
)
def
select
(
self
,
tasks
):
selection
=
self
.
_taskview
.
get_selection
()
model
=
self
.
_taskview
.
get_model
()
if
not
isinstance
(
tasks
,
(
list
,
tuple
)):
tasks
=
[
tasks
]
tasks_ref
=
[
id
(
task
)
for
task
in
tasks
]
for
index
,
row
in
enumerate
(
model
):
if
row
[
self
.
COLUMN_REF
]
in
tasks_ref
:
selection
.
select_path
((
index
,))
else
:
selection
.
unselect_path
((
index
,))
def
_edit_task_name
(
self
,
cell
,
path
,
new_text
):
def
_edit_task_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
task
=
self
.
get_by_path
(
path
)
task_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
if
task
and
(
new_text
!=
task
[
"name"
])
and
new_text
:
task
=
[
t
for
t
in
self
if
id
(
t
)
==
task_ref
][
0
]
if
(
new_text
!=
task
[
"name"
])
and
new_text
:
task
[
"name"
]
=
new_text
task
[
"name"
]
=
new_text
def
_trigger_table_update
(
self
):
def
_trigger_table_update
(
self
):
...
@@ -179,8 +150,7 @@ class Tasks(pycam.Plugins.ListPluginBase):
...
@@ -179,8 +150,7 @@ class Tasks(pycam.Plugins.ListPluginBase):
self
.
gui
.
get_object
(
"NameCell"
),
self
.
_render_task_name
)
self
.
gui
.
get_object
(
"NameCell"
),
self
.
_render_task_name
)
def
_render_task_name
(
self
,
column
,
cell
,
model
,
m_iter
):
def
_render_task_name
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
task
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
task
=
self
[
path
[
0
]]
cell
.
set_property
(
"text"
,
task
[
"name"
])
cell
.
set_property
(
"text"
,
task
[
"name"
])
def
_get_type
(
self
,
name
=
None
):
def
_get_type
(
self
,
name
=
None
):
...
...
pycam/Plugins/Toolpaths.py
View file @
31c4d85e
...
@@ -40,13 +40,16 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
...
@@ -40,13 +40,16 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self
.
core
.
register_ui
(
"main"
,
"Toolpaths"
,
self
.
tp_box
,
weight
=
50
)
self
.
core
.
register_ui
(
"main"
,
"Toolpaths"
,
self
.
tp_box
,
weight
=
50
)
self
.
_gtk_handlers
=
[]
self
.
_gtk_handlers
=
[]
self
.
_modelview
=
self
.
gui
.
get_object
(
"ToolpathTable"
)
self
.
_modelview
=
self
.
gui
.
get_object
(
"ToolpathTable"
)
self
.
set_gtk_modelview
(
self
.
_modelview
)
self
.
register_model_update
(
lambda
:
self
.
core
.
emit_event
(
"toolpath-list-changed"
))
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ToolpathListModel"
)
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ToolpathListModel"
)
self
.
_treemodel
.
clear
()
self
.
_treemodel
.
clear
()
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ToolpathMoveUp"
),
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ToolpathMoveUp"
),
(
self
.
ACTION_DOWN
,
"ToolpathMoveDown"
),
(
self
.
ACTION_DOWN
,
"ToolpathMoveDown"
),
(
self
.
ACTION_DELETE
,
"ToolpathDelete"
),
(
self
.
ACTION_DELETE
,
"ToolpathDelete"
),
(
self
.
ACTION_CLEAR
,
"ToolpathDeleteAll"
)):
(
self
.
ACTION_CLEAR
,
"ToolpathDeleteAll"
)):
self
.
register_list_action_button
(
action
,
self
.
_modelview
,
self
.
register_list_action_button
(
action
,
self
.
gui
.
get_object
(
obj_name
))
self
.
gui
.
get_object
(
obj_name
))
# toolpath operations
# toolpath operations
toolpath_handling_obj
=
self
.
gui
.
get_object
(
toolpath_handling_obj
=
self
.
gui
.
get_object
(
...
@@ -73,22 +76,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
...
@@ -73,22 +76,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self
.
_gtk_handlers
.
append
((
selection
,
"changed"
,
self
.
_gtk_handlers
.
append
((
selection
,
"changed"
,
"toolpath-selection-changed"
))
"toolpath-selection-changed"
))
selection
.
set_mode
(
gtk
.
SELECTION_MULTIPLE
)
selection
.
set_mode
(
gtk
.
SELECTION_MULTIPLE
)
# model handling
def
update_model
():
if
not
hasattr
(
self
,
"_model_cache"
):
self
.
_model_cache
=
{}
cache
=
self
.
_model_cache
for
row
in
self
.
_treemodel
:
cache
[
row
[
self
.
COLUMN_REF
]]
=
list
(
row
)
self
.
_treemodel
.
clear
()
for
index
,
item
in
enumerate
(
self
):
if
id
(
item
)
in
cache
:
self
.
_treemodel
.
append
(
cache
[
id
(
item
)])
else
:
self
.
_treemodel
.
append
((
id
(
item
),
"Toolpath #
%
d"
%
index
,
True
))
self
.
core
.
emit_event
(
"toolpath-list-changed"
)
self
.
register_model_update
(
update_model
)
self
.
_event_handlers
=
(
self
.
_event_handlers
=
(
(
"toolpath-changed"
,
self
.
_update_widgets
),
(
"toolpath-changed"
,
self
.
_update_widgets
),
(
"toolpath-list-changed"
,
self
.
_update_widgets
),
(
"toolpath-list-changed"
,
self
.
_update_widgets
),
...
@@ -111,9 +98,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
...
@@ -111,9 +98,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self
.
unregister_event_handlers
(
self
.
_event_handlers
)
self
.
unregister_event_handlers
(
self
.
_event_handlers
)
self
.
core
.
set
(
"toolpaths"
,
None
)
self
.
core
.
set
(
"toolpaths"
,
None
)
def
get_selected
(
self
):
return
self
.
_get_selected
(
self
.
_modelview
,
force_list
=
True
)
def
get_visible
(
self
):
def
get_visible
(
self
):
return
[
self
[
index
]
for
index
,
item
in
enumerate
(
self
.
_treemodel
)
return
[
self
[
index
]
for
index
,
item
in
enumerate
(
self
.
_treemodel
)
if
item
[
self
.
COLUMN_VISIBLE
]]
if
item
[
self
.
COLUMN_VISIBLE
]]
...
...
pycam/Plugins/Tools.py
View file @
31c4d85e
...
@@ -28,7 +28,6 @@ class Tools(pycam.Plugins.ListPluginBase):
...
@@ -28,7 +28,6 @@ class Tools(pycam.Plugins.ListPluginBase):
DEPENDS
=
[
"ParameterGroupManager"
]
DEPENDS
=
[
"ParameterGroupManager"
]
CATEGORIES
=
[
"Tool"
]
CATEGORIES
=
[
"Tool"
]
UI_FILE
=
"tools.ui"
UI_FILE
=
"tools.ui"
COLUMN_REF
=
0
def
setup
(
self
):
def
setup
(
self
):
self
.
core
.
set
(
"tools"
,
self
)
self
.
core
.
set
(
"tools"
,
self
)
...
@@ -41,10 +40,13 @@ class Tools(pycam.Plugins.ListPluginBase):
...
@@ -41,10 +40,13 @@ class Tools(pycam.Plugins.ListPluginBase):
self
.
core
.
register_chain
(
"get_toolpath_information"
,
self
.
core
.
register_chain
(
"get_toolpath_information"
,
self
.
get_toolpath_information
)
self
.
get_toolpath_information
)
self
.
_modelview
=
self
.
gui
.
get_object
(
"ToolTable"
)
self
.
_modelview
=
self
.
gui
.
get_object
(
"ToolTable"
)
self
.
set_gtk_modelview
(
self
.
_modelview
)
self
.
register_model_update
(
lambda
:
self
.
core
.
emit_event
(
"tool-list-changed"
))
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ToolMoveUp"
),
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ToolMoveUp"
),
(
self
.
ACTION_DOWN
,
"ToolMoveDown"
),
(
self
.
ACTION_DOWN
,
"ToolMoveDown"
),
(
self
.
ACTION_DELETE
,
"ToolDelete"
)):
(
self
.
ACTION_DELETE
,
"ToolDelete"
)):
self
.
register_list_action_button
(
action
,
self
.
_modelview
,
self
.
register_list_action_button
(
action
,
self
.
gui
.
get_object
(
obj_name
))
self
.
gui
.
get_object
(
obj_name
))
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"ToolNew"
),
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"ToolNew"
),
"clicked"
,
self
.
_tool_new
))
"clicked"
,
self
.
_tool_new
))
...
@@ -95,18 +97,6 @@ class Tools(pycam.Plugins.ListPluginBase):
...
@@ -95,18 +97,6 @@ class Tools(pycam.Plugins.ListPluginBase):
"edited"
,
self
.
_edit_tool_name
))
"edited"
,
self
.
_edit_tool_name
))
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ToolList"
)
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ToolList"
)
self
.
_treemodel
.
clear
()
self
.
_treemodel
.
clear
()
def
update_model
():
if
not
hasattr
(
self
,
"_model_cache"
):
self
.
_model_cache
=
{}
cache
=
self
.
_model_cache
for
row
in
self
.
_treemodel
:
cache
[
row
[
self
.
COLUMN_REF
]]
=
list
(
row
)
self
.
_treemodel
.
clear
()
for
index
,
item
in
enumerate
(
self
):
if
not
id
(
item
)
in
cache
:
cache
[
id
(
item
)]
=
[
id
(
item
)]
self
.
_treemodel
.
append
(
cache
[
id
(
item
)])
self
.
core
.
emit_event
(
"tool-list-changed"
)
# selector
# selector
self
.
_gtk_handlers
.
append
((
self
.
_modelview
.
get_selection
(),
self
.
_gtk_handlers
.
append
((
self
.
_modelview
.
get_selection
(),
"changed"
,
"tool-selection-changed"
))
"changed"
,
"tool-selection-changed"
))
...
@@ -121,7 +111,6 @@ class Tools(pycam.Plugins.ListPluginBase):
...
@@ -121,7 +111,6 @@ class Tools(pycam.Plugins.ListPluginBase):
(
"tool-changed"
,
self
.
_trigger_table_update
),
(
"tool-changed"
,
self
.
_trigger_table_update
),
(
"tool-list-changed"
,
self
.
_trigger_table_update
),
(
"tool-list-changed"
,
self
.
_trigger_table_update
),
(
"tool-shape-changed"
,
self
.
_store_tool_settings
))
(
"tool-shape-changed"
,
self
.
_store_tool_settings
))
self
.
register_model_update
(
update_model
)
self
.
register_gtk_handlers
(
self
.
_gtk_handlers
)
self
.
register_gtk_handlers
(
self
.
_gtk_handlers
)
self
.
register_event_handlers
(
self
.
_event_handlers
)
self
.
register_event_handlers
(
self
.
_event_handlers
)
self
.
_update_widgets
()
self
.
_update_widgets
()
...
@@ -151,17 +140,6 @@ class Tools(pycam.Plugins.ListPluginBase):
...
@@ -151,17 +140,6 @@ class Tools(pycam.Plugins.ListPluginBase):
self
.
pop
()
self
.
pop
()
return
True
return
True
def
get_selected
(
self
,
index
=
False
):
return
self
.
_get_selected
(
self
.
_modelview
,
index
=
index
)
def
select
(
self
,
tool
):
if
tool
in
self
:
selection
=
self
.
_modelview
.
get_selection
()
# check for identity instead of equality
index
=
[
id
(
t
)
for
t
in
self
]
.
index
(
id
(
tool
))
selection
.
unselect_all
()
selection
.
select_path
((
index
,))
def
get_toolpath_information
(
self
,
item
,
data
):
def
get_toolpath_information
(
self
,
item
,
data
):
if
item
in
self
:
if
item
in
self
:
data
[
"tool_id"
]
=
item
[
"id"
]
data
[
"tool_id"
]
=
item
[
"id"
]
...
@@ -180,8 +158,9 @@ class Tools(pycam.Plugins.ListPluginBase):
...
@@ -180,8 +158,9 @@ class Tools(pycam.Plugins.ListPluginBase):
cell
.
set_property
(
"text"
,
str
(
tool
[
key
]))
cell
.
set_property
(
"text"
,
str
(
tool
[
key
]))
def
_render_tool_shape
(
self
,
column
,
cell
,
model
,
m_iter
):
def
_render_tool_shape
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
tool
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
tool
=
self
[
path
[
0
]]
if
not
tool
:
return
parameters
=
tool
[
"parameters"
]
parameters
=
tool
[
"parameters"
]
if
"radius"
in
parameters
:
if
"radius"
in
parameters
:
text
=
"
%
g
%
s"
%
(
2
*
parameters
[
"radius"
],
self
.
core
.
get
(
"unit"
))
text
=
"
%
g
%
s"
%
(
2
*
parameters
[
"radius"
],
self
.
core
.
get
(
"unit"
))
...
@@ -190,21 +169,17 @@ class Tools(pycam.Plugins.ListPluginBase):
...
@@ -190,21 +169,17 @@ class Tools(pycam.Plugins.ListPluginBase):
cell
.
set_property
(
"text"
,
text
)
cell
.
set_property
(
"text"
,
text
)
def
_edit_tool_name
(
self
,
cell
,
path
,
new_text
):
def
_edit_tool_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
tool
=
self
.
get_by_path
(
path
)
tool_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
if
tool
and
(
new_text
!=
tool
[
"name"
])
and
new_text
:
tool
=
[
t
for
t
in
self
if
id
(
t
)
==
tool_ref
][
0
]
if
(
new_text
!=
tool
[
"name"
])
and
new_text
:
tool
[
"name"
]
=
new_text
tool
[
"name"
]
=
new_text
def
_edit_tool_id
(
self
,
cell
,
path
,
new_text
):
def
_edit_tool_id
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
tool
=
self
.
get_by_path
(
path
)
tool_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
tool
=
[
t
for
t
in
self
if
id
(
t
)
==
tool_ref
][
0
]
try
:
try
:
new_value
=
int
(
new_text
)
new_value
=
int
(
new_text
)
except
ValueError
:
except
ValueError
:
return
return
if
new_value
!=
tool
[
"id"
]
:
if
tool
and
(
new_value
!=
tool
[
"id"
])
:
tool
[
"id"
]
=
new_value
tool
[
"id"
]
=
new_value
def
_get_shape
(
self
,
name
=
None
):
def
_get_shape
(
self
,
name
=
None
):
...
...
pycam/Plugins/__init__.py
View file @
31c4d85e
...
@@ -358,6 +358,7 @@ class ListPluginBase(PluginBase, list):
...
@@ -358,6 +358,7 @@ class ListPluginBase(PluginBase, list):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
ListPluginBase
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
ListPluginBase
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
_update_model_funcs
=
[]
self
.
_update_model_funcs
=
[]
self
.
_gtk_modelview
=
None
def
get_function
(
func_name
):
def
get_function
(
func_name
):
return
lambda
*
args
,
**
kwargs
:
\
return
lambda
*
args
,
**
kwargs
:
\
self
.
_change_wrapper
(
func_name
,
*
args
,
**
kwargs
)
self
.
_change_wrapper
(
func_name
,
*
args
,
**
kwargs
)
...
@@ -370,9 +371,14 @@ class ListPluginBase(PluginBase, list):
...
@@ -370,9 +371,14 @@ class ListPluginBase(PluginBase, list):
self
.
_update_model
()
self
.
_update_model
()
return
value
return
value
def
_get_selected
(
self
,
modelview
,
index
=
False
,
force_list
=
False
,
content
=
None
):
def
get_selected
(
self
,
**
kwargs
):
if
content
is
None
:
if
self
.
_gtk_modelview
:
content
=
self
return
self
.
_get_gtk_selected
(
**
kwargs
)
else
:
return
None
def
_get_gtk_selected
(
self
,
index
=
False
,
force_list
=
False
):
modelview
=
self
.
_gtk_modelview
if
hasattr
(
modelview
,
"get_selection"
):
if
hasattr
(
modelview
,
"get_selection"
):
# a treeview selection
# a treeview selection
selection
=
modelview
.
get_selection
()
selection
=
modelview
.
get_selection
()
...
@@ -393,7 +399,7 @@ class ListPluginBase(PluginBase, list):
...
@@ -393,7 +399,7 @@ class ListPluginBase(PluginBase, list):
if
index
:
if
index
:
get_result
=
lambda
path
:
path
[
0
]
get_result
=
lambda
path
:
path
[
0
]
else
:
else
:
get_result
=
lambda
path
:
content
[
path
[
0
]]
get_result
=
self
.
get_by_path
if
(
selection_mode
==
gtk
.
SELECTION_MULTIPLE
)
or
force_list
:
if
(
selection_mode
==
gtk
.
SELECTION_MULTIPLE
)
or
force_list
:
result
=
[]
result
=
[]
for
path
in
paths
:
for
path
in
paths
:
...
@@ -405,7 +411,57 @@ class ListPluginBase(PluginBase, list):
...
@@ -405,7 +411,57 @@ class ListPluginBase(PluginBase, list):
result
=
get_result
(
paths
[
0
])
result
=
get_result
(
paths
[
0
])
return
result
return
result
def
select
(
self
,
selected
):
if
not
isinstance
(
selected
,
(
list
,
tuple
)):
selected
=
[
selected
]
if
self
.
_gtk_modelview
:
self
.
_select_gtk
(
selected
)
def
_select_gtk
(
self
,
selected_objs
):
selection
=
self
.
_gtk_modelview
.
get_selection
()
selected_uuids
=
[
item
[
"uuid"
]
for
item
in
selected_objs
]
for
index
,
item
in
enumerate
(
self
):
if
item
[
"uuid"
]
in
selected_uuids
:
selection
.
select_path
((
index
,
))
else
:
selection
.
unselect_path
((
index
,
))
def
set_gtk_modelview
(
self
,
modelview
):
self
.
_gtk_modelview
=
modelview
def
_update_gtk_treemodel
(
self
):
if
not
self
.
_gtk_modelview
:
return
treemodel
=
self
.
_gtk_modelview
.
get_model
()
current_uuids
=
[
item
[
"uuid"
]
for
item
in
self
]
# remove all superfluous rows from "treemodel"
removal_indices
=
[
index
for
index
,
item
in
enumerate
(
treemodel
)
if
not
item
[
0
]
in
current_uuids
]
removal_indices
.
reverse
()
for
index
in
removal_indices
:
treemodel
.
remove
(
treemodel
.
get_iter
((
index
,
)))
# add all missing items to "treemodel"
model_uuids
=
[
row
[
0
]
for
row
in
treemodel
]
for
uuid
in
current_uuids
:
if
not
uuid
in
model_uuids
:
treemodel
.
append
((
uuid
,
))
# reorder the treemodel according to the current list
sorted_indices
=
[
current_uuids
.
index
(
row
[
0
])
for
row
in
treemodel
]
treemodel
.
reorder
(
sorted_indices
)
self
.
core
.
emit_event
(
"tool-list-changed"
)
def
get_by_path
(
self
,
path
):
if
not
self
.
_gtk_modelview
:
return
None
uuid
=
self
.
_gtk_modelview
.
get_model
()[
int
(
path
[
0
])][
0
]
objs
=
[
t
for
t
in
self
if
uuid
==
t
[
"uuid"
]]
if
objs
:
return
objs
[
0
]
else
:
return
None
def
_update_model
(
self
):
def
_update_model
(
self
):
self
.
_update_gtk_treemodel
()
for
update_func
in
self
.
_update_model_funcs
:
for
update_func
in
self
.
_update_model_funcs
:
update_func
()
update_func
()
...
@@ -426,8 +482,7 @@ class ListPluginBase(PluginBase, list):
...
@@ -426,8 +482,7 @@ class ListPluginBase(PluginBase, list):
self
.
log
.
info
(
"Invalid action for ListPluginBase.list_action: "
+
\
self
.
log
.
info
(
"Invalid action for ListPluginBase.list_action: "
+
\
str
(
action
))
str
(
action
))
return
return
selected_items
=
self
.
_get_selected
(
modelview
,
index
=
True
,
selected_items
=
self
.
get_selected
(
index
=
True
,
force_list
=
True
)
force_list
=
True
)
selected_items
.
sort
()
selected_items
.
sort
()
if
action
in
(
self
.
ACTION_DOWN
,
self
.
ACTION_DELETE
):
if
action
in
(
self
.
ACTION_DOWN
,
self
.
ACTION_DELETE
):
selected_items
.
sort
(
reverse
=
True
)
selected_items
.
sort
(
reverse
=
True
)
...
@@ -466,7 +521,7 @@ class ListPluginBase(PluginBase, list):
...
@@ -466,7 +521,7 @@ class ListPluginBase(PluginBase, list):
modelview
=
args
[
-
3
]
modelview
=
args
[
-
3
]
action
=
args
[
-
2
]
action
=
args
[
-
2
]
button
=
args
[
-
1
]
button
=
args
[
-
1
]
paths
=
self
.
_get_selected
(
modelview
,
index
=
True
,
force_list
=
True
)
paths
=
self
.
get_selected
(
index
=
True
,
force_list
=
True
)
if
action
==
self
.
ACTION_CLEAR
:
if
action
==
self
.
ACTION_CLEAR
:
button
.
set_sensitive
(
len
(
self
)
>
0
)
button
.
set_sensitive
(
len
(
self
)
>
0
)
elif
not
paths
:
elif
not
paths
:
...
@@ -479,7 +534,8 @@ class ListPluginBase(PluginBase, list):
...
@@ -479,7 +534,8 @@ class ListPluginBase(PluginBase, list):
else
:
else
:
button
.
set_sensitive
(
True
)
button
.
set_sensitive
(
True
)
def
register_list_action_button
(
self
,
action
,
modelview
,
button
):
def
register_list_action_button
(
self
,
action
,
button
):
modelview
=
self
.
_gtk_modelview
if
hasattr
(
modelview
,
"get_selection"
):
if
hasattr
(
modelview
,
"get_selection"
):
# a treeview
# a treeview
selection
=
modelview
.
get_selection
()
selection
=
modelview
.
get_selection
()
...
@@ -504,7 +560,7 @@ class ObjectWithAttributes(dict):
...
@@ -504,7 +560,7 @@ class ObjectWithAttributes(dict):
def
__init__
(
self
,
key
,
params
=
None
):
def
__init__
(
self
,
key
,
params
=
None
):
if
not
params
is
None
:
if
not
params
is
None
:
self
.
update
(
params
)
self
.
update
(
params
)
self
[
"uuid"
]
=
uuid
.
uuid4
(
)
self
[
"uuid"
]
=
str
(
uuid
.
uuid4
()
)
self
.
node_key
=
key
self
.
node_key
=
key
...
...
share/ui/bounds.ui
View file @
31c4d85e
...
@@ -65,8 +65,8 @@
...
@@ -65,8 +65,8 @@
</object>
</object>
<object
class=
"GtkListStore"
id=
"BoundsList"
>
<object
class=
"GtkListStore"
id=
"BoundsList"
>
<columns>
<columns>
<!-- column-name
ref
-->
<!-- column-name
uuid
-->
<column
type=
"g
ulong
"
/>
<column
type=
"g
chararray
"
/>
</columns>
</columns>
</object>
</object>
<object
class=
"GtkVPaned"
id=
"BoundsBox"
>
<object
class=
"GtkVPaned"
id=
"BoundsBox"
>
...
...
share/ui/models.ui
View file @
31c4d85e
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
<!-- interface-naming-policy project-wide -->
<!-- interface-naming-policy project-wide -->
<object
class=
"GtkListStore"
id=
"ModelList"
>
<object
class=
"GtkListStore"
id=
"ModelList"
>
<columns>
<columns>
<!-- column-name id -->
<!-- column-name
uu
id -->
<column
type=
"g
ulong
"
/>
<column
type=
"g
chararray
"
/>
</columns>
</columns>
</object>
</object>
<object
class=
"GtkWindow"
id=
"window1"
>
<object
class=
"GtkWindow"
id=
"window1"
>
...
...
share/ui/processes.ui
View file @
31c4d85e
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
</object>
</object>
<object
class=
"GtkListStore"
id=
"ProcessList"
>
<object
class=
"GtkListStore"
id=
"ProcessList"
>
<columns>
<columns>
<!-- column-name
ref
-->
<!-- column-name
uuid
-->
<column
type=
"g
ulong
"
/>
<column
type=
"g
chararray
"
/>
</columns>
</columns>
</object>
</object>
<object
class=
"GtkVPaned"
id=
"ProcessBox"
>
<object
class=
"GtkVPaned"
id=
"ProcessBox"
>
...
@@ -49,7 +49,9 @@
...
@@ -49,7 +49,9 @@
<object
class=
"GtkTreeViewColumn"
id=
"NameColumn"
>
<object
class=
"GtkTreeViewColumn"
id=
"NameColumn"
>
<property
name=
"title"
>
Name
</property>
<property
name=
"title"
>
Name
</property>
<child>
<child>
<object
class=
"GtkCellRendererText"
id=
"NameCell"
/>
<object
class=
"GtkCellRendererText"
id=
"NameCell"
>
<property
name=
"editable"
>
True
</property>
</object>
</child>
</child>
</object>
</object>
</child>
</child>
...
...
share/ui/tasks.ui
View file @
31c4d85e
...
@@ -28,8 +28,8 @@
...
@@ -28,8 +28,8 @@
</object>
</object>
<object
class=
"GtkListStore"
id=
"TaskList"
>
<object
class=
"GtkListStore"
id=
"TaskList"
>
<columns>
<columns>
<!-- column-name
index
-->
<!-- column-name
uuid
-->
<column
type=
"g
ulong
"
/>
<column
type=
"g
chararray
"
/>
</columns>
</columns>
</object>
</object>
<object
class=
"GtkVPaned"
id=
"TaskBox"
>
<object
class=
"GtkVPaned"
id=
"TaskBox"
>
...
@@ -60,7 +60,9 @@
...
@@ -60,7 +60,9 @@
<object
class=
"GtkTreeViewColumn"
id=
"NameColumn"
>
<object
class=
"GtkTreeViewColumn"
id=
"NameColumn"
>
<property
name=
"title"
>
Name
</property>
<property
name=
"title"
>
Name
</property>
<child>
<child>
<object
class=
"GtkCellRendererText"
id=
"NameCell"
/>
<object
class=
"GtkCellRendererText"
id=
"NameCell"
>
<property
name=
"editable"
>
True
</property>
</object>
</child>
</child>
</object>
</object>
</child>
</child>
...
...
share/ui/tools.ui
View file @
31c4d85e
...
@@ -28,8 +28,8 @@
...
@@ -28,8 +28,8 @@
</object>
</object>
<object
class=
"GtkListStore"
id=
"ToolList"
>
<object
class=
"GtkListStore"
id=
"ToolList"
>
<columns>
<columns>
<!-- column-name
object_ref
-->
<!-- column-name
uuid
-->
<column
type=
"g
ulong
"
/>
<column
type=
"g
chararray
"
/>
</columns>
</columns>
</object>
</object>
<object
class=
"GtkVPaned"
id=
"ToolBox"
>
<object
class=
"GtkVPaned"
id=
"ToolBox"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment