示例#1
0
 def __init__(self, mapper):
     """ create the interface """
     self.mapper = mapper
     self.dialog = Window()
     self.dialog.setTitle('Mapper 1.0')
     # notebook
     tabs = ['Routine', 'Accumulate']
     pages = self.dialog.addNotebook('notebook', tabs)
     # routine page
     self.routine = pages[0]
     today = datetime.date.today()
     self.dt = today.strftime('%d,%m,%Y,%B').split(',')
     self.routine.addEntry('title', 'Map Title', width=60)
     self.routine.set(
         'title',
         '24 Hour Precipitation Ending 7 AM {0[3]} {0[0]}, {0[2]}'.format(
             self.dt))
     self.routine.plot('title', row=0)
     self.routine.addEntry('outfile', 'Output Filename', width=40)
     self.routine.set('outfile',
                      'pcpn{0[1]}{0[0]}{0[2]}.png'.format(self.dt))
     self.routine.plot('outfile', row=1)
     jobs = ['Make KMLs', 'Make Maps']
     self.routine.addCheck('jobs', 'Jobs', jobs)
     self.routine.set('jobs', jobs[:2])
     self.routine.plot('jobs', row=2)
     # accum pcpn page
     self.accum = pages[1]
     parms = [[2, 1, 12], [2, 1, 31], [4, 2000, 2100]]
     self.accum.addSpin('endDate',
                        parms,
                        '/',
                        'Ending Date',
                        command=self.updateAccum)
     self.accum.set('endDate', [today.month, today.day, today.year])
     self.accum.plot('endDate', row=0)
     self.accum.addSpin('daysBack', [[2, 1, 45]],
                        '',
                        'Days back',
                        command=self.updateAccum)
     self.accum.set('daysBack', [2])
     self.accum.plot('daysBack', row=1)
     self.accum.addEntry('title', 'Title', width=60)
     self.accum.plot('title', row=2)
     self.accum.addEntry('outfile', 'Output Filename', width=40)
     self.accum.plot('outfile', row=3)
     self.updateAccum()
     # dialog
     self.dialog.addText('messages', 70, 15, 'Messages')
     self.dialog.plot('messages', row=1)
     self.dialog.addButton('commands', space=20)
     self.dialog.changeWidget('commands', 0, command=self.go)
     self.dialog.changeWidget('commands', 1, text='Exit')
     self.dialog.plot('commands', row=2)
     self.dialog.plot('notebook', row=0)
     self.dialog.set('notebook', 0)
示例#2
0
 def __init__(self):
     """ create the GUI """
     categories = ['Trees', 'Birds', 'Flowers']
     self.gui = Window()
     self.gui.setTitle('Dynamic Widget Demo')
     self.gui.addRadio('category', 'Item Types', categories)
     self.gui.addCombo('items', 'Items', None, postcommand=self.update)
     self.gui.addButton('command')
     self.gui.set('category', 'Trees')
     self.gui.set('items', '...')
     self.gui.plot('category', row=0)
     self.gui.plot('items', row=1, pady=20)
     self.gui.plot('command', row=2)
示例#3
0
    def __init__(self):
        # read configuration file
        self.config = configparser.ConfigParser()
        self.config.read('config_parameters.ini')

        # write gui
        self.gui = Window()
        self.gui.setTitle('Export ScanInfo to Gsheet')
        self.gui.addChooseDir('dir_date',
                              'Scan Date Folder',
                              width=40,
                              initialdir='')
        self.gui.addEntry('para_list', 'Parameters to list', width=50)
        self.gui.addCombo('gdir',
                          'Save location in google drive',
                          None,
                          postcommand=self.gdir_update,
                          width=47)
        self.gui.set('para_list', self.config['DEFAULT']['parameters'])
        self.gui.addText('status', width=40, height=5, prompt='Status:')
        self.gui.addCheck('auto_update', '', ['Turn On Auto Update'])
        self.gui.addButton('commands')
        self.gui.changeWidget('commands',
                              0,
                              text='Export',
                              command=self.export)

        self.gui.plot('dir_date', row=0)
        self.gui.plot('para_list', row=1, pady=5)
        self.gui.plot('gdir', row=2, pady=5)
        self.gui.plot('status', row=3, pady=10)
        self.gui.plot('auto_update', row=4)
        self.gui.plot('commands', row=5, pady=10)

        self.exported = False
        self.proj = None  # bella project name
        self.g_name = None  # google drive folder name
        self.g_ID = None  # google drive folder id

        self.autoupdateOn = False
        self.update()
示例#4
0
 def __init__(self):
     """ create the GUI """
     counties = ['Clark','Crawford','Dubois','Floyd','Harrison','Jefferson',
         'Orange','Perry','Scott','Washigton']
     damage = ['EF0','EF1','EF2','EF3','EF4','EF5']
     dateParms = [[2,1,12],[2,1,12],[4,1900,2100]]
     initDate = [1,1,1980]
     cols = [['Date', 100],['County', 100],['Damage', 100]]
     self.gui = Window()
     self.gui.setTitle('Tornado Path Generator')
     self.gui.addSpin('tdate', dateParms, '/', 'Date of Tornado')
     self.gui.set('tdate', initDate)
     self.gui.addCombo('county', 'Affected County', counties)
     self.gui.addRadio('level', 'Maximum EF Damage', damage)
     self.gui.addCollector('paths', 10, cols, ['tdate','county','level'], 'Included Tornadoes')
     self.gui.addButton('command')
     self.gui.plot('tdate', row=0, pady=5)
     self.gui.plot('county', row=1, pady=5)
     self.gui.plot('level', row=2, pady=5)
     self.gui.plot('paths', row=3, pady=5)
     self.gui.plot('command', row=4, pady=10)
