Esempio n. 1
0
    def __init__(self, parent, config):
        Frame.__init__(self, parent)
        self.loggedIn = None
        self.config = config

        self.pack(fill=BOTH, expand=1, padx=10, pady=10)

        self.bind("<Return>", self.login)

        self.message = StringVar()
        l = Label(self, textvariable=self.message)
        l.pack()

        l = Label(self, text="Email:")
        l.pack(anchor=W, pady=(10, 0))

        self.email = StringVar()
        self.email.set(self.config.get("credentials", "email"))

        e = Entry(self, textvariable=self.email, width=40, font=("Helvetica", 16))
        e.pack(fill=X)
        e.focus_set()
        e.icursor(END)
        e.selection_range(0, END)

        l = Label(self, text="Password:"******"credentials", "password"))

        e = Entry(self, show="*", textvariable=self.password, font=("Helvetica", 16))
        e.pack(fill=X)

        self.submit = Button(self, text="Login", command=self.login)
        self.submit.pack(ipady=10, pady=10, fill=X)
Esempio n. 2
0
class editPool(Frame):

    font_decorations = ("italic", "bold", "subscript", "superscript")
    font_decorations_to_names = {
        "italic": _("italic"),
        "bold": _("bold"),
        "subscript": _("subscript"),
        "superscript": _("superscript"),
    }
    font_decorations_to_html = {"italic": "i", "bold": "b", "subscript": "sub", "superscript": "sup"}

    def __init__(self, master, buttons=("interpret", "asis"), **kw):
        Frame.__init__(self, master, **kw)
        self.text = ""
        self.interpret = 1
        self.editPool = Entry(self, width=50, state="disabled", font="Helvetica 12")
        self.editPool.pack(side="left")

        self.editPool.bind("<Return>", self._interpretButtonPressed)
        self.editPool.bind("<Escape>", self._cancel)

        self.editPool.bind("<Control-s>", lambda e: self._tag_it("sub"))
        self.editPool.bind("<Control-S>", lambda e: self._tag_it("sup"))
        self.editPool.bind("<Control-i>", lambda e: self._tag_it("i"))
        self.editPool.bind("<Control-b>", lambda e: self._tag_it("b"))

        self.editPool.bind("<KeyPress>", self._key)

        if "interpret" in buttons:
            pix = Store.app.request("pixmap", name="interpret")
            self.interpretButton = Button(
                self,
                text=_("Interpret"),
                image=pix,
                command=self._interpretButtonPressed,
                state="disabled",
                bd=config.border_width,
            )
            Store.app.balloon.bind(self.interpretButton, _("Interpret text (where applicable)"))
            self.interpretButton.pack(side="left")
        else:
            self.interpretButton = None

        if "asis" in buttons:
            pix = Store.app.request("pixmap", name="asis")
            self.setButton = Button(
                self,
                image=pix,
                text=_("As is"),
                command=self._setButtonPressed,
                state="disabled",
                bd=config.border_width,
            )
            Store.app.balloon.bind(self.setButton, _("Leave text as is - do not interpret"))
            self.setButton.pack(side="left")
        else:
            self.setButton = None

        pix = Store.app.request("pixmap", name="subnum")
        self.numbersToSubButton = Button(
            self,
            image=pix,
            text=_("Sub numbers"),
            command=self._numbersToSubButtonPressed,
            state="disabled",
            bd=config.border_width,
        )
        Store.app.balloon.bind(self.numbersToSubButton, _("Convert numbers to subscript"))
        self.numbersToSubButton.pack(side="left")

        # text decoration
        decorFrame = Frame(self)
        decorFrame.pack(padx=5, side="left")
        for i in self.font_decorations:
            pix = Store.app.request("pixmap", name=i)
            self.__dict__[i] = Button(
                self,
                image=pix,
                command=misc.lazy_apply(self._tag_it, (self.font_decorations_to_html[i],)),
                state="disabled",
                text=self.font_decorations_to_names[i],
                bd=config.border_width,
            )
            Store.app.balloon.bind(self.__dict__[i], self.font_decorations_to_names[i])
            self.__dict__[i].pack(side="left")

        # special characters
        pix = Store.app.request("pixmap", name="specialchar")
        self.specialCharButton = Button(
            self,
            image=pix,
            text=_("Special Character"),
            command=self._specialCharButtonPressed,
            state="disabled",
            bd=config.border_width,
        )
        Store.app.balloon.bind(self.specialCharButton, _("Insert a special character"))
        self.specialCharButton.pack(side="left")
        self.active = False

    def _interpretButtonPressed(self, *e):
        t = self.editPool.get()
        if string.lower(t) in groups_table:
            self._setText(t)
            # self._setText( groups_table[ string.lower(t)]['text'])
            # self.editPool.insert(0, self.text)
        else:
            self._setText(t)
            self.text = re.sub("\\\\n", "\n", self.text)
        self._quit()

    def _setButtonPressed(self, *e):
        self._setText(self.editPool.get())
        self.interpret = 0
        self._quit()

    def _numbersToSubButtonPressed(self, *e):
        self._setText(re.sub("\d+", "<sub>\g<0></sub>", self.editPool.get()))
        self._quit()

    def _cancel(self, e):
        self._setText(None)
        self.active = False
        self._quit()

    def _quit(self):
        self.grab_release()
        self._disable()
        self._normaly_terminated = 1
        self.active = False
        self.quit()

    def _disable(self):
        self.interpretButton.configure(state="disabled")
        self.numbersToSubButton.configure(state="disabled")
        self.setButton.configure(state="disabled")
        self.editPool.configure(state="disabled")
        self.italic.configure(state="disabled")
        self.bold.configure(state="disabled")
        self.superscript.configure(state="disabled")
        self.subscript.configure(state="disabled")
        self.specialCharButton.configure(state="disabled")

    def _enable(self):
        self.interpretButton.configure(state="normal")
        self.numbersToSubButton.configure(state="normal")
        self.setButton.configure(state="normal")
        self.editPool.configure(state="normal")
        self.italic.configure(state="normal")
        self.bold.configure(state="normal")
        self.superscript.configure(state="normal")
        self.subscript.configure(state="normal")
        self.specialCharButton.configure(state="normal")

    def _setText(self, text):
        self.text = text
        self._update()

    def _update(self):
        self.editPool.delete(0, last="end")
        if self.text:
            self.editPool.insert(0, self.text)

    def activate(self, text=None, select=1):
        """activates edit_pool and returns inserted value (None if cancel occured),
    if parameter text is None it preserves the old one, use text='' to delete old text"""
        self.active = True
        self.interpret = 1
        self.focus_set()
        self.grab_set()
        self._enable()
        # this is because I need to distinguish whether the mainloop was terminated "from inside"
        # or from outside (this most of the time means the application was killed and the widgets are no longer available)
        self._normaly_terminated = 0
        if text != None:
            self._setText(text)
        self.editPool.focus_set()
        if select:
            self.editPool.selection_range(0, "end")
        self.mainloop()
        if self._normaly_terminated:
            return self.text
        else:
            return None

    def _tag_it(self, tag):
        if self.editPool.selection_present():
            self.editPool.insert(Tkinter.SEL_FIRST, "<%s>" % tag)
            self.editPool.insert(Tkinter.SEL_LAST, "</%s>" % tag)
        else:
            self.editPool.insert(Tkinter.INSERT, "<%s></%s>" % (tag, tag))
            self.editPool.icursor(self.editPool.index(Tkinter.INSERT) - len(tag) - 3)

    def _key(self, event):
        if len(event.keysym) > 1 and event.keysym in keysyms:
            if self.editPool.selection_present():
                self.editPool.delete("anchor", "insert")
            self.editPool.insert("insert", unicode(keysyms[event.keysym]))
            return "break"

    def _specialCharButtonPressed(self):
        dialog = special_character_menu(self._insertText)
        dialog.post(self.specialCharButton.winfo_rootx(), self.specialCharButton.winfo_rooty())

    def _insertText(self, text):
        if text != None:
            self.editPool.insert(Tkinter.INSERT, text)
        self.grab_set()
