Add filedialog() function, make everything work 100% with Python

master
skylarmt 9 years ago
parent 1228b7254f
commit cde9e7e1db

@ -66,6 +66,7 @@ import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import static net.apocalypselabs.symat.Main.API_URL; import static net.apocalypselabs.symat.Main.API_URL;
import org.matheclipse.core.eval.EvalUtilities; import org.matheclipse.core.eval.EvalUtilities;
@ -848,7 +849,10 @@ public class Functions {
* @param max Maximum value, inclusive * @param max Maximum value, inclusive
* @return random integer * @return random integer
*/ */
public int rand(int min, int max) { public double rand(int min, int max) {
if (min == 0 && max == 0) {
return rand();
}
return rng.nextInt((max - min) + 1) + min; return rng.nextInt((max - min) + 1) + min;
} }
@ -995,7 +999,9 @@ public class Functions {
public void plot(String function) { public void plot(String function) {
showGraph(); showGraph();
graphwin.graphFunction(function); if (!function.equals("")) {
graphwin.graphFunction(function);
}
} }
public void plot(double[] x, double[] y) { public void plot(double[] x, double[] y) {
@ -1023,15 +1029,20 @@ public class Functions {
plot(f); plot(f);
} }
public void plotname(String t) {
graphwin.setWindowTitle(t);
graphwin.setLabel(t);
}
public String plotname() { public String plotname() {
return graphwin.getTitle(); return graphwin.getTitle();
} }
public String plotname(String t) {
if (t.equals("symatpythonnullplotname")) {
return graphwin.getTitle();
} else {
graphwin.setWindowTitle(t);
graphwin.setLabel(t);
return "";
}
}
public void plot() { public void plot() {
showGraph(); showGraph();
} }
@ -1061,6 +1072,21 @@ public class Functions {
FileUtils.saveFile(content, path, false); FileUtils.saveFile(content, path, false);
} }
/**
* Show a file dialog and return the path of the chosen file (or "" if
* canceled).
*
* @return
*/
public String filedialog() {
JFileChooser fc = new JFileChooser();
int result = fc.showDialog(Main.maingui, "Choose");
if (result == JFileChooser.APPROVE_OPTION) {
return fc.getSelectedFile().getPath();
}
return "";
}
public String md5sum(String data) { public String md5sum(String data) {
return FileUtils.MD5(data); return FileUtils.MD5(data);
} }

@ -14,14 +14,10 @@ def deg(num):
return _.deg(num) return _.deg(num)
def subs(fun,var): def subs(fun,var):
return _.subs(fun,var) return _.subs(fun,var)
def plot(): def plot(fun=""):
_.plot()
def plot(fun):
_.plot(fun) _.plot(fun)
def plotname(fun): def plotname(fun='symatpythonnullplotname'):
_.plotname(fun) return _.plotname(fun)
def plotname():
return _.plotname()
def xlim(min,max): def xlim(min,max):
_.xlim(min,max) _.xlim(min,max)
def plotclr(): def plotclr():
@ -50,9 +46,7 @@ def divide(*a):
return _.divide(a) return _.divide(a)
def mod(*a): def mod(*a):
return _.mod(a) return _.mod(a)
def rand(): def rand(min=0,max=0):
return _.rand()
def rand(min,max):
return _.rand(min,max) return _.rand(min,max)
def randb(): def randb():
return _.randb() return _.randb()
@ -93,4 +87,6 @@ def sech(a):
def csch(a): def csch(a):
return _.csch(a) return _.csch(a)
def coth(a): def coth(a):
return _.coth(a) return _.coth(a)
def filedialog():
return _.filedialog()

@ -59,4 +59,5 @@ solve(f,'x',0)|Solve function f for 'x' when it equals 0.
solve(f,'x')|Solve function f for 'x', assuming equal to 0. solve(f,'x')|Solve function f for 'x', assuming equal to 0.
solve(f)|Solve function f, assuming 'x' and 0. solve(f)|Solve function f, assuming 'x' and 0.
printa(array)|Get array contents as text. printa(array)|Get array contents as text.
primes(n)|Find all prime numbers up to n. primes(n)|Find all prime numbers up to n.
filedialog()|Open a file chooser and return the chosen file path.
Loading…
Cancel
Save