Autore Topic: [Risolto] [Wizard] Inserire un evento tra una schermata e l'altra  (Letto 783 volte)

vaillant86

  • Visitatore
Premessa: ho cercato nella documentazione e in questo forum ma non sono riuscito a trovare una soluzione.

Ho un wizard con 8 schermate e ho necessità di far partire uno script shell tra una schermata e l'altra, precisamente tra la n°2 e la n°3, una volta premuto il pulsante di avanzamento. Posto l'intero codice
Codice: gambas [Seleziona]
' Gambas class file

PUBLIC SUB Form_Open()
  ME.Center
  ME.Caption = ("Wizard")

  SHELL "mkdir -p ubuntu-builder/configs/wizard" WAIT
  SHELL "mkdir -p ubuntu-builder/configs/wizard/debs" WAIT
  SHELL "cd ubuntu-builder/configs/wizard && touch APPS AUTOCOMMANDS BUILDISO DISTRO ISOFILE ISOSAVE" WAIT

  TextBox_DistName.MaxLength = 32
  TextBox_HostName.MaxLength = 32
  TextBox_LiveCD_User.MaxLength = 32

  Preset_Box.Add(("Select..."))
  Preset_Box.Add("GNOME")
  Preset_Box.Add("KDE")
  Preset_Box.Add("XFCE4")
  Preset_Box.Add("LXDE")
  Preset_Box.Add("OpenBox")
  Preset_Box.Add("FluxBox")
  Preset_Box.Add("BlackBox")
  Preset_Box.Add("IceWM")
END

' Seleziona file ISO
PUBLIC SUB ISO_FileChooser_Change()
  ISO_FileChooser.Filter = ["*.iso", ("ISO Images")]
  SHELL "echo " & ISO_FileChooser.Value & " > ~/ubuntu-builder/configs/wizard/ISOFILE"
END

' Informazioni sul sistema
PUBLIC SUB TextBox_DistName_Change()
  File.Save("~/ubuntu-builder/configs/DIST", TextBox_DistName.Text)
END

PUBLIC SUB TextBox_HostName_Change()
  File.Save("~/ubuntu-builder/configs/HNAME", TextBox_HostName.Text)
END

PUBLIC SUB TextBox_LiveCD_User_Change()
  TextBox_LiveCD_User.Text = (Trim(LCase(TextBox_LiveCD_User.Text)))
  File.Save("~/ubuntu-builder/configs/LIVEUSER", TextBox_LiveCD_User.Text)
END

PUBLIC SUB TextBox_ReleaseNotes_Change()
  Trim(TextBox_ReleaseNotes.Text)
  File.Save("~/ubuntu-builder/ISO/.disk/release_notes_url", TextBox_ReleaseNotes.Text)
END

PUBLIC SUB TextBox_DistName_KeyPress()
  SELECT Key.text  
    CASE "@", "#", "!", "~", "(", ")", "{", "}", "[", "]"
    STOP EVENT  
  END SELECT
END

PUBLIC SUB TextBox_HostName_KeyPress()
  SELECT Key.text
    CASE "@", "#", "!", "~", "(", ")", "{", "}", "[", "]"
    STOP EVENT  
  END SELECT
END

PUBLIC SUB TextBox_LiveCD_User_KeyPress()
  SELECT Key.text
    CASE "@", "#", "!", "~", "(", ")", "{", "}", "[", "]"
    STOP EVENT  
  END SELECT
END

' Lista dei presets da installare
PUBLIC SUB Install_Packages_Click()
  SELECT CASE Preset_Box.Text
    CASE "GNOME"
      File.Save("~/ubuntu-builder/configs/wizard/APPS", "gnome-core xserver-xorg")
    CASE "KDE"
      File.Save("~/ubuntu-builder/configs/wizard/APPS", "kde-standard xserver-xorg")
    CASE "XFCE4"
      File.Save("~/ubuntu-builder/configs/wizard/APPS", "xfce4 xserver-xorg")
    CASE "LXDE"
      File.Save("~/ubuntu-builder/configs/wizard/APPS", "lxde-core xserver-xorg")
    CASE "OpenBox"
      File.Save("~/ubuntu-builder/configs/wizard/APPS", "menu openbox obconf xserver-xorg")
    CASE "FluxBox"
      File.Save("~/ubuntu-builder/configs/wizard/APPS", "menu fluxbox xserver-xorg")
    CASE "BlackBox"
      File.Save("~/ubuntu-builder/configs/wizard/APPS", "menu blackbox xserver-xorg")
    CASE "IceWM"
      File.Save("~/ubuntu-builder/configs/wizard/APPS", "icewm xserver-xorg")
    END SELECT
