#
# $RCSfile: pwscf.itcl,v $ --
#
#      This file is the main Tcl file for the PWSCF GUI.
#
# Copyright (c) 2003  Anton Kokalj   Email: tone.kokalj@ijs.si
#
#
# This file is distributed under the terms of the GNU General Public
# License. See the file `COPYING' in the root directory of the present
# distribution, or http://www.gnu.org/copyleft/gpl.txt .
#
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# ANTON KOKALJ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#
# $Id: pwscf.itcl,v 1.15 2011-04-06 10:14:48 kokalj Exp $ 
#

tk_setPalette  #d9d9d9
option add *Menu*borderWidth                 1         startupFile
option add *Menubar*borderWidth              1         100
option add *Menubar*activeBorderWidth        1         100
option add *Menubar*activeBackground        \#007d8d   startupFile
option add *Menubar*activeForeground        \#ffffff   startupFile

option readfile [file join $::env(PWGUI) src pwscf.theme] startupFile
option readfile [file join $::guib::library guib.theme]   startupFile

option add *selectColor                     \#ffffff   userDefault

#
# initialization
#
pwscf::init

# ------------------------------------------------------------------------
# create IMAGES
# ------------------------------------------------------------------------

image create photo logo -format gif \
    -file [file join $env(PWGUI) images pwgui-logo.gif]

image create photo pwscf   -format gif \
    -file [file join $env(PWGUI) images pwscf-logo.gif] 



# ------------------------------------------------------------------------
# create the PWgui's GUI object
# ------------------------------------------------------------------------