示例#5
0
class Gui(object):
    """ Gui for stopwatch """
    def __init__(self, stopwatch):
        """ init stopwatch gui
            stopwatch:Stopwatch -> """
        self.win = Window()  # make window an attribute
        self.stopw = stopwatch  # make stopwatch an attribute
        self.makeGui()  # create gui

    def makeGui(self):
        """ create the Gui """
        self.win.setTitle('Stopwatch v1.0')
        self.win.addStyle(
            'r.TLabel',
            foreground='red',  # create the styles
            font=('Helvetica', '30'))
        self.win.addStyle('g.TLabel',
                          foreground='green',
                          font=('Helvetica', '30'))
        self.win.addLabel('elapsed', 'Elapsed Time', style='r.TLabel')
        buttons = [('Start', self.startstop), ('Reset', self.reset),
                   ('Exit', self.win.cancel)]  # label and assign buttons
        self.win.addButton('buttons', cmd=buttons)  # create buttons
        self.win.plot('elapsed', row=0)
        self.win.plot('buttons', row=1, pady=10)
        self.update()  # update display

    def startstop(self):
        """ start or stop the stopwatch """
        if self.stopw.running:
            self.stopw.stop()
            self.win.changeWidget('buttons', 0, text='Start')  # relabel button
            self.win.changeWidget('elapsed', style='r.TLabel')  # color display
            self.win.changeState('buttons', 1, ['!disabled'])  # enable Reset
        else:
            self.stopw.start()
            self.win.changeWidget('buttons', 0, text='Stop')  # relabel button
            self.win.changeWidget('elapsed', style='g.TLabel')  # color display
            self.win.changeState('buttons', 1, ['disabled'])  # disable Reset

    def reset(self):
        """ reset stopwatch """
        self.stopw.reset()  # reset it

    def update(self):
        """ update display """
        etime = self.stopw.check()  # get elapsed time
        template = '{:02}:{:02}:{:02}.{:02}'  # 2 digits leading zero
        stime = template.format(*etime)  # format as hh:mm:ss.cc
        self.win.set('elapsed', stime)  # update display
        self.win.master.after(10, self.update)  # call again after .01 sec
示例#6
0
from tkintertoy import Window


def update(gui):  # callback function
    """ set the alist attribute by what is in the radio button box """
    lookup = {
        'Trees': ['Oak', 'Maple', 'Beech'],
        'Birds': ['Cardinal', 'Robin', 'Sparrow'],
        'Flowers': ['Rose', 'Petunia', 'Daylily']
    }
    select = gui.get('category')
    gui.set('items', lookup[select], allValues=True)


categories = ['Trees', 'Birds', 'Flowers']
gui = Window()
gui.setTitle('Dynamic Widget Demo')
gui.addRadio('category', 'Item Types', categories)
gui.addCombo('items', 'Items', None, postcommand=(lambda: update(gui)))
gui.addButton('command')
gui.set('category', 'Trees')
gui.set('items', '...')
gui.plot('category', row=0)
gui.plot('items', row=1, pady=20)
gui.plot('command', row=2)
gui.waitforUser()
if gui.content:
    selected_cat = gui.get('category')
    item = gui.get('items')
    # more code would go here...
    gui.cancel()
示例#7
0
 def __init__(self):
     self.gui = Window()
     self.gui.setTitle('Tkintertoy Gallery')
     self.makeGui()
