Ejemplo n.º 1
0
    def run(self):
        try:
            N = int(self.str_N.get())
        except ValueError:
            import tkMessageBox
            tkMessageBox.Message(
                type="ok",
                message=("Please enter a number in the \"N\" box")).show()
            return

        #Search through the listbox and check that it doesnt already exist
        list = self.parentframe_conductedrunslist.get()
        for item in list:
            if item == self.controller.constructRunlabel(
                    self.str_method.get(), self.str_name.get()):
                import tkMessageBox
                tkMessageBox.Message(
                    type="ok",
                    message=(
                        "This run already exists, please select another name"
                    )).show()
                return

        self.controller.run(self.str_method.get(), self.str_name.get(), N)

        self.parentframe_conductedrunslist.insert(
            'end',
            self.controller.constructRunlabel(self.str_method.get(),
                                              self.str_name.get()))
Ejemplo n.º 2
0
    def continue_(self):
        # must have run simulate first, i.e., self.w.s.t must exist
        if not hasattr(self.w.s, 't'):
            message = 'You must first press Simulate, then Stop '\
                      'and then Continue'
            tkMessageBox.Message(icon='info',
                                 type='ok',
                                 message=message,
                                 title='About').show()
            return

        # the user may have changed parameters, but changing n is illegal
        if self.w.s.numerical_prm['n'] != self.nGUI['no of grid cells']:
            message = 'You have changed the grid. This has no effect '\
                      'in a continued simulation. Start new simulation.'
            tkMessageBox.Message(icon='info',
                                 type='ok',
                                 message=message,
                                 title='About').show()
            return

        self.w.s.set(tstop=self.nGUI['stop time for simulation'],
                     safety_factor=self.nGUI['safety factor for time step'])
        self.w.g.configure(sleep=1.0 - self.nGUI['movie speed'])

        self.w.s.dump()
        # no self.w.s.set_ic(); we start from previous state
        self.w.s.solve_problem()
Ejemplo n.º 3
0
    def compute(self):
        """Run oscillator and visualize results."""
        # create a subdirectory:
        d = self.p['case'].get()  # name of subdirectory
        print 'name of subdir:', d
        print 'm:', self.p['m'].get()
        import shutil
        if os.path.isdir(d):  # does d exist?
            shutil.rmtree(d)  # yes, remove old directory
        os.mkdir(d)  # make new directory d
        os.chdir(d)  # move to new directory d
        f = open('%s.i' % d, 'w')
        filevars = tuple([self.p[name].get() for name in \
                         ('m', 'b', 'c', 'func', 'A', 'w', 'y0',
                          'tstop', 'dt')])
        print filevars

        f.write('%g\n%g\n%g\n%s\n%g\n%g\n%g\n%g\n%g\n' % filevars)
        f.close()
        # run simulator:
        cmd = 'oscillator < %s.i' % d  # command to run
        failure = os.system(cmd)

        if failure:
            tkMessageBox.Message(icon='error',
                                 type='ok',
                                 message='Underlying simviz1.py script failed',
                                 title='Error').show()

        os.chdir(os.pardir)  # move up from simulation dir.
        self.visualize()
Ejemplo n.º 4
0
 def askyesnocancel(self, title=None, message=None, **options):
     s = tkMessageBox.Message(title=title,
                              message=message,
                              icon=tkMessageBox.QUESTION,
                              type=tkMessageBox.YESNOCANCEL,
                              **options).show()
     return s
Ejemplo n.º 5
0
    def simulate(self):
        try:
            self.w.s.set(I=self.pGUI['I func'], c=self.pGUI['H func'])
        except (AttributeError, KeyError):
            message = 'You must set physics parameters\n'\
                      '(first press Physics button and then Apply)'
            tkMessageBox.Message(icon='info',
                                 type='ok',
                                 message=message,
                                 title='About').show()
            return

        self.w.s.set(L=10,
                     n=self.nGUI['no of grid cells'],
                     tstop=self.nGUI['stop time for simulation'],
                     safety_factor=self.nGUI['safety factor for time step'],
                     user_action=self.w.action,
                     dt=0,
                     scheme_coding=self.scheme_coding)  # 'scalar'/'vectorized'
        self.w.g.configure(sleep=1.0 - self.nGUI['movie speed'])

        # ooops: user may have chosen parameters that are incompatible
        # with [-1,1] as range (can read from drawing, but not the others)
        self.w.set_graphics(ymax=1.0, ymin=-1.0, xcoor=self.w.s.x)
        self.w.s.dump()
        self.w.s.set_ic()
        self.w.s.solve_problem()
