Exemplo n.º 1
0
 def add_configurable(self):
     '''Add configurable file, selecting a existing project file that can
     be a xml or json file, but there's no restriction by file type.
     '''
     if self.node:
         path = filedialog.askopenfilename(
             title=_('Select the configurable file:'),
             initialdir=self.node.path,
             parent=self.window
         )
         if path:
             path = OS.get_default_path(path)
             filename = self.configurable_application.get_filename(path)
             if not self.configurable_application.is_child(self.node.path,
                                                           path):
                 messagebox.showwarning(
                     _('Warning'),
                     _('Select a file inside the selected folder')
                 )
                 self.add_configurable()
             else:
                 self.node.open = True
                 child = self.configurable_application.create_child(
                     self.node, filename
                 )
                 self.render_treeview()
                 self.configurable_editor.show(child, True,
                                               self.render_treeview)
Exemplo n.º 2
0
    def __init__(self, builder, application, variable_application,
                 template_application):
        self.application = application
        self.variable_application = variable_application
        self.template_application = template_application

        self.is_new = None
        self.node = None
        self.call_back = None

        self.window = builder.get_object('window_toplevel')
        self.dialog = builder.get_object('configurable_toplevel')
        self.editor = builder.get_object('configurable_editor_text')
        self.combobox = builder.get_object('configurable_variable_combobox')
        cancel_button = builder.get_object('configurable_cancel_button')
        save_button = builder.get_object('configurable_save_button')

        # translate labels
        self.dialog.title(_('[Templatizator] Configurable file editing'))
        builder.get_object('configurable_variable_label')['text'] = _(
            'Add variable:')
        cancel_button['text'] = _('Cancel')
        save_button['text'] = _('Save')

        cancel_button['command'] = self.cancel
        save_button['command'] = self.save
        self.combobox.bind('<<ComboboxSelected>>', self.variable_selected)
        self.dialog.protocol('WM_DELETE_WINDOW', self.cancel)

        self.dialog.resizable(False, False)
        self.dialog.withdraw()
Exemplo n.º 3
0
    def variable_action(self):
        '''Add or save edition when add/save button is clicked'''
        name = self.name.get()
        value = self.value.get()
        selected_id = self.treeview.focus()

        if not name or not value:
            messagebox.showwarning(
                _('Warning'),
                _('Fill variable name and value')
            )
            return

        # add
        if not self.row:
            try:
                self.application.add(name, value)
                self.treeview.insert('', 'end', values=(name, value,
                                                        REMOVE_ICON))
            except ProjectNotSet:
                # show warning in case of no project selected
                messagebox.showwarning(
                    _('Warning'),
                    _('Select a project first')
                )
        # edit
        else:
            self.treeview.item(selected_id, values=(name, value,
                                                    REMOVE_ICON))
            self.application.change(self.old_name, name, value)

        self.cancel_action()
Exemplo n.º 4
0
 def before_show_tooltip(self, col, iid, tooltip):
     '''Decides wich tooltip message to show or if will show'''
     node = self.application.find_node(self.filetree, iid)
     if col == '#2' and isinstance(node, Directory):
         tooltip.text = _('Add template')
         return True
     if col == '#2' and isinstance(node, File):
         tooltip.text = _('Remove')
         return True
     if col == '#1' and isinstance(node, File):
         tooltip.text = _('Save it in the project?')
         return True
     return False
Exemplo n.º 5
0
    def add_template(self):
        '''Add a template inside selected node'''
        parent = self.node
        if self.application.configuration_path:
            parent.open = True
            child = self.template_application.create_child(
                parent, _('new_template.[ext]')
            )
            self.editor.show(child, True, self.render_treeview)
        else:
            messagebox.showwarning(
                _('Warning'),
                _('Select where to save the templates first')
            )

        self.render_treeview()