示例#8
0
class Gui(object):
    def __init__(self):
        self.gui = Window()
        self.gui.setTitle('Tkintertoy Gallery')
        self.makeGui()

    def makeGui(self):
        # a simple menu
        mymenu = self.gui.addMenu('ttmainmenu',
                                  self.gui.master)  # create a main menu
        fmenu = [
            ['command', {
                'label': 'Open...',
                'command': self.popOpen
            }],  # create a file menu
            ['command', {
                'label': 'Save As...',
                'command': self.popSaveAs
            }],
            [
                'command', {
                    'label': 'Choose Directory...',
                    'command': self.popChooseDir
                }
            ],
            ['command', {
                'label': 'Exit',
                'command': self.gui.cancel
            }]
        ]
        mmenu = [
            ['command', {
                'label': 'About',
                'command': self.popAbout
            }],  # create a misc menu
            ['command', {
                'label': 'ChooseColor',
                'command': self.popColor
            }]
        ]
        self.gui.addMenu('ttfmenu', mymenu, fmenu)  # create sub menus
        self.gui.addMenu('ttmmenu', mymenu, mmenu)
        mymenu.add('cascade', label='File',
                   menu=self.gui.get('ttfmenu'))  # add them to the main menu
        mymenu.add('cascade', label='Misc', menu=self.gui.get('ttmmenu'))
        self.gui.master['menu'] = mymenu  # connect the main menu to the window
        # Notebook
        tabs = ['Simple', 'Dialog', 'Multi', 'Other']  # label the tabs
        self.pages = self.gui.addNotebook('ttnotebook',
                                          tabs)  # create the notebook
        # Text Box
        self.gui.addText('ttext', 60, 10, 'Text Box')  # create text area
        self.gui.plot('ttext', row=1)
        # Progress Bar
        self.gui.addProgress('ttprogress', 100,
                             'Progress Bar')  # create progrees bar
        self.gui.plot('ttprogress', row=2)
        # Command Buttons
        cmd = [['Collect', self.collect],
               ['Exit', self.gui.cancel]]  # create two buttons
        self.gui.addButton('ttbutton', '', cmd)
        self.gui.plot('ttbutton', row=3)
        # Notebook Pages
        self.makeSimple()
        self.makeDialog()
        self.makeMulti()
        self.makeOther()
        self.gui.plot('ttnotebook', row=0, column=0)

    def makeSimple(self):
        self.simplePage = self.pages[0]
        # Label
        self.simplePage.addLabel('ttlabel', '', 'bold')  # create a label
        self.simplePage.set('ttlabel',
                            'This is a BOLD label')  # fill in the value
        self.simplePage.plot('ttlabel', row=0)
        # Line
        self.simplePage.addLine('ttline')  # create a horizontal line
        self.simplePage.plot('ttline', row=1)
        # Message
        self.simplePage.addMessage('ttmessage', 'Message')  # create a message
        self.simplePage.set('ttmessage', 'Useful for multi-line messages')
        self.simplePage.plot('ttmessage', row=2)
        # Entry
        self.simplePage.addStyle('g.TEntry',
                                 foreground='green')  # create a green entry
        self.simplePage.addEntry('ttentry', 'Entry', style='g.TEntry')
        self.simplePage.set('ttentry', 'Default Entry')  # fill in the value
        self.simplePage.plot('ttentry', row=3)
        # Option
        alist = ['Option1', 'Option2', 'Option3']
        self.simplePage.addOption('ttoption', 'Option List',
                                  alist)  # create an option list
        self.simplePage.set('ttoption', 'Option1')
        self.simplePage.plot('ttoption', row=5)
        # Combobox and Style
        acombo = ['ComboOption1', 'ComboOption2', 'ComboOption3']
        self.simplePage.addCombo('ttcombo', 'Combo Box',
                                 acombo)  # create combobox
        self.simplePage.plot('ttcombo', row=6)
        # Checkboxes
        achecks = ['CheckOption1', 'CheckOption2', 'CheckOption3']
        self.simplePage.addCheck('ttchecks', 'Check Box',
                                 achecks)  # create 3 checkboxes
        self.simplePage.plot('ttchecks', row=7)
        self.simplePage.changeState('ttchecks', 1,
                                    ['disabled'])  # disable CheckOption2
        # Radio Buttons
        aradio = ['RadioOption1', 'RadioOption2', 'RadioOption3']
        self.simplePage.addRadio(
            'ttradio', 'RadioButton Box', aradio
        )  # create 3 radiobuttons      self.simplePage.plot('ttradio', row=8)
        # Scale
        self.simplePage.addScale('ttscale', [1, 10], 'Scale',
                                 width=2)  # create a scale
        self.simplePage.plot('ttscale', row=9)
        # Spinners
        adate = [[2, 1, 12], [2, 1, 31], [4, 2000, 2099]]
        self.simplePage.addSpin('ttspin', adate, '/',
                                'Date Box')  # create a date entry box
        self.simplePage.set('ttspin', [11, 17, 2017])
        self.simplePage.plot('ttspin', row=10)

    def makeDialog(self):
        self.dialogPage = self.pages[1]
        # Open
        self.dialogPage.addOpen('ttopen', 'Open', width=40)  # open dialog
        self.dialogPage.plot('ttopen', row=0)
        # SaveAs
        self.dialogPage.addSaveAs('ttsaveas', 'Save As',
                                  width=40)  # save as dialog
        self.dialogPage.plot('ttsaveas', row=1)
        # ChooseDir
        self.dialogPage.addChooseDir('ttchoosedir', 'Choose Dir',
                                     width=40)  # choose dir dialog
        self.dialogPage.plot('ttchoosedir', row=2)

    def popOpen(self):
        # open dialog
        self.gui.set('ttext', self.gui.popOpen(title='Open a File') + '\n')

    def popSaveAs(self):
        # save as dialog
        self.gui.set('ttext', self.gui.popSaveAs(title='Save a File') + '\n')

    def popChooseDir(self):
        # choose dir dialog
        self.gui.set('ttext',
                     self.gui.popChooseDir(title='Select a Directory') + '\n')

    def popColor(self):
        # Color Chooser
        self.gui.set(
            'ttext',
            str(self.gui.popColorChooser(title='Select a Color')) + '\n')

    def popAbout(self):
        # Pop Up Message Box
        self.gui.popMessage('Tkintertoy Gallery')

    def makeMulti(self):
        self.multiPage = self.pages[2]
        # List
        alist = ['ListOption1', 'ListOption2', 'ListOption3']
        self.multiPage.addList('ttlist', 'List', alist,
                               height=4)  # create list
        self.multiPage.plot('ttlist', row=0)
        # Ledger
        cols = [['column1', 100], ['column2', 80], ['column3', 80]]
        self.multiPage.addLedger('ttledger', 4, cols,
                                 'Ledger')  # create ledger
        self.multiPage.set('ttledger', [['header1', 'item1-1', 'item1-2']])
        self.multiPage.set('ttledger', [['header2', 'item2-1', 'item2-2']])
        self.multiPage.set('ttledger', [['header3', 'tiem3-1', 'item2-3']])
        self.multiPage.plot('ttledger', row=1)
        # Collector Frame
        self.subwin = self.multiPage.addFrame('ttframe', '', relief='groove')
        # -Combobox
        acombo = ['ComboOption2-1', 'ComboOption2-2', 'ComboOption2-3']
        self.subwin.addCombo('ttcombo2', 'Combo Box 2', acombo)
        self.subwin.plot('ttcombo2', row=0)
        # -Radio Button
        aradio = ['Radio2-1', 'Radio2-2', 'Radio2-3']
        self.subwin.addRadio('ttradio2', 'RadioButton Box 2', aradio)
        self.subwin.plot('ttradio2', row=1)
        # -Collector
        cols = [['Combo', 100], ['Radio', 100]]
        self.subwin.addCollector('ttcollector', 4, cols,
                                 ['ttcombo2', 'ttradio2'], 'Collector')
        self.subwin.plot('ttcollector', row=2)
        self.multiPage.plot('ttframe', row=2)

    def makeOther(self):
        self.otherPage = self.pages[3]
        # Canvas
        self.otherPage.addCanvas('ttcanvas', 300, 100,
                                 'Canvas')  # create canvas
        self.otherPage.get('ttcanvas').create_oval(10,
                                                   10,
                                                   290,
                                                   90,
                                                   fill='green')
        self.otherPage.plot('ttcanvas', row=0)
        # Multipane
        paneTitles = ['Pane 1', 'Pane 2', 'Pane 3']
        panes = self.otherPage.addPanes('ttpane',
                                        paneTitles,
                                        orient='horizontal')
        for i in range(3):
            # -Label
            tag = 'ttlabel' + str(i)
            panes[i].addLabel(tag)
            panes[i].set(tag, 'Inner label {}'.format(i + 1))
            panes[i].plot(tag)
        self.otherPage.plot('ttpane', row=1)

    def collect(self):
        # show contents of all widgets
        result = 'Contents of widgets\n  Simple Page:\n    '
        result += self.simplePage.get('ttlabel') + '\n    '
        result += self.simplePage.get('ttmessage') + '\n    '
        result += self.simplePage.get('ttentry') + '\n    '
        result += self.simplePage.get('ttoption') + '\n    '
        result += self.simplePage.get('ttcombo') + '\n    '
        result += str(self.simplePage.get('ttchecks')) + '\n    '
        result += str(self.simplePage.get('ttradio')) + '\n    '
        result += str(self.simplePage.get('ttscale')) + '\n    '
        result += str(self.simplePage.get('ttspin')) + '\n    '
        self.gui.set('ttprogress', 33)
        self.gui.set('ttext', result, allValues=True)
        self.gui.master.after(500)  # wait .5 sec
        result = '  File Page:\n    '
        result += self.dialogPage.get('ttopen') + '\n    '
        result += self.dialogPage.get('ttsaveas') + '\n    '
        result += self.dialogPage.get('ttchoosedir') + '\n    '
        self.gui.set('ttprogress', 66)
        self.gui.set('ttext', result)
        self.gui.master.after(500)  # wait .5 sec
        result = '  Multi Page:\n    '
        result += str(self.multiPage.get('ttlist')) + '\n    '
        result += str(self.multiPage.get('ttledger')) + '\n    '
        result += str(self.subwin.get('ttcollector',
                                      allValues=True)) + '\n    '
        # Progress Bar
        self.gui.set('ttprogress', 100)
        self.gui.set('ttext', result)
        self.gui.master.after(1000)  # wait 1 sec
        self.gui.set('ttprogress', 0)
