예제 #1
0
from browser import window
import random
from controller import Controller
from models import A
from setup import init, setup_eachs

init()

jq = window.jQuery.noConflict(True)

key = [('x', 'desc')]
filter = ('my_filter', {'x': 5, 'y': 10})
Controller('MyController', key, filter)
Controller('MyController2', key, filter, first=True)

setup_eachs()

button_send = jq('#button')
sent_initial_data = False


def send_data():
    global sent_initial_data
    if not sent_initial_data:
        Controller.subscribe_all()
        sent_initial_data = True
    try:
        if random.random() < 0.5:
            obj = A(None, x=random.randint(0, 10))
        else:
            obj = random.choice(list(A.objects.values()))
예제 #2
0
#!python
import re
import sys
import os
import getpass
import setup

if sys.version_info.major!=3:
    sys.exit("Please use python3!")
setup.init()

from samplequery.models import Record
from django.contrib.auth import authenticate
  #
username = input("Username:"******"This will delete all records in the database!")
        act = 'y' if input("Continue?[y/N]").lower()=='y' else 'n'
        if act == 'y':
            allRecords = Record.objects.all().delete()
            sys.exit("Action completed!")
        else:
            sys.exit("Action aborted!")
    else:
        sys.exit("Permission not allowed!")
else:
    sys.exit("Username/Password not match!")
