Passing an argument from Filemanager to a Gambas-App

Post

Posted
Rating:
#1 (In Topic #743)
Regular
01McAc is in the usergroup ‘Regular’
I know the class gb.args and how command line arguments will be passed to a Gambas application. It's probably me but I have no idea how to proceed with this use case:
In a filemanager (i.e. KDE/Dolphin) I want to right-click an image. The context menue appears and I want to start my Gambas fileviewer-app to open and view the selected file. The filemanager opens my coded Gambas-fileviewer-app in the background passing just a single argument (path/filename as string) to the app.
Unfortunately, Gambas arguments require two dashes "–" upfront and that's why

Code

Application.Args[1-n]
is null in my fileviewer-app. Any idea how to pass a single argument to the app without two dashes?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’
I don't really understand your question or why you are talking about gb.Args, I think you just need the standard Application class.

I would have thought you could just start your Gambas program with something like: myImageViewer filename

…and then read the filename from Application.Args[0] in your code.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
01McAc is in the usergroup ‘Regular’
 sorry for the misunderstanding. I want the filemanager Dolphin to start my app (see attachment). Application.Args[0] shows only the path and name of the app but not the filename I clicked in Dolphin. I would expect the filename L1007019.jpg in Application.Args[1] but it's empty.

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
There is no need for gb.args. The basic one works fine for what you are looking for. The 'Arguments' are passed to Gambas as an array. The 1st argument, [0], in the array is the name of your program so what you need is the 2nd argument, [1]. Your file manager will pass the full path to Gambas so, try this code: -

Code (gambas)

  1. PictureBox1.Picture = Picture[Args[1]]
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
stevedee is in the usergroup ‘Regular’
Yes sorry, its argument [1] as Charlie said, not [0] which is always the name of the program.

I modified some code to test it:-

Code (gambas)

  1.   If Application.Args[1] <> "" Then
  2.     strThumbNail = LibRAW.ExtractSingleThumbnail(Application.Args[1])
  3.     Me.Text = "Arg found:" & Application.Args[1]
  4.   Else
  5.     strThumbNail = LibRAW.ExtractSingleThumbnail(RAW_FILE_NAME)
  6.  
  7.   pBox.Image = Image.Load(strThumbNail)
  8.   pBox.Stretch = True

I also modified "Open With..." properties in the file manager so it always loads my program if I double click on a RAW file type …but you may want to chose each time.
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
01McAc is in the usergroup ‘Regular’
Thanks. Seems to be a user problem. This is my original example:

Code

Public Sub Form_Open()
  Dim myFile As Variant
  
  If IsNull(Application.Args[1]) Then
     Message("No Argument")
     Quit
  Else
     myFile = Val(Application.Args[1])
     
  Endif '  Application.Args

  message("arg0: " & Application.Args[0] & gb.NewLine & "arg1: " & myFile & gb.NewLine & "arg2: " & Application.Args[2])
End

I found out that arg[1] is empty because the function val() destroys obviously the string. When I replace

Code

myFile = Val(Application.Args[1])
with

Code

myFile = Application.Args[1]
it works! Thanks for your time.
Online now: No Back to the top
1 guest and 0 members have just viewed this.