示例#9
0
from tkintertoy import Window
gui = Window()
gui.setTitle('My First Tkintertoy GUI!')
gui.addEntry('name', 'Type in your name')
gui.addLabel('welcome', 'Welcome message')
gui.addButton('commands')
gui.plot('name', row=0)
gui.plot('welcome', row=1)
gui.plot('commands', row=2, pady=10)
while True:
    gui.waitforUser()
    if gui.content:
        gui.set('welcome', 'Welcome ' + gui.get('name'))
    else:
        break
示例#10
0
""" Some initial comments here at the top
of the screen. This just shows how we can
comment multiline"""

from tkintertoy import Window
bob = ''
bob2 = ''
bob3 = ''
categories = ['Car', 'Bike', 'Bus']
gui = Window()
gui.setTitle('My First Tkintertoy GUI!')
gui.addEntry('name', 'Type in your name')
gui.addLabel('welcome', 'Welcome message *** TEST ***')
gui.addEntry('Age', 'Type in your age')
gui.addLabel('old', 'You are of age')
gui.addButton('commands')
gui.addRadio('')
gui.addRadio('category', 'Item Types', categories)
gui.plot('name', row=0)
gui.plot('Age', row=1)
gui.plot('welcome', row=2)
gui.plot('old', row=3)
gui.plot('category', row=4)
gui.plot('commands', row=5, pady=10)
while True:
    gui.waitforUser()
    if gui.content:
        gui.set('welcome', 'Welcome ' + gui.get('name'))
        bob = gui.get('name')
        gui.set('old', gui.get('Age'))
        bob2 = gui.get('Age')