END

PUBLIC SUB Chroot_Commands_TextArea_Change()
  File.Save("~/ubuntu-builder/configs/wizard/AUTOCOMMANDS", Chroot_Commands_TextArea.Text)
END

' Schermata aggiungi/rimuovi file .deb
PUBLIC SUB Add_DEB_Click()
  DIM i AS Integer
  DIM deb AS String[30]
  DIM deb2 AS String[30]
  DIM list AS String

  Dialog.Title = ("Please select a DEB package")
  Dialog.Filter = ["*.deb", ("Debian Packages")]
  Dialog.Path = "/var/cache/apt/archives"
  IF Dialog.OpenFile(TRUE) THEN RETURN

  FOR EACH list IN Dialog.Paths
    SHELL "echo " & list & " >> ~/ubuntu-builder/configs/wizard/DEBS"
  NEXT

  FOR i = 0 TO 29
    SHELL "cat ~/ubuntu-builder/configs/wizard/DEBS | sed -n '" & Str(i + 1) & "p'" TO deb[i]
    deb[i] = Replace(deb[i], "\n", "")
    SHELL "cp " & deb[i] & " ~/ubuntu-builder/configs/wizard/debs/"
  NEXT
  
  FOR i = 0 TO 29
    SHELL "ls ~/ubuntu-builder/configs/wizard/debs/ | sed -n '" & Str(i + 1) & "p'" TO deb2[i]
    deb2[i] = Replace(deb2[i], "\n", "")
    IF (deb2[i]) THEN DEBs_ListBox.Add(deb2[i])
  NEXT
END

PUBLIC SUB DEBs_ListBox_KeyPress()
  DIM i AS Integer
  IF Key.Code = Key.Delete THEN  
    i = 0
    WHILE i < DEBs_ListBox.Count
    IF DEBs_ListBox[i].Selected THEN
      SHELL "rm ~/ubuntu-builder/configs/wizard/debs/" & DEBs_ListBox[i].Text
      DEBs_ListBox.Remove(i)
      DEC i
    ENDIF
    INC i
    WEND
  ENDIF
END

PUBLIC SUB Remove_All_DEB_Click()
  DEBs_ListBox.Clear
  SHELL "rm ~/ubuntu-builder/configs/wizard/debs/*"
END

PUBLIC SUB Edit_Sources_Click()
  FEdit.Show
END

PUBLIC SUB Start_Synaptic_Click()
  SHELL "x-terminal-emulator -e sudo /usr/share/ubuntu-builder/extras/Synaptic"
END

PUBLIC SUB Wizard_Cancel()
  SHELL "rm ~/ubuntu-builder/configs/wizard/debs/*"
  FWizard.Close
  FMain.Show
END

PUBLIC SUB Wizard_Close()
  FWizard.Close
  SHELL "x-terminal-emulator -e sudo /usr/share/ubuntu-builder/extras/Wizard"
  FMain.Show
END

mentre questo è il file .form
Codice: [Seleziona]
# Gambas Form File 2.0

