Skip to content

Commit

Permalink
Mac BioConsole
Browse files Browse the repository at this point in the history
Console now works on Mac working without Bioformats.
  • Loading branch information
BiologyTools committed Feb 28, 2023
1 parent 9474aa4 commit af9a908
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 71 deletions.
3 changes: 3 additions & 0 deletions BioGTK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Version>2.3.0</Version>
<Platforms>AnyCPU;x64;ARM64</Platforms>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down Expand Up @@ -72,11 +73,13 @@
<None Remove="Glade\TextInput.glade" />
<None Remove="Glade\Tolerance.glade" />
<None Remove="Glade\Tools.glade" />
<None Remove="Info.plist" />
<None Remove="Resources\polyline.png" />
</ItemGroup>

<ItemGroup>
<Content Include="bioformats_package.dll" />
<Content Include="Info.plist" />
<Content Include="Resources\banner.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
Expand Down
1 change: 1 addition & 0 deletions Glade/Console.glade
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
</object>
<packing>
Expand Down
5 changes: 3 additions & 2 deletions Glade/Console.glade~
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
</child>
<child>
<object class="GtkFixed">
<property name="height-request">64</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
Expand All @@ -58,7 +59,7 @@
</object>
<packing>
<property name="x">400</property>
<property name="y">7</property>
<property name="y">15</property>
</packing>
</child>
<child>
Expand All @@ -71,7 +72,7 @@
</object>
<packing>
<property name="x">293</property>
<property name="y">8</property>
<property name="y">15</property>
</packing>
</child>
<child>
Expand Down
15 changes: 10 additions & 5 deletions Source/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,22 @@ public static void Initialize()
/// @return A boolean value.
public static bool SetImageJPath()
{
Gtk.FileChooserDialog filechooser =
new Gtk.FileChooserDialog("Select ImageJ Executable Location",Scripting.window,
FileChooserAction.Save,
"Cancel", ResponseType.Cancel,
"Save", ResponseType.Accept);
string title = "Select ImageJ Executable Location";
if (OperatingSystem.IsMacOS())
title = "Select ImageJ Executable Location (Fiji.app/Contents/MacOS/ImageJ-macosx)";
Gtk.FileChooserDialog filechooser =
new Gtk.FileChooserDialog(title, Scripting.window,
FileChooserAction.Open,
"Cancel", ResponseType.Cancel,
"Save", ResponseType.Accept);
filechooser.SetCurrentFolder(System.IO.Path.GetDirectoryName(Environment.ProcessPath));
if (filechooser.Run() != (int)ResponseType.Accept)
return false;
ImageJ.ImageJPath = filechooser.Filename;
filechooser.Destroy();
Settings.AddSettings("ImageJPath", filechooser.Filename);
Settings.Save();

return true;
}

