コード例 #1
0
ファイル: path_window.py プロジェクト: jumping/devassistant
    def open_window(self, data=None):
        """
        Function opens the Options dialog
        """
        self.args = dict()
        if data is not None:
            self.top_assistant = data.get('top_assistant', None)
            self.current_main_assistant = data.get('current_main_assistant', None)
            self.kwargs = data.get('kwargs', None)
            self.data['debugging'] = data.get('debugging', False)
        text = config_manager.get_config_value("da.project_dir") or self.get_user_path()
        self.dir_name.set_text(text)
        self.label_full_prj_dir.set_text(text)
        self.dir_name.set_sensitive(True)
        self.dir_name_browse_btn.set_sensitive(True)
        self._remove_widget_items()
        if self.current_main_assistant.name != 'crt' and self.project_name_shown:
            self.box6.remove(self.box_project)
            self.project_name_shown = False
        elif self.current_main_assistant.name == 'crt' and not self.project_name_shown:
            self.box6.remove(self.box_path_main)
            self.box6.pack_start(self.box_project, False, False, 0)
            self.box6.pack_end(self.box_path_main, False, False, 0)
            self.project_name_shown = True
        caption_text = "Project: "
        row = 0
        # get selectected assistants, but without TopAssistant itself
        path = self.top_assistant.get_selected_subassistant_path(**self.kwargs)[1:]
        caption_parts = []

        # Finds any dependencies
        found_deps = [x for x in path if x.dependencies()]
        # This bool variable is used for showing text "Available options:"
        any_options = False
        for assistant in path:
            caption_parts.append("<b>" + assistant.fullname + "</b>")
            for arg in sorted([x for x in assistant.args if not '--name' in x.flags], key=lambda y: y.flags):
                if not (arg.name == "deps_only" and not found_deps):
                    row = self._add_table_row(arg, len(arg.flags) - 1, row) + 1
                    any_options = True
        if not any_options:
            self.title.set_text("")
        else:
            self.title.set_text("Available options:")
        caption_text += ' -> '.join(caption_parts)
        self.label_caption.set_markup(caption_text)
        self.path_window.show_all()
        self.entry_project_name.set_text(os.path.basename(self.kwargs.get('name', '')))
        self.entry_project_name.set_sensitive(True)
        self.run_btn.set_sensitive(not self.project_name_shown or self.entry_project_name.get_text() != "")
        if 'name' in self.kwargs:
            self.dir_name.set_text(os.path.dirname(self.kwargs.get('name', '')))
        for arg_name, arg_dict in [(k, v) for (k, v) in self.args.items() if self.kwargs.get(k)]:
            if 'checkbox' in arg_dict:
                arg_dict['checkbox'].set_active(True)
            if 'entry' in arg_dict:
                arg_dict['entry'].set_sensitive(True)
                arg_dict['entry'].set_text(self.kwargs[arg_name])
            if 'browse_btn' in arg_dict:
                arg_dict['browse_btn'].set_sensitive(True)
コード例 #2
0
ファイル: argument.py プロジェクト: przor3n/devassistant
    def get_gui_hint(self, hint):
        """Returns the value for specified gui hint (or a sensible default value,
        if this argument doesn't specify the hint).

        Args:
            hint: name of the hint to get value for
        Returns:
            value of the hint specified in yaml or a sensible default
        """
        if hint == 'type':
            # 'self.kwargs.get('nargs') == 0' is there for default_iff_used, which may
            # have nargs: 0, so that it works similarly to 'store_const'
            if self.kwargs.get('action') == 'store_true' or self.kwargs.get(
                    'nargs') == 0:
                return 'bool'
            # store_const is represented by checkbox, but computes default differently
            elif self.kwargs.get('action') == 'store_const':
                return 'const'
            return self.gui_hints.get('type', 'str')
        elif hint == 'default':
            hint_type = self.get_gui_hint('type')
            hint_default = self.gui_hints.get('default', None)
            arg_default = self.kwargs.get('default', None)
            preserved_value = None
            if 'preserved' in self.kwargs:
                preserved_value = config_manager.get_config_value(
                    self.kwargs['preserved'])

            if hint_type == 'path':
                if preserved_value is not None:
                    default = preserved_value
                elif hint_default is not None:
                    default = hint_default.replace('$(pwd)',
                                                   utils.get_cwd_or_homedir())
                else:
                    default = arg_default or '~'
                return os.path.abspath(os.path.expanduser(default))
            elif hint_type == 'bool':
                return hint_default or arg_default or False
            elif hint_type == 'const':
                return hint_default or arg_default
            else:
                if hint_default == '$(whoami)':
                    hint_default = getpass.getuser()
                return preserved_value or hint_default or arg_default or ''
