AFAIK there is no possiblity to react to the OS drag & drop, but I would'nt be surprised if someone has found a way to get that work. Anyway, the following is roughly what I'd do:
guidefinition = Deploy@Panel@DynamicModule[{ num1 = 100, num2 = 10, path = FileNameJoin[{$HomeDirectory, "Desktop", "file.xls"}], year = Null, month = Null, day = Null, date = Null, res = "" }, Column[{ "First number", InputField[Dynamic[num1], Number], "Second number", InputField[Dynamic[num2], Number], "InputData", Row[{ InputField[Dynamic[path], String, Enabled -> False], FileNameSetter[Dynamic[path], "Open", {"Excel Files" -> {"*.xls"}}] }], "Date", Row[{ InputField[ Dynamic[day, (day = #; date = date2strng[year, month, day]) &], Number, FieldSize -> 2, Alignment -> Right, FieldHint -> "DD"], "/", InputField[ Dynamic[month, (month = #; date = date2strng[year, month, day]) &], Number, FieldSize -> 2, Alignment -> Right, FieldHint -> "MM"], "/", InputField[ Dynamic[year, (year = #; date = date2strng[year, month, day]) &], Number, FieldSize -> 4, Alignment -> Left, FieldHint -> "YYYY"] }], Button["Proceed", res = compute[num1, num2, path, date], ImageSize -> Automatic,Method->"Queued"], Dynamic[res] } ], Initialization :> ( date2strng = Function[ If[FreeQ[{##}, Null], StringJoin[ IntegerString[#3, 10, 2], "/", IntegerString[#2, 10, 2], "/", IntegerString[#1, 10, 4] ], Null ] ]; compute[num1_, num2_, path_, date_] := {num1, num2, path, date}; ) ]
once the gui looks and behaves as desired you can do:
CDFDeploy[ FileNameJoin[{$HomeDirectory, "Desktop", "simplegui.cdf"}], guidefinition, WindowSize -> {500, 300} ]
It will:
- Display only GUI by creating a
DynamicModule embedded in a CDF. All your code should go into the Initialization option. This way there is no need for "another" notebook, as the one (the cdf) you create contains all the code. Open the cdf and the gui is ready to work (depending on where you save it, you will need to accept to allow dynamic evaluation of "potential unsafe content"). - Input filename via
FileSetter which opens the system file opener dialog, preset to only accept xls files. Not exactly drag and drop but probably the most convenient way to get an existing file name that can be done easily with the documented gui features of Mathematica. - Use
Dynamic[res] to show the results, which will be automatically updated when the "Proceed" button is pressed. - Use a single
InputField for day, month and year, each with a FieldHint option to show the information about how to enter the date. The date string is then automatically created from those inputs whenever one of them changes.
You could of course use the FieldHint option also with only one string inputfield for the date, but with the above you have already some additional "checks" for valid input. To be on the save side I would probably combine these features with appropriate input checks as Istvan has shown.
CDFDeploy only is available for Mathematica 8.0.4, if you use older versions or prefer to create a notebook instead of a CDF-document, you could replace the CDFDeploy with something like:
nb = CreateDocument[{guidefinition}, WindowSize -> {500, 300}]; NotebookSave[nb,FileNameJoin[{$HomeDirectory, "Desktop", "simplegui.nb"}]]
This is not directly related to your questions, but I think you should also be aware of the restriction that a CDF-document "played" with the free CDF-Player will AFAIK not allow to import data from local files. It should work alright if you open the CDF-document with Mathematica or Player Pro, though.