Beispiel #1
0
    def accept(self):
        searches = tprefs['saved_searches']
        all_names = {x['name'] for x in searches} - {self.original_name}
        n = unicode(self.search_name.text()).strip()
        search = self.search
        if not n:
            return error_dialog(self, _('Must specify name'), _(
                'You must specify a search name'), show=True)
        if n in all_names:
            return error_dialog(self, _('Name exists'), _(
                'Another search with the name %s already exists') % n, show=True)
        search['name'] = n

        f = unicode(self.find.text())
        if not f:
            return error_dialog(self, _('Must specify find'), _(
                'You must specify a find expression'), show=True)
        search['find'] = f

        r = unicode(self.replace.text())
        search['replace'] = r

        search['dot_all'] = bool(self.dot_all.isChecked())
        search['case_sensitive'] = bool(self.case_sensitive.isChecked())
        search['mode'] = self.mode_box.mode

        if self.search_index == -1:
            searches.append(search)
        else:
            searches[self.search_index] = search
        tprefs.set('saved_searches', searches)

        Dialog.accept(self)
    def accept(self):
        if not self.func_name:
            return error_dialog(
                self,
                _('Must specify name'),
                _('You must specify a name for this function.'),
                show=True)
        source = self.source
        try:
            mod = compile_code(source, self.func_name)
        except Exception as err:
            return error_dialog(
                self,
                _('Invalid Python code'),
                _('The code you created is not valid Python code, with error: %s'
                  ) % err,
                show=True)
        if not callable(mod.get('replace')):
            return error_dialog(
                self,
                _('No replace function'),
                _('You must create a Python function named replace in your code'
                  ),
                show=True)
        user_functions[self.func_name] = source
        functions(refresh=True)
        refresh_boxes()

        Dialog.accept(self)
Beispiel #3
0
 def accept(self):
     if self.state == 0:
         return self.reject()
     if self.state == 1:
         resources = self.choose_resources.resources
         self.download_status(resources)
         self.wait.setCurrentIndex(2)
         self.bb.setVisible(False)
         t = Thread(name='DownloadResources', target=self.download_resources, args=(resources,))
         t.daemon = True
         t.start()
         return
     if self.state == 2:
         return
     self.wait.stop()
     Dialog.accept(self)
Beispiel #4
0
 def accept(self):
     if self.state == 0:
         return self.reject()
     if self.state == 1:
         resources = self.choose_resources.resources
         self.download_status(resources)
         self.wait.setCurrentIndex(2)
         self.bb.setVisible(False)
         t = Thread(name='DownloadResources', target=self.download_resources, args=(resources,))
         t.daemon = True
         t.start()
         return
     if self.state == 2:
         return
     self.wait.stop()
     Dialog.accept(self)
Beispiel #5
0
 def accept(self):
     if not self.theme_name:
         return error_dialog(self, _('No name specified'), _(
             'You must specify a name for your theme'), show=True)
     if '*' + self.theme_name in custom_theme_names():
         return error_dialog(self, _('Name already used'), _(
             'A custom theme with the name %s already exists') % self.theme_name, show=True)
     return Dialog.accept(self)
Beispiel #6
0
    def accept(self):
        if not self.func_name:
            return error_dialog(self, _('Must specify name'), _(
                'You must specify a name for this function.'), show=True)
        source = self.source
        try:
            mod = compile_code(source, self.func_name)
        except Exception as err:
            return error_dialog(self, _('Invalid python code'), _(
                'The code you created is not valid python code, with error: %s') % err, show=True)
        if not callable(mod.get('replace')):
            return error_dialog(self, _('No replace function'), _(
                'You must create a python function named replace in your code'), show=True)
        user_functions[self.func_name] = source
        functions(refresh=True)
        refresh_boxes()

        Dialog.accept(self)
Beispiel #7
0
 def accept(self):
     if not self.theme_name:
         return error_dialog(self, _("No name specified"), _("You must specify a name for your theme"), show=True)
     if "*" + self.theme_name in custom_theme_names():
         return error_dialog(
             self,
             _("Name already used"),
             _("A custom theme with the name %s already exists") % self.theme_name,
             show=True,
         )
     return Dialog.accept(self)
Beispiel #8
0
    def accept(self):
        searches = tprefs['saved_searches']
        all_names = {x['name'] for x in searches} - {self.original_name}
        n = unicode(self.search_name.text()).strip()
        search = self.search
        if not n:
            return error_dialog(self,
                                _('Must specify name'),
                                _('You must specify a search name'),
                                show=True)
        if n in all_names:
            return error_dialog(
                self,
                _('Name exists'),
                _('Another search with the name %s already exists') % n,
                show=True)
        search['name'] = n

        f = unicode(self.find.text())
        if not f:
            return error_dialog(self,
                                _('Must specify find'),
                                _('You must specify a find expression'),
                                show=True)
        search['find'] = f

        r = unicode(self.replace.text())
        search['replace'] = r

        search['dot_all'] = bool(self.dot_all.isChecked())
        search['case_sensitive'] = bool(self.case_sensitive.isChecked())
        search['mode'] = self.mode_box.mode

        if self.search_index == -1:
            searches.append(search)
        else:
            searches[self.search_index] = search
        tprefs.set('saved_searches', searches)

        Dialog.accept(self)
Beispiel #9
0
 def accept(self):
     if self.stack.currentIndex() > 0:
         err = self.edit_snip.validate()
         if err is None:
             self.stack.setCurrentIndex(0)
             if self.edit_snip.creating_snippet:
                 item = self.snip_to_item(self.edit_snip.snip)
             else:
                 item = self.snip_list.currentItem()
                 snip = self.edit_snip.snip
                 item.setText(self.snip_to_text(snip))
                 item.setData(Qt.UserRole, snip)
             self.snip_list.setCurrentItem(item)
             self.snip_list.scrollToItem(item)
         else:
             error_dialog(self, _('Invalid snippet'), err, show=True)
         return
     user_snippets['snippets'] = [self.snip_list.item(i).data(Qt.UserRole) for i in range(self.snip_list.count())]
     snippets(refresh=True)
     return Dialog.accept(self)
Beispiel #10
0
 def accept(self):
     if self.stack.currentIndex() > 0:
         err = self.edit_snip.validate()
         if err is None:
             self.stack.setCurrentIndex(0)
             if self.edit_snip.creating_snippet:
                 item = self.snip_to_item(self.edit_snip.snip)
             else:
                 item = self.snip_list.currentItem()
                 snip = self.edit_snip.snip
                 item.setText(self.snip_to_text(snip))
                 item.setData(Qt.ItemDataRole.UserRole, snip)
             self.snip_list.setCurrentItem(item)
             self.snip_list.scrollToItem(item)
         else:
             error_dialog(self, _('Invalid snippet'), err, show=True)
         return
     user_snippets['snippets'] = [self.snip_list.item(i).data(Qt.ItemDataRole.UserRole) for i in range(self.snip_list.count())]
     snippets(refresh=True)
     return Dialog.accept(self)
Beispiel #11
0
 def accept(self):
     with tprefs:
         self.reports.save()
     Dialog.accept(self)
Beispiel #12
0
 def accept(self):
     with tprefs:
         self.reports.save()
     Dialog.accept(self)
Beispiel #13
0
 def accept(self):
     tprefs['spell-check-table-state'] = bytearray(self.words_view.horizontalHeader().saveState())
     Dialog.accept(self)