コード例 #3
0
ファイル: argument.py プロジェクト: Rorosha/devassistant
    def get_gui_hint(self, hint):
        """Returns the value for specified gui hint (or a sensible default value,
        if this argument doesn't specify the hint).

        Args:
            hint: name of the hint to get value for
        Returns:
            value of the hint specified in yaml or a sensible default
        """
        if hint == 'type':
            # 'self.kwargs.get('nargs') == 0' is there for default_iff_used, which may
            # have nargs: 0, so that it works similarly to 'store_const'
            if self.kwargs.get('action') == 'store_true' or self.kwargs.get('nargs') == 0:
                return 'bool'
            # store_const is represented by checkbox, but computes default differently
            elif self.kwargs.get('action') == 'store_const':
                return 'const'
            return self.gui_hints.get('type', 'str')
        elif hint == 'default':
            hint_type = self.get_gui_hint('type')
            hint_default = self.gui_hints.get('default', None)
            arg_default = self.kwargs.get('default', None)
            preserved_value = None
            if 'preserved' in self.kwargs:
                preserved_value = config_manager.get_config_value(self.kwargs['preserved'])

            if hint_type == 'path':
                if preserved_value is not None:
                    default = preserved_value
                elif hint_default is not None:
                    default = hint_default.replace('$(pwd)', utils.get_cwd_or_homedir())
                else:
                    default = arg_default or '~'
                return os.path.abspath(os.path.expanduser(default))
            elif hint_type == 'bool':
                return hint_default or arg_default or False
            elif hint_type == 'const':
                return hint_default or arg_default
            else:
                if hint_default == '$(whoami)':
                    hint_default = getpass.getuser()
                return preserved_value or hint_default or arg_default or ''
コード例 #4
0
    def _add_table_row(self, arg, number, row):
        """
        Function adds options to a grid
        """
        self.args[arg.name] = dict()
        self.args[arg.name]['arg'] = arg
        check_box_title = arg.flags[number][2:].title()
        self.args[arg.name]['label'] = check_box_title
        align = self.gui_helper.create_alignment()
        if arg.kwargs.get('required'):
            # If argument is required then red star instead of checkbox
            star_label = self.gui_helper.create_label('<span color="#FF0000">*</span>')
            star_label.set_padding(0, 3)
            label = self.gui_helper.create_label(check_box_title)
            box = self.gui_helper.create_box()
            box.pack_start(star_label, False, False, 6)
            box.pack_start(label, False, False, 6)
            align.add(box)
        else:
            chbox = self.gui_helper.create_checkbox(check_box_title)
            chbox.set_alignment(0, 0)
            if arg.name == "deps_only":
                chbox.connect("clicked", self._deps_only_toggled)
            else:
                chbox.connect("clicked", self._check_box_toggled, arg.name)
            align.add(chbox)
            self.args[arg.name]['checkbox'] = chbox
        if row == 0:
            self.grid.add(align)
        else:
            self.grid.attach(align, 0, row, 1, 1)
        label = self.gui_helper.create_label(arg.kwargs['help'], justify=Gtk.Justification.LEFT)
        label.set_alignment(0, 0)
        label.set_padding(0, 3)
        self.grid.attach(label, 1, row, 1, 1)
        label_check_box = self.gui_helper.create_label(name="")
        self.grid.attach(label_check_box, 0, row, 1, 1)
        if arg.get_gui_hint('type') not in ['bool', 'const']:
            new_box = self.gui_helper.create_box(spacing=6)
            entry = self.gui_helper.create_entry(text="")
            align = self.gui_helper.create_alignment()
            align.add(entry)
            new_box.pack_start(align, False, False, 6)
            align_btn = self.gui_helper.create_alignment()
            ''' If a button is needed please add there and in function
                _check_box_toggled
                Also do not forget to create a function for that button
                This can not be done by any automatic tool from those reasons
                Some fields needs a input user like user name for GitHub
                and some fields needs to have interaction from user like selecting directory
            '''
            entry.set_text(arg.get_gui_hint('default'))
            entry.set_sensitive(arg.kwargs.get('required') == True)

            if arg.get_gui_hint('type') == 'path':
                browse_btn = self.gui_helper.button_with_label("Browse")
                browse_btn.connect("clicked", self.browse_clicked, entry)
                browse_btn.set_sensitive(arg.kwargs.get('required') == True)
                align_btn.add(browse_btn)
                self.args[arg.name]['browse_btn'] = browse_btn
            elif arg.get_gui_hint('type') == 'str':
                if arg.name == 'github' or arg.name == 'github-login':
                    link_button = self.gui_helper.create_link_button(text="For registration visit GitHub Homepage",
                                                                     uri="https://www.github.com")
                    align_btn.add(link_button)
            new_box.pack_start(align_btn, False, False, 6)
            row += 1
            self.args[arg.name]['entry'] = entry
            self.grid.attach(new_box, 1, row, 1, 1)
        else:
            if 'preserved' in arg.kwargs and config_manager.get_config_value(arg.kwargs['preserved']):
                if 'checkbox' in self.args[arg.name]:
                    self.args[arg.name]['checkbox'].set_active(True)
        return row