Exemplo n.º 6
0
    def __init__(self, builder, application):
        self.application = application

        self.name = builder.get_object('variable_name_entry')
        self.value = builder.get_object('variable_value_entry')
        self.action = builder.get_object('variable_action_button')
        self.cancel = builder.get_object('variable_cancel_button')
        self.treeview = builder.get_object('variables_treeview')
        self.action_tooltip = Tooltip(self.action, _('Add'))
        Tooltip(self.cancel, _('Cancel'))
        Tooltip(self.treeview, _('Remove'), col='#3')

        # translate labels
        builder.get_object('variable_name_label')['text'] = _('Name:')
        builder.get_object('variable_value_label')['text'] = _('Value:')
        self.treeview.heading('variable_name_treeviewcolumn', text=_('Name'))
        self.treeview.heading('variable_value_treeviewcolumn', text=_('Value'))

        self.treeview.bind('<ButtonRelease-1>', self.row_selected)
        self.action['command'] = self.variable_action
        self.cancel['command'] = self.cancel_action
        self.row = None
        self.old_name = None

        self.reload()
Exemplo n.º 7
0
    def remove_file(self):
        '''Remove file: template or configurable'''
        is_template = isinstance(self.node, Template)
        name = _('template') if is_template else _('configurable file')
        if messagebox.askyesno(
                _('Question:'),
                _('Did you sure that you want to remove the {name}?').format(
                    name=name
                )
        ):
            if is_template:
                self.template_application.remove(self.node)
            else:
                self.configurable_application.remove(self.node)
            self.node.remove()
            self.filetree = self.application.get()

        self.render_treeview()
Exemplo n.º 8
0
 def save_templates(self):
     '''Call aplication layer to save the templates into the project folder.
     After the files are recorded asks user if he wants to open the project
     directory.
     It also shows a default error dialog if something goes wrong
     '''
     try:
         self.application.save_into_project()
         open_project = messagebox.askyesno(
             _('Templates saved successfully in the project!'),
             _('Do you want to open the project folder?'),
             icon='info'
         )
         if open_project:
             OS.open_with(self.filetree.path)
     except ProjectNotSet:
         messagebox.showwarning(
             _('Warning'),
             _('Select a project first')
         )
     except Exception as ex:
         messagebox.showerror(
             _('Error'),
             _('It was not possible to save the templates in the project')
         )
         raise ex
Exemplo n.º 9
0
 def configuration_selected(self, path):
     '''Handle configuration selected path calling application layer and
     re-rendering items
     '''
     self.application.change_configuration_path(path)
     if self.filetree.path:
         self.application.change_path(self.filetree.path)
         self.label['project']['text'] = self.filetree.path
     else:
         self.label['project']['text'] = _('Select a directory...')
     self.variables.reload()
     self.filetree = self.application.get()
     self.render_treeview()
Exemplo n.º 10
0
 def select_project(self):
     '''Calls project path selector window to set the project path'''
     path = self.filetree.path
     path = filedialog.askdirectory(
         title=_('Select the project directory:'),
         initialdir=path if path else self.application.home_path,
         mustexist=True,
         parent=self.window
     )
     if path:
         path = OS.get_default_path(path)
         self.label['project']['text'] = path
         self.project_selected(path)
Exemplo n.º 11
0
    def __init__(self, builder, application, variable_application):
        self.application = application
        self.variable_application = variable_application

        self.node = None
        self.is_new = True
        self.last_selected = None
        self.call_back = None

        self.dialog = builder.get_object('editor_toplevel')
        self.window = builder.get_object('window')
        self.filelabel = builder.get_object('editor_filename_label')
        self.filename = builder.get_object('editor_filename_entry')
        self.editor = builder.get_object('editor_text')
        self.combobox = builder.get_object('editor_variable_combobox')
        cancel_button = builder.get_object('editor_cancel_button')
        save_button = builder.get_object('editor_save_button')

        # translate labels
        self.dialog.title(_('[Templatizator] Template editing'))
        self.filelabel['text'] = _('File name:')
        builder.get_object('editor_variable_label')['text'] = \
            _('Add variable:')
        cancel_button['text'] = _('Cancel')
        save_button['text'] = _('Save')

        save_button['command'] = self.save
        cancel_button['command'] = self.cancel

        self.combobox.bind('<<ComboboxSelected>>', self.variable_selected)
        self.filename.bind('<Button-1>', self.input_selected, self.filename)
        self.editor.bind('<Button-1>', self.input_selected, self.editor)
        self.dialog.protocol('WM_DELETE_WINDOW', self.cancel)

        self.dialog.resizable(False, False)
        self.dialog.withdraw()
