25 public Gdk.Pixbuf pixbuf;
31 private Builder _builder;
32 public static int IconWidth = 50;
33 public static int IconHeight = 50;
34 public static string dataset =
"";
35 public static long id;
36 public static List<string> files =
new List<string>();
37 public static bool uploading =
false;
38 public List<Image> images =
new List<Image>();
39 private ListStore store;
41#pragma warning disable 649
43 private Gtk.SearchEntry searchBox;
45 private Gtk.IconView view;
47 private Gtk.ComboBox comboBox;
49 private Gtk.ScrolledWindow scrollWind;
51 private Gtk.CheckButton loadIconsBut;
53 private Gtk.MenuItem uploadMenu;
54#pragma warning restore 649
58 #region Constructors / Destructors
65 Builder builder =
new Builder(
new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) +
"/" +
"Glade/omero.glade", FileMode.Open));
66 return new OMERO(builder, builder.GetObject(
"omeroViewer").Handle);
70 protected OMERO(Builder builder, IntPtr handle) : base(handle)
73 builder.Autoconnect(
this);
75 this.SizeAllocated += OMERO_SizeAllocated;
76 searchBox.Changed += SearchBox_Changed;
77 comboBox.Changed += ComboBox_Changed;
78 uploadMenu.ButtonPressEvent += UploadMenu_ButtonPressEvent;
79 view.ItemActivated += View_ItemActivated;
81 Gtk.Drag.DestSet(
this, DestDefaults.All,
new TargetEntry[]
83 new TargetEntry(
"text/uri-list", TargetFlags.OtherApp, 0)
84 }, Gdk.DragAction.Copy);
85 this.DragDataReceived += View_DragDataReceived;
86 App.ApplyStyles(
this);
89 private void UploadMenu_ButtonPressEvent(
object o, ButtonPressEventArgs args)
92 FileChooserDialog filechooser =
new FileChooserDialog(
"Choose files to import.",
this, FileChooserAction.Open,
"Cancel", ResponseType.Cancel,
"OK", ResponseType.Accept);
93 filechooser.SelectMultiple =
true;
94 if (filechooser.Run() != (
int)ResponseType.Accept)
96 string[] sts = filechooser.Filenames;
98 if(
BioLib.OMERO.password ==
"")
100 Login log = Login.Create();
101 int status = log.Run();
102 if (status != (
int)ResponseType.Ok)
108 foreach (
string s
in sts)
110 Thread ths =
new Thread(StartUpload);
116 public static void StartUpload()
118 foreach (var f
in files)
120 prog = Progress.Create(
"Uploading",
"Uploading image.",f);
123 Thread th =
new Thread(UpdateProgress);
126 Thread ths =
new Thread(Upload);
131 private static void Upload()
133 BioLib.OMERO.Upload(BioImage.OpenFile(fi).Result,
id);
136 public static void UpdateProgress()
140 OMERO.prog.ProgressValue =
BioLib.OMERO.progress;
142 }
while (OMERO.uploading);
146 private void View_DragDataReceived(
object o, DragDataReceivedArgs args)
150 string receivedData = System.Text.Encoding.UTF8.GetString(args.SelectionData.Data);
153 string[] uris = receivedData.Split(
new[] {
'\r',
'\n' }, StringSplitOptions.RemoveEmptyEntries);
154 foreach (
string uri
in uris)
156 if (Uri.TryCreate(uri, UriKind.Absolute, out Uri fileUri) && fileUri.IsFile)
158 string filePath = fileUri.LocalPath;
166 private void View_ItemActivated(
object o, ItemActivatedArgs args)
169 TreePath path = args.Path;
170 store.GetIter(out TreeIter iter, path);
172 if (loadIconsBut.Active)
173 selectedItem = (string)store.GetValue(iter, 1);
175 selectedItem = (string)store.GetValue(iter, 0);
176 string[] sts = selectedItem.Split(
' ');
177 foreach (var item
in images)
179 if (item.name.Contains(sts[0]))
181 BioImage bm =
BioLib.OMERO.GetImage(selectedItem, item.dataset);
182 App.tabsView.AddTab(bm);
187 private void OMERO_SizeAllocated(
object o, SizeAllocatedArgs args)
189 view.HeightRequest = scrollWind.AllocatedHeight;
192 private void ComboBox_Changed(
object sender, EventArgs e)
195 comboBox.Model.GetIterFromString(out iter, comboBox.Active.ToString());
196 string selectedItem = (string)comboBox.Model.GetValue(iter, 0);
197 string[] sts = selectedItem.Split(
' ');
199 id =
long.Parse(sts[1]);
203 private void InitIcons()
205 List<DatasetData> dbs =
BioLib.OMERO.GetDatasetsData();
206 if (loadIconsBut.Active)
208 var listStore =
new ListStore(typeof(Gdk.Pixbuf), typeof(
string));
209 view.PixbufColumn = 0;
213 if (comboBox.Active != -1)
216 comboBox.Model.GetIterFromString(out iter, comboBox.Active.ToString());
217 string selectedItem = (string)comboBox.Model.GetValue(iter, 0);
218 string[] sts = selectedItem.Split(
' ');
219 List<string> str =
BioLib.OMERO.GetDatasetFiles(
id);
220 Dictionary<long, Pixbuf> dict =
BioLib.OMERO.GetThumbnails(str.ToArray(), IconWidth, IconHeight);
222 foreach (var item
in dict)
224 Image image =
new Image();
225 image.pixbuf = item.Value;
227 image.name =
BioLib.OMERO.GetNameFromID(item.Key);
231 foreach (var im
in images)
233 listStore.AppendValues(im.pixbuf, im.name);
235 view.Model = listStore;
240 var listStore =
new ListStore(typeof(
string));
244 if (comboBox.Active != -1)
245 foreach (var db
in dbs)
248 comboBox.Model.GetIterFromString(out iter, comboBox.Active.ToString());
249 string selectedItem = (string)comboBox.Model.GetValue(iter, 0);
250 string[] sts = selectedItem.Split(
' ');
251 if (db.getId() ==
long.Parse(sts[1]))
253 List<long> str =
BioLib.OMERO.GetDatasetIds(db.getId());
256 foreach (var item
in str)
258 Image image =
new Image();
260 image.dataset = db.getId();
261 image.name =
BioLib.OMERO.GetNameFromID(item);
265 foreach (var im
in images)
267 listStore.AppendValues(im.name);
269 view.Model = listStore;
273 public void InitItems()
275 var comStore =
new ListStore(typeof(
string));
276 List<DatasetData> dbs =
BioLib.OMERO.GetDatasetsData();
277 foreach (var im
in dbs)
279 comStore.AppendValues(im.getName() +
" " + im.getId());
281 comboBox.Model = comStore;
284 public void UpdateROIs()
286 var ro =
BioLib.OMERO.gateway.getROIService(
BioLib.OMERO.sc);
289 public void UpdateItems(
string filt)
291 var listStore =
new ListStore(typeof(Gdk.Pixbuf), typeof(
string));
292 view.PixbufColumn = 0;
294 foreach (var im
in images)
296 if(im.name.Contains(filt) || filt ==
"")
297 listStore.AppendValues(im.pixbuf, im.name);
299 view.Model = listStore;
301 private void SearchBox_Changed(
object sender, EventArgs e)
303 UpdateItems(searchBox.Buffer.Text);