Expand Down
53 changes: 22 additions & 31 deletions Source/Bio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static BioImage GetImage(string ids)
{
for (int i = 0; i < images.Count; i++)
{
if (images[i].ID.Contains(ids) || images[i].file == ids)
if (images[i].ID == ids || images[i].file == ids)
return images[i];
}
return null;
Expand Down Expand Up @@ -80,7 +80,7 @@ public static int GetImageCountByName(string s)
string name = Path.GetFileNameWithoutExtension(s);
for (int im = 0; im < images.Count; im++)
{
if (images[im].ID.Contains(name))
if (images[im].ID == s)
i++;
}
return i;
Expand Down Expand Up @@ -148,11 +148,11 @@ public static void RemoveImage(string id)
/// @param id The id of the image to update.
/// @param im The BioImage to update with.
/// @return The image is being returned.
public static void UpdateImage(string id, BioImage im)
public static void UpdateImage(BioImage im)
{
for (int i = 0; i < images.Count; i++)
{
if (images[i].Filename == id)
if (images[i].ID == im.ID)
{
images[i] = im;
return;
Expand Down Expand Up @@ -4076,28 +4076,27 @@ private static void InitOME()
public static void SaveFile(string file, string ID)
{
string[] sts = new string[1];
sts[0] = file;
SaveSeries(sts, ID);
sts[0] = ID;
SaveSeries(sts, file);
}
/// It takes a list of image files, and saves them as a single multi-page TIFF file
/// It takes a list of image IDs, and saves them as a single multi-page TIFF file.
///
/// @param files an array of file paths to the images to be saved
/// @param ID The path to the file to save to.
public static void SaveSeries(string[] files, string ID)
/// @param An array of IDs of the images to save
/// @param The path to the file to save to.
public static void SaveSeries(string[] IDs, string file)
{
string desc = "";
int stride = 0;
ImageJDesc j = new ImageJDesc();
BioImage bi = Images.GetImage(files[0]);
BioImage bi = Images.GetImage(IDs[0]);
j.FromImage(bi);
desc = j.GetString();
for (int fi = 0; fi < files.Length; fi++)
for (int fi = 0; fi < IDs.Length; fi++)
{
string file = files[fi];

BioImage b = Images.GetImage(file);
string fn = Path.GetFileNameWithoutExtension(ID);
string dir = Path.GetDirectoryName(ID);
string id = IDs[fi];
BioImage b = Images.GetImage(id);
string fn = Path.GetFileNameWithoutExtension(id);
string dir = Path.GetDirectoryName(file);
stride = b.Buffers[0].Stride;

//Save ROIs to CSV file.
Expand All @@ -4121,15 +4120,15 @@ public static void SaveSeries(string[] files, string ID)
desc += "-ImageInfo:" + fi + ":" + json + NewLine;
}

Tiff image = Tiff.Open(ID, "w");
for (int fi = 0; fi < files.Length; fi++)
Tiff image = Tiff.Open(file, "w");
for (int fi = 0; fi < IDs.Length; fi++)
{
int im = 0;
string file = files[fi];
string id = IDs[fi];
//Progress pr = new //Progress(file, "Saving");
//pr.Show();
//Application.DoEvents();
BioImage b = Images.GetImage(file);
BioImage b = Images.GetImage(id);
int sizec = 1;
if (!b.isRGB)
{
Expand Down Expand Up @@ -4169,7 +4168,7 @@ public static void SaveSeries(string[] files, string ID)
image.SetField(TiffTag.SUBFILETYPE, FileType.PAGE);
// specify the page number
buffer = b.Buffers[im].GetSaveBytes(true);
image.SetField(TiffTag.PAGENUMBER, im + (b.Buffers.Count * fi), b.Buffers.Count * files.Length);
image.SetField(TiffTag.PAGENUMBER, im + (b.Buffers.Count * fi), b.Buffers.Count * IDs.Length);
for (int i = 0, offset = 0; i < b.SizeY; i++)
{
image.WriteScanline(buffer, offset, i, 0);
Expand Down Expand Up @@ -4552,6 +4551,7 @@ public static BioImage OpenFile(string file, int series, bool tab, bool addToIma
else
b.StackThreshold(false);
Recorder.AddLine("Bio.BioImage.Open(" + '"' + file + '"' + ");");
if(addToImages)
Images.AddImage(b,tab);
//pr.Close();
//pr.Dispose();
Expand Down Expand Up @@ -6610,15 +6610,6 @@ public static void OpenAsync(string file)
App.progress.Title = "Opening File";
App.progress.Text = file;
App.progress.Show();
// start a background task to update progress bar
System.Threading.Tasks.Task.Run(() =>
{
// update progress bar on main UI thread
Application.Invoke(delegate
{
App.progress.ProgressValue = progressValue;
});
});
}
/// It opens a file asynchronously
///
Expand Down
9 changes: 6 additions & 3 deletions Source/BioConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BioConsole : Window
/// <summary> Used to load in the glade file resource as a window. </summary>
private Builder _builder;
public static bool onTab = false;
public static bool useBioformats = false;
public static bool useBioformats = true;
public static bool headless = false;
public static bool resultInNewTab = false;
int line = 0;
Expand Down Expand Up @@ -73,6 +73,8 @@ protected void SetupHandlers()
tabRadioBut.Clicked += TabRadioBox_Clicked;
this.KeyPressEvent += Console_KeyPressEvent;
this.DeleteEvent += BioConsole_DeleteEvent;
if (OperatingSystem.IsMacOS())
bioformatsBox.Active = false;
}

private void ResultsBox_Clicked(object sender, EventArgs e)
Expand All @@ -88,13 +90,13 @@ private void BioConsole_DeleteEvent(object o, DeleteEventArgs args)

private void Console_KeyPressEvent(object o, KeyPressEventArgs args)
{
if (args.Event.Key == Gdk.Key.Up)
if (args.Event.Key == Gdk.Key.w)
{
line++;
string[] s = consoleBox.Buffer.Text.Split(Environment.NewLine);
textBox.Buffer.Text = s[s.Length - 1 - line];
}
if (args.Event.Key == Gdk.Key.Down)
if (args.Event.Key == Gdk.Key.s)
{
line--;
string[] s = consoleBox.Buffer.Text.Split(Environment.NewLine);
Expand All @@ -119,6 +121,7 @@ private void BioformatsBox_Clicked(object sender, EventArgs e)
else
{
BioImage.OMESupport();
bioformatsBox.Active = false;
}
}

Expand Down
Loading

0 comments on commit af9a908

Please sign in to comment.