Example #1
0
    def run(self):
        dialog = SaveAs(master=None, filetypes=[('Excel', '*.xls')]).show()

        if dialog.find('.xls') == -1:
            dialog = dialog + '.xls'

        wb = xlwt.Workbook()
        ws = wb.add_sheet('test')

        ws.write(0, 0, '№')
        ws.write(0, 1, 'Время')
        ws.write(0, 2, 'Пользователь')
        ws.write(0, 3, 'Экзамен')
        ws.write(0, 4, 'Оценка')

        numberRow = 1
        for obj in self.test:
            ws.write(numberRow, 0, obj.id)
            ws.write(numberRow, 1, obj.time.isoformat(sep='T'))
            ws.write(numberRow, 2, obj.user.username)
            ws.write(numberRow, 3, obj.exam.name)
            ws.write(numberRow, 4,
                     str(obj.mark) + '/' + str(obj.exam.number_questions))
            numberRow += 1

        wb.save(dialog)
Example #2
0
    def asksaveasfile(mode="w", **options):
        "Ask for a filename to save as, and returned the opened file"

        filename = SaveAs(**options).show()
        if filename:
            return open(filename, mode)
        return None
Example #3
0
    def _saveIfChanged(self):
        """
        Check to see if the current document has changed. If so, ask the
        user if it should be saved. If so, prompt for a path and save the
        file to that path. If the user does not want to save the file, or
        the Cancel button is pressed in the Save As dialog, do nothing.
        """

        # If the current document is unchanged, return.
        changed = self._sourceLibraryDocumentEditor.getChanged()
        if not changed: return

        # The current document has changed, so ask the user if it
        # should be saved. If not, return.
        path = self._path
        if path is None:
            message = 'The document has been modified.'
        else:
            message = 'The document "%s" has been modified. ' % path
        message += ' Do you want to save your changes?'
        saveFile = askyesno(title = 'ModelEditor', message = message)
        if not saveFile:
            return

        # If the file has no associated path, get one. If the Cancel button
        # is pressed, return without saving the file.
        if path is None:
            path = SaveAs().show()
            if path == '':
                return

        # Save the document.
        self._save(path)
Example #4
0
    def _onFileExportToObsSim(self):
        if debug: print ('File/Export to ObsSim...')

        # Get the new path for this document. If none, return.
        path = SaveAs().show()
        if path == ():
            return

        # Export the file.
        self._exportToObsSim(path)
Example #5
0
    def _onFileSaveAs(self):
        if debug: print ('File/Save As...')

        # Get the new path for this document. If none, return.
        path = SaveAs().show()
        if path == ():
            return

        # Save the document.
        self._save(path)
 def my_asksaveasfilename(self):  # objects remember last result dir/file
     if not self.saveDialog:
         self.saveDialog = SaveAs(initialdir=self.startfiledir,
                                  filetypes=self.ftypes)
     return self.saveDialog.show()