Ejemplo n.º 6
0
    def save(self, event):
        if not self.filename:
            self.save_as(event)
        else:
            # Check the time of most recent content modification so the
            # user doesn't accidentally overwrite a newer version of the file.
            if self.file_timestamp != os.stat(self.filename).st_mtime:
                dlg = tkMessageBox.Message(
                        master=self.text,
                        title="File has changed",
                        message=(
                            "The file has changed since reading it!\n\n"
                            "Do you really want to overwrite it?"),
                        default=tkMessageBox.NO,
                        icon=tkMessageBox.WARNING,
                        type=tkMessageBox.YESNO)
                res = dlg.show()
                if not self.text.tk.getboolean(str(res)):
                    return

            if self.writefile(self.filename):
                self.file_timestamp = os.stat(self.filename).st_mtime
                self.set_saved(1)
                try:
                    self.editwin.store_file_breaks()
                except AttributeError:  # may be a PyShell
                    pass
        self.text.focus_set()
        return "break"
Ejemplo n.º 7
0
    def createRunset(self):
        """
        Call the controller with the correct arguments and then lockdown
        """
        import os
        path = os.path.join(self.str_folder.get(), self.str_name.get())
        if os.path.isdir(path):
            import tkMessageBox
            if tkMessageBox.askokcancel(
                    "Already exists",
                    "A run with this name is already saved here. Overwrite?"):
                import shutil
                shutil.rmtree(path)
                tkMessageBox.Message(type="ok",
                                     message=("Folder " + path +
                                              " was removed")).show()
            else:
                return

        self.controller.createRunset(self.str_folder.get(),
                                     self.str_name.get(),
                                     float(self.str_m.get()),
                                     float(self.str_l.get()),
                                     float(self.str_omega.get()),
                                     float(self.str_A.get()),
                                     float(self.str_viscosity.get()),
                                     float(self.str_phi0.get()),
                                     float(self.str_v0.get()),
                                     float(self.str_tend.get()))
        self.lockdown()
Ejemplo n.º 8
0
 def plotV(self):
     try:
         index = self.parentframe_conductedrunslist.getvalue()[0]
     except IndexError:
         import tkMessageBox
         tkMessageBox.Message(
             type="ok", message=("Please select a run to plot")).show()
         return
     self.controller.plotFunc(index, "dtheta/dt")
Ejemplo n.º 9
0
 def ask_save_dialog(self):
     msg = "Source Must Be Saved\n" + 5 * ' ' + "OK to Save?"
     mb = tkMessageBox.Message(title="Save Before Run or Check",
                               message=msg,
                               icon=tkMessageBox.QUESTION,
                               type=tkMessageBox.OKCANCEL,
                               default=tkMessageBox.OK,
                               master=self.editpage.text)
     return mb.show()
Ejemplo n.º 10
0
 def handActionAdd(self):
     try:
         a = self.textHand.get("1.0",'end-1c')
         value = int(a)
         #print (str(value))
         if value >= 0 and value <= 180:
             self.instructions.add(Hand(value))
             self.refreshList()
     except:
         tkMessageBox.Message("Error on value")
Ejemplo n.º 11
0
 def print_window(self, event):
     m = tkMessageBox.Message(title="Print",
                              message="Print to Default Printer",
                              icon=tkMessageBox.QUESTION,
                              type=tkMessageBox.OKCANCEL,
                              default=tkMessageBox.OK,
                              master=self.text)
     reply = m.show()
     if reply != tkMessageBox.OK:
         self.text.focus_set()
         return "break"
     tempfilename = None
     saved = self.get_saved()
     if saved:
         filename = self.filename
     # shell undo is reset after every prompt, looks saved, probably isn't
     if not saved or filename is None:
         (tfd, tempfilename) = tempfile.mkstemp(prefix='IDLE_tmp_')
         filename = tempfilename
         os.close(tfd)
         if not self.writefile(tempfilename):
             os.unlink(tempfilename)
             return "break"
     platform = os.name
     printPlatform = 1
     if platform == 'posix':  #posix platform
         command = idleConf.GetOption('main', 'General',
                                      'print-command-posix')
         command = command + " 2>&1"
     elif platform == 'nt':  #win32 platform
         command = idleConf.GetOption('main', 'General',
                                      'print-command-win')
     else:  #no printing for this platform
         printPlatform = 0
     if printPlatform:  #we can try to print for this platform
         command = command % filename
         pipe = os.popen(command, "r")
         # things can get ugly on NT if there is no printer available.
         output = pipe.read().strip()
         status = pipe.close()
         if status:
             output = "Printing failed (exit status 0x%x)\n" % \
                      status + output
         if output:
             output = "Printing command: %s\n" % repr(command) + output
             tkMessageBox.showerror("Print status",
                                    output,
                                    master=self.text)
     else:  #no printing for this platform
         message = "Printing is not enabled for this platform: %s" % platform
         tkMessageBox.showinfo("Print status", message, master=self.text)
     if tempfilename:
         os.unlink(tempfilename)
     return "break"
