Exemple #1
0
    def set_widgets(self):
        """Set all widgets on the tab."""
        contacts = Contact.get_rows()

        for contact in contacts:
            contact_name = contact.name
            contact_email = ' - ' + contact.email if contact.email else ''
            contact_phone = ' - ' + contact.phone if contact.phone else ''

            contact_item = QListWidgetItem(contact_name + contact_email +
                                           contact_phone)

            contact_item.setData(Qt.UserRole, contact)
            self.project_contact_list.addItem(contact_item)

        self.project_contact_list.setSelectionMode(
            QAbstractItemView.ExtendedSelection)

        icon_path = resources_path('images', 'throbber.gif')
        movie = QMovie(icon_path)
        self.throbber_loader.setMovie(movie)
        movie.start()
        self.get_available_organisations()
        self.organisation_box.setFocus()
        self.project_description_text.setTabChangesFocus(True)
Exemple #2
0
    def test_resources_url(self):
        """Test we can get the path as a local url nicely.

        .. versionadded:: 3.0
        """
        url = resource_url(resources_path('img', 'logos', 'cadasta-logo.png'))
        self.assertTrue('file://' in url, url + ' is not valid')
Exemple #3
0
 def to_html(self):
     """Render as html.
     """
     uri = resource_url(resources_path('images', 'logo_white.png'))
     snippet = ('<div class="branding">'
                '<img src="%s" title="%s" alt="%s" %s/></div>') % (
                    uri, 'Cadasta', 'Cadasta', self.html_attributes())
     return snippet
    def set_widgets(self):
        """Set all widgets on the tab."""
        self.project_combo_box.currentIndexChanged.connect(
            self.project_combo_box_changed)

        icon_path = resources_path('images', 'throbber.gif')
        movie = QMovie(icon_path)
        self.throbber_loader.setMovie(movie)
        movie.start()
        self.get_available_projects()
        self.project_combo_box.setFocus()
 def _create_about_dialog(self):
     """Create action for help diaog."""
     icon_path = resources_path('images', 'icon.png')
     self.action_options_wizard = self.add_action(
         icon_path,
         text=self.tr(u'About'),
         parent=self.iface.mainWindow(),
         add_to_toolbar=False,
         enabled_flag=True,
         callback=self.show_about_dialog
     )
 def _create_contact_dialog(self):
     """Create action for contact."""
     icon_path = resources_path('images', 'cadasta-contact-64.png')
     self.action_options_wizard = self.add_action(
         icon_path,
         text=self.tr(u'Contact'),
         parent=self.iface.mainWindow(),
         add_to_toolbar=False,
         enabled_flag=True,
         callback=self.show_contact_dialog
     )
 def _create_project_update_wizard(self):
     """Create action for project update wizard."""
     icon_path = resources_path('images', 'cadasta-update-64.png')
     self.project_update_wizard = self.add_action(
         icon_path,
         text=self.tr(u'Update Project'),
         parent=self.iface.mainWindow(),
         add_to_toolbar=False,
         enabled_flag=True,
         callback=self.show_project_update_wizard
     )
def logo_element():
    """Create a sanitised local url to the logo for insertion into html.

    :returns: A sanitised local url to the logo.
    :rtype: str
    """
    path = os.path.join(resources_path(), 'images',
                        'cadasta-logo-transparent.png')

    if os.name == 'nt':
        path = 'file:///' + path

    url = QUrl(path)
    path = url.toLocalFile()
    return path
Exemple #9
0
    def set_widgets(self):
        """Set all widgets on the tab."""
        self.project_combo_box.currentIndexChanged.connect(
            self.project_combo_box_changed)

        checkbox_checked = get_setting('public_project')
        if checkbox_checked:
            self.public_projects_checkbox.setCheckState(Qt.Checked)
        self.public_projects_checkbox.stateChanged.connect(
            self.public_check_box_changed)

        icon_path = resources_path('images', 'throbber.gif')
        movie = QMovie(icon_path)
        self.throbber_loader.setMovie(movie)
        movie.start()
        self.get_available_projects()
        self.add_contact_label.mousePressEvent = self.add_contact_label_clicked
        self.set_enabled_add_contact_label(False)
        self.project_combo_box.setFocus()
        set_setting('public_project',
                    self.public_projects_checkbox.checkState() == Qt.Checked)
    def generate_new_questionnaire(self, current_layer, mapped_fields,
                                   current_questionnaire):
        """Generate new questionnaire.

        This will get current questionnaire or create from default
        questionnaire. Updating it by looking of fields from current layer.

        Questionnaire is based on current layer field.
        All of new field that not in questionnaire will be append to
        question group -> 'location_attributes'

        :param current_layer: layer that using for generate questionnaire
        :type current_layer: QgsVectorLayer

        :param mapped_fields: Mapping fields of layer to key on questionnaire
        :type mapped_fields: dict

        :param current_questionnaire: Questionnaire that found
        :type current_questionnaire: Str

        :return: generated questionnaire
        :rtype: str
        """

        questionnaire_path = resources_path('questionnaire.json')
        # get default questionnaire
        with open(questionnaire_path) as data_file:
            default_questionnaire = json.load(data_file)

        try:
            current_questionnaire = json.dumps(
                json.loads(current_questionnaire))
            current_questionnaire = re.sub(r'"id":[ ]?"(.*?)"', "",
                                           current_questionnaire)
            current_questionnaire = re.sub(r',[ ]?}', '}',
                                           current_questionnaire)
            current_questionnaire = re.sub(r',[ ]?,', ',',
                                           current_questionnaire)
            questionnaire = json.loads(current_questionnaire)
            questionnaire.pop('version', None)
            questionnaire.pop('id_string', None)
            questionnaire.pop('md5_hash', None)
            questionnaire.pop('xls_form', None)
        except ValueError as e:
            default_questionnaire['filename'] = current_layer.name()
            default_questionnaire['title'] = current_layer.name()
            default_questionnaire['id_string'] = current_layer.name()
            questionnaire = default_questionnaire

        # get all question name in questionnaire
        attributes_in_questionnaire = []
        for question in questionnaire["questions"]:
            attributes_in_questionnaire.append(question["name"])

        # get question group in questionnaire question group
        if 'question_groups' not in questionnaire:
            questionnaire['question_groups'] = []

        # Get current fields
        # Current field of layer for attribute
        # insert into 'location_attributes'
        location_attributes = {
            "name": "location_attributes",
            "label": "Location Attributes",
            "type": 'group',
            "questions": []
        }
        index = 1
        for field in current_layer.fields():
            field_name = field.name()
            if field_name != 'id':
                if field_name not in mapped_fields:
                    try:
                        # check location attributes in question group
                        location_attributes["questions"].append({
                            "name":
                            field_name,
                            "label":
                            field_name,
                            "type":
                            mapping_type[field.typeName().lower()],
                            "required":
                            False
                        })
                    except KeyError:
                        pass
                    index += 1

        # insert into questionnaire
        index = -1
        for question_group in questionnaire['question_groups']:
            index += 1
            if question_group['name'] == 'location_attributes':
                break

        if index == -1:
            questionnaire['question_groups'].append(location_attributes)
        else:
            questionnaire['question_groups'][index] = location_attributes

        return json.dumps(questionnaire, indent=4)