Esempio n. 3
0
class editPool(Frame):

    font_decorations = ('italic', 'bold', 'subscript', 'superscript')
    font_decorations_to_names = {
        'italic': _('italic'),
        'bold': _('bold'),
        'subscript': _('subscript'),
        'superscript': _('superscript')
    }
    font_decorations_to_html = {
        'italic': 'i',
        'bold': 'b',
        'subscript': 'sub',
        'superscript': 'sup'
    }

    def __init__(self, master, buttons=('interpret', 'asis'), **kw):
        Frame.__init__(self, master, **kw)
        self.text = ''
        self.interpret = 1
        self.editPool = Entry(self,
                              width=50,
                              state='disabled',
                              font="Helvetica 12")
        self.editPool.pack(side='left')

        self.editPool.bind('<Return>', self._interpretButtonPressed)
        self.editPool.bind('<Escape>', self._cancel)

        self.editPool.bind('<Control-s>', lambda e: self._tag_it("sub"))
        self.editPool.bind('<Control-S>', lambda e: self._tag_it("sup"))
        self.editPool.bind('<Control-i>', lambda e: self._tag_it("i"))
        self.editPool.bind('<Control-b>', lambda e: self._tag_it("b"))

        self.editPool.bind("<KeyPress>", self._key)

        if 'interpret' in buttons:
            pix = Store.app.request('pixmap', name='interpret')
            self.interpretButton = Button(self,
                                          text=_('Interpret'),
                                          image=pix,
                                          command=self._interpretButtonPressed,
                                          state='disabled',
                                          bd=config.border_width)
            Store.app.balloon.bind(self.interpretButton,
                                   _('Interpret text (where applicable)'))
            self.interpretButton.pack(side='left')
        else:
            self.interpretButton = None

        if 'asis' in buttons:
            pix = Store.app.request('pixmap', name='asis')
            self.setButton = Button(self,
                                    image=pix,
                                    text=_('As is'),
                                    command=self._setButtonPressed,
                                    state='disabled',
                                    bd=config.border_width)
            Store.app.balloon.bind(self.setButton,
                                   _('Leave text as is - do not interpret'))
            self.setButton.pack(side='left')
        else:
            self.setButton = None

        pix = Store.app.request('pixmap', name='subnum')
        self.numbersToSubButton = Button(
            self,
            image=pix,
            text=_('Sub numbers'),
            command=self._numbersToSubButtonPressed,
            state='disabled',
            bd=config.border_width)
        Store.app.balloon.bind(self.numbersToSubButton,
                               _('Convert numbers to subscript'))
        self.numbersToSubButton.pack(side='left')

        # text decoration
        decorFrame = Frame(self)
        decorFrame.pack(padx=5, side="left")
        for i in self.font_decorations:
            pix = Store.app.request('pixmap', name=i)
            self.__dict__[i] = Button(
                self,
                image=pix,
                command=misc.lazy_apply(self._tag_it,
                                        (self.font_decorations_to_html[i], )),
                state='disabled',
                text=self.font_decorations_to_names[i],
                bd=config.border_width)
            Store.app.balloon.bind(self.__dict__[i],
                                   self.font_decorations_to_names[i])
            self.__dict__[i].pack(side="left")

        # special characters
        pix = Store.app.request('pixmap', name='specialchar')
        self.specialCharButton = Button(self,
                                        image=pix,
                                        text=_('Special Character'),
                                        command=self._specialCharButtonPressed,
                                        state='disabled',
                                        bd=config.border_width)
        Store.app.balloon.bind(self.specialCharButton,
                               _('Insert a special character'))
        self.specialCharButton.pack(side='left')
        self.active = False

    def _interpretButtonPressed(self, *e):
        t = self.editPool.get()
        if string.lower(t) in groups_table:
            self._setText(t)
            #self._setText( groups_table[ string.lower(t)]['text'])
            #self.editPool.insert(0, self.text)
        else:
            self._setText(t)
            self.text = re.sub("\\\\n", "\n", self.text)
        self._quit()

    def _setButtonPressed(self, *e):
        self._setText(self.editPool.get())
        self.interpret = 0
        self._quit()

    def _numbersToSubButtonPressed(self, *e):
        self._setText(re.sub("\d+", '<sub>\g<0></sub>', self.editPool.get()))
        self._quit()

    def _cancel(self, e):
        self._setText(None)
        self.active = False
        self._quit()

    def _quit(self):
        self.grab_release()
        self._disable()
        self._normaly_terminated = 1
        self.active = False
        self.quit()

    def _disable(self):
        self.interpretButton.configure(state='disabled')
        self.numbersToSubButton.configure(state='disabled')
        self.setButton.configure(state='disabled')
        self.editPool.configure(state='disabled')
        self.italic.configure(state='disabled')
        self.bold.configure(state='disabled')
        self.superscript.configure(state='disabled')
        self.subscript.configure(state='disabled')
        self.specialCharButton.configure(state='disabled')

    def _enable(self):
        self.interpretButton.configure(state='normal')
        self.numbersToSubButton.configure(state='normal')
        self.setButton.configure(state='normal')
        self.editPool.configure(state='normal')
        self.italic.configure(state='normal')
        self.bold.configure(state='normal')
        self.superscript.configure(state='normal')
        self.subscript.configure(state='normal')
        self.specialCharButton.configure(state='normal')

    def _setText(self, text):
        self.text = text
        self._update()

    def _update(self):
        self.editPool.delete(0, last='end')
        if self.text:
            self.editPool.insert(0, self.text)

    def activate(self, text=None, select=1):
        """activates edit_pool and returns inserted value (None if cancel occured),
    if parameter text is None it preserves the old one, use text='' to delete old text"""
        self.active = True
        self.interpret = 1
        self.focus_set()
        self.grab_set()
        self._enable()
        # this is because I need to distinguish whether the mainloop was terminated "from inside"
        # or from outside (this most of the time means the application was killed and the widgets are no longer available)
        self._normaly_terminated = 0
        if text != None:
            self._setText(text)
        self.editPool.focus_set()
        if select:
            self.editPool.selection_range(0, 'end')
        self.mainloop()
        if self._normaly_terminated:
            return self.text
        else:
            return None

    def _tag_it(self, tag):
        if self.editPool.selection_present():
            self.editPool.insert(Tkinter.SEL_FIRST, '<%s>' % tag)
            self.editPool.insert(Tkinter.SEL_LAST, '</%s>' % tag)
        else:
            self.editPool.insert(Tkinter.INSERT, '<%s></%s>' % (tag, tag))
            self.editPool.icursor(
                self.editPool.index(Tkinter.INSERT) - len(tag) - 3)

    def _key(self, event):
        if len(event.keysym) > 1 and event.keysym in keysyms:
            if self.editPool.selection_present():
                self.editPool.delete("anchor", "insert")
            self.editPool.insert('insert', unicode(keysyms[event.keysym]))
            return "break"

    def _specialCharButtonPressed(self):
        dialog = special_character_menu(self._insertText)
        dialog.post(self.specialCharButton.winfo_rootx(),
                    self.specialCharButton.winfo_rooty())

    def _insertText(self, text):
        if text != None:
            self.editPool.insert(Tkinter.INSERT, text)
        self.grab_set()