예제 #3
0
    def __init__(self, parent):
        '''
        Inputs
        ------
            parent : tk.Tk instance
                root propagated throughout the different Frames and Canvas
        '''

        self.parent = parent
        self.color = 'white smoke'
        self.parent.config(cursor='arrow', bg=self.color)

        # Initial program setup
        self.settings, errCode = setup.init()
        self.font = self.settings['font']
        self.loadPath = self.settings['path']

        # Check that given paths exist
        if not opath.exists(self.loadPath) or not opath.exists(
                self.settings['iconPath']):
            raise IOError(
                'One of the path in the yaml configuration file does not exist.'
            )

        icons = iconload(self.settings['iconPath'])
        projects = self.settings['projects']

        if errCode != 0:
            print(
                'YAML configuration could not be read correctly. A new one with default values has been created instead.'
            )

        # Miscellaneous parameters
        self.cpuCount = multiprocessing.cpu_count()

        ######################################################
        #               Check for old projects               #
        ######################################################

        # If project file still exists, add it to the list
        self.projects = []
        for proj in projects:
            if opath.isfile(proj):
                self.projects.append(proj)

        # It at least one project exist, show validation window at startup
        if len(self.projects) > 0:

            # Validation window
            window = Validate(
                self,
                self,
                parent,
                mainText=
                'You have old projects saved in the setting file. Select the files you want to open.',
                listNames=self.projects,
                textProperties={
                    'highlightthickness': 0,
                    'bd': 0,
                    'bg': self.color,
                    'font': (self.font, 10)
                },
                buttonsProperties={
                    'bg': 'floral white',
                    'activebackground': 'linen'
                },
                winProperties={'bg': self.color},
                acceptFunction=lambda *args, **kwargs: self.loadProjects(
                    *args, **kwargs))

            self.parent.lift()

            # For MAC it seems we must set False and then True
            window.overrideredirect(False)
            window.overrideredirect(True)

            window.focus_force()
            window.grab_set()
            window.geometry('+%d+%d' % (self.parent.winfo_screenwidth() // 2 -
                                        2 * window.winfo_reqwidth(),
                                        self.parent.winfo_screenheight() // 2 -
                                        window.winfo_reqheight()))
            window.state('normal')

        ###########################################################
        #                    Custom ttk styles                    #
        ###########################################################

        # Custom style for Notebook
        self.style = ttk.Style()
        self.style.configure('main.TNotebook', background=self.color)

        self.style.configure('main.TNotebook.Tab',
                             padding=[5, 2],
                             font=('fixed', 10))
        self.style.map('main.TNotebook.Tab',
                       background=[("selected", 'lavender'),
                                   ('!selected', 'white smoke')],
                       foreground=[('selected', 'RoyalBlue2')])

        #############################################################
        #               Load icons into Image objects               #
        #############################################################
        self.iconDict = {}
        self.iconDict['FOLDER'] = tk.BitmapImage(data=icons['FOLDER'],
                                                 maskdata=icons['FOLDER_MASK'],
                                                 background='goldenrod')
        self.iconDict['FOLDER_256'] = tk.BitmapImage(
            data=icons['FOLDER_256'],
            maskdata=icons['FOLDER_256_MASK'],
            background='goldenrod')
        self.iconDict['FOLDER_17'] = tk.BitmapImage(
            data=icons['FOLDER_17'],
            maskdata=icons['FOLDER_17_MASK'],
            background='goldenrod')
        self.iconDict['DELETE'] = tk.BitmapImage(data=icons['DELETE'],
                                                 maskdata=icons['DELETE_MASK'],
                                                 background='light cyan',
                                                 foreground='black')
        self.iconDict['DUPPLICATE'] = tk.BitmapImage(
            data=icons['DUPPLICATE'],
            maskdata=icons['DUPPLICATE_MASK'],
            background='black',
            foreground='black')
        self.iconDict['CONFIG'] = tk.BitmapImage(data=icons['CONFIG'],
                                                 maskdata=icons['CONFIG_MASK'],
                                                 background=self.color,
                                                 foreground='black')
        self.iconDict['RUN'] = tk.BitmapImage(data=icons['RUN'],
                                              maskdata=icons['RUN_MASK'],
                                              background='SpringGreen4',
                                              foreground='white')
        self.iconDict['CHECK'] = tk.BitmapImage(data=icons['CHECK'],
                                                maskdata=icons['CHECK_MASK'],
                                                background=self.color,
                                                foreground='firebrick1')

        #############################################
        #                 Buttons                   #
        #############################################

        # Top frame with buttons and sliders
        self.topframe = tk.Frame(self.parent,
                                 bg=self.color,
                                 bd=0,
                                 relief=tk.GROOVE)

        self.confButton = tk.Button(self.topframe,
                                    image=self.iconDict['CONFIG'],
                                    bd=0,
                                    bg=self.color,
                                    highlightbackground=self.color,
                                    relief=tk.FLAT,
                                    activebackground=self.color)

        self.loadButton = tk.Button(self.topframe,
                                    image=self.iconDict['FOLDER'],
                                    bd=0,
                                    bg=self.color,
                                    highlightbackground=self.color,
                                    relief=tk.FLAT,
                                    activebackground='black')

        self.delButton = tk.Button(self.topframe,
                                   image=self.iconDict['DELETE'],
                                   bd=0,
                                   bg=self.color,
                                   highlightbackground=self.color,
                                   relief=tk.FLAT,
                                   activebackground=self.color)

        self.duppButton = tk.Button(self.topframe,
                                    image=self.iconDict['DUPPLICATE'],
                                    bd=0,
                                    bg=self.color,
                                    highlightbackground=self.color,
                                    relief=tk.FLAT,
                                    activebackground=self.color)

        ##############################################
        #                   Scales                   #
        ##############################################

        self.scaleframe = tk.Frame(self.topframe,
                                   bg=self.color,
                                   bd=0,
                                   highlightthickness=0)
        self.latframe = tk.Frame(self.scaleframe,
                                 bg=self.color,
                                 bd=0,
                                 highlightthickness=0)
        self.longframe = tk.Frame(self.scaleframe,
                                  bg=self.color,
                                  bd=0,
                                  highlightthickness=0)

        self.latLabel = tk.Label(self.latframe, text='Latitude', bg=self.color)
        self.longLabel = tk.Label(self.longframe,
                                  text='Longitude',
                                  bg=self.color)

        self.latScale = tk.Scale(
            self.latframe,
            length=200,
            width=12,
            orient='horizontal',
            from_=-90,
            to=90,
            cursor='hand1',
            showvalue=False,
            bg=self.color,
            bd=1,
            highlightthickness=1,
            highlightbackground=self.color,
            troughcolor='lavender',
            activebackground='black',
            font=('fixed', 11),
            command=lambda value: self.updateScale('latitude', value))

        self.longScale = tk.Scale(
            self.longframe,
            length=200,
            width=12,
            orient='horizontal',
            from_=-180,
            to=180,
            cursor='hand1',
            showvalue=False,
            bg=self.color,
            bd=1,
            highlightthickness=1,
            highlightbackground=self.color,
            troughcolor='lavender',
            activebackground='black',
            font=('fixed', 11),
            command=lambda value: self.updateScale('longitude', value))

        ###########################################################
        #                     Bottom notebook                     #
        ###########################################################

        self.notebook = ttk.Notebook(self.parent, style='main.TNotebook')

        # Keep track of notebook tabs
        self.tabs = {}
        self.addTab()

        #######################################################################
        #                               Bindings                              #
        #######################################################################

        self.parent.bind(
            '<Control-o>',
            lambda *args, **kwargs: self.tabs[self.notebook.select()].askLoad(
            ))
        self.parent.bind(
            '<Control-p>',
            lambda *args, **kwargs: self.showConfigWindow(*args, **kwargs))

        self.confButton.bind(
            '<Enter>', lambda *args, **kwargs: self.iconDict['CONFIG'].
            configure(foreground='RoyalBlue2'))
        self.confButton.bind(
            '<Leave>', lambda *args, **kwargs: self.iconDict['CONFIG'].
            configure(foreground='black'))
        self.confButton.bind(
            '<Button-1>',
            lambda *args, **kwargs: self.showConfigWindow(*args, **kwargs))

        self.loadButton.bind(
            '<Enter>', lambda *args, **kwargs: self.tabs[self.notebook.select(
            )].loadButton.configure(bg='black')
            if not self.tabs[self.notebook.select()].loaded else None)
        self.loadButton.bind(
            '<Leave>', lambda *args, **kwargs: self.tabs[self.notebook.select(
            )].loadButton.configure(bg='lavender')
            if not self.tabs[self.notebook.select()].loaded else None)
        self.loadButton.bind(
            '<Button-1>',
            lambda *args, **kwargs: self.tabs[self.notebook.select()].askLoad(
            ))

        self.delButton.bind(
            '<Enter>', lambda *args, **kwargs: self.iconDict['DELETE'].
            configure(foreground='red', background=self.color))
        self.delButton.bind(
            '<Leave>', lambda *args, **kwargs: self.iconDict['DELETE'].
            configure(foreground='black', background='light cyan'))
        self.delButton.bind(
            '<Button-1>', lambda *args, **kwargs: self.delTab(*args, **kwargs))

        self.plotWindow = None
        self.duppButton.bind(
            '<Enter>', lambda *args, **kwargs: self.iconDict['DUPPLICATE'].
            configure(background='RoyalBlue2'))
        self.duppButton.bind(
            '<Leave>', lambda *args, **kwargs: self.iconDict['DUPPLICATE'].
            configure(background='black'))
        self.duppButton.bind('<Button-1>',
                             lambda *args, **kwargs: self.showPlotWindow())

        self.latScale.bind(
            '<Enter>', lambda *args, **kwargs: self.latScale.configure(
                highlightbackground='RoyalBlue2'))
        self.latScale.bind(
            '<Leave>', lambda *args, **kwargs: self.latScale.configure(
                highlightbackground=self.color))
        self.longScale.bind(
            '<Enter>', lambda *args, **kwargs: self.longScale.configure(
                highlightbackground='RoyalBlue2'))
        self.longScale.bind(
            '<Leave>', lambda *args, **kwargs: self.longScale.configure(
                highlightbackground=self.color))

        self.notebook.bind(
            '<<NotebookTabChanged>>',
            lambda *args, **kwargs: self.tabCghanged(*args, **kwargs))

        ##########################################################
        #                     Drawing frames                     #
        ##########################################################

        self.confButton.pack(side=tk.LEFT, pady=10)
        self.loadButton.pack(side=tk.LEFT, pady=10)
        self.delButton.pack(side=tk.LEFT, pady=10)

        self.latLabel.grid(row=0, stick=tk.W)
        self.longLabel.grid(row=0, stick=tk.W)
        self.latScale.grid(row=1)
        self.longScale.grid(row=1)

        self.latframe.pack(side=tk.LEFT, padx=10)
        self.longframe.pack(side=tk.LEFT, padx=10)
        self.scaleframe.pack(side=tk.LEFT, padx=10, fill='x', expand=True)

        self.duppButton.pack(side=tk.RIGHT)

        self.topframe.pack(fill='x', padx=10)
        self.notebook.pack(fill='both', expand=True)
예제 #4
0
파일: main.py 프로젝트: asymy/explorathon
def run():
    setup.init()