mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-07-04 13:38:37 +02:00
implementation of work with the list of bouquets
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
<requires lib="gtk+" version="3.12"/>
|
||||
<object class="GtkAboutDialog" id="about_dialog">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="icon_name">system-help</property>
|
||||
<property name="type_hint">normal</property>
|
||||
<property name="program_name">DemonEditor</property>
|
||||
@@ -42,11 +44,13 @@ dmitry.v.yefremov@gmail.com
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkMessageDialog" id="error_dialog">
|
||||
<property name="width_request">320</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="default_width">320</property>
|
||||
<property name="default_height">240</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="icon_name">accessories-text-editor</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="message_type">error</property>
|
||||
@@ -71,12 +75,105 @@ dmitry.v.yefremov@gmail.com
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkMessageDialog" id="question dialog">
|
||||
<object class="GtkDialog" id="input_dialog">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes"> </property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="icon_name">gtk-edit</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkBox" id="input_dialog_vbox">
|
||||
<property name="width_request">320</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkButtonBox" id="dialog-action_area2">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="button3">
|
||||
<property name="label">gtk-undo</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button4">
|
||||
<property name="label">gtk-ok</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="input_dialog_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="input_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="primary_icon_stock">gtk-edit</property>
|
||||
<property name="primary_icon_activatable">False</property>
|
||||
<property name="secondary_icon_activatable">False</property>
|
||||
<property name="secondary_icon_sensitive">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="-6">button3</action-widget>
|
||||
<action-widget response="-5">button4</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
<object class="GtkMessageDialog" id="question_dialog">
|
||||
<property name="width_request">320</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="default_width">320</property>
|
||||
<property name="default_height">240</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="message_type">question</property>
|
||||
<property name="buttons">ok-cancel</property>
|
||||
|
||||
@@ -29,7 +29,8 @@ __channels = {}
|
||||
__bouquets = {}
|
||||
# dynamically active elements depending on the selected view
|
||||
__tool_elements = None
|
||||
_SERVICE__ELEMENTS = ("copy_tool_button", "to_fav_tool_button", "copy_menu_item")
|
||||
_SERVICE_ELEMENTS = ("copy_tool_button", "to_fav_tool_button", "copy_menu_item")
|
||||
_BOUQUET_ELEMENTS = ("edit_tool_button", "new_tool_button")
|
||||
_REMOVE_ELEMENTS = ("remove_tool_button", "delete_menu_item")
|
||||
_FAV_ELEMENTS = ("up_tool_button", "down_tool_button", "cut_tool_button",
|
||||
"paste_tool_button", "cut_menu_item", "paste_menu_item")
|
||||
@@ -60,6 +61,8 @@ def get_handlers():
|
||||
"on_copy": on_copy,
|
||||
"on_paste": on_paste,
|
||||
"on_delete": on_delete,
|
||||
"on_new_bouquet": on_new_bouquet,
|
||||
"on_bouquets_edit": on_bouquets_edit,
|
||||
"on_to_fav_move": on_to_fav_move,
|
||||
"on_services_tree_view_drag_data_get": on_services_tree_view_drag_data_get,
|
||||
"on_fav_tree_view_drag_data_get": on_fav_tree_view_drag_data_get,
|
||||
@@ -159,14 +162,14 @@ def on_delete(item):
|
||||
fav_bouquet = None
|
||||
|
||||
if bq_selected:
|
||||
fav_bouquet = __bouquets[bq_selected]
|
||||
fav_bouquet = __bouquets.get(bq_selected, None)
|
||||
|
||||
for itr in itrs:
|
||||
if fav_bouquet and model_name == FAV_LIST_NAME:
|
||||
del fav_bouquet[int(model.get_path(itr)[0])]
|
||||
|
||||
if model_name == BOUQUETS_LIST_NAME:
|
||||
if model.iter_has_child(itr):
|
||||
if len(model.get_path(itr)) < 2:
|
||||
show_dialog("error_dialog", "This item is not allowed to be removed!")
|
||||
return
|
||||
else:
|
||||
@@ -192,6 +195,61 @@ def on_delete(item):
|
||||
return rows
|
||||
|
||||
|
||||
def on_new_bouquet(view):
|
||||
""" Creates a new item in the bouquets tree """
|
||||
model, paths = view.get_selection().get_selected_rows()
|
||||
|
||||
if paths:
|
||||
itr = model.get_iter(paths[0])
|
||||
bq_type = model.get_value(itr, 1)
|
||||
bq_name = "bouquet"
|
||||
count = 0
|
||||
key = "{}:{}".format(bq_name, bq_type)
|
||||
# Generating name of new bouquet
|
||||
while key in __bouquets:
|
||||
count += 1
|
||||
bq_name = "bouquet{}".format(count)
|
||||
key = "{}:{}".format(bq_name, bq_type)
|
||||
|
||||
response = show_dialog("input_dialog", bq_name)
|
||||
|
||||
if response == Gtk.ResponseType.CANCEL:
|
||||
return
|
||||
|
||||
bq = response, bq_type
|
||||
|
||||
if model.iter_n_children(itr): # parent
|
||||
model.insert(itr, 0, bq)
|
||||
else:
|
||||
parent_itr = model.iter_parent(itr)
|
||||
if parent_itr:
|
||||
index = int(model.get_path(itr)[1]) + 1
|
||||
model.insert(parent_itr, index, bq)
|
||||
else:
|
||||
model.append(itr, bq)
|
||||
__bouquets[key] = []
|
||||
|
||||
|
||||
def on_bouquets_edit(view):
|
||||
""" Rename bouquets """
|
||||
if not is_bouquet_selected():
|
||||
show_dialog("error_dialog", "This item is not allowed to edit!")
|
||||
return
|
||||
|
||||
model, paths = view.get_selection().get_selected_rows()
|
||||
|
||||
if paths:
|
||||
itr = model.get_iter(paths[0])
|
||||
bq_name, bq_type = model.get(itr, 0, 1)
|
||||
response = show_dialog("input_dialog", bq_name)
|
||||
|
||||
if response == Gtk.ResponseType.CANCEL:
|
||||
return
|
||||
|
||||
model.set_value(itr, 0, response)
|
||||
__bouquets["{}:{}".format(response, bq_type)] = __bouquets.pop("{}:{}".format(bq_name, bq_type))
|
||||
|
||||
|
||||
def on_to_fav_move(view):
|
||||
""" Move items from main to fav list """
|
||||
selection = get_selection(view)
|
||||
@@ -312,6 +370,7 @@ def open_data():
|
||||
__services_model.append(ch)
|
||||
|
||||
bouquets = get_bouquets(data_path)
|
||||
|
||||
for bouquet in bouquets:
|
||||
parent = __bouquets_model.append(None, [bouquet.name, bouquet.type])
|
||||
for bt in bouquet.bouquets:
|
||||
@@ -320,13 +379,12 @@ def open_data():
|
||||
__bouquets["{}:{}".format(name, bt_type)] = bt.services
|
||||
except Exception as e:
|
||||
__status_bar.push(1, getattr(e, "message", repr(e)))
|
||||
raise e # temp for debug
|
||||
|
||||
|
||||
@run_task
|
||||
def on_data_save(*args):
|
||||
# Perhaps needs a dialog to choose what we need to save!!!
|
||||
if show_dialog("question dialog") == Gtk.ResponseType.CANCEL:
|
||||
if show_dialog("question_dialog") == Gtk.ResponseType.CANCEL:
|
||||
return
|
||||
|
||||
path = __options["data_dir_path"]
|
||||
@@ -397,7 +455,7 @@ def is_bouquet_selected():
|
||||
selection = __bouquets_view.get_selection()
|
||||
model, path = selection.get_selected_rows()
|
||||
|
||||
if len(path) < 1 or model.iter_has_child(model.get_iter(path)):
|
||||
if not path or len(path[0]) < 2:
|
||||
return False
|
||||
|
||||
return "{}:{}".format(*model.get(model.get_iter(path), 0, 1))
|
||||
@@ -409,10 +467,22 @@ def show_dialog(dialog_name, text=None):
|
||||
builder.add_from_file("ui/dialogs.glade")
|
||||
dialog = builder.get_object(dialog_name)
|
||||
dialog.set_transient_for(__main_window)
|
||||
if text:
|
||||
dialog.set_markup(text)
|
||||
|
||||
if dialog_name == "path_chooser_dialog":
|
||||
dialog.set_current_folder(__options["data_dir_path"])
|
||||
|
||||
if dialog_name == "input_dialog":
|
||||
entry = builder.get_object("input_entry")
|
||||
entry.set_text(text)
|
||||
response = dialog.run()
|
||||
txt = entry.get_text()
|
||||
dialog.destroy()
|
||||
|
||||
return txt if response == Gtk.ResponseType.OK else Gtk.ResponseType.CANCEL
|
||||
|
||||
if text:
|
||||
dialog.set_markup(text)
|
||||
|
||||
response = dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
@@ -441,9 +511,14 @@ def on_tree_view_key_release(view, event):
|
||||
move_items(Gdk.KEY_Up)
|
||||
elif ctrl and key == Gdk.KEY_Down:
|
||||
move_items(Gdk.KEY_Down)
|
||||
elif key == Gdk.KEY_Insert and model_name == SERVICE_LIST_NAME:
|
||||
elif key == Gdk.KEY_Insert:
|
||||
# Move items from main to fav list
|
||||
on_to_fav_move(view)
|
||||
if model_name == SERVICE_LIST_NAME:
|
||||
on_to_fav_move(view)
|
||||
elif model_name == BOUQUETS_LIST_NAME:
|
||||
on_new_bouquet(view)
|
||||
elif key == Gdk.KEY_F2 and model_name == BOUQUETS_LIST_NAME:
|
||||
on_bouquets_edit(view)
|
||||
elif ctrl and (key == Gdk.KEY_c or key == Gdk.KEY_C) and model_name == SERVICE_LIST_NAME:
|
||||
on_copy(view)
|
||||
elif ctrl and key == Gdk.KEY_x or key == Gdk.KEY_X:
|
||||
@@ -468,6 +543,7 @@ def on_reload(item):
|
||||
pass
|
||||
|
||||
|
||||
@run_task
|
||||
def on_view_focus(view, focus_event):
|
||||
model = view.get_model()
|
||||
model_name = model.get_name()
|
||||
@@ -480,14 +556,16 @@ def on_view_focus(view, focus_event):
|
||||
if model_name == BOUQUETS_LIST_NAME:
|
||||
for elem in __tool_elements:
|
||||
__tool_elements[elem].set_sensitive(False)
|
||||
__tool_elements["new_tool_button"].set_sensitive(True)
|
||||
for elem in _BOUQUET_ELEMENTS:
|
||||
__tool_elements[elem].set_sensitive(True)
|
||||
else:
|
||||
is_service = model_name == SERVICE_LIST_NAME
|
||||
for elem in _FAV_ELEMENTS:
|
||||
__tool_elements[elem].set_sensitive(not is_service)
|
||||
for elem in _SERVICE__ELEMENTS:
|
||||
for elem in _SERVICE_ELEMENTS:
|
||||
__tool_elements[elem].set_sensitive(is_service)
|
||||
__tool_elements["new_tool_button"].set_sensitive(False)
|
||||
for elem in _BOUQUET_ELEMENTS:
|
||||
__tool_elements[elem].set_sensitive(False)
|
||||
|
||||
for elem in _REMOVE_ELEMENTS:
|
||||
__tool_elements[elem].set_sensitive(not empty)
|
||||
@@ -532,7 +610,8 @@ def init_ui():
|
||||
"paste_tool_button", "to_fav_tool_button",
|
||||
"new_tool_button", "remove_tool_button",
|
||||
"cut_menu_item", "copy_menu_item",
|
||||
"paste_menu_item", "delete_menu_item")}
|
||||
"paste_menu_item", "delete_menu_item",
|
||||
"edit_tool_button")}
|
||||
builder.connect_signals(get_handlers())
|
||||
init_drag_and_drop() # drag and drop
|
||||
__main_window.show_all()
|
||||
|
||||
@@ -6,16 +6,27 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="menuitem6">
|
||||
<property name="label">gtk-add</property>
|
||||
<object class="GtkImageMenuItem" id="bouquets_new_popup_menui_tem">
|
||||
<property name="label">gtk-new</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="activate" handler="on_new_bouquet" object="bouquets_tree_view" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="menuitem7">
|
||||
<object class="GtkImageMenuItem" id="bouguets_edit_popup_menui_tem">
|
||||
<property name="label">gtk-edit</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="activate" handler="on_bouquets_edit" object="bouquets_tree_view" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="bouquets_remove_popup_menui_tem">
|
||||
<property name="label">gtk-remove</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
@@ -569,12 +580,38 @@
|
||||
<property name="label" translatable="yes">New</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-new</property>
|
||||
<signal name="clicked" handler="on_new_bouquet" object="bouquets_tree_view" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="edit_tool_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Edit </property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-edit</property>
|
||||
<signal name="clicked" handler="on_bouquets_edit" object="bouquets_tree_view" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorToolItem" id="separatortoolitem4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="remove_tool_button">
|
||||
<property name="visible">True</property>
|
||||
@@ -618,6 +655,7 @@
|
||||
<object class="GtkToolButton" id="tools_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Satellites edit tool</property>
|
||||
<property name="label" translatable="yes">Tools</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="icon_name">applications-utilities</property>
|
||||
@@ -1071,6 +1109,7 @@
|
||||
<property name="activate_on_single_click">True</property>
|
||||
<signal name="button-press-event" handler="on_view_popup_menu" object="bouquets_popup_menu" swapped="no"/>
|
||||
<signal name="focus-in-event" handler="on_view_focus" swapped="no"/>
|
||||
<signal name="key-release-event" handler="on_tree_view_key_release" swapped="no"/>
|
||||
<signal name="row-activated" handler="on_bouquets_selection" object="bouquets_tree_store" swapped="no"/>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="bouquets_selection"/>
|
||||
|
||||
Reference in New Issue
Block a user