Esempio n. 4
0
class StatePopup(object):
    def __init__(self, master, default_value, state_probs):
        top = self.top = Toplevel(master.canvas)
        self.master = master

        self.l = Label(top, text="New State")
        self.l.grid(row=0, column=0, columnspan=2)

        self.lb = Listbox(
            top
        )  # OptionMenu(top, Tkinter.StringVar().set(self.states[-1]), *self.states)
        self.lb.insert("end", "0")
        for i, (state,
                color) in enumerate(self.master.trail.colorlist.items()):
            str = ",".join(["{:x}".format(x) for x in state])
            self.lb.insert("end", str)
            self.lb.itemconfig(i + 1, {"bg": color})
        self.lb.grid(row=1, column=1, padx=MARGIN_LR / 2, pady=MARGIN_TB)
        self.lb.config(height=5, width=8)
        self.lb.bind(
            "<Double-Button-1>",
            lambda x: self.set_text(self.lb.get(self.lb.curselection())))

        self.e = Entry(top)
        self.e.insert(0, default_value)
        self.e.bind("<Control-KeyRelease-a>", lambda x: self.select_all())
        self.e.grid(row=1,
                    column=0,
                    sticky=N,
                    padx=MARGIN_LR / 2,
                    pady=MARGIN_TB)
        self.e.select_range(0, 'end')
        self.e.icursor('end')
        self.e.focus()

        self.b = Button(top, text='Ok', command=self.check_cleanup)
        self.top.protocol("WM_DELETE_WINDOW", self.close)
        self.b.grid(row=3, column=0, columnspan=2)

        self.l2 = Label(top, text="Probabilities")
        self.l2.grid(row=4, column=0, columnspan=2)
        for i, x in enumerate(state_probs):
            # if x > 0:
            #    l = Label(top, text=hex(i)[2:] + ":" + str(x))
            #    l.pack()
            pass

        self.top.bind("<Return>", lambda x: self.check_cleanup())
        self.top.bind("<Escape>", lambda x: self.close())
        self.value = None
        self.top.wait_visibility()
        # stop interaction in other gui
        self.top.grab_set()

    def set_text(self, text):
        self.e.delete(0, 'end')
        self.e.insert(0, text)

    def select_all(event):
        event.e.select_range(0, 'end')
        # move cursor to the end
        event.e.icursor('end')
        return 'break'

    def check_cleanup(self):
        newstate = self.e.get()
        if newstate == "":
            self.value = range(
                0, 2**(self.master.trail.statebitsize /
                       self.master.trail.statesize))
        elif newstate == "*":
            self.value = range(
                1, 2**(self.master.trail.statebitsize /
                       self.master.trail.statesize))
        else:
            try:
                state = []
                for x in newstate.split(","):
                    x = x.strip()
                    x = int(x, 16)
                    assert x < 2**(self.master.trail.statebitsize /
                                   self.master.trail.statesize)
                    state.append(x)
                assert len(state) > 0
                self.value = state
            except Exception as e:
                print "Exception: " + str(e)
                self.value = None
                return

        self.close()

    def close(self):
        self.top.grab_release()
        self.top.destroy()