def edit_image(self, params_path, title, png_path, pixmap_item, plot_type="forest"): if plot_type == "forest": plot_editor_window = edit_forest_plot_form.EditPlotWindow( params_path, png_path, pixmap_item, title=title, parent=self) if plot_editor_window is not None: plot_editor_window.show() else: # TODO show a warning print "sorry - can't edit" elif plot_type == "forest__phylo": plot_editor_window = edit_phylo_forest_plot_form.EditPhyloForestPlotWindow( params_path, png_path, pixmap_item, title=title, parent=self) if plot_editor_window is not None: plot_editor_window.show() else: # TODO show a warning print "sorry - can't edit" elif plot_type == "funnel": funnel_params = python_to_R.get_funnel_params(params_path) edit_form = EditFunnelPlotForm(funnel_params) if edit_form.exec_(): new_funnel_params = edit_form.get_params() python_to_R.regenerate_funnel_plot(params_path, png_path, edited_funnel_params=new_funnel_params) new_pixmap = self.generate_pixmap(png_path, custom_scale=1) pixmap_item.setPixmap(new_pixmap) elif plot_type in ["histogram","scatterplot"]: params = python_to_R.get_exploratory_params(params_path) edit_form = EditDataExplorationPlotForm(form_type=plot_type, params=params) if edit_form.exec_(): new_params = edit_form.get_params() python_to_R.regenerate_exploratory_plot(params_path, png_path, plot_type=plot_type, edited_params=new_params) new_pixmap = self.generate_pixmap(png_path, custom_scale=1) pixmap_item.setPixmap(new_pixmap)
def save_image_as(self, params_path, title, plot_type="forest", unscaled_image=None, fmt="png"): if fmt not in ["pdf","png"]: raise Exception("Invalid fmt, needs to be either pdf or png!") print("unscaled_image: %s" % str(unscaled_image)) #if not unscaled_image: # note that the params object will, by convention, # have the (generic) name 'plot.data' -- after this # call, this object will be in the namespace ##if plot_type not in ["funnel", "histogram", "scatterplot", "forest__phylo"]: ## python_to_R.load_in_R("%s.plotdata" % params_path) ## print("Loaded: %s" % "%s.plotdata" % params_path) if plot_type in ["forest", "regression"]: python_to_R.load_in_R("%s.plotdata" % params_path) print("Loaded: %s" % "%s.plotdata" % params_path) elif plot_type == "forest plot of coefficients": python_to_R.load_in_R("%s.coef_fp_data" % params_path) print("Loaded: %s" % "%s.coef_fp_data" % params_path) suffix = unicode("."+fmt) default_filename = {"forest":"forest_plot", "forest__phylo":"forest_plot", "regression":"regression", "funnel":"funnel_plot", "histogram":"histogram", "scatterplot":"scatterplot", "forest plot of coefficients":"forest_plot_of_coefficients"}[plot_type] + suffix default_path = os.path.join(get_user_desktop_path(), default_filename) print("default_path for graphic: %s" % default_path) default_path = QString(default_path) default_path dfilter = fmt + " files (*." + fmt +")" print("filter: %s" % dfilter) # where to save the graphic? file_path = unicode(QFileDialog.getSaveFileName(self, "OpenMEE -- save plot as", default_path,)) #filter=QString(dfilter))) # now we re-generate it, unless they canceled, of course if file_path != "": if file_path[-4:] != suffix: file_path += suffix if plot_type == "forest": if self._is_side_by_side_fp(title): python_to_R.generate_forest_plot(file_path, side_by_side=True) else: python_to_R.generate_forest_plot(file_path) elif plot_type == "forest__phylo": python_to_R.regenerate_phylo_forest_plot(file_path) elif plot_type == "regression": python_to_R.generate_reg_plot(file_path) elif plot_type == "funnel": python_to_R.regenerate_funnel_plot(params_path, file_path) elif plot_type in ["histogram","scatterplot"]: python_to_R.regenerate_exploratory_plot(params_path, file_path, plot_type=plot_type) elif plot_type == "forest plot of coefficients": python_to_R.regenerate_forest_plot_of_coefficients(file_path, params_path, fmt) else: print "sorry -- I don't know how to draw %s plots!" % plot_type # else: # case where we just have the png and can't regenerate the pdf from plot data # print("Can't regenerate pdf") # default_path = '.'.join([title.replace(' ','_'),"png"]) # file_path = unicode(QFileDialog.getSaveFileName(self, "OpenMeta[Analyst] -- save plot as", QString(default_path))) # unscaled_image.save(QString(file_path),"PNG") self.statusbar.showMessage("Saved image to %s" % file_path, 10000)