diff --git a/Tst/tst/tc_management.py b/Tst/tst/tc_management.py index e8c4a937f8a4cd7ed22857923165fa8bf6a9be0a..846a1ccb99e379ec86c2c05f18eea2374d98c329 100644 --- a/Tst/tst/tc_management.py +++ b/Tst/tst/tc_management.py @@ -1,17 +1,48 @@ #!/usr/bin/env python3 import gi + gi.require_version("Gtk", "3.0") gi.require_version("GtkSource", "3.0") -from gi.repository import Gtk, GtkSource +from gi.repository import Gtk, Gdk, GtkSource import confignator import sys sys.path.append(confignator.get_option('paths', 'ccs')) import ccs_function_lib as cfl +import tc_management as tcm tc_type = None +dictionary_of_commands = cfl.get_tc_list() +read_in_list_of_commands = list(dictionary_of_commands.keys()) +list_of_commands = [] +type_list = [] +subtype_list = [] + +descr_list = [] +calibrations_list = [] +minval_list = [] +maxval_list = [] +altxt_list = [] +alval_list = [] + + +for command in read_in_list_of_commands: + command = list(command) + del command[0] + myorder = [2, 3, 0, 1] + command = [command[i] for i in myorder] + command[0] = int(command[0]) + command[1] = int(command[1]) + list_of_commands.append(command) + if command[0] not in type_list: + type_list.append(command[0]) + + +type_list.sort() +subtype_list.sort() + def get_variables(tc_type): @@ -107,12 +138,147 @@ def get_calibrations(tc_type, cpc_descr): -descr_list = [] -calibrations_list = [] -minval_list = [] -maxval_list = [] -altxt_list = [] -alval_list = [] + +""" +Gesamtbild bestehend aus TcTable und CommandDescriptionBox hier einfügen +""" + +class TcBox(Gtk.Box): + pass + +""" +TcTable hier einfügen +""" + + + +class TcTable(Gtk.Grid): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.set_size_request(500,500) + # self.set_orientation(Gtk.Orientation.VERTICAL) + # self.grid = Gtk.Grid + + self.telecommand_liststore = Gtk.ListStore(int, int, str, str) + for telecommand_ref in list_of_commands: + self.telecommand_liststore.append(list(telecommand_ref)) + self.current_filter_telecommand = None + + # Creating the filter, feeding it with the liststore model + self.telecommand_filter = self.telecommand_liststore.filter_new() + # setting the filter function + self.telecommand_filter.set_visible_func(self.telecommand_filter_func) + + # Create ListStores for the ComboBoxes + self.type_liststore = Gtk.ListStore(int) + for type_ref in type_list: + self.type_liststore.append([type_ref, ]) + # self.current_filter_type = None + + self.type_combo = Gtk.ComboBox.new_with_model(self.type_liststore) + self.type_combo.connect("changed", self.on_type_combo_changed) + renderer_text = Gtk.CellRendererText() + self.type_combo.pack_start(renderer_text, True) + self.type_combo.add_attribute(renderer_text, "text", 0) + self.attach(self.type_combo, 0, 0, 1, 1) + + self.clear_button = Gtk.Button(label="Clear") + self.clear_button.connect("clicked", self.on_clear_button_clicked) + self.attach_next_to( + self.clear_button, self.type_combo, Gtk.PositionType.RIGHT, 1, 1 + ) + + # creating the treeview, making it use the filter a model, adding columns + self.treeview = Gtk.TreeView.new_with_model(Gtk.TreeModelSort(self.telecommand_filter)) + for i, column_title in enumerate( + ["#TYPE", "SUBTYPE", "DESCR", "LONGDESCR"] + ): + renderer = Gtk.CellRendererText() + column = Gtk.TreeViewColumn(column_title, renderer, text=i) + column.set_sort_column_id(i) + self.treeview.append_column(column) + + # Handle selection + self.selected_row = self.treeview.get_selection() + self.selected_row.connect("changed", self.item_selected) + + # setting up layout, treeview in scrollwindow + self.scrollable_treelist = Gtk.ScrolledWindow() + self.scrollable_treelist.set_vexpand(True) + self.scrollable_treelist.set_hexpand(True) + self.attach(self.scrollable_treelist, 0, 1, 8, 10) + + self.scrollable_treelist.add(self.treeview) + + self.command_entry = Gtk.Entry() + self.command_entry.set_placeholder_text("<Command Variables>") + self.attach_next_to(self.command_entry, self.scrollable_treelist, Gtk.PositionType.BOTTOM, 8, 1) + + self.variable_box = CommandDescriptionBox() + self.attach_next_to(self.variable_box, self.command_entry, Gtk.PositionType.BOTTOM, 8, 5) + + # Set up Drag and Drop + self.treeview.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.COPY) + self.treeview.drag_source_set_target_list(None) + self.treeview.drag_source_add_text_targets() + + self.treeview.connect("drag-data-get", self.on_drag_data_get) + self.treeview.connect("drag-begin", self.on_drag_begin) + + self.show_all() + + def on_type_combo_changed(self, combo): + combo_iter = combo.get_active_iter() + if combo_iter is not None: + model = combo.get_model() + number = model[combo_iter][0] + # print(number) + self.current_filter_telecommand = int(number) + + self.telecommand_filter.refilter() + + + def on_clear_button_clicked(self, widget): + self.current_filter_telecommand = None + self.telecommand_filter.refilter() + + def item_selected(self, selection): + model, row = selection.get_selected() + if row is not None: + global descr + descr = model[row][2] + self.command_entry.set_text(cfl.make_tc_template(descr, comment=False)) + global tc_type + tc_type = descr + cpc_descr = get_cpc_descr(tc_type) + global descr_list + descr_list.clear() + descr_list = cpc_descr + self.variable_box.refresh_descr_treeview() + calibrations_list.clear() + self.variable_box.refresh_cal_treeview() + else: + pass + + def telecommand_filter_func(self, model, iter, data): + + if ( + self.current_filter_telecommand is None + or self.current_filter_telecommand == "None" + ): + return True + else: + return model[iter][0] == self.current_filter_telecommand + + def on_drag_data_get(self, treeview, drag_context, selection_data, info, time, *args): + treeselection = treeview.get_selection() + model, my_iter = treeselection.get_selected() + selection_data.set_text(cfl.make_tc_template(descr, comment=False), -1) + + def on_drag_begin(self, *args): + pass + @@ -134,7 +300,7 @@ class CommandDescriptionBox(Gtk.Box): # setting the filter function self.descr_filter.set_visible_func(self.descr_filter_func) - self.treeview = Gtk.TreeView(model=self.descr_filter) + self.descr_treeview = Gtk.TreeView(model=self.descr_filter) for i, column_title in enumerate( @@ -143,12 +309,12 @@ class CommandDescriptionBox(Gtk.Box): renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(column_title, renderer, text=i) column.colnr = i - self.treeview.append_column(column) + self.descr_treeview.append_column(column) # item selection # self.treeview.connect("button-press-event", self.on_cell_clicked) - self.selected_row = self.treeview.get_selection() + self.selected_row = self.descr_treeview.get_selection() self.selected_row.connect("changed", self.item_selected) @@ -156,7 +322,7 @@ class CommandDescriptionBox(Gtk.Box): self.scrollable_treelist.set_vexpand(True) self.pack_start(self.scrollable_treelist, True, True, 0) - self.scrollable_treelist.add(self.treeview) + self.scrollable_treelist.add(self.descr_treeview) @@ -220,7 +386,7 @@ class CommandDescriptionBox(Gtk.Box): self.descr_liststore = Gtk.ListStore(str) for descr_ref in descr_list: self.descr_liststore.append(tuple(descr_ref)) - self.treeview.set_model(self.descr_liststore) + self.descr_treeview.set_model(self.descr_liststore) def cal_filter_func(self, model, iter, data): @@ -233,6 +399,7 @@ class CommandDescriptionBox(Gtk.Box): return model[iter][2] == self.current_filter_descr def refresh_cal_treeview(self): + self.cal_liststore = Gtk.ListStore(str, str, str, str) if calibrations_list == [] or calibrations_list == [[]]: diff --git a/Tst/tst/tst.py b/Tst/tst/tst.py index fd383386f12b6da5205fb371ec14140fb1883044..b8d4741ed8054d89016c511a6125dcc25e6d8b3d 100755 --- a/Tst/tst/tst.py +++ b/Tst/tst/tst.py @@ -24,27 +24,12 @@ import toolbox import tc_management as tcm + # creating lists for type and subtype to get rid of duplicate entries, for TC List -dictionary_of_commands = cfl.get_tc_list() -read_in_list_of_commands = list(dictionary_of_commands.keys()) -list_of_commands = [] -type_list = [] -subtype_list = [] - -for command in read_in_list_of_commands: - command = list(command) - del command[0] - myorder = [2, 3, 0, 1] - command = [command[i] for i in myorder] - command[0] = int(command[0]) - command[1] = int(command[1]) - list_of_commands.append(command) - if command[0] not in type_list: - type_list.append(command[0]) - - -type_list.sort() -subtype_list.sort() + + + + path_icon = os.path.join(os.path.dirname(__file__), 'style/tst.svg') menu_xml = os.path.join(os.path.dirname(__file__), 'app_menu.xml') @@ -316,10 +301,21 @@ class TstAppWindow(Gtk.ApplicationWindow): self.feature_area.append_page(child=self.log_view, tab_label=self.label_widget_log_view) # command list tab + + self.tcm = tcm.TcTable() + self.label_widget_tcm = Gtk.Label() + self.label_widget_tcm.set_text('TC Table') + self.feature_area.append_page(child=self.tcm, tab_label=self.label_widget_tcm) + + + """ self.tcm = TCTableClass() self.label_widget_tcm = Gtk.Label() self.label_widget_tcm.set_text('TC Table') self.feature_area.append_page(child=self.tcm, tab_label=self.label_widget_tcm) + """ + + self.box.pack_start(self.work_desk, True, True, 0) @@ -763,114 +759,6 @@ class TstAppWindow(Gtk.ApplicationWindow): Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) Gtk.StyleContext.reset_widgets(Gdk.Screen.get_default()) -class TCTableClass(Gtk.Grid): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - self.set_size_request(500,500) - # self.set_orientation(Gtk.Orientation.VERTICAL) - # self.grid = Gtk.Grid - - self.telecommand_liststore = Gtk.ListStore(int, int, str, str) - for telecommand_ref in list_of_commands: - self.telecommand_liststore.append(list(telecommand_ref)) - self.current_filter_telecommand = None - - # Creating the filter, feeding it with the liststore model - self.telecommand_filter = self.telecommand_liststore.filter_new() - # setting the filter function - self.telecommand_filter.set_visible_func(self.telecommand_filter_func) - - # Create ListStores for the ComboBoxes - self.type_liststore = Gtk.ListStore(int) - for type_ref in type_list: - self.type_liststore.append([type_ref, ]) - # self.current_filter_type = None - - self.type_combo = Gtk.ComboBox.new_with_model(self.type_liststore) - self.type_combo.connect("changed", self.on_type_combo_changed) - renderer_text = Gtk.CellRendererText() - self.type_combo.pack_start(renderer_text, True) - self.type_combo.add_attribute(renderer_text, "text", 0) - self.attach(self.type_combo, 0, 0, 1, 1) - - self.clear_button = Gtk.Button(label="Clear") - self.clear_button.connect("clicked", self.on_clear_button_clicked) - self.attach_next_to( - self.clear_button, self.type_combo, Gtk.PositionType.RIGHT, 1, 1 - ) - - # creating the treeview, making it use the filter a model, adding columns - self.treeview = Gtk.TreeView.new_with_model(Gtk.TreeModelSort(self.telecommand_filter)) - for i, column_title in enumerate( - ["#TYPE", "SUBTYPE", "DESCR", "LONGDESCR"] - ): - renderer = Gtk.CellRendererText() - column = Gtk.TreeViewColumn(column_title, renderer, text=i) - column.set_sort_column_id(i) - self.treeview.append_column(column) - - # Handle selection - self.selected_row = self.treeview.get_selection() - self.selected_row.connect("changed", self.item_selected) - - # setting up layout, treeview in scrollwindow - self.scrollable_treelist = Gtk.ScrolledWindow() - self.scrollable_treelist.set_vexpand(True) - self.scrollable_treelist.set_hexpand(True) - self.attach(self.scrollable_treelist, 0, 1, 8, 10) - - self.scrollable_treelist.add(self.treeview) - - self.command_entry = Gtk.Entry() - self.command_entry.set_placeholder_text("<Command Variables>") - self.attach_next_to(self.command_entry, self.scrollable_treelist, Gtk.PositionType.BOTTOM, 8, 1) - - self.variable_box = tcm.CommandDescriptionBox() - self.attach_next_to(self.variable_box, self.command_entry, Gtk.PositionType.BOTTOM, 8, 5) - - self.show_all() - - def on_type_combo_changed(self, combo): - combo_iter = combo.get_active_iter() - if combo_iter is not None: - model = combo.get_model() - number = model[combo_iter][0] - # print(number) - self.current_filter_telecommand = int(number) - - self.telecommand_filter.refilter() - - - def on_clear_button_clicked(self, widget): - self.current_filter_telecommand = None - self.telecommand_filter.refilter() - - def item_selected(self, selection): - model, row = selection.get_selected() - if row is not None: - descr = model[row][2] - self.command_entry.set_text(cfl.make_tc_template(descr, comment=False)) - tcm.tc_type = descr - cpc_descr = tcm.get_cpc_descr(tcm.tc_type) - tcm.descr_list.clear() - tcm.descr_list = cpc_descr - self.variable_box.refresh_descr_treeview() - tcm.calibrations_list.clear() - self.variable_box.refresh_cal_treeview() - else: - pass - - def telecommand_filter_func(self, model, iter, data): - - if ( - self.current_filter_telecommand is None - or self.current_filter_telecommand == "None" - ): - return True - else: - return model[iter][0] == self.current_filter_telecommand - class ViewModelAsJson(Gtk.Box): def __init__(self, *args, **kwargs): diff --git a/Tst/tst/view.py b/Tst/tst/view.py index 14060441699393193e49268c0537b2df5cba7b09..68a5044daeb320891db632f66c078cf27c7d1114 100644 --- a/Tst/tst/view.py +++ b/Tst/tst/view.py @@ -701,10 +701,21 @@ class StepWidget(Gtk.EventBox): self.commands_view.set_indent_on_tab(True) self.commands_view.set_insert_spaces_instead_of_tabs(True) self.commands_buffer = self.commands_view.get_buffer() + # draganddrop here + """ + self.commands_view.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY) + self.commands_view.drag_dest_set_target_list(None) + self.commands_view.drag_dest_add_text_targets() + + self.commands_view.connect("drag-motion", self.on_drag_motion_2) + self.commands_view.connect("drag-leave", self.on_drag_leave) + """ + self.commands_buffer.set_language(lngg) # self.commands_buffer.set_style_scheme(self.board.current_scheme) self.commands_scrolled_window.add(self.commands_view) + self.whole_commands_box.pack_start(self.lbl_box_commands, False, False, 0) self.whole_commands_box.pack_start(self.commands_scrolled_window, True, True, 0) self.detail_box.pack_start(self.whole_commands_box, True, True, 0) @@ -1595,6 +1606,7 @@ class Edit_Pre_Post_Con_Dialog(Gtk.Dialog): self.make_section_dict() self.view() + self.show_all() def make_section_dict(self):