コード例 #5
0
 def get_default_project_dir(self):
     """Returns a project directory to prefill in GUI.
     It is either stored value or current directory (if exists) or home directory.
     """
     ret = config_manager.get_config_value('da.project_dir')
     return ret or utils.get_cwd_or_homedir()
コード例 #6
0
    def _add_table_row(self, arg, number, row):
        """
        Function adds options to a grid
        """
        self.args[arg.name] = dict()
        self.args[arg.name]['arg'] = arg
        check_box_title = arg.flags[number][2:].title()
        self.args[arg.name]['label'] = check_box_title
        align = self.gui_helper.create_alignment()
        if arg.kwargs.get('required'):
            # If argument is required then red star instead of checkbox
            star_label = self.gui_helper.create_label(
                '<span color="#FF0000">*</span>')
            star_label.set_padding(0, 3)
            label = self.gui_helper.create_label(check_box_title)
            box = self.gui_helper.create_box()
            box.pack_start(star_label, False, False, 6)
            box.pack_start(label, False, False, 6)
            align.add(box)
        else:
            chbox = self.gui_helper.create_checkbox(check_box_title)
            chbox.set_alignment(0, 0)
            if arg.name == "deps_only":
                chbox.connect("clicked", self._deps_only_toggled)
            else:
                chbox.connect("clicked", self._check_box_toggled, arg.name)
            align.add(chbox)
            self.args[arg.name]['checkbox'] = chbox
        if row == 0:
            self.grid.add(align)
        else:
            self.grid.attach(align, 0, row, 1, 1)
        label = self.gui_helper.create_label(arg.kwargs['help'],
                                             justify=Gtk.Justification.LEFT)
        label.set_alignment(0, 0)
        label.set_padding(0, 3)
        self.grid.attach(label, 1, row, 1, 1)
        label_check_box = self.gui_helper.create_label(name="")
        self.grid.attach(label_check_box, 0, row, 1, 1)
        if arg.get_gui_hint('type') not in ['bool', 'const']:
            new_box = self.gui_helper.create_box(spacing=6)
            entry = self.gui_helper.create_entry(text="")
            align = self.gui_helper.create_alignment()
            align.add(entry)
            new_box.pack_start(align, False, False, 6)
            align_btn = self.gui_helper.create_alignment()
            ''' If a button is needed please add there and in function
                _check_box_toggled
                Also do not forget to create a function for that button
                This can not be done by any automatic tool from those reasons
                Some fields needs a input user like user name for GitHub
                and some fields needs to have interaction from user like selecting directory
            '''
            entry.set_text(arg.get_gui_hint('default'))
            entry.set_sensitive(arg.kwargs.get('required') == True)

            if arg.get_gui_hint('type') == 'path':
                browse_btn = self.gui_helper.button_with_label("Browse")
                browse_btn.connect("clicked", self.browse_clicked, entry)
                browse_btn.set_sensitive(arg.kwargs.get('required') == True)
                align_btn.add(browse_btn)
                self.args[arg.name]['browse_btn'] = browse_btn
            elif arg.get_gui_hint('type') == 'str':
                if arg.name == 'github' or arg.name == 'github-login':
                    link_button = self.gui_helper.create_link_button(
                        text="For registration visit GitHub Homepage",
                        uri="https://www.github.com")
                    align_btn.add(link_button)
            new_box.pack_start(align_btn, False, False, 6)
            row += 1
            self.args[arg.name]['entry'] = entry
            self.grid.attach(new_box, 1, row, 1, 1)
        else:
            if 'preserved' in arg.kwargs and config_manager.get_config_value(
                    arg.kwargs['preserved']):
                if 'checkbox' in self.args[arg.name]:
                    self.args[arg.name]['checkbox'].set_active(True)
        return row
コード例 #7
0
 def get_default_project_dir(self):
     """Returns a project directory to prefill in GUI.
     It is either stored value or current directory (if exists) or home directory.
     """
     ret = config_manager.get_config_value('da.project_dir')
     return ret or utils.get_cwd_or_homedir()