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):
UI_FILE
=
"bounds.ui"
DEPENDS
=
[
"Models"
]
CATEGORIES
=
[
"Bounds"
]
COLUMN_REF
=
0
# mapping of boundary types and GUI control elements
BOUNDARY_TYPES
=
{
...
...
@@ -57,29 +56,19 @@ class Bounds(pycam.Plugins.ListPluginBase):
bounds_box
.
unparent
()
self
.
core
.
register_ui
(
"main"
,
"Bounds"
,
bounds_box
,
30
)
self
.
_boundsview
=
self
.
gui
.
get_object
(
"BoundsTable"
)
self
.
_gtk_handlers
=
[]
self
.
_gtk_handlers
.
append
((
self
.
_boundsview
.
get_selection
(),
"changed"
,
"bounds-selection-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
)
self
.
set_gtk_modelview
(
self
.
_boundsview
)
self
.
register_model_update
(
lambda
:
self
.
core
.
emit_event
(
"bounds-list-changed"
))
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"BoundsMoveUp"
),
(
self
.
ACTION_DOWN
,
"BoundsMoveDown"
),
(
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
.
_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"
),
"clicked"
,
self
.
_bounds_new
))
# model selector
...
...
@@ -159,16 +148,6 @@ class Bounds(pycam.Plugins.ListPluginBase):
while
len
(
self
)
>
0
:
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
):
return
self
.
models_control
.
get_value
()
...
...
@@ -176,8 +155,9 @@ class Bounds(pycam.Plugins.ListPluginBase):
self
.
models_control
.
set_value
(
models
)
def
_render_bounds_size
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
bounds
=
self
[
path
[
0
]]
bounds
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
if
not
bounds
:
return
low
,
high
=
bounds
.
get_absolute_limits
()
if
None
in
low
or
None
in
high
:
text
=
""
...
...
@@ -186,8 +166,7 @@ class Bounds(pycam.Plugins.ListPluginBase):
cell
.
set_property
(
"text"
,
text
)
def
_render_bounds_name
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
bounds
=
self
[
path
[
0
]]
bounds
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
cell
.
set_property
(
"text"
,
bounds
[
"name"
])
def
_trigger_table_update
(
self
):
...
...
@@ -392,10 +371,8 @@ class Bounds(pycam.Plugins.ListPluginBase):
self
.
select
(
new_bounds
)
def
_edit_bounds_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
bounds_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
bounds
=
[
bound
for
bound
in
self
if
id
(
bound
)
==
bounds_ref
]
if
(
new_text
!=
bounds
[
"name"
])
and
new_text
:
bounds
=
self
.
get_by_path
(
path
)
if
bounds
and
(
new_text
!=
bounds
[
"name"
])
and
new_text
:
bounds
[
"name"
]
=
new_text
...
...
pycam/Plugins/Models.py
View file @
31c4d85e
...
...
@@ -33,7 +33,6 @@ class Models(pycam.Plugins.ListPluginBase):
UI_FILE
=
"models.ui"
CATEGORIES
=
[
"Model"
]
COLUMN_REF
=
0
ICONS
=
{
"visible"
:
"visible.svg"
,
"hidden"
:
"visible_off.svg"
}
FALLBACK_COLOR
=
{
"red"
:
0.5
,
"green"
:
0.5
,
"blue"
:
1.0
,
"alpha"
:
1.0
}
...
...
@@ -53,11 +52,14 @@ class Models(pycam.Plugins.ListPluginBase):
self
.
core
.
register_ui_section
(
"model_handling"
,
add_model_handling_item
,
clear_model_handling_obj
)
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"
),
(
self
.
ACTION_DOWN
,
"ModelMoveDown"
),
(
self
.
ACTION_DELETE
,
"ModelDelete"
),
(
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
.
_gtk_handlers
=
[]
self
.
_gtk_handlers
.
extend
((
...
...
@@ -68,18 +70,6 @@ class Models(pycam.Plugins.ListPluginBase):
self
.
_edit_model_name
)))
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ModelList"
)
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
.
set_mode
(
self
.
_gtk
.
SELECTION_MULTIPLE
)
self
.
_gtk_handlers
.
append
((
selection
,
"changed"
,
...
...
@@ -90,7 +80,6 @@ class Models(pycam.Plugins.ListPluginBase):
self
.
register_gtk_handlers
(
self
.
_gtk_handlers
)
self
.
register_event_handlers
(
self
.
_event_handlers
)
self
.
_get_colors_of_selected_models
()
self
.
register_model_update
(
update_model
)
# update the model list
self
.
core
.
emit_event
(
"model-list-changed"
)
self
.
core
.
register_namespace
(
"models"
,
...
...
@@ -145,16 +134,13 @@ class Models(pycam.Plugins.ListPluginBase):
self
.
_visualize_visible_state
)
def
_edit_model_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
model_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
model
=
[
m
for
m
in
self
if
id
(
m
)
==
model_ref
][
0
]
if
(
new_text
!=
model
[
"name"
])
and
new_text
:
model
=
self
.
get_by_path
(
path
)
if
model
and
(
new_text
!=
model
[
"name"
])
and
new_text
:
model
[
"name"
]
=
new_text
def
_render_model_name
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
model_dict
=
self
[
path
[
0
]]
cell
.
set_property
(
"text"
,
model_dict
[
"name"
])
model_obj
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
cell
.
set_property
(
"text"
,
model_obj
[
"name"
])
def
_visualize_visible_state
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
...
...
@@ -175,9 +161,6 @@ class Models(pycam.Plugins.ListPluginBase):
model
[
"visible"
]
=
not
model
[
"visible"
]
self
.
core
.
emit_event
(
"visual-item-updated"
)
def
get_selected
(
self
):
return
self
.
_get_selected
(
self
.
_modelview
,
force_list
=
True
)
def
get_visible
(
self
):
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):
DEPENDS
=
[
"ParameterGroupManager"
]
CATEGORIES
=
[
"Process"
]
UI_FILE
=
"processes.ui"
COLUMN_REF
=
0
def
setup
(
self
):
self
.
core
.
set
(
"processes"
,
self
)
...
...
@@ -40,10 +39,13 @@ class Processes(pycam.Plugins.ListPluginBase):
self
.
_gtk_handlers
=
[]
self
.
core
.
register_ui
(
"main"
,
"Processes"
,
process_frame
,
weight
=
20
)
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"
),
(
self
.
ACTION_DOWN
,
"ProcessMoveDown"
),
(
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
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"ProcessNew"
),
"clicked"
,
self
.
_process_new
))
...
...
@@ -84,23 +86,11 @@ class Processes(pycam.Plugins.ListPluginBase):
"edited"
,
self
.
_edit_process_name
))
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ProcessList"
)
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"
),
"changed"
,
"process-strategy-changed"
))
self
.
register_model_update
(
update_model
)
self
.
_event_handlers
=
(
(
"process-strategy-list-changed"
,
self
.
_update_widgets
),
(
"process-list-changed"
,
self
.
_trigger_table_update
),
(
"process-selection-changed"
,
self
.
_process_switch
),
(
"process-changed"
,
self
.
_store_process_settings
),
(
"process-strategy-changed"
,
self
.
_store_process_settings
))
...
...
@@ -127,33 +117,19 @@ class Processes(pycam.Plugins.ListPluginBase):
self
.
pop
()
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
):
path
=
model
.
get_path
(
m_iter
)
data
=
self
[
path
[
0
]]
process
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
# TODO: describe the strategy
text
=
"TODO"
cell
.
set_property
(
"text"
,
text
)
def
_render_process_name
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
data
=
self
[
path
[
0
]]
cell
.
set_property
(
"text"
,
data
[
"name"
])
process
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
cell
.
set_property
(
"text"
,
process
[
"name"
])
def
_edit_process_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
process_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
process
=
[
p
for
p
in
self
if
id
(
p
)
==
process_ref
][
0
]
if
(
new_text
!=
process
[
"name"
])
and
new_text
:
process
=
self
.
get_by_path
(
path
)
if
process
and
(
new_text
!=
process
[
"name"
])
and
new_text
:
process
[
"name"
]
=
new_text
def
_trigger_table_update
(
self
):
...
...
pycam/Plugins/Tasks.py
View file @
31c4d85e
...
...
@@ -31,7 +31,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
UI_FILE
=
"tasks.ui"
CATEGORIES
=
[
"Task"
]
COLUMN_REF
=
0
DEPENDS
=
[
"Models"
,
"Tools"
,
"Processes"
,
"Bounds"
,
"Toolpaths"
]
def
setup
(
self
):
...
...
@@ -43,10 +42,13 @@ class Tasks(pycam.Plugins.ListPluginBase):
task_frame
.
unparent
()
self
.
core
.
register_ui
(
"main"
,
"Tasks"
,
task_frame
,
weight
=
40
)
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"
),
(
self
.
ACTION_DOWN
,
"TaskMoveDown"
),
(
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
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"TaskNew"
),
"clicked"
,
self
.
_task_new
))
...
...
@@ -102,19 +104,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
self
.
_generate_selected_toolpaths
),
(
self
.
gui
.
get_object
(
"GenerateAllToolPathsButton"
),
"clicked"
,
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
self
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"TaskTypeSelector"
),
"changed"
,
"task-type-changed"
))
...
...
@@ -126,7 +115,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
(
"task-type-changed"
,
self
.
_store_task
),
(
"task-selection-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_event_handlers
(
self
.
_event_handlers
)
self
.
_update_widgets
()
...
...
@@ -152,26 +140,9 @@ class Tasks(pycam.Plugins.ListPluginBase):
while
len
(
self
)
>
0
:
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
):
path
=
int
(
path
)
task_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
task
=
[
t
for
t
in
self
if
id
(
t
)
==
task_ref
][
0
]
if
(
new_text
!=
task
[
"name"
])
and
new_text
:
task
=
self
.
get_by_path
(
path
)
if
task
and
(
new_text
!=
task
[
"name"
])
and
new_text
:
task
[
"name"
]
=
new_text
def
_trigger_table_update
(
self
):
...
...
@@ -179,8 +150,7 @@ class Tasks(pycam.Plugins.ListPluginBase):
self
.
gui
.
get_object
(
"NameCell"
),
self
.
_render_task_name
)
def
_render_task_name
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
task
=
self
[
path
[
0
]]
task
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
cell
.
set_property
(
"text"
,
task
[
"name"
])
def
_get_type
(
self
,
name
=
None
):
...
...
pycam/Plugins/Toolpaths.py
View file @
31c4d85e
...
...
@@ -40,13 +40,16 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self
.
core
.
register_ui
(
"main"
,
"Toolpaths"
,
self
.
tp_box
,
weight
=
50
)
self
.
_gtk_handlers
=
[]
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
.
clear
()
for
action
,
obj_name
in
((
self
.
ACTION_UP
,
"ToolpathMoveUp"
),
(
self
.
ACTION_DOWN
,
"ToolpathMoveDown"
),
(
self
.
ACTION_DELETE
,
"ToolpathDelete"
),
(
self
.
ACTION_CLEAR
,
"ToolpathDeleteAll"
)):
self
.
register_list_action_button
(
action
,
self
.
_modelview
,
self
.
register_list_action_button
(
action
,
self
.
gui
.
get_object
(
obj_name
))
# toolpath operations
toolpath_handling_obj
=
self
.
gui
.
get_object
(
...
...
@@ -73,22 +76,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self
.
_gtk_handlers
.
append
((
selection
,
"changed"
,
"toolpath-selection-changed"
))
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
=
(
(
"toolpath-changed"
,
self
.
_update_widgets
),
(
"toolpath-list-changed"
,
self
.
_update_widgets
),
...
...
@@ -111,9 +98,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self
.
unregister_event_handlers
(
self
.
_event_handlers
)
self
.
core
.
set
(
"toolpaths"
,
None
)
def
get_selected
(
self
):
return
self
.
_get_selected
(
self
.
_modelview
,
force_list
=
True
)
def
get_visible
(
self
):
return
[
self
[
index
]
for
index
,
item
in
enumerate
(
self
.
_treemodel
)
if
item
[
self
.
COLUMN_VISIBLE
]]
...
...
pycam/Plugins/Tools.py
View file @
31c4d85e
...
...
@@ -28,7 +28,6 @@ class Tools(pycam.Plugins.ListPluginBase):
DEPENDS
=
[
"ParameterGroupManager"
]
CATEGORIES
=
[
"Tool"
]
UI_FILE
=
"tools.ui"
COLUMN_REF
=
0
def
setup
(
self
):
self
.
core
.
set
(
"tools"
,
self
)
...
...
@@ -41,10 +40,13 @@ class Tools(pycam.Plugins.ListPluginBase):
self
.
core
.
register_chain
(
"get_toolpath_information"
,
self
.
get_toolpath_information
)
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"
),
(
self
.
ACTION_DOWN
,
"ToolMoveDown"
),
(
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
.
_gtk_handlers
.
append
((
self
.
gui
.
get_object
(
"ToolNew"
),
"clicked"
,
self
.
_tool_new
))
...
...
@@ -95,18 +97,6 @@ class Tools(pycam.Plugins.ListPluginBase):
"edited"
,
self
.
_edit_tool_name
))
self
.
_treemodel
=
self
.
gui
.
get_object
(
"ToolList"
)
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
self
.
_gtk_handlers
.
append
((
self
.
_modelview
.
get_selection
(),
"changed"
,
"tool-selection-changed"
))
...
...
@@ -121,7 +111,6 @@ class Tools(pycam.Plugins.ListPluginBase):
(
"tool-changed"
,
self
.
_trigger_table_update
),
(
"tool-list-changed"
,
self
.
_trigger_table_update
),
(
"tool-shape-changed"
,
self
.
_store_tool_settings
))
self
.
register_model_update
(
update_model
)
self
.
register_gtk_handlers
(
self
.
_gtk_handlers
)
self
.
register_event_handlers
(
self
.
_event_handlers
)
self
.
_update_widgets
()
...
...
@@ -151,17 +140,6 @@ class Tools(pycam.Plugins.ListPluginBase):
self
.
pop
()
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
):
if
item
in
self
:
data
[
"tool_id"
]
=
item
[
"id"
]
...
...
@@ -180,8 +158,9 @@ class Tools(pycam.Plugins.ListPluginBase):
cell
.
set_property
(
"text"
,
str
(
tool
[
key
]))
def
_render_tool_shape
(
self
,
column
,
cell
,
model
,
m_iter
):
path
=
model
.
get_path
(
m_iter
)
tool
=
self
[
path
[
0
]]
tool
=
self
.
get_by_path
(
model
.
get_path
(
m_iter
))
if
not
tool
:
return
parameters
=
tool
[
"parameters"
]
if
"radius"
in
parameters
:
text
=
"
%
g
%
s"
%
(
2
*
parameters
[
"radius"
],
self
.
core
.
get
(
"unit"
))
...
...
@@ -190,21 +169,17 @@ class Tools(pycam.Plugins.ListPluginBase):
cell
.
set_property
(
"text"
,
text
)
def
_edit_tool_name
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
tool_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
tool
=
[
t
for
t
in
self
if
id
(
t
)
==
tool_ref
][
0
]
if
(
new_text
!=
tool
[
"name"
])
and
new_text
:
tool
=
self
.
get_by_path
(
path
)
if
tool
and
(
new_text
!=
tool
[
"name"
])
and
new_text
:
tool
[
"name"
]
=
new_text
def
_edit_tool_id
(
self
,
cell
,
path
,
new_text
):
path
=
int
(
path
)
tool_ref
=
self
.
_treemodel
[
path
][
self
.
COLUMN_REF
]
tool
=
[
t
for
t
in
self
if
id
(
t
)
==
tool_ref
][
0
]
tool
=
self
.
get_by_path
(
path
)
try
:
new_value
=
int
(
new_text
)
except
ValueError
:
return
if
new_value
!=
tool
[
"id"
]
:
if
tool
and
(
new_value
!=
tool
[
"id"
])
:
tool
[
"id"
]
=
new_value
def
_get_shape
(
self
,
name
=
None
):
...
...
pycam/Plugins/__init__.py
View file @
31c4d85e
...
...
@@ -358,6 +358,7 @@ class ListPluginBase(PluginBase, list):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
ListPluginBase
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
_update_model_funcs
=
[]
self
.
_gtk_modelview
=
None
def
get_function
(
func_name
):
return
lambda
*
args
,
**
kwargs
:
\
self
.
_change_wrapper
(
func_name
,
*
args
,
**
kwargs
)
...
...
@@ -370,9 +371,14 @@ class ListPluginBase(PluginBase, list):
self
.
_update_model
()
return
value
def
_get_selected
(
self
,
modelview
,
index
=
False
,
force_list
=
False
,
content
=
None
):
if
content
is
None
:
content
=
self
def
get_selected
(
self
,
**
kwargs
):
if
self
.
_gtk_modelview
:
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"
):
# a treeview selection
selection
=
modelview
.
get_selection
()
...
...
@@ -393,7 +399,7 @@ class ListPluginBase(PluginBase, list):
if
index
:
get_result
=
lambda
path
:
path
[
0
]
else
:
get_result
=
lambda
path
:
content
[
path
[
0
]]
get_result
=
self
.
get_by_path
if
(
selection_mode
==
gtk
.
SELECTION_MULTIPLE
)
or
force_list
:
result
=
[]
for
path
in
paths
:
...
...
@@ -405,7 +411,57 @@ class ListPluginBase(PluginBase, list):
result
=
get_result
(
paths
[
0
])
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
):
self
.
_update_gtk_treemodel
()
for
update_func
in
self
.
_update_model_funcs
:
update_func
()
...
...
@@ -426,8 +482,7 @@ class ListPluginBase(PluginBase, list):
self
.
log
.
info
(
"Invalid action for ListPluginBase.list_action: "
+
\
str
(
action
))
return
selected_items
=
self
.
_get_selected
(
modelview
,
index
=
True
,
force_list
=
True
)
selected_items
=
self
.
get_selected
(
index
=
True
,
force_list
=
True
)
selected_items
.
sort
()
if
action
in
(
self
.
ACTION_DOWN
,
self
.
ACTION_DELETE
):
selected_items
.
sort
(
reverse
=
True
)
...
...
@@ -466,7 +521,7 @@ class ListPluginBase(PluginBase, list):
modelview
=
args
[
-
3
]
action
=
args
[
-
2
]
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
:
button
.
set_sensitive
(
len
(
self
)
>
0
)
elif
not
paths
:
...
...
@@ -479,7 +534,8 @@ class ListPluginBase(PluginBase, list):
else
:
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"
):
# a treeview
selection
=
modelview
.
get_selection
()
...
...
@@ -504,7 +560,7 @@ class ObjectWithAttributes(dict):
def
__init__
(
self
,
key
,
params
=
None
):
if
not
params
is
None
:
self
.
update
(
params
)
self
[
"uuid"
]
=
uuid
.
uuid4
(
)
self
[
"uuid"
]
=
str
(
uuid
.
uuid4
()
)
self
.
node_key
=
key
...
...
share/ui/bounds.ui
View file @
31c4d85e
...
...
@@ -65,8 +65,8 @@
</object>
<object
class=
"GtkListStore"
id=
"BoundsList"
>
<columns>
<!-- column-name
ref
-->
<column
type=
"g
ulong
"
/>
<!-- column-name
uuid
-->
<column
type=
"g
chararray
"
/>
</columns>
</object>
<object
class=
"GtkVPaned"
id=
"BoundsBox"
>
...
...
share/ui/models.ui
View file @
31c4d85e
...
...
@@ -4,8 +4,8 @@
<!-- interface-naming-policy project-wide -->
<object
class=
"GtkListStore"
id=
"ModelList"
>
<columns>
<!-- column-name id -->
<column
type=
"g
ulong
"
/>
<!-- column-name
uu
id -->
<column
type=
"g
chararray
"
/>
</columns>
</object>
<object
class=
"GtkWindow"
id=
"window1"
>
...
...
share/ui/processes.ui
View file @
31c4d85e
...
...
@@ -18,8 +18,8 @@
</object>
<object
class=
"GtkListStore"
id=
"ProcessList"
>
<columns>
<!-- column-name
ref
-->
<column
type=
"g
ulong
"
/>
<!-- column-name
uuid
-->
<column
type=
"g
chararray
"
/>
</columns>
</object>
<object
class=
"GtkVPaned"
id=
"ProcessBox"
>
...
...
@@ -49,7 +49,9 @@
<object
class=
"GtkTreeViewColumn"
id=
"NameColumn"
>
<property
name=
"title"
>
Name
</property>
<child>
<object
class=
"GtkCellRendererText"
id=
"NameCell"
/>
<object
class=
"GtkCellRendererText"
id=
"NameCell"
>
<property
name=
"editable"
>
True
</property>
</object>
</child>
</object>
</child>
...
...
share/ui/tasks.ui
View file @
31c4d85e
...
...
@@ -28,8 +28,8 @@
</object>
<object
class=
"GtkListStore"
id=
"TaskList"
>
<columns>
<!-- column-name
index
-->
<column
type=
"g
ulong
"
/>
<!-- column-name
uuid
-->
<column
type=
"g
chararray
"
/>
</columns>
</object>
<object
class=
"GtkVPaned"
id=
"TaskBox"
>
...
...
@@ -60,7 +60,9 @@
<object
class=
"GtkTreeViewColumn"
id=
"NameColumn"
>
<property
name=
"title"
>
Name
</property>
<child>
<object
class=
"GtkCellRendererText"
id=
"NameCell"
/>
<object
class=
"GtkCellRendererText"
id=
"NameCell"
>
<property
name=
"editable"
>
True
</property>
</object>
</child>
</object>
</child>
...
...
share/ui/tools.ui
View file @
31c4d85e
...
...
@@ -28,8 +28,8 @@
</object>
<object
class=
"GtkListStore"
id=
"ToolList"
>
<columns>
<!-- column-name
object_ref
-->
<column
type=
"g
ulong
"
/>
<!-- column-name
uuid
-->
<column
type=
"g
chararray
"
/>
</columns>
</object>
<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