Exemplo n.º 1
0
    def open_file_dialog(self):
        file_types = ('Text Files (*.txt;*.sh;*.md;*.py;*.c)', 'All files (*.*)')

        file_name = self.window.create_file_dialog(webview.OPEN_DIALOG, allow_multiple=False, file_types=file_types)
        if file_name and file_name[0]:
            with open(file_name[0]) as f:
                return Viaduc.callback('loadFile', {'fileName': file_name, 'content': f.read()})
        else:
            return Viaduc.done()
Exemplo n.º 2
0
 def do_something(self, vals):
     print('do_something: {}'.format(vals))
     v = self.map_vals(vals)
     if not v['inputEmail4']:
         raise ValueError('Empty email')
     if not v['inputPassword4']:
         raise ValueError('Empty password')
     if v['inputCheck']:
         return Viaduc.callback('callback',
                                {'message': 'This is a sample callback'})
     else:
         return Viaduc.done('Operation completed')
Exemplo n.º 3
0
    def open_dir_dialog(self, dir_name):
        if not dir_name:
            dir_name = self.get_dir_name()
            if not dir_name:
                # cancel was pressed
                return Viaduc.done()

        image_files = []
        for f in os.listdir(dir_name):
            if f.endswith('.png') or f.endswith('.jpg') or f.endswith('.gif'):
                image_files.append(f)
        if not image_files:
            raise ValueError(f'No image files in {dir_name}')

        return Viaduc.callback('loadDir', {'dir': dir_name, 'imageFiles': image_files})
Exemplo n.º 4
0
 def do_something(self, vals):
     v = self.map_vals(vals)
     if not v['_email']:
         raise ValueError('Empty email')
     if not v['_password']:
         raise ValueError('Empty password')
     print(v)
     return Viaduc.done('Operation completed')
Exemplo n.º 5
0
    def save_file_dialog(self, vals):
        v = self.map_vals(vals)

        file_name = self.window.create_file_dialog(webview.SAVE_DIALOG, directory=os.path.dirname(v['_fileName']),
                                                   save_filename=os.path.basename(v['_fileName']))
        if file_name:
            with open(file_name, "w+") as f:
                f.write(v['_editor'])

        return Viaduc.done()
Exemplo n.º 6
0
 def convert(self, vals):
     v = self.map_vals(vals)
     if not v['_fahrenheit']:
         raise ValueError('Enter a temperature')
     return Viaduc.callback('showCelsius', {'celsius': fahrenheit_to_celsius(v['_fahrenheit'])})
Exemplo n.º 7
0
#! /usr/bin/env python3
import sys

from viaduc import Viaduc


def fahrenheit_to_celsius(fahrenheit):
    return round((5 / 9) * (float(fahrenheit) - 32), 2)


class Api(Viaduc.Api):
    def convert(self, vals):
        v = self.map_vals(vals)
        if not v['_fahrenheit']:
            raise ValueError('Enter a temperature')
        return Viaduc.callback('showCelsius', {'celsius': fahrenheit_to_celsius(v['_fahrenheit'])})


class Presentation(Viaduc.Presentation):
    width = 320
    height = 468
    title = 'temperature converter'
    html = '''
    <!-- copy file here -->
    '''
    file = "temperature-converter.html"


if __name__ == '__main__':
    Viaduc(api=Api(), presentation=Presentation(), args=sys.argv + ['--frameless'])
Exemplo n.º 8
0
                doAlert('alert-danger', 'error', e);
            });
    }

    function deviceClick(e) {
        pywebview.api.click(e.pageX * 4, e.pageY * 4)
            .then(obtainScreenshot)
            .catch(e => {
                doAlert('alert-danger', 'error', e);
            });
    }
</script>

