Example #1
0
 def save_subtree_file():
     vf, s_id, msg = self.update_or_copy_vf()
     if s_id == None:
         return msg
     tree_type = request.json['tree_type']
     if tree_type == 'newick':
         suffix = 'nwk'
     elif tree_type == 'nexus':
         suffix = 'nxs'
     elif tree_type == 'phyloxml' or tree_type == 'nexml':
         suffix = 'xml'
     default_filename = 'navargator_subtree.{}'.format(suffix)
     selected_vars = request.json['selected_vars']
     subtree = vf.tree.get_subtree(selected_vars, keep_root_branch=False)
     subtree_string = vf.get_tree_string(subtree, tree_type)
     if saveAs and self.web_server == False:
         root = tk_root()
         root.withdraw()
         filename = saveAs(initialdir=os.getcwd(), initialfile=default_filename)
         root.destroy()
         if filename:
             vf.save_tree_file(filename, subtree_string)
         saved_locally, subtree_string = True, ''
     else:
         saved_locally = False
     return json.dumps({'session_id':s_id, 'saved_locally':saved_locally, 'tree_string':subtree_string, 'filename':default_filename})
Example #2
0
 def save(self):
     filename = saveAs(title="Save image as...",
                       filetype=(("PNG images", "*.png"),
                                 ("JPEG images", "*.jpg"), ("GIF images",
                                                            "*.gif")))
     self.c.postscript(file=filename + '.eps')
     img = Image.open(filename + '.eps')
     img.save(filename + '.png', "png")
Example #3
0
 def save_csv():
     root = tk_root()
     filename = saveAs()
     root.destroy()
     if filename:
         csvStr = request.form['csvStr'].encode('UTF-8')
         if not filename.endswith('.csv'):
             filename += '.csv'
         with open(filename, 'wb') as f:
             f.write(csvStr)
         return 'Csv file saved to %s' % (filename)
     else:
         return 'Csv file not saved, as no filename was chosen.'
Example #4
0
 def save_svg():
     svgData = request.form['svgData'].encode('UTF-8')
     root = tk_root()
     filename = saveAs()
     root.destroy()
     if filename:
         if not filename.endswith('.svg'):
             filename += '.svg'
         with open(filename, 'wb') as f:
             f.write(svgData)
         ret_msg = 'Svg file saved to %s' % (filename)
     else:
         ret_msg = 'File not saved.'
     return ret_msg
Example #5
0
def save_btn():
    try:
        filename = saveAs(defaultextension='.jpg',
                          filetypes=(("PNG images", "*.png"),
                                     ("JPEG images", "*.jpg"), ("GIF images",
                                                                "*.gif")))
        x = root.winfo_rootx() + canvas.winfo_x()
        y = root.winfo_rooty() + canvas.winfo_y()
        x1 = x + root.winfo_width()
        y1 = y + root.winfo_height() - 50

        ImageGrab.grab().crop((x, y, x1, y1)).save(filename)

        messagebox.showinfo('Save As', 'image save as...' + str(filename))
    except:
        messagebox.showinfo('Save As', 'failed image save as...')
Example #6
0
 def save_nvrgtr_file():
     vf, s_id, msg = self.update_or_copy_vf()
     if s_id == None:
         return msg
     default_filename = 'navargator_session.nvrgtr'
     include_distances = request.json['include_distances']
     if saveAs and self.web_server == False:
         root = tk_root()
         root.withdraw()
         filename = saveAs(initialdir=os.getcwd(), initialfile=default_filename)
         root.destroy()
         if filename:
             vf.save_navargator_file(filename, include_distances=include_distances)
         saved_locally, nvrgtr_str = True, ''
     else:
         saved_locally = False
         nvrgtr_str = vf.get_navargator_string(include_distances=include_distances)
     return json.dumps({'session_id':s_id, 'saved_locally':saved_locally, 'nvrgtr_as_string':nvrgtr_str, 'filename':default_filename}, ensure_ascii=False)
Example #7
0
        def save_csv():
            default_filename = 'miphy_data.csv'

            if self.downloads_dir != '':
                # The user specified a downloads location
                if not os.path.isdir(self.downloads_dir):
                    os.makedirs(self.downloads_dir)
                if os.path.isfile(os.path.join(self.downloads_dir, default_filename)):
                    # File already exists, ensure it won't be overwritten
                    basename = default_filename[:-4]
                    file_ind = 2
                    while os.path.isfile(os.path.join(self.downloads_dir, '{}_{}.csv'.format(basename, file_ind))):
                        file_ind += 1
                    filename = os.path.join(self.downloads_dir, '{}_{}.csv'.format(basename, file_ind))
                else:
                    filename = os.path.join(self.downloads_dir, default_filename)
            else:
                # The user didn't specify a downloads location; ask, or if unable default to cwd
                if saveAs == None:
                    filename = os.path.join(os.getcwd(), default_filename)
                else:
                    try:
                        root = tk_root()
                        root.withdraw()
                        filename = saveAs(initialdir=os.getcwd(), initialfile=default_filename)
                        root.destroy()
                    except:
                        filename = os.path.join(os.getcwd(), default_filename)
            if filename:
                csvStr = request.form['csvStr'].encode('UTF-8')
                if not filename.lower().endswith('.csv'):
                    filename += '.csv'
                with open(filename, 'wb') as f:
                    f.write(csvStr)
                print('Score data saved to {}'.format(filename))
                return 'Csv file saved to %s' % (filename)
            else:
                return 'Csv file not saved, as no filename was chosen.'
Example #8
0
 def save_svg():
     default_filename = 'miphy_tree.svg'
     svgData = request.form['svgData'].encode('UTF-8')
     if self.downloads_dir != '':
         # The user specified a downloads location
         if not os.path.isdir(self.downloads_dir):
             os.makedirs(self.downloads_dir)
         if os.path.isfile(os.path.join(self.downloads_dir, default_filename)):
             # File already exists, ensure it won't be overwritten
             basename = default_filename[:-4]
             file_ind = 2
             while os.path.isfile(os.path.join(self.downloads_dir, '{}_{}.svg'.format(basename, file_ind))):
                 file_ind += 1
             filename = os.path.join(self.downloads_dir, '{}_{}.svg'.format(basename, file_ind))
         else:
             filename = os.path.join(self.downloads_dir, default_filename)
     else:
         # The user didn't specify a downloads location; ask, or if unable default to cwd
         if saveAs == None:
             filename = os.path.join(os.getcwd(), default_filename)
         else:
             try:
                 root = tk_root()
                 root.withdraw()
                 filename = saveAs(initialdir=os.getcwd(), initialfile=default_filename)
                 root.destroy()
             except:
                 filename = os.path.join(os.getcwd(), default_filename)
     if filename:
         if not filename.lower().endswith('.svg'):
             filename += '.svg'
         with open(filename, 'wb') as f:
             f.write(svgData)
         print('Tree image saved to {}'.format(filename))
         ret_msg = 'Svg file saved to %s' % (filename)
     else:
         ret_msg = 'File not saved.'
     return ret_msg
Example #9
0
def save():
    filename = saveAs(title="Save image as...",
                      filetype=(("PNG images", "*.png"),
                                ("JPEG images", "*.jpg"), ("GIF images",
                                                           "*.gif")))
    image1.save(filename)