{ Form Form
  MoveScaled(0,0,78,53)
  Text = ("Wizard")
  Icon = Picture["ubuntu-builder.png"]
  Border = Window.Fixed
  { Wizard Wizard
    MoveScaled(1,1,76,51)
    Count = 9
    Index = 0
    Text = ("# Welcome")
    { TextLabel5 TextLabel
      MoveScaled(1,1,73,9)
      Text = ("Welcome to Ubuntu Builder. This wizard will guide you during the creation of your customized distribuzion. Just follow the various steps and you can enjoy your new operating system.")
    }
    Index = 1
    Text = ("# Select an ISO image")
    { ISO_FileChooser FileChooser
      MoveScaled(1,1,73,38)
      Filter = []
    }
    Index = 2
    Text = ("# System informations")
    { TextLabel6 TextLabel
      MoveScaled(1,1,73,9)
      Text = ("Type the distribution name, the user name used for the live cd and the computer name in the fields below. If you want, you can also type the URL of the release notes of your distribution.")
    }
    { TextBox_DistName TextBox
      MoveScaled(38,16,29,3)
      Text = ("")
    }
    { TextBox_LiveCD_User TextBox
      MoveScaled(38,22,29,3)
      Text = ("")
    }
    { TextBox_HostName TextBox
      MoveScaled(38,28,29,3)
      Text = ("")
    }
    { TextBox_ReleaseNotes TextBox
      MoveScaled(38,34,29,3)
      Text = ("")
    }
    { Label1 Label
      MoveScaled(1,16,29,3)
      Text = ("Distribution Name")
      Alignment = Align.Left
    }
    { Label2 Label
      MoveScaled(1,22,29,3)
      Text = ("LiveCD User Name")
      Alignment = Align.Left
    }
    { Label3 Label
      MoveScaled(1,28,29,3)
      Text = ("Computer Name")
      Alignment = Align.Left
    }
    { Label4 Label
      MoveScaled(1,34,29,3)
      Text = ("Release Notes")
      Alignment = Align.Left
    }
    Index = 3
    Text = ("# Repository and GUI")
    { Preset_Box ComboBox
      MoveScaled(28,29,17,3)
      ReadOnly = True
      Text = ("")
    }
    { TextLabel4 TextLabel
      MoveScaled(1,17,73,9)
      Text = ("You can add a desktop environment or a window manager to your distribution by selecting one of the presets below.\n\nIf you don't choose anyone of them, anything will be automatically installed on your distribution.")
    }
    { Edit_Sources Button
      MoveScaled(28,10,17,3)
      Text = ("Edit sources")
    }
    { TextLabel7 TextLabel
      MoveScaled(1,1,73,9)
      Text = ("Edit the software sources to increase the availability of packages you can install.")
    }
    Index = 4
    Text = ("# Install DEB packages")
    { TextLabel3 TextLabel
      MoveScaled(1,1,73,9)
      Text = ("Add the DEB packages you want to install. The wizard will check all the required dependencies to install them. You can remove one package by pressing the CANC button on your keyboard of pressing \"Remove all\" to clear the packages list.")
    }
    { DEBs_ListBox ListBox
      MoveScaled(1,11,73,21)
      Mode = Select.Multiple
      Sorted = True
    }
    { Add_DEB Button
      MoveScaled(6,34,17,3)
      Text = ("Add")
    }
    { Remove_All_DEB Button
      MoveScaled(52,34,17,3)
      Text = ("Remove all")
    }
    Index = 5
    Text = ("# Execute commands via chroot")
    { TextLabel2 TextLabel
      MoveScaled(1,1,73,9)
      Text = ("Here you can enter the commands which will be executed via chroot. Be careful to type the commands correctly; otherwise, the building process may fail.")
    }
    { Chroot_Commands_TextArea TextArea
      MoveScaled(1,11,73,21)
      Text = ("")
      Wrap = True
    }
    Index = 6
    Text = ("# Choose where the ISO should be saved")
    { ISO_DirChooser DirChooser
      MoveScaled(1,1,73,38)
      ShowDetailed = True
    }
    Index = 7
    Text = ("# Do you need more?")
    { Start_Synaptic Button
      MoveScaled(28,10,17,3)
      Text = ("Start Synaptic")
    }
    { TextLabel9 TextLabel
      MoveScaled(1,1,73,9)
      Text = ("You can use Synaptic to install whatever you need or remove whatever you don't.")
    }
    { TextLabel8 TextLabel
      MoveScaled(1,17,73,9)
      Text = ("Do you need more options? Customize your distribution via textual or graphical chroot. Suggested for advanced users.")
    }
    { GUI_chroot Button
      MoveScaled(45,29,17,3)
      Text = ("Desktop")
    }
    { CLI_chroot Button
      MoveScaled(12,29,17,3)
      Text = ("Console")
    }
    Index = 8
    Text = ("# Ready to build")
    { TextLabel1 TextLabel
      MoveScaled(1,1,73,9)
      Text = ("All of the preparation has been done. Hit the OK button to start the automated proccess.")
    }
    Index = 0
  }
}
dovrei inserirlo tra index=1 e index=2 in modo che:

- arrivo alla seconda schermata;
- il wizard si nasconde
- parte lo script shell
- una volta terminata l'operazione, il wizard riappare e posso continuare con le altre schermate

Grazie :)
« Ultima modifica: 21 Marzo 2012, 16:02:41 da vaillant »

Offline fsurfing

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.484
    • Mostra profilo
Re: [Wizard] Inserire un evento tra una schermata e l'altra
« Risposta #1 il: 21 Marzo 2012, 13:56:45 »
Codice: [Seleziona]
PUBLIC SUB Wizard1_BeforeChange()

  IF Wizard1.Index = 1 THEN
    ME.Hide
    SHELL "gksudo nautilus" WAIT
    ME.Show
  ENDIF