Exemplo n.º 12
0
 def select_configuration(self):
     '''Calls configuration path selector window to set
     the configuration path
     '''
     path = self.application.configuration_path
     path = filedialog.askdirectory(
         title=_('Select the directory where the templates will be saved:'),
         initialdir=path if path else self.application.home_path,
         mustexist=True,
         parent=self.window
     )
     if path:
         path = OS.get_default_path(path)
         self.label['configuration']['text'] = path
         self.configuration_selected(path)
Exemplo n.º 13
0
    def row_selected(self, event):
        '''Select to edit or delete variable according column clicked'''
        selected_id = self.treeview.focus()
        item = self.treeview.item(selected_id)
        col = self.treeview.identify_column(event.x)

        row_name = item['values'][0]
        row_value = item['values'][1]

        # remove
        if col == '#3':
            self.application.remove(row_name)
            self.treeview.delete(selected_id)
        # edit
        else:
            Variables.set_entry_text(self.name, row_name)
            Variables.set_entry_text(self.value, row_value)
            self.action['text'] = SAVE_ICON
            self.action_tooltip.text = _('Save')
            self.row = selected_id
            self.old_name = row_name
Exemplo n.º 14
0
    def __init__(self, builder, variables, editor, configurable_editor,
                 application, template_application, configurable_application):
        self.application = application
        self.template_application = template_application
        self.configurable_application = configurable_application

        self.pretty_icons = is_unicode_available(ICONS.folderopened)

        # selected node
        self.node = None

        self.variables = variables
        self.editor = editor
        self.configurable_editor = configurable_editor

        self.window = builder.get_object('window_toplevel')
        self.treeview = builder.get_object('project_treeview')
        self.directory_menu = Menu(self.treeview, tearoff=0)
        self.directory_menu.add_command(label=_('Add template'),
                                        command=self.add_template)
        self.directory_menu.add_command(label=_('Add configurable file'),
                                        command=self.add_configurable)
        self.file_menu = Menu(self.treeview, tearoff=0)
        self.file_menu.add_command(label=_('Open'), command=self.open_file)
        self.file_menu.add_command(label=_('Open with...'),
                                   command=self.open_with)
        self.file_menu.add_command(label=_('Remove'), command=self.remove_file)
        Tooltip(self.treeview, col='#', before=self.before_show_tooltip)

        self.label = {
            'project': builder.get_object('project_file_label'),
            'configuration': builder.get_object('configuration_file_label')
        }

        # translate labels
        builder.get_object('configuration_labelframe')['text'] = _(
            'Save templates on:')
        builder.get_object('project_labelframe')['text'] = _('Project:')
        builder.get_object('variables_labelframe')['text'] = _(
            'Replacement variables:')
        builder.get_object('project_selected_labelframe')['text'] = _(
            'Selected project:')
        self.label['configuration']['text'] = _('Select a directory...')
        self.label['project']['text'] = _('Select a directory...')
        builder.get_object('configuration_file_button')['text'] = _('Select')
        builder.get_object('project_file_button')['text'] = _('Select')
        builder.get_object('templates_save_button')['text'] = _(
            'Save templates in the project')

        builder.get_object('project_file_button')['command'] = \
            self.select_project
        builder.get_object('configuration_file_button')['command'] = \
            self.select_configuration
        builder.get_object('templates_save_button')['command'] = \
            self.save_templates
        self.treeview.bind('<ButtonRelease-1>', self.row_selected)
        self.treeview.bind('<<TreeviewOpen>>', self.row_opened)
        self.treeview.bind('<<TreeviewClose>>', self.row_closed)
        self.treeview.bind('<ButtonRelease-3>', self.row_popup_selected)

        Window.center(self.window)

        if application.configuration_path:
            self.label['configuration']['text'] = \
                application.configuration_path

        self.filetree = self.application.get()
        if self.filetree and self.filetree.path:
            self.label['project']['text'] = self.filetree.path
            self.render_treeview()