void SetupWidgets() { histogram_expander = new Expander(Strings.Histogram); histogram_expander.Activated += (s, e) => { ContextSwitchStrategy.SetHistogramVisible(Context, histogram_expander.Expanded); UpdateHistogram(); }; histogram_expander.StyleSet += (s, a) => { Gdk.Color c = Toplevel.Style.Backgrounds[(int)Gtk.StateType.Active]; histogram.RedColorHint = (byte)(c.Red / 0xff); histogram.GreenColorHint = (byte)(c.Green / 0xff); histogram.BlueColorHint = (byte)(c.Blue / 0xff); histogram.BackgroundColorHint = 0xff; UpdateHistogram(); }; histogram_image = new Image(); histogram = new Histogram(); histogram_expander.Add(histogram_image); Add(histogram_expander); info_expander = new Expander(Strings.ImageInformation); info_expander.Activated += (s, e) => { ContextSwitchStrategy.SetInfoBoxVisible(Context, info_expander.Expanded); }; info_table = new Table(head_rows, 2, false) { BorderWidth = 0 }; AddLabelEntry(null, null, null, null, photos => { return(Strings.NumberPhotos(photos.Length)); }); AddLabelEntry(null, Strings.Name, null, (photo, file) => { return(photo.Name ?? string.Empty); }, null); version_list = new ListStore(typeof(IPhotoVersion), typeof(string), typeof(bool)); version_combo = new ComboBox(); var version_name_cell = new CellRendererText { Ellipsize = Pango.EllipsizeMode.End }; version_combo.PackStart(version_name_cell, true); version_combo.SetCellDataFunc(version_name_cell, new CellLayoutDataFunc(VersionNameCellFunc)); version_combo.Model = version_list; version_combo.Changed += OnVersionComboChanged; AddEntry(null, Strings.Version, null, version_combo, 0.5f, (widget, photo, file) => { version_list.Clear(); version_combo.Changed -= OnVersionComboChanged; int count = 0; foreach (var version in photo.Versions) { version_list.AppendValues(version, version.Name, true); if (version == photo.DefaultVersion) { version_combo.Active = count; } count++; } if (count <= 1) { version_combo.Sensitive = false; version_combo.TooltipText = Strings.ParenNoEditsParen; } else { version_combo.Sensitive = true; version_combo.TooltipText = Catalog.GetPluralString(Strings.ParenOneEditParen, Strings.ParenXEditsParen(count - 1), count - 1); } version_combo.Changed += OnVersionComboChanged; }, null); AddLabelEntry("date", Strings.Date, Strings.ShowDate, (photo, file) => { return($"{photo.Time.ToShortDateString()}{Environment.NewLine}{photo.Time.ToShortTimeString()}"); }, photos => { var first = photos[photos.Length - 1]; IPhoto last = photos[0]; if (first.Time.Date == last.Time.Date) { return(Strings.OnDateBetweenTimeAndTime(first.Time.ToShortDateString(), first.Time.ToShortTimeString(), last.Time.ToShortTimeString())); } else { return(Strings.BetweenTimeAndTime(first.Time.ToShortDateString(), last.Time.ToShortDateString())); } }); AddLabelEntry("size", Strings.Size, Strings.ShowSize, (photo, metadata) => { int width = 0; int height = 0; if (null != metadata.Properties) { width = metadata.Properties.PhotoWidth; height = metadata.Properties.PhotoHeight; } if (width != 0 && height != 0) { return($"{width}x{height}"); } return(Strings.ParenUnknownParen); }, null); AddLabelEntry("exposure", Strings.Exposure, Strings.ShowExposure, (photo, metadata) => { var fnumber = metadata.ImageTag.FNumber; var exposure_time = metadata.ImageTag.ExposureTime; var iso_speed = metadata.ImageTag.ISOSpeedRatings; string info = string.Empty; if (fnumber.HasValue && fnumber.Value != 0.0) { info += $"f/{fnumber.Value:.0} "; } if (exposure_time.HasValue) { if (Math.Abs(exposure_time.Value) >= 1.0) { info += $"{exposure_time.Value} sec "; } else { info += $"1/{(int)(1 / exposure_time.Value)} sec "; } } if (iso_speed.HasValue) { info += $"{Environment.NewLine}ISO {iso_speed.Value}"; } var exif = metadata.ImageTag.Exif; if (exif != null) { var flash = exif.ExifIFD.GetLongValue(0, (ushort)TagLib.IFD.Tags.ExifEntryTag.Flash); if (flash.HasValue) { if ((flash.Value & 0x01) == 0x01) { info += $", {Strings.FlashFired}"; } else { info += $", {Strings.FlashDidntFire}"; } } } if (info == string.Empty) { return(Strings.ParenNoneParen); } return(info); }, null); AddLabelEntry("focal_length", Strings.FocalLength, Strings.ShowFocalLength, false, (photo, metadata) => { var focal_length = metadata.ImageTag.FocalLength; if (focal_length == null) { return(Strings.ParenUnknownParen); } return($"{focal_length.Value} mm"); }, null); AddLabelEntry("camera", Strings.Camera, Strings.ShowCamera, false, (photo, metadata) => { return(metadata.ImageTag.Model ?? Strings.ParenUnknownParen); }, null); AddLabelEntry("creator", Strings.Creator, Strings.ShowCreator, (photo, metadata) => { return(metadata.ImageTag.Creator ?? Strings.ParenUnknownParen); }, null); AddLabelEntry("file_size", Strings.FileSize, Strings.ShowFileSize, false, (photo, metadata) => { try { var fileSize = new System.IO.FileInfo(photo.DefaultVersion.Uri.AbsolutePath).Length; return(Format.SizeForDisplay(fileSize)); } catch (Exception e) { Hyena.Log.DebugException(e); return(Strings.ParenFileReadErrorParen); } }, null); var rating_entry = new RatingEntry { HasFrame = false, AlwaysShowEmptyStars = true }; rating_entry.Changed += HandleRatingChanged; var rating_align = new Gtk.Alignment(0, 0, 0, 0); rating_align.Add(rating_entry); AddEntry("rating", Strings.Rating, Strings.ShowRating, rating_align, false, (widget, photo, metadata) => { ((widget as Alignment).Child as RatingEntry).Value = (int)photo.Rating; }, null); AddEntry("tag", null, Strings.ShowTags, new TagView(), false, (widget, photo, metadata) => { (widget as TagView).Current = photo; }, null); UpdateTable(); var eb = new EventBox(); eb.Add(info_table); info_expander.Add(eb); eb.ButtonPressEvent += HandleButtonPressEvent; Add(info_expander); }
private void SetupWidgets() { histogram_expander = new Expander(Catalog.GetString("Histogram")); histogram_expander.Activated += delegate(object sender, EventArgs e) { ContextSwitchStrategy.SetHistogramVisible(Context, histogram_expander.Expanded); UpdateHistogram(); }; histogram_image = new Gtk.Image(); histogram = new Histogram(); histogram_expander.Add(histogram_image); Window window = MainWindow.Toplevel.Window; Gdk.Color c = window.Style.Backgrounds [(int)Gtk.StateType.Active]; histogram.RedColorHint = (byte)(c.Red / 0xff); histogram.GreenColorHint = (byte)(c.Green / 0xff); histogram.BlueColorHint = (byte)(c.Blue / 0xff); histogram.BackgroundColorHint = 0xff; Add(histogram_expander); info_expander = new Expander(Catalog.GetString("Image Information")); info_expander.Activated += delegate(object sender, EventArgs e) { ContextSwitchStrategy.SetInfoBoxVisible(Context, info_expander.Expanded); }; Table info_table = new Table(7, 2, false); info_table.BorderWidth = 0; string name_pre = "<b>"; string name_post = "</b>"; name_label = CreateRightAlignedLabel(name_pre + Catalog.GetString("Name") + name_post); info_table.Attach(name_label, 0, 1, 0, 1, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); version_label = CreateRightAlignedLabel(name_pre + Catalog.GetString("Version") + name_post); info_table.Attach(version_label, 0, 1, 1, 2, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); date_label = CreateRightAlignedLabel(name_pre + Catalog.GetString("Date") + name_post + Environment.NewLine); info_table.Attach(date_label, 0, 1, 2, 3, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); size_label = CreateRightAlignedLabel(name_pre + Catalog.GetString("Size") + name_post); info_table.Attach(size_label, 0, 1, 3, 4, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); default_exposure_string = name_pre + Catalog.GetString("Exposure") + name_post; exposure_label = CreateRightAlignedLabel(default_exposure_string); info_table.Attach(exposure_label, 0, 1, 4, 5, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); rating_label = CreateRightAlignedLabel(name_pre + Catalog.GetString("Rating") + name_post); info_table.Attach(rating_label, 0, 1, 5, 6, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); rating_label.Visible = false; name_value_label = new Label(); name_value_label.Ellipsize = Pango.EllipsizeMode.Middle; name_value_label.Justify = Gtk.Justification.Left; name_value_label.Selectable = true; name_value_label.Xalign = 0; info_table.Attach(name_value_label, 1, 2, 0, 1, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill, 3, 0); date_value_label = AttachLabel(info_table, 2, name_value_label); size_value_label = AttachLabel(info_table, 3, name_value_label); exposure_value_label = AttachLabel(info_table, 4, name_value_label); version_option_menu = new OptionMenu(); info_table.Attach(version_option_menu, 1, 2, 1, 2, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); date_value_label.Text = Environment.NewLine; exposure_value_label.Text = Environment.NewLine; Gtk.Alignment rating_align = new Gtk.Alignment(0, 0, 0, 0); info_table.Attach(rating_align, 1, 2, 5, 6, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); rating_view = new RatingSmall(); rating_view.Visible = false; rating_view.Changed += HandleRatingChanged; rating_align.Add(rating_view); tag_view = new TagView(MainWindow.ToolTips); info_table.Attach(tag_view, 0, 2, 6, 7, AttachOptions.Fill, AttachOptions.Fill, TABLE_XPADDING, TABLE_YPADDING); tag_view.Show(); info_table.ShowAll(); info_expander.Add(info_table); Add(info_expander); rating_label.Visible = show_rating; rating_view.Visible = show_rating; }
private void SetupWidgets() { histogram_expander = new Expander(Catalog.GetString("Histogram")); histogram_expander.Activated += delegate(object sender, EventArgs e) { ContextSwitchStrategy.SetHistogramVisible(Context, histogram_expander.Expanded); UpdateHistogram(); }; histogram_expander.StyleSet += delegate(object sender, StyleSetArgs args) { Gdk.Color c = this.Toplevel.Style.Backgrounds[(int)Gtk.StateType.Active]; histogram.RedColorHint = (byte)(c.Red / 0xff); histogram.GreenColorHint = (byte)(c.Green / 0xff); histogram.BlueColorHint = (byte)(c.Blue / 0xff); histogram.BackgroundColorHint = 0xff; UpdateHistogram(); }; histogram_image = new Gtk.Image(); histogram = new Histogram(); histogram_expander.Add(histogram_image); Add(histogram_expander); info_expander = new Expander(Catalog.GetString("Image Information")); info_expander.Activated += (sender, e) => { ContextSwitchStrategy.SetInfoBoxVisible(Context, info_expander.Expanded); }; info_table = new Table(head_rows, 2, false) { BorderWidth = 0 }; AddLabelEntry(null, null, null, null, photos => { return(String.Format(Catalog.GetString("{0} Photos"), photos.Length)); }); AddLabelEntry(null, Catalog.GetString("Name"), null, (photo, file) => { return(photo.Name ?? String.Empty); }, null); version_list = new ListStore(typeof(IPhotoVersion), typeof(string), typeof(bool)); version_combo = new ComboBox(); CellRendererText version_name_cell = new CellRendererText(); version_name_cell.Ellipsize = Pango.EllipsizeMode.End; version_combo.PackStart(version_name_cell, true); version_combo.SetCellDataFunc(version_name_cell, new CellLayoutDataFunc(VersionNameCellFunc)); version_combo.Model = version_list; version_combo.Changed += OnVersionComboChanged; AddEntry(null, Catalog.GetString("Version"), null, version_combo, 0.5f, (widget, photo, file) => { version_list.Clear(); version_combo.Changed -= OnVersionComboChanged; int count = 0; foreach (IPhotoVersion version in photo.Versions) { version_list.AppendValues(version, version.Name, true); if (version == photo.DefaultVersion) { version_combo.Active = count; } count++; } if (count <= 1) { version_combo.Sensitive = false; version_combo.TooltipText = Catalog.GetString("(No Edits)"); } else { version_combo.Sensitive = true; version_combo.TooltipText = String.Format(Catalog.GetPluralString("(One Edit)", "({0} Edits)", count - 1), count - 1); } version_combo.Changed += OnVersionComboChanged; }, null); AddLabelEntry("date", Catalog.GetString("Date"), Catalog.GetString("Show Date"), (photo, file) => { return(String.Format("{0}{2}{1}", photo.Time.ToShortDateString(), photo.Time.ToShortTimeString(), Environment.NewLine)); }, photos => { IPhoto first = photos[photos.Length - 1]; IPhoto last = photos[0]; if (first.Time.Date == last.Time.Date) { //Note for translators: {0} is a date, {1} and {2} are times. return(String.Format(Catalog.GetString("On {0} between \n{1} and {2}"), first.Time.ToShortDateString(), first.Time.ToShortTimeString(), last.Time.ToShortTimeString())); } else { return(String.Format(Catalog.GetString("Between {0} \nand {1}"), first.Time.ToShortDateString(), last.Time.ToShortDateString())); } }); AddLabelEntry("size", Catalog.GetString("Size"), Catalog.GetString("Show Size"), (photo, metadata) => { int width = 0; int height = 0; if (null != metadata.Properties) { width = metadata.Properties.PhotoWidth; height = metadata.Properties.PhotoHeight; } if (width != 0 && height != 0) { return(String.Format("{0}x{1}", width, height)); } return(Catalog.GetString("(Unknown)")); }, null); AddLabelEntry("exposure", Catalog.GetString("Exposure"), Catalog.GetString("Show Exposure"), (photo, metadata) => { var fnumber = metadata.ImageTag.FNumber; var exposure_time = metadata.ImageTag.ExposureTime; var iso_speed = metadata.ImageTag.ISOSpeedRatings; string info = String.Empty; if (fnumber.HasValue && fnumber.Value != 0.0) { info += String.Format("f/{0:.0} ", fnumber.Value); } if (exposure_time.HasValue) { if (Math.Abs(exposure_time.Value) >= 1.0) { info += String.Format("{0} sec ", exposure_time.Value); } else { info += String.Format("1/{0} sec ", (int)(1 / exposure_time.Value)); } } if (iso_speed.HasValue) { info += String.Format("{0}ISO {1}", Environment.NewLine, iso_speed.Value); } var exif = metadata.ImageTag.Exif; if (exif != null) { var flash = exif.ExifIFD.GetLongValue(0, (ushort)TagLib.IFD.Tags.ExifEntryTag.Flash); if (flash.HasValue) { if ((flash.Value & 0x01) == 0x01) { info += String.Format(", {0}", Catalog.GetString("flash fired")); } else { info += String.Format(", {0}", Catalog.GetString("flash didn't fire")); } } } if (info == String.Empty) { return(Catalog.GetString("(None)")); } return(info); }, null); AddLabelEntry("focal_length", Catalog.GetString("Focal Length"), Catalog.GetString("Show Focal Length"), false, (photo, metadata) => { var focal_length = metadata.ImageTag.FocalLength; if (focal_length == null) { return(Catalog.GetString("(Unknown)")); } return(String.Format("{0} mm", focal_length.Value)); }, null); AddLabelEntry("camera", Catalog.GetString("Camera"), Catalog.GetString("Show Camera"), false, (photo, metadata) => { return(metadata.ImageTag.Model ?? Catalog.GetString("(Unknown)")); }, null); AddLabelEntry("creator", Catalog.GetString("Creator"), Catalog.GetString("Show Creator"), (photo, metadata) => { return(metadata.ImageTag.Creator ?? Catalog.GetString("(Unknown)")); }, null); AddLabelEntry("file_size", Catalog.GetString("File Size"), Catalog.GetString("Show File Size"), false, (photo, metadata) => { try { GFile file = FileFactory.NewForUri(photo.DefaultVersion.Uri); GFileInfo file_info = file.QueryInfo("standard::size", FileQueryInfoFlags.None, null); return(Format.SizeForDisplay(file_info.Size)); } catch (GLib.GException e) { Hyena.Log.DebugException(e); return(Catalog.GetString("(File read error)")); } }, null); var rating_entry = new RatingEntry { HasFrame = false, AlwaysShowEmptyStars = true }; rating_entry.Changed += HandleRatingChanged; var rating_align = new Gtk.Alignment(0, 0, 0, 0); rating_align.Add(rating_entry); AddEntry("rating", Catalog.GetString("Rating"), Catalog.GetString("Show Rating"), rating_align, false, (widget, photo, metadata) => { ((widget as Alignment).Child as RatingEntry).Value = (int)photo.Rating; }, null); AddEntry("tag", null, Catalog.GetString("Show Tags"), new TagView(), false, (widget, photo, metadata) => { (widget as TagView).Current = photo; }, null); UpdateTable(); EventBox eb = new EventBox(); eb.Add(info_table); info_expander.Add(eb); eb.ButtonPressEvent += HandleButtonPressEvent; Add(info_expander); }