Example #7
0
        def __init__(self,
                     master,
                     cid_path=None,
                     data_path=None,
                     config=dict(),
                     **keywords):
            """
            Set up a frame with widgets to validate ``id_path`` and ``data_path``.

            :param master: Tk master or root in which the frame should show up
            :param cid_path: optional preset for :guilabel:`CID` widget
            :type cid_path: str or None
            :param data_path: optional preset for :guilabel:`Data` widget
            :type data_path: str or None
            :param config: Tk configuration
            :param keywords: Tk keywords
            """
            assert has_tk
            assert master is not None

            if six.PY2:
                # In Python 2, Frame is an old style class.
                Frame.__init__(self, master, config, **keywords)
            else:
                super().__init__(master, config, **keywords)

            self._master = master

            # Define basic layout.
            self.grid(padx=_PADDING, pady=_PADDING)
            # self.grid_columnconfigure(1, weight=1)
            self.grid_rowconfigure(_VALIDATION_REPORT_ROW, weight=1)

            # Choose CID.
            self._cid_label = Label(self, text='CID:')
            self._cid_label.grid(row=_CID_ROW, column=0, sticky=E)
            self._cid_path_entry = Entry(self, width=55)
            self._cid_path_entry.grid(row=_CID_ROW, column=1, sticky=E + W)
            self._choose_cid_button = Button(self,
                                             command=self.choose_cid,
                                             text='Choose...')
            self._choose_cid_button.grid(row=_CID_ROW, column=2)
            self.cid_path = cid_path

            # Choose data.
            self._data_label = Label(self, text='Data:')
            self._data_label.grid(row=_DATA_ROW, column=0, sticky=E)
            self._data_path_entry = Entry(self, width=55)
            self._data_path_entry.grid(row=_DATA_ROW, column=1, sticky=E + W)
            self._choose_data_button = Button(self,
                                              command=self.choose_data,
                                              text='Choose...')
            self._choose_data_button.grid(row=_DATA_ROW, column=2)
            self.data_path = data_path

            # Validate.
            self._validate_button = Button(self,
                                           command=self.validate,
                                           text='Validate')
            self._validate_button.grid(row=_VALIDATE_BUTTON_ROW,
                                       column=0,
                                       padx=_PADDING,
                                       pady=_PADDING)

            # Validation status text.
            self._validation_status_text = StringVar()
            validation_status_label = Label(
                self, textvariable=self._validation_status_text)
            validation_status_label.grid(row=_VALIDATE_BUTTON_ROW, column=1)

            # Validation result.
            validation_report_frame = LabelFrame(self,
                                                 text='Validation report')
            validation_report_frame.grid(row=_VALIDATION_REPORT_ROW,
                                         columnspan=3,
                                         sticky=E + N + S + W)
            validation_report_frame.grid_columnconfigure(0, weight=1)
            validation_report_frame.grid_rowconfigure(0, weight=1)
            self._validation_report_text = Text(validation_report_frame)
            self._validation_report_text.grid(column=0,
                                              row=0,
                                              sticky=E + N + S)
            _validation_report_scrollbar = Scrollbar(validation_report_frame)
            _validation_report_scrollbar.grid(column=1,
                                              row=0,
                                              sticky=N + S + W)
            _validation_report_scrollbar.config(
                command=self._validation_report_text.yview)
            self._validation_report_text.config(
                yscrollcommand=_validation_report_scrollbar.set)

            # Set up file dialogs.
            self._choose_cid_dialog = Open(
                initialfile=self.cid_path,
                title='Choose CID',
            )
            self._choose_data_dialog = Open(
                initialfile=self.data_path,
                title='Choose data',
            )
            self._save_log_as_dialog = SaveAs(
                defaultextension='.log',
                initialfile='cutplace.log',
                title='Save validation result',
            )

            menubar = Menu(master)
            master.config(menu=menubar)
            self._file_menu = Menu(menubar, tearoff=False)
            self._file_menu.add_command(command=self.choose_cid,
                                        label='Choose CID...')
            self._file_menu.add_command(command=self.choose_data,
                                        label='Choose data...')
            self._file_menu.add_command(command=self.save_validation_report_as,
                                        label='Save validation report as...')
            self._file_menu.add_command(command=self.quit, label='Quit')
            menubar.add_cascade(label='File', menu=self._file_menu)
            help_menu = Menu(menubar, tearoff=False)
            help_menu.add_command(command=self.show_about, label='About')
            menubar.add_cascade(label='Help', menu=help_menu)

            self._enable_usable_widgets()
Example #8
0
# e.g. 11-5
import sys, math, os
from tkinter import *
from tkinter.filedialog import SaveAs, Directory

from PIL import Image
from PIL.ImageTk import PhotoImage
from viewer_thumbs import makeThumbs


saveDialog = SaveAs(title='Save As (filename gives image type)')
openDialog = Directory(title='Select Image Directory To Open')

trace = print
appname = 'PyPhoto 1.1'


class ScrolledCanvas(Canvas):
    def __init__(self, container):
        Canvas.__init__(self, container)
        self.config(borderwidth=0)

        vbar = Scrollbar(container)
        hbar = Scrollbar(container, orient=HORIZONTAL)

        vbar.pack(side=RIGHT, fill=Y)
        hbar.pack(side=BOTTOM, fill=X)
        self.pack(side=TOP, fill=BOTH, expand=YES)

        vbar.config(command=self.yview)
        hbar.config(command=self.xview)
Example #9
0
 def my_asksaveasfilename(self):
     if not self.saveDialog:
         self.saveDialog = SaveAs(initialdir=self.startfiledir,
                                  filetypes=self.ftypes)
         return self.saveDialog.show()
Example #10
0
 def Save_As():
     global sgpas
     path.set(
         SaveAs(title="Save File",
                initialdir="C:/",
                filetypes=(("Excel Workbook", "*.xlsx"),
                           ("All Files", "*.*"))) +
         ".xlsx")
     if (path.get() != ""):
         XL_File = Workbook("%s" % (path.get()))
         keys = list(sgpas.keys())
         s1 = XL_File.add_worksheet("%s to %s" %
                                    (keys[0], keys[-1]))
         s1.write("A1", "Roll Num")
         s1.write("B1", "Result")
         roll_num, res = [], []
         for i in keys:
             roll_num.append(i)
             x = XL_File.add_worksheet("%s" % (i))
             x.write("C1", i)
             x.write("A2", "Subject Code")
             x.write("B2", "Subject Name")
             x.write("C2", "Grade / Status")
             x.write("D2", "Credits")
             sgpa, fails = 0, 0
             gra, crs = [], []
             for j in range(len(sgpas[i])):
                 l = ["A", "B", "C", "D"]
                 for k in sgpas[i][j]:
                     ind = l[sgpas[i][j].index(k)]
                     x.write("%s%i" % (ind, j + 3),
                             "%s" % (k))
                     if (l.index(ind) == 2):
                         if (k == "O"): gra.append(10)
                         elif (k == "S"): gra.append(9)
                         elif (k == "A"): gra.append(8)
                         elif (k == "B"): gra.append(7)
                         elif (k == "C"): gra.append(6)
                         elif (k == "D"): gra.append(5)
                         elif (k == "F"): fails += 1
                         else: gra.append(0)
                     if (l.index(ind) == 3):
                         crs.append(int(k))
             for z in range(len(gra)):
                 sgpa += gra[z] * crs[z]
             try:
                 if (fails <= 0):
                     Y = sgpa / sum(crs)
                     res.append(Y)
                     x.write("C%i" % (j + 4), "SGPA:")
                     x.write("D%i" % (j + 4),
                             "%.3f" % (Y))
                 else:
                     x.write("D%i" % (j + 4), "Failed!")
                     res.append("Failed!")
             except Exception:
                 pass
             for i in range(len(roll_num)):
                 s1.write("A%i" % (i + 2), roll_num[i])
                 s1.write("B%i" % (i + 2), res[i])
         XL_File.close()
         mb.showinfo("Success :)",
                     "File Saved Successfully...")
     else:
         path.set("Please Try Again...")
