File: AMC-gui.pl.in

package info (click to toggle)
auto-multiple-choice 1.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 92,612 kB
  • sloc: perl: 26,752; xml: 24,889; cpp: 1,997; python: 895; makefile: 569; sh: 233; ansic: 195
file content (167 lines) | stat: -rwxr-xr-x 4,337 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#! @/PERLPATH/@
#
# Copyright (C) 2008-2025 Alexis Bienvenüe <paamc@passoire.fr>
#
# This file is part of Auto-Multiple-Choice
#
# Auto-Multiple-Choice is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# Auto-Multiple-Choice is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Auto-Multiple-Choice.  If not, see
# <http://www.gnu.org/licenses/>.

use warnings;
use 5.012;

use Getopt::Long;

use Gtk3 -init;

use Glib::Object::Introspection;
use Glib qw/TRUE FALSE/;

use Cwd;
use File::Spec::Functions
  qw/splitpath catpath splitdir/;
use I18N::Langinfo qw(langinfo CODESET);

use AMC::Basic;
use AMC::Config;
use AMC::Project;
use AMC::Gui::Main;

use_gettext;
use_amc_plugins();

POSIX::setlocale( &POSIX::LC_NUMERIC, "C" );

my $debug      = 0;
my $debug_file = '';
my $do_nothing = 0;
my $testing    = 0;

my $profile     = '';
my $project_dir = '';

GetOptions(
    "debug!"       => \$debug,
    "debug-file=s" => \$debug_file,
    "profile=s"    => \$profile,
    "p=s"          => \$project_dir,
    "do-nothing!"  => \$do_nothing,
    "testing!"     => \$testing,
);

if ( $debug || $debug_file ) {
    set_debug( $debug_file || 'new' );
    print "DEBUG ==> " . debug_file() . "\n";
}

debug_pm_version("Gtk3");

Gtk3::IconTheme::get_default->prepend_search_path( amc_specdir('icons') );
Gtk3::Window::set_default_icon_list(
    [
        map {
            Gtk3::IconTheme::get_default->load_icon( "auto-multiple-choice",
                $_, "force-svg" )
        } ( 8, 16, 32, 48, 64, 128 )
    ]
);

my %w = ();

my $home_dir         = Glib::get_home_dir();
my $encodage_systeme = langinfo( CODESET() );

my $shortcuts = AMC::Path::new( home_dir => $home_dir );
my $config    = AMC::Config::new(
    shortcuts => $shortcuts,
    home_dir  => $home_dir,
    profile   => $profile,
    testing   => $testing,
);

# goes to a specific directory if the project directory is given as a
# command-line option

if ( -f $project_dir ) {
    $project_dir =~ s/\/?options\.xml$//;
}
$project_dir =~ s/\/+$//;

if ( -d $project_dir ) {
    my ( $projects_home, $project_name ) = split_project_dir($project_dir);
    $config->set( 'rep_projets', $projects_home );
    @ARGV = $project_name;
}

# creates projets and models directories if needed (if not present,
# Edit/Parameters can be disrupted)

for my $k (qw/projects_home rep_modeles/) {
    my $path = $config->get_absolute($k);
    if ( -e $path ) {
        debug "WARNING: $path ($k) is not a directory!" if ( !-d $path );
    } else {
        mkdir($path);
    }
}

$config->set_projects_home( $config->get('rep_projets') );

my $project = AMC::Project->new( config => $config );
my $main    = AMC::Gui::Main->new(
    config     => $config,
    project    => $project,
    do_nothing => $do_nothing,
    testing    => $testing,
);
$project->set( 'gui', $main );

#######################################

exit 0 if ($do_nothing);

#######################################

$main->projet_ouvre( $ARGV[0] );

#######################################
# For MacPorts with latexfree variant, for example

if ( "@/LATEX_FREE/@" =~ /(1|true|yes)/i ) {
    my $message = '';
    if ( !commande_accessible("kpsewhich") ) {
        $message = sprintf( __("I don't find the command %s."), "kpsewhich" )
          . __("Perhaps LaTeX is not installed?");
    } else {
        if ( !get_sty() ) {

# TRANSLATORS: Do not translate 'auto-multiple-choice latex-link', which is a command to be typed on MacOsX
            $message = __(
"The style file automultiplechoice.sty seems to be unreachable. Try to use command 'auto-multiple-choice latex-link' as root to fix this."
            );
        }
    }
    if ($message) {
        my $dialog = Gtk3::MessageDialog->new( $main->get_ui('main_window'),
            'destroy-with-parent', 'error', 'ok', $message );
        $dialog->run;
        $dialog->destroy;
    }
}

Gtk3->main();

1;

__END__