Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

# -*- coding: UTF-8 -*- 

# Copyright 2011 Luc Saffre 

# License: BSD (see file COPYING for details) 

""" 

Generate the local files for running :mod:`lino.ui.qx`. 

""" 

from __future__ import print_function 

 

import logging 

logger = logging.getLogger(__name__) 

 

import sys 

import os 

from os.path import join, dirname 

from optparse import make_option 

import codecs 

import subprocess 

import re 

from shutil import copytree, rmtree 

 

#~ from Cheetah.Template import Template as CheetahTemplate 

 

from django.db import models 

from django.conf import settings 

from django.utils.translation import ugettext as _ 

from django.utils.encoding import force_text 

from django.core.management import call_command 

from django.core.management.base import BaseCommand, CommandError 

from django.db.models import loading 

 

import lino 

from lino.core import dbtables 

from lino.core import actions 

from lino.core.utils import app_labels 

from lino.utils import confirm 

from lino.utils import rstgen 

from lino.core.menus import Menu, MenuItem 

from lino.utils import jsgen 

from lino.management.commands.makedocs import GeneratingCommand 

 

 

def a2class(a): 

    #~ return 'lino.%s' % a 

    return 'lino.%s_%s_%s' % (a.actor.app_label, a.actor._actor_name, a.name) 

 

 

#~ from importlib import import_module 

#~ m = import_module(settings.ROOT_URLCONF) 

#~ m.ui.make_local_files() 

 

class Command(GeneratingCommand): 

    help = """Writes files (.js, .html, .css) for this Site. 

    """ 

 

    def handle(self, *args, **options): 

        #~ options.update(output_dir=QXAPP_PATH) 

        if args: 

            print("Warning : ignored arguments", args) 

        QXAPP_PATH = os.path.join( 

            settings.QOOXDOO_PATH, 'lino_apps', settings.SITE.project_name) 

        args = [QXAPP_PATH] 

        super(Command, self).handle(*args, **options) 

 

        args = [sys.executable] 

        args.append( 

            os.path.join(settings.QOOXDOO_PATH, 'tool', 'bin', 'generator.py')) 

        args.append('source') 

        args.append('build') 

        os.chdir(self.output_dir) 

        subprocess.call(args) 

 

    def generate_files(self): 

        settings.SITE.setup() 

        from lino.ui import qx 

        src = join(dirname(qx.__file__), 'qxapp_init', 'source') 

        dest = join(self.output_dir, 'source') 

        #~ dest = join(self.output_dir,'qxapp','source') 

        if os.path.exists(dest): 

            rmtree(dest) 

        copytree(src, dest) 

        self.tmpl_dir = join(dirname(qx.__file__), 'tmpl') 

        from lino.ui.qx.urls import ui 

        context = dict( 

            py2js=jsgen.py2js, 

            jsgen=jsgen, 

            a2class=a2class, 

            models=models, settings=settings) 

        for fn in ('config.json', 'generate.py', 'Manifest.json'): 

        #~ for fn in ('config.json',): 

            self.generate(fn + '.tmpl', 

                          join(self.output_dir, fn), **context) 

                #~ join(self.output_dir,'qxapp',fn),**context) 

 

        self.generate_class_file( 

            'lino.Application', 'Application.js.tmpl', **context) 

        #~ self.generate('Application',application_lines(self)) 

        for rpt in (dbtables.master_reports 

                    + dbtables.slave_reports 

                    + list(dbtables.generic_slaves.values())): 

            rh = rpt.get_handle() 

            #~ js += "Ext.namespace('Lino.%s')\n" % rpt 

            #~ f.write("Ext.namespace('Lino.%s')\n" % rpt) 

            context.update(rh=rh) 

            for a in rpt.get_actions(): 

                if isinstance(a, dbtables.GridEdit): 

                    context.update(action=a) 

                    self.generate_class_file( 

                        a2class(a), 'XyzTableWindow.js.tmpl', **context) 

                if isinstance(a, actions.ShowDetailAction): 

                    context.update(action=a) 

                    self.generate_class_file(a2class(a), 

                                             'XyzDetailWindow.js.tmpl', 

                                             **context) 

        for d in (join(self.output_dir, 'source', 'translation'), 

                  join(self.output_dir, 'source', 'script'), 

                  join(self.output_dir, 'source', 'resource', 'lino')): 

            settings.SITE.makedirs_if_missing(d) 

 

    #~ def generate(self,fn,lines): 

    def generate_class_file(self, class_name, tpl, **kw): 

        assert class_name.startswith("lino."), class_name 

        #~ class_name = "lino." + class_name 

        fn = class_name.replace('.', os.path.sep) 

        fn += '.js' 

        fn = os.path.join(self.output_dir, 'source', 'class', fn) 

        kw.update(class_name=class_name) 

        self.generate(tpl, fn, **kw) 

        #~ os.makedirs(os.path.dirname(fn)) 

        #~ fd = codecs.open(fn,'w',encoding='UTF-8') 

        #~ for ln in lines: 

            #~ fd.write(ln + "\n") 

        #~ fd.close() 

        #~ self.generated_count += 1