</body>
</html>   
    '''


class Presentation(Viaduc.Presentation):
    html = HTML
    title = 'android device viewer'
    frameless = True
    window_background_color = '#000'
    display_real_size = culebratester.get_display_real_size()
    width = display_real_size.x / 4
    height = display_real_size.y / 4


if __name__ == '__main__':
    Viaduc(api=Api(), presentation=Presentation(), args=sys.argv + ['--debug'])
Exemplo n.º 9
0
from viaduc import Viaduc


class Api(Viaduc.Api):
    def do_something(self, vals):
        print('do_something: {}'.format(vals))
        v = self.map_vals(vals)
        if not v['inputEmail4']:
            raise ValueError('Empty email')
        if not v['inputPassword4']:
            raise ValueError('Empty password')
        if v['inputCheck']:
            return Viaduc.callback('callback',
                                   {'message': 'This is a sample callback'})
        else:
            return Viaduc.done('Operation completed')


class Presentation(Viaduc.Presentation):
    width = 800
    height = 520
    title = 'complex form example'
    # NOTE: Usually we want html to be a string so everything is contained in one file, however in this case we are
    # reading it from a file as an example of how it can be done.
    file = "complexform-mui.html"


if __name__ == '__main__':
    Viaduc(api=Api(), presentation=Presentation(), args=sys.argv)
Exemplo n.º 10
0
    <div class="jumbotron">
        <h1>{{title}}</h1>
        <p class="lead">Welcome to <em>Viaduc</em>, the simplest way of creating a GUI in python.</p>
    </div>
    
    <div class="container-fluid">
        <div class="row">
        <div class="col">
            <button type="button" class="btn btn-success" style="min-width: 100%"
                onclick="processResponse(Promise.resolve({action:'SUCCESS', message:'Hello'}));">Success</button>
        </div>
        <div class="col">
            <button type="button" class="btn btn-danger" style="min-width: 100%"
                onclick="processResponse(Promise.resolve({action:'ERROR', message:'Danger'}));">Error</button>
        </div>
        <div class="col">
            <button type="button" class="btn btn-warning" style="min-width: 100%"
                onclick="processResponse(Promise.resolve({action:'WARNING', message:'Warning'}));">Warning</button>
        </div>
        </div>
    </div>
    {{bootstrap_js}}

  </body>  
 </html>
'''


if __name__ == '__main__':
    Viaduc(presentation=Presentation(), args=['', '--debug'])
Exemplo n.º 11
0
 def load_image(self, image):
     mime, encoding = mimetypes.guess_type(image)
     with open(image, 'rb') as i:
         data = base64.b64encode(i.read()).decode("ascii")
         src = f'data:{mime};base64,{data}'
         return Viaduc.callback('showImage', {'image': image, 'src': src})
Exemplo n.º 12
0
 def get_vals(self, vals):
     v = self.map_vals(vals)
     return Viaduc.done(f'vals: {v}')
Exemplo n.º 13
0
        
        <div class="row mb-3">
            <div class="col-12">
                <label for="_cars">Select multiple options</label>
                <select name="cars" id="_cars" class="form-control custom-select" multiple>
                    <option value="volvo">Volvo</option>
                    <option value="saab">Saab</option>
                    <option value="opel">Opel</option>
                    <option value="audi">Audi</option>
                </select>
            </div>
        </div>        
                
        <button type="button" class="btn btn-primary" onclick="doGetVals()">Get vals</button>
    </div>
    
    <script>
        function doGetVals() {
            processResponse(pywebview.api.get_vals(getVals()));
        }
    </script>
    {{bootstrap_js}}

  </body>  
 </html>
'''


if __name__ == '__main__':
    Viaduc(api=Api(), presentation=Presentation(), args=['', '--debug'])
Exemplo n.º 14
0
from viaduc import Viaduc


class Presentation(Viaduc.Presentation):
    title = 'hello world'
    html = '''
<!DOCTYPE html>
<html lang="en">
  <head>
    {{bootstrap_meta}}

    {{bootstrap_css}}

    <title>{{title}}</title>
  </head>
  <body>
    <div class="jumbotron">
        <h1>{{title}}</h1>
        <p class="lead">Welcome to <em>Viaduc</em>, the simplest way of creating a GUI in python.</p>
    </div>
    
    {{bootstrap_js}}

  </body>  
 </html>
'''


if __name__ == '__main__':
    Viaduc(presentation=Presentation())
Exemplo n.º 15
0
#! /usr/bin/env python3

from viaduc import Viaduc

if __name__ == '__main__':
    Viaduc()