示例#11
0
class Gui(object):
    """ the GUI for the script """
    def __init__(self, mapper):
        """ create the interface """
        self.mapper = mapper
        self.dialog = Window()
        self.dialog.setTitle('Mapper 1.0')
        # notebook
        tabs = ['Routine', 'Accumulate']
        pages = self.dialog.addNotebook('notebook', tabs)
        # routine page
        self.routine = pages[0]
        today = datetime.date.today()
        self.dt = today.strftime('%d,%m,%Y,%B').split(',')
        self.routine.addEntry('title', 'Map Title', width=60)
        self.routine.set(
            'title',
            '24 Hour Precipitation Ending 7 AM {0[3]} {0[0]}, {0[2]}'.format(
                self.dt))
        self.routine.plot('title', row=0)
        self.routine.addEntry('outfile', 'Output Filename', width=40)
        self.routine.set('outfile',
                         'pcpn{0[1]}{0[0]}{0[2]}.png'.format(self.dt))
        self.routine.plot('outfile', row=1)
        jobs = ['Make KMLs', 'Make Maps']
        self.routine.addCheck('jobs', 'Jobs', jobs)
        self.routine.set('jobs', jobs[:2])
        self.routine.plot('jobs', row=2)
        # accum pcpn page
        self.accum = pages[1]
        parms = [[2, 1, 12], [2, 1, 31], [4, 2000, 2100]]
        self.accum.addSpin('endDate',
                           parms,
                           '/',
                           'Ending Date',
                           command=self.updateAccum)
        self.accum.set('endDate', [today.month, today.day, today.year])
        self.accum.plot('endDate', row=0)
        self.accum.addSpin('daysBack', [[2, 1, 45]],
                           '',
                           'Days back',
                           command=self.updateAccum)
        self.accum.set('daysBack', [2])
        self.accum.plot('daysBack', row=1)
        self.accum.addEntry('title', 'Title', width=60)
        self.accum.plot('title', row=2)
        self.accum.addEntry('outfile', 'Output Filename', width=40)
        self.accum.plot('outfile', row=3)
        self.updateAccum()
        # dialog
        self.dialog.addText('messages', 70, 15, 'Messages')
        self.dialog.plot('messages', row=1)
        self.dialog.addButton('commands', space=20)
        self.dialog.changeWidget('commands', 0, command=self.go)
        self.dialog.changeWidget('commands', 1, text='Exit')
        self.dialog.plot('commands', row=2)
        self.dialog.plot('notebook', row=0)
        self.dialog.set('notebook', 0)

    def updateAccum(self):
        """ update widgets on accum page """
        end = self.accum.get('endDate')
        endDate = datetime.date(end[2], end[0], end[1])
        endDateFmt = endDate.strftime('%d,%m,%Y,%B').split(',')
        daysBack = self.accum.get('daysBack')[0]
        self.accum.set(
            'title',
            '{0} Day Precipitation Total Ending {1[3]} {1[0]}, {1[2]}'.format(
                int(daysBack), endDateFmt))
        begDate = endDate - datetime.timedelta(
            int(self.accum.get('daysBack')[0]) - 1)
        begDateFmt = begDate.strftime('%d,%m').split(',')
        self.accum.set(
            'outfile', 'accum{0[1]}{0[0]}-{1[1]}{1[0]}{1[2]}.png'.format(
                begDateFmt, endDateFmt))

    def go(self):
        """ get current selected page and make map """
        run = self.dialog.get('notebook')  # get selected tab
        mapper = self.mapper(self)  # create a Mapper instance using the Gui
        # instance which is self
        try:
            if run == 0:
                mapper.runRoutine()
            elif run == 1:
                mapper.runAccum()
        except:
            self.dialog.set('messages', self.dialog.catchExcept())
示例#12
0
import pygsheets
from tkintertoy import Window
import smtplib
import email

#Connect to server
server = smtplib.SMTP('smtp.outlook.com:587')
server.starttls()

#Set up GUI
gui = Window()
gui.setTitle('Pick two ports for your NP class!')
gui.addEntry('stu_no', 'Type in your student number',width=35)
gui.addEntry('pass', 'Type in your student account\'s password',width=35, show="*")
gui.addEntry('port_1', 'Pick port 1',width=35)
gui.addEntry('port_2', 'Pick port 2',width=35)
gui.addLabel('message', '',width=35, effects='bold', padding=5, foreground='red')
gui.addButton('commands')
gui.plot('stu_no', row=0, pady=10)
gui.plot('pass', row=1, pady=10)
gui.plot('port_1', row=2, pady=10)
gui.plot('port_2', row=3, pady=10)
gui.plot('message', row=4, pady=10)
gui.plot('commands', row=5, pady=10)

#spreadsheet information
SPREADSHEET_ID = "1mn93Hl0zT7Cb2YaPryj523IQEzelVa1HWLrR3ZxrJRU" # <Your spreadsheet ID>
RANGE_NAME = "data" # <Your worksheet name>

