コード例 #1
0
    def actionHighlighted(self, act_on_this, keypress):
        """Do something, because a key was pressed."""
        # cancel if there are no values
        if len(self.values) < 1:
            return False

        # get old
        old_key = act_on_this[0]
        old_val = act_on_this[1]

        # ask new stuff
        file = npyscreen.selectFile(
            starting_value=old_val,
            confirm_if_exists=False
        )

        name = npyscreen.notify_input(
            'Name of template:',
            pre_text=old_key
        )

        if name:
            if self.offerinvoice == 'offer':
                self.parent.parentApp.tmpDefault.del_offer_template(key=old_key)
                self.parent.parentApp.tmpDefault.add_offer_template(
                    key=name, value=file
                )
            else:
                self.parent.parentApp.tmpDefault.del_invoice_template(key=old_key)
                self.parent.parentApp.tmpDefault.add_invoice_template(
                    key=name, value=file
                )

            self.update_values()
コード例 #2
0
    def add_template(self, keypress=None):
        """Add template."""
        file = npyscreen.selectFile(
            starting_value=os.path.expanduser('~'),
            confirm_if_exists=False
        )

        name = npyscreen.notify_input(
            'Name of template:'
        )

        # add if name and not exists in dict
        if self.offerinvoice == 'offer':
            if (
                name and
                name not in self.parent.parentApp.tmpDefault.get_offer_templates()
            ):
                self.parent.parentApp.tmpDefault.add_offer_template(
                    key=name, value=file
                )
        else:
            if (
                name and
                name not in self.parent.parentApp.tmpDefault.get_invoice_templates()
            ):
                self.parent.parentApp.tmpDefault.add_invoice_template(
                    key=name, value=file
                )

        self.update_values()
コード例 #3
0
ファイル: Zadanie4.py プロジェクト: Belfegor8625/PwJS
 def whenPressed(self):
     the_selected_file = npyscreen.selectFile()
     file = open(the_selected_file, "r")
     try:
         for line in file:
             line = line.strip()
             line = re.split("[^a-zA-Z\d@.]+", line)
             allDataList.append(
                 StudentData(line[1], line[2], line[3], line[4]))
     finally:
         file.close()
     npyscreen.blank_terminal()
     self.parent.parentApp.switchForm("BASEOPTIONS")
コード例 #4
0
ファイル: Zadanie3.py プロジェクト: Belfegor8625/PwJS
        def whenPressed(self):
            the_selected_file = npyscreen.selectFile()
            file = open(the_selected_file, "r")
            try:
                for line in file:
                    self.dataList.append(line)
                    line = line.strip()
                    line = line.split(" ")
                    allDataList.append(WorkerData(line[0], line[1]))

            finally:
                file.close()
            npyscreen.blank_terminal()
            self.parent.parentApp.switchForm("BASEOPTIONS")
コード例 #5
0
    def load(self):
        """Load a JSON file for testing"""
        # choose the file
        file = npyscreen.selectFile(must_exist=True, confirm_if_exists=False)

        # open the file
        with open(file, "r") as file:
            try:
                # try to pull data from file
                self.test = json.load(file)["test"]
                # make the "start test" button visible
                self.btn_start.hidden = False
                # update UI
                self.display()

            except (json.JSONDecodeError, KeyError):
                # if bad file
                npyscreen.notify_confirm(
                    "Error in JSON file, please fix and retry.", title="JSON Error"
                )
                return
コード例 #6
0
    def bulk_host_popup(self):
        file= npyscreen.selectFile()
        try:
            with open(file, 'r') as f:
                content = f.read()
                content = content.replace('\r\n', '\n')
                from detect_delimiter import detect
                delimiter = detect(content, whitelist=['\n', ','])
                ip_addresses = content.split(delimiter)
                current_value = self.add_hosts_ip_addresses.get_value()
                self.add_hosts_ip_addresses.set_value(f"{current_value}{',' if current_value[-1] != ',' else ''}{','.join(filter(None, ip_addresses))}")

        except FileNotFoundError:
            npyscreen.notify_confirm("File was not found!", title="Information Missing/Incorrect", wide=True, editw=1)
        except PermissionError:
            npyscreen.notify_confirm("You do not have permissions to open this file!", title="Information Missing/Incorrect", wide=True, editw=1)
        except UnicodeDecodeError:
            npyscreen.notify_confirm("We are unable to open the file. Make sure the file is human readable", title="Information Missing/Incorrect", wide=True, editw=1)
        except Exception as e:
            npyscreen.notify_confirm(f"Something went wrong, please retry, or select a different file.\nStack Trace:\n:{str(e)}",
                                     title="Equivalent of a 500 error", wide=True, editw=1)
        self.DISPLAY()
コード例 #7
0
 def _select_file(self):
     t = npyscreen.selectFile('~/',
                              confirm_if_exists=False,
                              must_exist=True)
     chartFile = open(t, 'rb')
     self.document.file.put(chartFile)
コード例 #8
0
ファイル: testFilebox.py プロジェクト: fengye110/npyscreen
def test_function(scr):
    t = npyscreen.selectFile('~/',)
    npyscreen.notify_confirm(title='Selected File', message=t)
コード例 #9
0
 def whenPressed(self):
     media = npyscreen.selectFile(must_exist=True)
     SelectButton.path.append(os.path.realpath(media))
コード例 #10
0
ファイル: read_spikes.py プロジェクト: markplagge/NeMo
	def spawn_file_dialog(self, code_of_key_pressed):
		the_selected_file = npyscreen.selectFile(confirm_if_exists=False)
		#npyscreen.notify_wait('That returned: {}'.format(the_selected_file), title='results')
		self.selectedFile = the_selected_file
コード例 #11
0
def test_function(scr):
    t = npyscreen.selectFile('~/', )
    npyscreen.notify_confirm(title='Selected File', message=t)
コード例 #12
0
 def _select_file(self):
     t = npyscreen.selectFile('~/',confirm_if_exists=False, must_exist=True)
     chartFile = open(t, 'rb')
     self.document.file.put(chartFile)
コード例 #13
0
ファイル: read_spikes.py プロジェクト: shirishbahirat/NeMo
 def spawn_file_dialog(self, code_of_key_pressed):
     the_selected_file = npyscreen.selectFile(confirm_if_exists=False)
     #npyscreen.notify_wait('That returned: {}'.format(the_selected_file), title='results')
     self.selectedFile = the_selected_file
コード例 #14
0
 def spawn_file_dialog(self, code_of_key_pressed):
     the_selected_file = npyscreen.selectFile()
     npyscreen.notify_wait('That returned: {}'.format(the_selected_file),
                           title='results')