END
questo è un esempio :)
il wait fa in modo che finchè non viene terminato il comando shell gambas si blocca

vaillant86

  • Visitatore
Re: [Wizard] Inserire un evento tra una schermata e l'altra
« Risposta #2 il: 21 Marzo 2012, 15:06:29 »
Eh avevo visto il beforechange ma non capivo come usarlo, almeno ero sulla buona strada ;D

Un dubbio: se per caso dall'indice successivo (2) torno indietro, mi si ripropone lo script? Se si, c'è un modo per farlo avviare solo una volta da quando è stato aperto il wizard?

vaillant86

  • Visitatore
Re: [Wizard] Inserire un evento tra una schermata e l'altra
« Risposta #3 il: 21 Marzo 2012, 16:02:27 »
Come non detto, ho letto bene. Viene attivato solo se passo dalla precedente alla successiva, non viceversa

Grazie fsurfing

Offline fsurfing

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.484
    • Mostra profilo
Re: [Risolto] [Wizard] Inserire un evento tra una schermata e l'altra
« Risposta #4 il: 21 Marzo 2012, 18:59:16 »
ti aiuto solo perchè poi mi serve ubuntubuilder!!  :P

vaillant86

  • Visitatore
Re: [Risolto] [Wizard] Inserire un evento tra una schermata e l'altra
« Risposta #5 il: 21 Marzo 2012, 19:37:33 »
Do ut des, mi sembra giusto ;D

vaillant86

  • Visitatore
Re: [Risolto] [Wizard] Inserire un evento tra una schermata e l'altra
« Risposta #6 il: 25 Marzo 2012, 12:44:32 »
Giusto per capire, questo è il codice che ho inserito
Codice: gambas [Seleziona]

PUBLIC SUB Wizard_BeforeChange()
  IF Wizard.Index = 1 THEN
    IF NOT ISO_FileChooser.Value THEN ' Se non viene selezionato un file iso da estrarre
      Message.Warning("Please select an ISO image") ' Avvisa l'utente che deve farlo
      STOP EVENT ' Fermati, non andare avanti alla successiva schermata
    ELSE
      ME.Hide ' Nascondi il wizard
      SHELL "x-terminal-emulator -e sudo " & SCRIPT &/ "/Extract" WAIT ' Avvia lo script di estrazione e aspetta che finisca
      ME.Show ' Mostra il wizard
    ENDIF
  ENDIF
END

su gnome funziona, mentre su xfce la schermata successiva compare simultaneamente al terminale con lo script di estrazione. Volevo capire: il codice è giusto? E' un problema che può essere legato al DE o al terminale usato da quel DE?

Offline fsurfing

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.484
    • Mostra profilo
Re: [Risolto] [Wizard] Inserire un evento tra una schermata e l'altra
« Risposta #7 il: 25 Marzo 2012, 18:51:57 »
sembrerebbe corretto , anche se potresti provare che succede con :

Codice: [Seleziona]

    PUBLIC SUB Wizard_BeforeChange() 
     IF Wizard.Index = 1 THEN   
       IF NOT ISO_FileChooser.Value THEN ' Se non viene selezionato un file iso da estrarre 
         Message.Warning("Please select an ISO image") ' Avvisa l'utente che deve farlo 
         wizard.index=0 ' Fermati, non andare avanti alla successiva schermata 
       ELSE   
         ME.Hide ' Nascondi il wizard 
          wait
         SHELL "sudo " & SCRIPT &/ "/Extract" WAIT ' Avvia lo script di estrazione e aspetta che finisca 
         ME.Show ' Mostra il wizard 
       ENDIF   
     ENDIF   
    END

ps:
 
a me personalmente non piace chiamare un componente con il nome della propria classe, io non lo chiamerei wizard ma che so .. wizard1
giusto perchè non si sa mai....

vaillant86

  • Visitatore
Re: [Risolto] [Wizard] Inserire un evento tra una schermata e l'altra
« Risposta #8 il: 25 Marzo 2012, 22:39:11 »
Grazie ma purtroppo non funziona comunque. Ho il sospetto che sia un problema legato a xfce perché l'utente che me lo ha segnalato ha riscontrato altri problemi che io e altri (su gnome e kde) non abbiamo trovato. Quasi quasi mi installo xubuntu e faccio prove dirette, magari mi rendo conto meglio.

Grazie dell'aiuto e del consiglio sul nome ;)