#setup google spreadsheet
gc = pygsheets.authorize(service_file='creds.json')
示例#13
0
class Gui(object):
    """ A simple gui class """
    def __init__(self):
        """ create the GUI """
        categories = ['Trees', 'Birds', 'Flowers']
        self.gui = Window()
        self.gui.setTitle('Dynamic Widget Demo')
        self.gui.addRadio('category', 'Item Types', categories)
        self.gui.addCombo('items', 'Items', None, postcommand=self.update)
        self.gui.addButton('command')
        self.gui.set('category', 'Trees')
        self.gui.set('items', '...')
        self.gui.plot('category', row=0)
        self.gui.plot('items', row=1, pady=20)
        self.gui.plot('command', row=2)

    def update(self):  # callback function
        """ set the combobox values by what is in the radio button box """
        lookup = {
            'Trees': ['Oak', 'Maple', 'Beech'],
            'Birds': ['Cardinal', 'Robin', 'Sparrow'],
            'Flowers': ['Rose', 'Petunia', 'Daylily']
        }
        select = self.gui.get('category')
        self.gui.set('items', lookup[select], allValues=True)
示例#14
0
class Gui(object):

    def __init__(self):
        self.gui = Window()
        self.gui.setTitle('Tkintertoy Gallery')
        self.makeGui()

    def makeGui(self):
        # a simple menu
        self.gui.addMenu('ttmainmenu', self.gui.master)
        menu = [['command', {'label':'About', 'command':self.popAbout}],
            ['command', {'label':'ChooseColor', 'command':self.popColor}]]
        self.gui.addMenu('ttmenu', self.gui.get('ttmainmenu'), menu)
        self.gui.get('ttmainmenu').add('cascade', label='Menu', menu=self.gui.get('ttmenu'))
        self.gui.master['menu'] = self.gui.get('ttmainmenu')
        # Notebook
        tabs = ['Simple','Dialog','Multi','Other']
        self.pages = self.gui.addNotebook('ttnotebook', tabs)
        # Text Box
        self.gui.addText('ttext', 60, 10, 'Text Box')
        self.gui.plot('ttext', row=1)
        # Progress Bar
        self.gui.addProgress('ttprogress', 100, 'Progress Bar')
        self.gui.plot('ttprogress', row=2)
        # Command Buttons
        cmd = [['Collect',self.collect],['Exit', self.gui.cancel]]
        self.gui.addButton('ttbutton', cmd)
        self.gui.plot('ttbutton', row=3)
        # Notebook Pages
        self.makeSimple()
        self.makeDialog()
        self.makeMulti()
        self.makeOther()
        self.gui.plot('ttnotebook', row=0)

    def makeSimple(self):
        self.simplePage = self.pages[0]
        # Label
        self.simplePage.addLabel('ttlabel','','bold', text='This is a BOLD label')
        self.simplePage.plot('ttlabel', row=0)
        # Line
        self.simplePage.addLine('ttline')
        self.simplePage.plot('ttline', row=1)
        # Message
        self.simplePage.addMessage('ttmessage', 'Message Box')
        self.simplePage.set('ttmessage', 'Useful for multi-line messages')
        self.simplePage.plot('ttmessage', row=2)
        # Entry
        self.simplePage.addEntry('ttentry', 'Entry Box')
        self.simplePage.set('ttentry', 'Default Entry')
        self.simplePage.plot('ttentry', row=3)
        # Option
        alist = ['Option1','Option2','Option3']
        self.simplePage.addOption('ttoption', alist, 'Option Box')
        self.simplePage.set('ttoption', 'Option1')
        self.simplePage.plot('ttoption', row=5)
        # Combobox and Style
        acombo = ['ComboOption1','ComboOption2','ComboOption3']
        self.simplePage.addStyle('new.TCombobox', foreground='red')
        self.simplePage.addCombo('ttcombo', acombo, 'Combo Box', style='new.TCombobox')
        self.simplePage.plot('ttcombo', row=6)
        # Checkboxes
        achecks = ['CheckOption1','CheckOption2','CheckOption3']
        self.simplePage.addCheck('ttchecks', achecks, 'Check Box')
        self.simplePage.plot('ttchecks', row=7)
        # Radio Buttons
        aradio = ['RadioOption1','RadioOption2','RadioOption3']
        self.simplePage.addRadio('ttradio', aradio, 'RadioButton Box')
        self.simplePage.plot('ttradio', row=8)
        # Scale
        self.simplePage.addScale('ttscale', 2, [1,10], 'Scale Box')
        self.simplePage.plot('ttscale', row=9)
        adate = [[2,1,12],[2,1,31],[4,2000,2099]]
        # Spinners
        self.simplePage.addSpin('ttspin', adate, '/', 'Date Box')
        self.simplePage.set('ttspin', [11,17,2017])
        self.simplePage.plot('ttspin', row=10)

    def makeDialog(self):
        self.dialogPage = self.pages[1]
        # Open
        self.dialogPage.addOpen('ttopen', 40, 'Open Box')
        self.dialogPage.plot('ttopen', row=0)
        # SaveAs
        self.dialogPage.addSaveAs('ttsaveas', 40, 'Save As Box')
        self.dialogPage.plot('ttsaveas', row=1)
        # ChooseDir
        self.dialogPage.addChooseDir('ttchoosedir', 40, 'Choose Dir Box')
        self.dialogPage.plot('ttchoosedir', row=2)

    def popColor(self):
        # Color Chooser
        self.gui.set('ttext', str(self.gui.popColorChooser(title='Select a Color')))

    def popAbout(self):
        # Pop Up Message Box
        self.gui.popMessage('Tkintertoy Gallery')

    def makeMulti(self):
        self.multiPage = self.pages[2]
        # List
        alist = ['ListOption1','ListOption2','ListOption3']
        self.multiPage.addList('ttlist', 'List Box', alist, height=4)
        self.multiPage.plot('ttlist', row=0)
        # Ledger
        cols = [['column1',100],['column2',80],['column3',80]]
        self.multiPage.addLedger('ttledger', 4, cols, 'Ledger Box')
        self.multiPage.set('ttledger', [['header1','item1-1','item1-2']])
        self.multiPage.set('ttledger', [['header2','item2-1','item2-2']])
        self.multiPage.set('ttledger', [['header3','tiem3-1','item2-3']])
        self.multiPage.plot('ttledger', row=1)
        # Collector Frame
        self.subwin = self.multiPage.addFrame('ttframe', '', relief='groove')
        # -Combobox
        acombo = ['ComboOption2-1','ComboOption2-2','ComboOption2-3']
        self.subwin.addCombo('ttcombo2', acombo, 'Combo Box 2')
        self.subwin.plot('ttcombo2', row=0)
        # -Radio Button
        aradio = ['Radio2-1','Radio2-2','Radio2-3']
        self.subwin.addRadio('ttradio2',aradio, 'RadioButton Box 2')
        self.subwin.plot('ttradio2', row=1)
        # -Collector
        cols = [['Combo',100],['Radio', 100]]
        self.subwin.addCollector('ttcollector', 4, cols, ['ttcombo2','ttradio2'], 'Collector Box')
        self.subwin.plot('ttcollector', row=2)
        self.multiPage.plot('ttframe', row=2)

    def makeOther(self):
        self.otherPage = self.pages[3]
        # Canvas
        self.otherPage.addCanvas('ttcanvas', 300, 100, 'Canvas Box')
        self.otherPage.get('ttcanvas').create_oval(10 ,10 ,290 ,90 ,fill='green')
        self.otherPage.plot('ttcanvas', row=0)
        # Multipane
        paneTitles = ['Pane 1','Pane 2','Pane 3']
        panes = self.otherPage.addPanes('ttpane', paneTitles, orient='horizontal')
        for i in range(3):
            # -Label
            tag = 'ttlabel' + str(i)
            panes[i].addLabel(tag)
            panes[i].set(tag, 'Inner label {}'.format(i+1))
            panes[i].plot(tag)
        self.otherPage.plot('ttpane', row=1)

    def collect(self):
        # show contents of all widgets
        result = 'Contents of widgets\n  Simple Page:\n    '
        result += self.simplePage.get('ttlabel') + '\n    '
        result += self.simplePage.get('ttmessage') + '\n    '
        result += self.simplePage.get('ttentry') + '\n    '
        result += self.simplePage.get('ttcombo') + '\n    '
        result += str(self.simplePage.get('ttchecks')) + '\n    '
        result += str(self.simplePage.get('ttradio')) +'\n    '
        result += self.simplePage.get('ttoption') + '\n\n    '
        result += str(self.simplePage.get('ttscale')) + '\n\n    '
        result += str(self.simplePage.get('ttspin')) + '\n\n    '
        result += str(self.multiPage.get('ttlist')) + '\n    '
        self.gui.set('ttprogress', 33)
        self.gui.set('ttext', result, setValues=True)
        time.sleep(.5)
        result = '  File Page:\n    '
        result += self.dialogPage.get('ttopen') + '\n    '
        result += self.dialogPage.get('ttsaveas') + '\n    '
        result += self.dialogPage.get('ttchoosedir') + '\n    '
        self.gui.set('ttprogress', 66)
        self.gui.set('ttext', result)
        time.sleep(.5)
        result = '  Multi Page:\n    '
        result += str(self.multiPage.get('ttlist', True)) + '\n    '
        result += str(self.multiPage.get('ttledger', True)) + '\n    '
        result += str(self.subwin.get('ttcollector',True)) + '\n    '
        # Progress Bar
        self.gui.set('ttprogress', 100)
        self.gui.set('ttext', result)
        time.sleep(1.0)
        self.gui.set('ttprogress', 0)
