def __validate_input(self): ''' Set the treview_state to TreeViewState.OK. Checks if the parent id of the __current_treeview_item is set and if so it searches for the parent in the __added_treeview_items array. If it finds the item the treeview_state remains unchanged. If the parent couldn't be found the treeview_state will be changed to TreeViewState.PARENT_NOT_EXISTS. If the parent id of the __current_treeview_item is not set the __treeview_state is set to TreeViewState.NO_PARENT. ''' log_enter_func('TreeViewControl', '__validate_input') self.__treeview_state = TreeViewState.OK if not self.__current_treeview_item.parent_id == None: parent_item = self.__search_parent() if parent_item == None: self.__treeview_state = TreeViewState.PARENT_NOT_EXISTS else: self.__treeview_state = TreeViewState.NO_PARENT log_set_var('TreeViewControl', '__validate_input', '__treeview_state', self.__treeview_state) log_leave_func('TreeViewControl', '__validate_input')
def on_new(self, event:Event) -> None: ''' ''' log_enter_func('MainWindowCNTLR', 'on_new', {'event':event}) log_set_var('MainWindowCNTLR', 'on_new', 'event.event_source', event.event_source) if event.event_source == MainWindowMenuKeys.KEY_PROJECT: if self.__model.is_project_open() \ and not self.__check_and_save_changes(): # user has cancelled the process return self.__model.create_new_project() elif event.event_source == MainWindowMenuKeys.KEY_HTML_PAGE: self.__model.create_page() self.__load_data_in_view() elif event.event_source == MainWindowMenuKeys.KEY_CSS_RULE: self.__model.create_css_rule() self.__load_data_in_view() elif event.event_source == MainWindowMenuKeys.KEY_JAVASCRIPT: self.__model.create_javascript() self.__load_data_in_view() elif event.event_source == MainWindowMenuKeys.KEY_TEXT: self.__model.create_text() self.__load_data_in_view() elif event.event_source == MainWindowMenuKeys.KEY_VARIABLE: self.__model.create_variable() self.__load_data_in_view() log_leave_func('MainWindowCNTLR', 'on_new')
def __init__(self): ''' Constructor ''' log_enter_func('MainWindowCNTLR', '__init__') self.__overview = OverviewControl(self.__gui.get_page_overview_frame()) self.__overview.add_obeserver(self) self.__configuration = ConfigurationControl(self.__gui.get_page_config_frame()) self.__configuration.add_obeserver(self) treeview_conf = TreeViewConfiguration() treeview_conf.column_count = 2 treeview_conf.add_column_name('Property', 0) treeview_conf.add_column_name('Value', 1) log_set_var('MainWindowCNTLR', '__init__', 'treeview_conf', treeview_conf) self.__properties = TreeViewControl(self.__gui.get_attributes_frame(), treeview_conf) self.__properties.add_observer(self) self.__model.add_observer(self) log_leave_func('MainWindowCNTLR', '__init__')
def __init__(self, text_elements, observer: ABSTextDialogObserver, master=None): ''' Constructor ''' log_enter_func('SelectText', '__init__', { 'text_elements': text_elements, 'observer': observer, 'master': master }) self.__text_elements = text_elements self.__observer = observer self.__selected_txt_coll_var = tk.StringVar() self.__selected_txt_item_var = tk.StringVar() self.__text_collections = [] for _tuple in self.__text_elements: if not _tuple[0] in self.__text_collections: self.__text_collections.append(_tuple[0]) log_set_var('SelectText', '__init__', '__text_collections', self.__text_collections) self.__text_items = [''] self.__text_select_dialog(master) log_leave_func('SelectText', '__init__')
def __on_collection_select(self, event): # @UnusedVariable ''' ''' log_enter_func('SelectText', '__on_collection_select', {'event': event}) self.__selected_txt_item_var.set('') selected_collection = self.__selected_txt_coll_var.get() log_set_var('SelectText', '__on_collection_select', 'selected_collection', selected_collection) self.__text_items_opm['menu'].delete(0, 'end') for _tuple in self.__text_elements: if _tuple[0] == selected_collection: log_set_var('SelectText', '__on_collection_select', 'adding _tuple', _tuple) self.__text_items_opm['menu'].add_command( label=_tuple[1], command=tk._setit(self.__selected_txt_item_var, _tuple[1])) log_leave_func('SelectText', '__on_collection_select')
def __on_ok(self): log_enter_func('CreateCssRuleSet', '__on_ok') selector_type = self.__selector_type_var.get() log_set_var('CreateCssRuleSet', '__on_ok', 'selector_type', selector_type) is_compound = self.__is_compound(selector_type) log_set_var('CreateCssRuleSet', '__on_ok', 'is_compound', is_compound) if not self.__check_user_input(is_compound): log_error('CreateCssRuleSet', '__on_ok', 'user input check failed') log_leave_func('CreateCssRuleSet', '__on_ok') return selector_element = self.__get_selector_element(selector_type) log_set_var('CreateCssRuleSet', '__on_ok', 'selector_element', selector_element) selector_specifier = self.__get_selector_specifier( selector_type, is_compound) log_set_var('CreateCssRuleSet', '__on_ok', 'selector_specifier', selector_specifier) self.__dialog.destroy() self.__observer.on_create_css_rule_set_closed( (self.__SELECTOR_TYPE_MAP[selector_type], selector_element, selector_specifier, is_compound, self.__SELECTOR_TYPE_SEP.get(selector_type))) log_leave_func('CreateCssRuleSet', '__on_ok')
def on_rename(self, event:Event) -> None: ''' ''' log_enter_func('MainWindowCNTLR', 'on_rename', {'event':event}) log_set_var('MainWindowCNTLR', 'on_rename', 'event.event_source', event.event_source) if event.event_source == MainWindowMenuKeys.KEY_RENAME_PROJECT: self.__model.rename_project() self.__load_data_in_view() elif event.event_source == MainWindowMenuKeys.KEY_RENAME: self.__model.rename() self.__load_data_in_view() log_leave_func('MainWindowCNTLR', 'on_rename')
def __notifiy_observer(self, event): # @UnusedVariable log_enter_func('ConfigurationControl', '__notifiy_observer', {'event': event}) conf_id = self.__configuration.focus() if conf_id == self.__root_id or conf_id == '': conf_id = None log_set_var('ConfigurationControl', '__notifiy_observer', 'conf_id', conf_id) for observer in self.__observers: observer.on_conf_selected(conf_id) log_leave_func('ConfigurationControl', '__notifiy_observer')
def __notifiy_observer(self, event): # @UnusedVariable log_enter_func('OverviewControl', '__notifiy_observer', {'event': event}) page_id = event.widget.selection()[0] if '.' not in page_id: page_id = None log_set_var('OverviewControl', '__notifiy_observer', 'page_id', page_id) for observer in self.__observers: observer.on_page_selected(page_id) log_leave_func('OverviewControl', '__notifiy_observer')
def on_exit(self, event:Event) -> None: # @UnusedVariable ''' ''' log_enter_func('MainWindowCNTLR', 'on_exit', {'event':event}) perform_exit = True if self.__model.is_project_open(): perform_exit = self.__check_and_save_changes() log_set_var('MainWindowCNTLR', 'on_exit', 'perform_exit', perform_exit) #if perform_exit == False, then the user has canceled # the exit during the check and save changes process. if perform_exit: self.__gui.unregister_observer(self) self.__root.quit() log_leave_func('MainWindowCNTLR', 'on_exit')
def on_open(self, event:Event) -> None: # @UnusedVariable ''' ''' log_enter_func('MainWindowCNTLR', 'on_open', {'event':event}) # if project is open: # if project is changed # open askyesno: save changes # if yes # save changes # open askopenfilename dialog # else # open askopenfilename dialog # else # open askopenfilename dialog # # if project open: # load data into the main window is_project_open = self.__model.is_project_open() log_set_var('MainWindowCNTLR', 'on_open', 'is_project_open', is_project_open) open_askopenfilename = False if is_project_open: open_askopenfilename = self.__check_and_save_changes() else: open_askopenfilename = True if open_askopenfilename: is_project_open = self.__model.open_project() log_set_var('MainWindowCNTLR', 'on_open', 'is_project_open', is_project_open) if is_project_open: #Load data into the ui self.__load_data_in_view() self.__enable_menu() log_leave_func('MainWindowCNTLR', 'on_open')
def __check_and_save_changes(self) -> bool: ''' Check if the model is changed If the model is changed it asks the user if changes shall be saved: User answer: 'yes' -> changes are saved -> return == True 'no' -> changes won't be saved -> return == True 'cancel' -> changes won't be saved -> return == False If the model is unchanged -> return == True Note: Only if this method returns True the process may be continued. If False is returned the process must be discontinued ''' log_enter_func('MainWindowCNTLR', '__check_and_save_changes') if self.__model.has_changes(): #Model is changed -> ask user if changes shall be saved. user_answer = askyesnocancel('Save on close', 'Save changes before closing the project?') log_set_var('MainWindowCNTLR', '__check_and_save_changes', 'user_answer', user_answer) if not user_answer == None: #Either 'yes' or 'no' has been pressed #Hence True must be returned if user_answer: #'yes' has been pressed. #Save project and open a new one self.__model.save() log_leave_func('MainWindowCNTLR', '__check_and_save_changes', True) return True else: # cancel has been pressed #-> process must be discontinued log_leave_func('MainWindowCNTLR', '__check_and_save_changes', False) return False else: #Model is unchanged log_leave_func('MainWindowCNTLR', '__check_and_save_changes', True) return True
def __on_ok(self): log_enter_func('SelectText', '__on_ok') selected_collection = self.__selected_txt_coll_var.get() log_set_var('SelectText', '__on_ok', 'selected_collection', selected_collection) selected_text_item = self.__selected_txt_item_var.get() log_set_var('SelectText', '__on_ok', 'selected_text_item', selected_text_item) if selected_text_item == '': messagebox.showerror('Input Error', 'Please select the text item!') else: self.__dialog.destroy() self.__observer.on_text_selected( (selected_collection, selected_text_item)) log_leave_func('SelectText', '__on_ok')
def insert_conf(self, conf_id: str, conf_name: str, parent: str = 'confs', pos: str = 'end'): log_enter_func( 'ConfigurationControl', 'insert_conf', { 'conf_id': conf_id, 'conf_name': conf_name, 'parent': parent, 'pos': pos }) if parent == None: parent = self.__root_id log_set_var('ConfigurationControl', 'insert_conf', 'parent', parent) self.__inserted.append(conf_id) self.__configuration.insert(parent, pos, conf_id, text=conf_name) self.__configuration.item(conf_id, open=True) log_leave_func('ConfigurationControl', 'insert_conf')
def __text_select_dialog(self, master): ''' ''' log_enter_func('SelectText', '__text_select_dialog', {'master': master}) self.__dialog = tk.Toplevel(master) self.__dialog.title('Select Text') top_frame = tk.Frame(self.__dialog) top_frame.pack(fill=tk.BOTH, side=tk.TOP, expand=True, padx=10, pady=10) tk.Label(top_frame, text='Text Collections:', anchor=tk.W).grid(row=0, column=0, padx=10, sticky=tk.W) text_collection_opm = tk.OptionMenu( top_frame, self.__selected_txt_coll_var, *self.__text_collections, command=self.__on_collection_select) text_collection_opm.grid(row=0, column=1, columnspan=1, sticky=tk.W, padx=10) tk.Label(top_frame, text='Text Items:', anchor=tk.W).grid(row=1, column=0, padx=10, sticky=tk.W) self.__text_items_opm = tk.OptionMenu(top_frame, self.__selected_txt_item_var, *self.__text_items) self.__text_items_opm.grid(row=1, column=1, columnspan=1, sticky=tk.W, padx=10) if len(self.__text_collections) == 1: log_set_var('SelectText', '__text_select_dialog', 'preselect text collection', self.__text_collections[0]) self.__selected_txt_coll_var.set(self.__text_collections[0]) self.__on_collection_select(None) buttons_frame = tk.Frame(self.__dialog) buttons_frame.pack(fill=tk.X, side=tk.BOTTOM, padx=20) tk.Button(buttons_frame, text='Ok', command=self.__on_ok).pack(side=tk.LEFT, padx=1) tk.Button(buttons_frame, text='Cancel', command=self.__on_cancel).pack(side=tk.LEFT, padx=1) log_leave_func('SelectText', '__text_select_dialog')
''' Created on 04.08.2020 @author: mthoma ''' from datetime import datetime from main_window.main_window_cntlr import MainWindowCNTLR from utils.logger import log_enter_func, log_leave_func, log_set_var VERSION = ' v0.3' if __name__ == '__main__': log_enter_func('application', '__main__') title = ''.join( ['Pryceless', VERSION, ' (2020-', str(datetime.now().year), ')']) log_set_var('application', '__main__', 'title', title) main_window = MainWindowCNTLR() main_window.show(title) log_leave_func('application', '__main__')