Example #11
0
def ask_saveas(title, message, filetypes, defaultDir=None, defaultFile=None):
    dlg = SaveAs(title=title, message=message, filetypes=filetypes)
    filename = dlg.show()
    return filename
Example #12
0
 def asksaveasfilename(**options):
     "Ask for a filename to save as."
     return SaveAs(**options).show()
Example #13
0
    def __init__(self,
                 master,
                 cid_path=None,
                 data_path=None,
                 config=dict(),
                 **keywords):
        assert has_tk
        if six.PY2:
            Frame.__init__(self, master, config, **keywords)
        else:
            super().__init__(master, config, **keywords)

        # Define basic layout.
        self.grid(padx=_PADDING, pady=_PADDING)
        # self.grid_columnconfigure(1, weight=1)
        self.grid_rowconfigure(_VALIDATION_RESULT_ROW, weight=1)

        # Choose CID.
        self._cid_label = Label(self, text='CID:')
        self._cid_label.grid(row=_CID_ROW, column=0, sticky=E)
        self._cid_path_entry = Entry(self, width=55)
        self._cid_path_entry.grid(row=_CID_ROW, column=1, sticky=E + W)
        self._choose_cid_button = Button(self,
                                         command=self.choose_cid,
                                         text='Choose...')
        self._choose_cid_button.grid(row=_CID_ROW, column=2)
        self.cid_path = cid_path

        # Choose data.
        self._data_label = Label(self, text='Data:')
        self._data_label.grid(row=_DATA_ROW, column=0, sticky=E)
        self._data_path_entry = Entry(self, width=55)
        self._data_path_entry.grid(row=_DATA_ROW, column=1, sticky=E + W)
        self._choose_data_button = Button(self,
                                          command=self.choose_data,
                                          text='Choose...')
        self._choose_data_button.grid(row=_DATA_ROW, column=2)
        self.data_path = data_path

        # Validate.
        self._validate_button = Button(self,
                                       command=self.validate,
                                       text='Validate')
        self._validate_button.grid(row=_VALIDATE_BUTTON_ROW,
                                   column=0,
                                   padx=_PADDING,
                                   pady=_PADDING)

        # Validation status text.
        self._validation_status_text = StringVar()
        validation_status_label = Label(
            self, textvariable=self._validation_status_text)
        validation_status_label.grid(row=_VALIDATE_BUTTON_ROW, column=1)

        # Validation result.
        validation_result_frame = LabelFrame(self, text='Validation result')
        validation_result_frame.grid(row=_VALIDATION_RESULT_ROW,
                                     columnspan=3,
                                     sticky=E + N + S + W)
        validation_result_frame.grid_columnconfigure(0, weight=1)
        validation_result_frame.grid_rowconfigure(0, weight=1)
        self._validation_result_text = Text(validation_result_frame)
        self._validation_result_text.grid(column=0, row=0, sticky=E + N + S)
        _validation_result_scrollbar = Scrollbar(validation_result_frame)
        _validation_result_scrollbar.grid(column=1, row=0, sticky=N + S + W)
        _validation_result_scrollbar.config(
            command=self._validation_result_text.yview)
        self._validation_result_text.config(
            yscrollcommand=_validation_result_scrollbar.set)

        # "Save validation result as" button.
        self._save_log_button = Button(self,
                                       command=self.save_log_as,
                                       text='Save validation result as...')
        self._save_log_button.grid(row=_SAVE_ROW,
                                   column=1,
                                   columnspan=2,
                                   sticky=E + S)

        # Set up file dialogs.
        self._choose_cid_dialog = Open(
            initialfile=self.cid_path,
            title='Choose CID',
        )
        self._choose_data_dialog = Open(
            initialfile=self.data_path,
            title='Choose data',
        )
        self._save_log_as_dialog = SaveAs(
            defaultextension='.log',
            initialfile='cutplace.log',
            title='Save validation result',
        )

        self.enable_usable_widgets()