Ejemplo n.º 12
0
def askyesnocancel(title=None, message=None, **options):
    import tkMessageBox
    s = tkMessageBox.Message(
        title=title, message=message,
        icon=tkMessageBox.QUESTION,
        type=tkMessageBox.YESNOCANCEL,
        **options).show()
    if isinstance(s, bool):
        return s
    if s == "cancel":
        raise Cancel
    return s == "yes"
Ejemplo n.º 13
0
 def gotoActionAdd(self):
     try:
         x = float(self.textGoToX.get("1.0",'end-1c'))
         print(x)
         y = float(self.textGoToY.get("1.0",'end-1c'))
         print(y)
         z = float(self.textGoToZ.get("1.0",'end-1c'))
         print(z)
         if (x >= -15 and x <= 9 and y >= -24 and y <= -6 and z >= -30 and z <= 19):
             instruction = GoTo((x, y, z))
             print (instruction.getSignature())
             self.instructions.add(instruction)
             self.refreshList()
     except:
         tkMessageBox.Message("Error on value")
Ejemplo n.º 14
0
    def compare(self):
        """Setup a comparison of two plots"""
        try:
            index = self.parentframe_conductedrunslist.getvalue()[0]
        except IndexError:
            import tkMessageBox
            tkMessageBox.Message(
                type="ok", message=("Please select a run to compare")).show()
            return

        if self.compare_plot1 == None:
            #First push
            self.compare_plot1 = index
            import tkMessageBox
            tkMessageBox.Message(
                type="ok",
                message=
                ("Select another run to compare with, and push \"Compare...\" again"
                 )).show()
        else:
            #Secound push
            compare_plot2 = index
            self.controller.compare(self.compare_plot1, compare_plot2)
            self.compare_plot1 = None
Ejemplo n.º 15
0
 def compute(self):
     """Run simviz1.py."""
     path = os.path.join(os.environ['scripting'], 'src', 'py', 'intro',
                         'simviz1.py')
     cmd = path + ' -screenplot '
     # join options; -X self.p['X'].get()
     opts = ['-%s %s' % (prm, str(self.p[prm].get())) for prm in self.p]
     cmd += ' '.join(opts)
     print cmd
     failure = os.system(cmd)
     if failure:
         tkMessageBox.Message(icon='error',
                              type='ok',
                              message='Underlying simviz1.py script failed',
                              title='Error').show()
Ejemplo n.º 16
0
 def compute(self):
     """Run simviz1.py."""
     # add simviz1.py's directory to PATH:
     os.environ['PATH'] += os.pathsep + os.path.join(
         os.environ['scripting'], 'src', 'py', 'intro')
     cmd = 'simviz1.py '
     # join options; -X self.p['X'].get()
     opts = ['-%s %s' % (prm, str(self.p[prm].get())) for prm in self.p]
     cmd += ' '.join(opts)
     print cmd
     failure, output = commands.getstatusoutput(cmd)
     if failure:
         tkMessageBox.Message(icon='error',
                              type='ok',
                              message='Underlying simviz1.py script failed',
                              title='Error').show()
Ejemplo n.º 17
0
 def maybesave(self):
     if self.get_saved():
         return "yes"
     message = "Do you want to save %s before closing?" % (
         self.filename or "this untitled document")
     m = tkMessageBox.Message(title="Save On Close",
                              message=message,
                              icon=tkMessageBox.QUESTION,
                              type=tkMessageBox.YESNOCANCEL,
                              master=self.text)
     reply = m.show()
     if reply == "yes":
         self.save(None)
         if not self.get_saved():
             reply = "cancel"
     self.text.focus_set()
     return reply