示例#15
0
 def __init__(self, stopwatch):
     """ init stopwatch gui
         stopwatch:Stopwatch -> """
     self.win = Window()  # make window an attribute
     self.stopw = stopwatch  # make stopwatch an attribute
     self.makeGui()  # create gui
示例#16
0
from tkintertoy import Window
gui = Window()
gui.setTitle('Create a Map')
csv = [('CSV files', ('*.csv'))]
gui.addOpen('input', 'Input CSV filename', width=40, filetypes=csv)
png = [('PNG files', ('*.png'))]
gui.addSaveAs('output', 'Output PNG filename', width=40, filetypes=png)
gui.addEntry('title', 'Map Title', width=40)
gui.addText('status', width=40, height=5, prompt='Status:')
gui.addButton('commands')
gui.plot('input', row=0, pady=10)
gui.plot('output', row=1, pady=10)
gui.plot('title', row=2, pady=10)
gui.plot('status', row=3, pady=10)
gui.plot('commands', row=4, pady=20)
gui.waitforUser()
if gui.content:
    message = 'Converting {} into {}...\n'.format(gui.get('input'), gui.get('output'))
    gui.set('status', message)
    gui.master.after(5000)
    # magic map making code goes here...
    gui.cancel()
示例#17
0
class Gui(object):
    def __init__(self):
        # read configuration file
        self.config = configparser.ConfigParser()
        self.config.read('config_parameters.ini')

        # write gui
        self.gui = Window()
        self.gui.setTitle('Export ScanInfo to Gsheet')
        self.gui.addChooseDir('dir_date',
                              'Scan Date Folder',
                              width=40,
                              initialdir='')
        self.gui.addEntry('para_list', 'Parameters to list', width=50)
        self.gui.addCombo('gdir',
                          'Save location in google drive',
                          None,
                          postcommand=self.gdir_update,
                          width=47)
        self.gui.set('para_list', self.config['DEFAULT']['parameters'])
        self.gui.addText('status', width=40, height=5, prompt='Status:')
        self.gui.addCheck('auto_update', '', ['Turn On Auto Update'])
        self.gui.addButton('commands')
        self.gui.changeWidget('commands',
                              0,
                              text='Export',
                              command=self.export)

        self.gui.plot('dir_date', row=0)
        self.gui.plot('para_list', row=1, pady=5)
        self.gui.plot('gdir', row=2, pady=5)
        self.gui.plot('status', row=3, pady=10)
        self.gui.plot('auto_update', row=4)
        self.gui.plot('commands', row=5, pady=10)

        self.exported = False
        self.proj = None  # bella project name
        self.g_name = None  # google drive folder name
        self.g_ID = None  # google drive folder id

        self.autoupdateOn = False
        self.update()

    def get_dirname_id(proj):
        '''Get the name and ID of google drive save locaion from google_dir.ini
        proj:'''
        config_g = configparser.ConfigParser()
        config_g.read('google_dir')

        name = [
            config_g[i]['name'] for i in config_g.sections()
            if config_g[i]['proj'] == proj
        ]
        ID = [
            config_g[i]['id'] for i in config_g.sections()
            if config_g[i]['proj'] == proj
        ]
        return name, ID

    def gdir_update(self):
        '''Update a saving location option on GUI, depending on your project'''
        # get BELLA project name
        dir_date = self.gui.get('dir_date', allValues=True)
        self.proj = get_proj_name(dir_date)

        # get google drive folder name and ID from .ini file
        cfg = configparser.ConfigParser()
        cfg.read('config_gdrive.ini')
        self.g_name = [
            cfg[i]['name'] for i in cfg.sections()
            if cfg[i]['proj'] == self.proj
        ]
        self.g_ID = [
            cfg[i]['id'] for i in cfg.sections() if cfg[i]['proj'] == self.proj
        ]

        # update save folder options in GUI
        self.gui.set('gdir', self.g_name, allValues=True)

    def export(self):
        '''When Export button is pressed, scan info is written into a google sheet'''
        # Get settings from GUI
        dir_date = self.gui.get('dir_date',
                                allValues=True)  # directory of scandata
        para_list = self.gui.get('para_list',
                                 allValues=True)  # parameters to save
        gdrive_name = self.gui.get('gdir')  # name of the google drive

        if not dir_date or not gdrive_name:
            self.gui.set('status', 'Please fill in all sections\n')
        else:
            gdrive_id = self.g_ID[self.g_name.index(
                gdrive_name)]  # google drive ID
            sheet_title = self.proj + ' ' + os.path.basename(
                dir_date) + ' ScanSummary'

            # write
            self.scaninfo = scaninfo2gsheet(dir_date, para_list)
            sheet = self.scaninfo.write(gdrive_id, sheet_title)
            self.exported = True

            # add text to status window
            message = 'Gsheet \'' + sheet.title + '\' saved\nURL: ' + sheet.url
            self.gui.set('status', message)

            # update the config file
            self.write_config(para_list, dir_date)

    def update(self):
        '''Update google sheet every minute.'''
        if bool(self.gui.get('auto_update')) and self.exported:
            # if autoupdate is turned on, message appears on status window
            if not self.autoupdateOn:
                self.gui.set('status', '\nAuto update On...')
            self.autoupdateOn = True

            nscan_new = self.scaninfo.update()
            # if there is a new scan, add text to the status window
            if nscan_new:
                message = '\nScan ' + str(nscan_new) + ' updated'
                self.gui.set('status', message)
        else:
            # if autoupdate is turned off, message appears on status window
            if self.autoupdateOn:
                self.gui.set('status', '\nAuto update Off')
            self.autoupdateOn = False

        self.gui.master.after(30 * 1000, self.update)  # wait for 30 seconds

    def write_config(self, para_list, dir_date):
        '''Save updated parameter list in config.ini file'''
        self.config['DEFAULT']['parameters'] = para_list
        with open('config_parameters.ini', 'w') as configfile:
            self.config.write(configfile)