set gui [::guib::GUI \#auto -title "PWgui: A PWscf's GUI" -appname PWgui]



# ------------------------------------------------------------------------
# define the PWSCF's modules
# ------------------------------------------------------------------------

$gui addModule module pw "PW.X" [file join $env(PWGUI) modules pw pw.tcl] { 
    {{PW.X Input Files} {*.pw.in *.pw.inp}}
}

$gui addModule separator sep1

$gui addModule module neb "NEB.X's neb.dat" [file join $env(PWGUI) modules neb neb.tcl] { 
    {{NEB.X (neb.dat) Input Files} {*.dat}}
}

$gui addModule module ph "PH.X" [file join $env(PWGUI) modules ph ph.tcl] {
    {{PH.X Input Files} {*.ph.in *.ph.inp}}
}
$gui addModule module pp "PP.X" [file join $env(PWGUI) modules pp pp.tcl] {
    {{PP.X Input Files} {*.pp.in *.pp.inp}}
}
$gui addModule module pr "ProjWFC.X" [file join $env(PWGUI) modules projwfc projwfc.tcl] {
    {{ProjWFC.X Input Files} {*.pr.in *.pr.inp}}
}
$gui addModule module bands "Bands.X" [file join $env(PWGUI) modules bands bands.tcl] {
    {{Bands.X Input Files} {*.bands.in *.bands.inp}}
}
$gui addModule module dos "Dos.X" [file join $env(PWGUI) modules dos dos.tcl] {
    {{Dos.X Input Files} {*.dos.in *.dos.inp}}
}
$gui addModule module d3 "D3.X" [file join $env(PWGUI) modules d3 d3.tcl] {
    {{D3.X Input Files} {*.d3.in *.d3.inp}}
}
$gui addModule module ld "LD1.X" [file join $env(PWGUI) modules atomic atomic.tcl] {
    {{LD1.X Input Files} {*.ld1.in *.ld1.inp}}
}

#$gui addModule cascade pwscf "PWscf files ..." {
#   $gui addModule command ...
#   ...
#}
#$gui addModule cascade fpmd "FPMD files ... " {
#   $gui addModule command ...
#   ...
#}


# ------------------------------------------------------------------------
# help Files
# ------------------------------------------------------------------------
#$gui addHelp help usersguide "User's Guide for Quantum-ESPRESSO" [file join $env(PWGUI) doc pwdocs users-guide users-guide.html]
$gui addHelp help usersguide "User's Guide for Quantum-ESPRESSO" [file join $env(PWGUI) doc pwdocs user_guide user_guide.html] word

$gui addHelp separator

$gui addHelp help pw           "PW.X Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_PW.html] none
$gui addHelp help neb       "NEB.DAT Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_NEB.html] none
$gui addHelp help ph           "PH.X Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_PH.html] none
$gui addHelp help pp           "PP.X Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_PP.html] none
$gui addHelp help projwfc "ProjWFC.X Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_PROJWFC.html] none
$gui addHelp help bands     "Bands.X Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_BANDS.html] none
$gui addHelp help dos         "Dos.X Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_DOS.html] none
$gui addHelp help d3           "D3.X Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_D3.html] none
$gui addHelp help ld          "LD1.X Input Syntax"  [file join $env(PWGUI) doc pwdocs INPUT_LD1.html] none

$gui addHelp separator

$gui addHelp help about "About PWgui" [file join $env(PWGUI) src about.html] none


# ------------------------------------------------------------------------
#  EXTRA GUI stuff ...
# ------------------------------------------------------------------------

$gui extra {
    #
    # add Settings menu-entry to FILE menu
    #
    set mb [component menubar]
    $mb insert .file.closetab command .file.settings -label "Settings" -command [list ::pwscf::settings $this]
    $mb insert .file.closetab separator .file.setsep

    #
    # EDIT menubutton
    #
    $mb add menubutton .edit -text "Edit" -menu {
	options -tearoff false
    }
    $mb add command   .edit.editOrig -label "Input with editor" -command [list ::pwscf::edit::inputByEditor original $this]
    $mb add command   .edit.editCopy -label "Input's copy with editor" -command [list ::pwscf::edit::inputByEditor copy $this]
    $mb add separator .edit.sep1
    $mb add command   .edit.settings -label "Settings" -command [list ::pwscf::settings $this]

    #
    # VIEW menubutton
    #
    $mb add menubutton .view -text "View" -menu {
	options -tearoff false
    }
    $mb add command  .view.xcrysden -label "Structure with XCrySDen" -command [list ::pwscf::view::structByXcrysden $this]
    $mb add command  .view.input    -label "Input file" -command [list ::pwscf::view::inputByPager $this]
    # t.k.
    #$mb add separator .view.sep1
    #$mb add command  .view.xc -label "XCRYSDEN" -command [list ::pwscf::XCRYSDEN $this]
    #/

    #
    # RUN menubutton
    #
    $mb add menubutton .run -text "Run" -menu {
	options -tearoff false
    }
    $mb add command   .run.run     -label "Run calculation" -command [list ::pwscf::run::run $this]
    $mb add command   .run.runAs   -label "Configure & Run calculation" -command [list ::pwscf::run::runAs $this]
    $mb add separator .run.sep1
    $mb add command   .run.runXC   -label "Run calculation + XCrySDen's display" -command [list ::pwscf::run::runAndXC $this]
    $mb add command   .run.runAsXC -label "Configure & Run calculation + XCrySDen's display" -command [list ::pwscf::run::runAsAndXC $this]

    #
    # add a PWscf's logo to TOOLBAR
    #
    set tb [component toolbar]
    set pwscf [$tb add label  pwscf  -borderwidth 1 -relief flat -image pwscf]
    pack configure $pwscf -side right
    

    #
    # put a big logo picture in logoframe
    #
    set con [component logoframe]
    set imagelabel [label $con.l -image logo -anchor center -background White]
    pack $imagelabel -expand 1 -ipadx 0 -ipady 0 -padx 0 -pady 0
}



# ------------------------------------------------------------------------
#  STATE GUI stuff ...
# ------------------------------------------------------------------------

$gui state {
    # syntax: menubar path command
    menubar .edit.editOrig ::pwscf::menustate::editable
    menubar .edit.editCopy ::pwscf::menustate::editable

    menubar .view.input    ::pwscf::menustate::editable
    menubar .view.xcrysden ::pwscf::menustate::xcrysden

    menubar .run.run     ::pwscf::menustate::runnable
    menubar .run.runAs   ::pwscf::menustate::runnable   
    menubar .run.runXC   ::pwscf::menustate::runnableXC
    menubar .run.runAsXC ::pwscf::menustate::runnableXC   

    # syntax: toolbar label command
    #...
}



# ------------------------------------------------------------------------
#  now activate the GUI ...
# ------------------------------------------------------------------------

$gui activate