Ejemplo n.º 18
0
 def asktoexit(self):
     #		if tkMessageBox.askokcancel("Quit?", "Are you sure you want to exit?"):
     #			self.master.destroy()
     #~ sys.exit()
     mbox = tkMessageBox.Message(
         title='Delete temporary files?',
         message='Would you like to delete all MIPPY temp files?',
         icon=tkMessageBox.QUESTION,
         type=tkMessageBox.YESNOCANCEL,
         master=self)
     reply = mbox.show()
     if reply == 'yes':
         self.clear_temp_dir()
         self.master.destroy()
     elif reply == 'no':
         self.master.destroy()
     else:
         return
     return
def ignoreMisconfiguration():
    import Tkinter, tkMessageBox as mb
    tk = Tkinter.Tk()
    tk.withdraw()
    #winsys = tk.tk.call('tk', 'windowingsystem')
    #if winsys == 'win32':
    #	filename = os.path.join(os.path.dirname(__file__), 'chimera',
    #			'Icons', 'chimera32.ico')
    #	tk.wm_iconbitmap(filename)
    message = mb.Message(title="OpenGL miconfiguration",
                         icon=mb.ERROR,
                         type=mb.YESNO,
                         default='no',
                         message="OpenGL misconfiguration detected.\n"
                         "%s differs from %s.\n"
                         "\n"
                         "See %s installation notes for details at\n"
                         "http://www.cgl.ucsf.edu/chimera/download.html.\n"
                         "\n"
                         "Continue even though chimera might crash?" %
                         (libGL + (sys.argv[1], )))
    return message.show() == 'yes'
Ejemplo n.º 20
0
def warningMessage(message):
    tkMessageBox.Message(icon='warning', type = 'ok', message = message, title = "Warning").show()
Ejemplo n.º 21
0
def meniji():
    tkMessageBox.Message(jedilnik)
Ejemplo n.º 22
0
import os
def run():
    global onoff
    tmax = tm.get()
    b = pbor.get()
    d = pdie.get()
    error = StringVar()

    n = n1.get()  #int(input)
    print '===start run==='
    cg.clear()

    v = []  # list of living individuals; stores a vertical position for each
    if n == 1: v = [0.5]  # start with one
    if n == 2: v = [0.3, 0.6]
    if n == 3: v = [0.25, 0.5, 0.75]
    if n == 4: v = [0.2, 0.4, 0.6, 0.8]

    t = 0
    while t <= tmax and len(v) > 0:
        t += dt
        rate = b * len(v)
        urv = random.random()
        if urv < rate * dt:
            print urv, b * len(v), d * len(v)
            if len(v) == 1:
                vnow = sum(v)
                v = [0.5 * vnow, 0.5 * (1 + vnow)]
                print v
                cg.drawb(t / tmax, v[0])
                cg.drawb(t / tmax, v[1])
                cg.drawv(t / tmax, v[0], v[1])
            else:
                i = random.randint(len(v))
                vm1 = v[i]
                if i == 0:
                    newv = (0.05 + vm1) / 2
                else:
                    vm2 = v[i - 1]
                    newv = vm1 + (vm2 - vm1) / 3.0
                v[i] = newv
                if i == len(v) - 1:
                    pairv = (0.95 + vm1) / 2
                else:
                    vm2 = v[i + 1]
                    pairv = vm1 + (vm2 - vm1) / 3.0
                v.append(pairv)
                cg.drawv(t / tmax, newv, pairv)
                cg.drawb(t / tmax, newv)
                cg.drawb(t / tmax, pairv)
                v.sort()
            print t, len(v)
        else:
            rate = (b + d) * len(v)
            if urv < rate * dt:
                print 'death'
                i = random.randint(len(v))
                cg.drawd(t / tmax, v[i])
                v.pop(i)

        cg.drawl(t / tmax, dt / tmax, v)
        tree.update()
        tree.after(5)
        if sum(v) == 0:
            tkMessageBox.Message(icon='info',
                                 type='ok',
                                 message='Population went extinct',
                                 title='Results').show()
            t = tmax

    print 'finished'