Esempio n. 1
0
    protected void OnRenderToActionActivated(object sender, System.EventArgs e)
    {
        Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Render image to",
                                                              this,
                                                              FileChooserAction.Save,
                                                              "Cancel", ResponseType.Cancel,
                                                              "Render", ResponseType.Accept);
        // Adding image filters
        FileFilter[] ffs = new FileFilter[3];
        ffs[0] = new FileFilter();
        ffs[0].Name = "JPEG image";
        ffs[0].AddCustom(FileFilterFlags.Filename, delegate (Gtk.FileFilterInfo ffi) {
            return (System.IO.Path.GetExtension(ffi.Filename).ToLower() == ".jpg") ||
                   (System.IO.Path.GetExtension(ffi.Filename).ToLower() == ".jpeg");
        });

        ffs[1] = new FileFilter();
        ffs[1].Name = "PNG image";
        ffs[1].AddCustom(FileFilterFlags.Filename, delegate (Gtk.FileFilterInfo ffi) {
            return System.IO.Path.GetExtension(ffi.Filename).ToLower() == ".png";
        });

        ffs[2] = new FileFilter();
        ffs[2].Name = "Plain 24 bpp bitmap (BMP)";
        ffs[2].AddCustom(FileFilterFlags.Filename, delegate (Gtk.FileFilterInfo ffi) {
            return System.IO.Path.GetExtension(ffi.Filename).ToLower() == ".bmp";
        });

        fcd.AddFilter(ffs[0]);
        fcd.AddFilter(ffs[1]);
        fcd.AddFilter(ffs[2]);

        // Adding prescaling widget
        PreScaleSelectorWidget pssw = new PreScaleSelectorWidget();
        pssw.Value = mStage.Prescale;
        fcd.ExtraWidget = pssw;

        int prescale = 2;
        string dest_type = "", fn = "";
        bool accept = false;

        fcd.CurrentName = System.IO.Path.GetFileNameWithoutExtension(mStage.RawFileName);
        fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.RawFileName));

        if (fcd.Run() == (int)Gtk.ResponseType.Accept)
        {
            fn = fcd.Filename;
            prescale = pssw.Value;
            if (fcd.Filter == ffs[0])
            {
                if (System.IO.Path.GetExtension(fn).ToLower() != ".jpeg" &&
                    System.IO.Path.GetExtension(fn).ToLower() != ".jpg")
                    fn += ".jpeg";

                dest_type = "jpeg";
            }
            if (fcd.Filter == ffs[1])
            {
                if (System.IO.Path.GetExtension(fn).ToLower() != ".png")
                    fn += ".png";

                dest_type = "png";
            }
            if (fcd.Filter == ffs[2])
            {
                if (System.IO.Path.GetExtension(fn).ToLower() != ".bmp")
                    fn += ".bmp";

                dest_type = "bmp";
            }
            accept = true;
        }
        fcd.Destroy();

        if (accept)
        {
            // Sending remote command to add stage to queue
            string command = "AddToQueue_StageData";
            string[] arguments = new string[]
            {
                mStage.SaveStageToString(),
                mStage.RawFileName,
                fn,
                dest_type,
                prescale.ToString()
            };
            MainClass.RemoteControlService.SendCommand(RemoteControlService.PackCommand(command, arguments));

        }
    }
Esempio n. 2
0
    /*
    public void LoadCEStage(string filename, bool findRawForCEStage)
    {
        try
        {
            mStage.LoadStage(filename);

            string raw_filename; int prescale = 2;
            if (mStage.Prescale != 0) prescale = mStage.Prescale;

            if (findRawForCEStage && MainClass.FindRawsForCestageAndAskToOpen(filename, out raw_filename, ref prescale))
            {
                mStage.AskLoadImage(raw_filename, prescale);
            }
        }
        catch (StageDeserializationException sdex)
        {
            Gtk.MessageDialog md = new Gtk.MessageDialog(
                this, DialogFlags.Modal,
                MessageType.Error, ButtonsType.Ok,
                false, "Can't load stage from the file \"{0}\".\n{1}", filename, sdex.Message);

            md.Title = MainClass.APP_NAME;

            md.Run();
            md.Destroy();
        }
    }
    */
    public bool ShowLoadImageDialog()
    {
        if (mStage.TheUIState == UIState.Loading)
        {
            Gtk.MessageDialog md = new Gtk.MessageDialog(this, DialogFlags.Modal,
                                                         MessageType.Error, ButtonsType.Ok,
                                                         "Loading is in progress");
            md.Title = MainClass.APP_NAME;
            md.Run();
            md.Destroy();
        }
        else
        {
            Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Open RAW image",
                                                                  this,
                                                                  FileChooserAction.Open,
                                                                  "Cancel", ResponseType.Cancel,
                                                                  "Open", ResponseType.Accept);

            // Filter for RAWs
            FileFilter ff = new FileFilter();

            ff.AddCustom(FileFilterFlags.Filename, delegate (Gtk.FileFilterInfo ffi) {
                return RawLoader.IsRaw(ffi.Filename);
            });
            ff.Name = "RAW image";

            fcd.AddFilter(ff);

            // Setting current folder to stage file folder or to RAW file folder
            if (mStage.StageFileName != null && mStage.StageFileName != ""
                    && !fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.StageFileName)))
                fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.RawFileName));

            // Adding preview widget

            ReceiptSelectorWidget rsw = new ReceiptSelectorWidget();
            RawPreviewWidget rpw = new RawPreviewWidget();

            // Adding options widget

            PreScaleSelectorWidget pssw = new PreScaleSelectorWidget();
            pssw.Value = 2;
            if (mStage.Prescale != 0) pssw.Value = mStage.Prescale;

            VBox preview_box = new VBox(false, 4);
            preview_box.PackStart(rpw, true, true, 0);
            preview_box.ShowAll();
            fcd.PreviewWidget = preview_box;

            HBox options_box = new HBox(false, 20);
            options_box.PackStart(rsw, true, true, 0);
            options_box.PackEnd(pssw, false, true, 0);
            fcd.ExtraWidget = options_box;
            options_box.ShowAll();

            // Adding events

            fcd.UpdatePreview += delegate {
                rpw.Filename = fcd.Filename;
            };
            fcd.SelectionChanged += delegate {
                rpw.Filename = fcd.Filename;
                rsw.RawFileName = fcd.Filename;
            };
            rpw.FileIsGoodChanged += delegate {
                options_box.Sensitive = rpw.FileIsGood;
                fcd.PreviewWidgetActive = rpw.FileIsGood;
            };

            if (mStage.RawFileName != null)
            {
                fcd.SetFilename(mStage.RawFileName);
                rpw.Filename = mStage.RawFileName;
                rsw.RawFileName = mStage.RawFileName;
                fcd.PreviewWidgetActive = rpw.FileIsGood;
                options_box.Sensitive = rpw.FileIsGood;
            }

            string filename = ""; int prescale = 2;
            bool ok = false;

            if (fcd.Run() == (int)Gtk.ResponseType.Accept)
            {
                ok = true;
                filename = fcd.Filename;
                prescale = pssw.Value;
            }

            fcd.Destroy();

            if (ok)
            {
                if (mStage.RawFileName != filename)
                {
                    mStage.AskLoadImage(filename, prescale);
                }
                mStage.LoadStage(rsw.SelectedReceiptFileName);
                return true;
            }
        }
        return false;
    }