Ejemplo n.º 1
0
    def test_edit_score(self):
        import LanguageDeck.session_tools.session_scope as scp

        c = Cards.LanguageBVocab(text="Es sieht aus, wie du errungen hast.")
        u1 = Cards.User(name="dude")
        self.sess.add_all([c, u1])
        self.sess.commit()

        with scp.session_scope(self.session) as sess:
            cds.edit_score(sess, c, u1, 8)

        with scp.session_scope(self.session) as sess:
            probe = cds.get_score(sess, u1, c)
            ans = 8
            self.assertEqual(probe, ans)

        with scp.session_scope(self.session) as sess:
            cds.edit_score(sess, c, u1, 3)

        with scp.session_scope(self.session) as sess:

            c = sess.query(Cards.LanguageBVocab).filter_by(id=c.id).one()
            probe = cds.get_score(self.sess, u1, c)
            ans = 3
            self.assertEqual(probe, ans)
Ejemplo n.º 2
0
    def add_translation_call(self):
        """Triggers the Add Translation call"""
        tl = tk.Toplevel()

        with session_scope(self.sf) as sess:
            cd = sess.query(self.card_type).filter_by(id=self.card_id).one()
            MapDeckView(cd, "translation", tl, self, self.sf)
Ejemplo n.º 3
0
    def add_example_call(self):
        """Triggers the add example window"""
        tl = tk.Toplevel()

        with session_scope(self.sf) as sess:
            cd = sess.query(self.card_type).filter_by(id=self.card_id).one()
            MapDeckView(cd, "example", tl, self, self.sf)
Ejemplo n.º 4
0
    def test_edit_date_touched(self):
        import LanguageDeck.session_tools.session_scope as scp

        with scp.session_scope(self.session) as sess:
            c = Cards.LanguageBVocab(
                text="Es sieht aus, wie du errungen hast.")

            d1 = datetime.date(2017, 4, 3)
            sess.add_all([c])
            sess.commit()

            cds.edit_date_touched(c, d1)
            sess.commit()

            probe = cds.get_touch_date(c)
            ans = datetime.date(2017, 4, 3)
            self.assertEqual(probe, ans)

            d2 = datetime.date(2017, 5, 2)
            cds.edit_date_touched(c, d2)
            sess.commit()

            probe = cds.get_touch_date(c)
            ans = datetime.date(2017, 5, 2)
            self.assertEqual(probe, ans)
Ejemplo n.º 5
0
    def browse_select_call(self, event):
        """view selected card in browse mode"""
        card_info = event.widget.selection()

        with sessc.session_scope(self.session_factory) as sess:
            card = self.get_card(card_info, sess)
            card_view.Browse_Card_View(card, self.browse_frame,
                                       self.session_factory)

        print("Card Browsing")
Ejemplo n.º 6
0
    def select_call(self, event):
        """Opens a Browse view of selected card from treeview"""
        card_info = event.widget.selection()[0]
        print(card_info)

        with session_scope(self.session_factory) as sess:
            card = self.get_card(card_info, sess)
            Browse_Card_View(card, self.view_frame, self.session_factory)

        print("Card Browsing")
Ejemplo n.º 7
0
    def title_save_call(self):
        self.title_save_button['state'] = 'disabled'
        self.title_nosave_button['state'] = 'disabled'
        self.title_edit_button['state'] = 'normal'
        self.card_title.set(self.title.get("1.0", "end"))
        self.card_text = self.card_title.get()
        self.title["state"] = "disabled"

        # update database
        if self.sf:
            with session_scope(self.sf) as sess:
                self.edit_title(sess, self.card_title.get())

        self.update_signal()
Ejemplo n.º 8
0
    def done_call(self):
        """Destroy current view.  commit changes to cards mappings"""
        updates = {
            "type": self.card_type,
            "ids": self.report,
            "card": self.card
        }
        with session_scope(self.session_factory) as sess:
            c = sess.query(type(self.card)).filter_by(id=self.card_id).one()
            if self.report.keys():
                update = sess.query(self.card_type).filter(
                    self.card_type.id.in_(self.report)).all()
            else:
                update = []
            setattr(c, self.map_attribute, update)

        self.report_dest.map_update()
        self.master.destroy()
Ejemplo n.º 9
0
 def default_select_call(self):
     window = tk.Toplevel()
     self.open_windows[window] = None
     window.bind("<Destroy>", self.destroyed_window)
     with sessc.session_scope(self.session_factory) as sess:
         c_id = self.tree_list.selection()
         card = self.get_card(c_id, sess)
         if c_id in self.open_cards:
             window.destroy()
             self.open_cards[c_id].lift()
             self.open_cards[c_id].focus()
         else:
             self.open_cards[c_id] = window
             self.open_windows[window] = c_id
             window.geometry(
                 "-30+{voff}".format(voff=str(30 + self.vertical_offset)))
             self.vertical_offset = (self.vertical_offset + 5) % 25
             #TODO: root logic
             card_view.CardView(card, window, self.session_factory)
Ejemplo n.º 10
0
    def test_edit_paradigm(self):
        import LanguageDeck.session_tools.session_scope as scp
        with scp.session_scope(self.session) as sess:
            c1 = Cards.LanguageAVocab(text="error")
            c2 = Cards.Grammar(paradigm="old paradigm")

            sess.add_all([c1, c2])
            sess.commit()

            try:
                cds.edit_g_paradigm(c1, "new paradigm")
            except AssertionError:
                print("caught assertion error")

            cds.edit_g_paradigm(c2, "new paradigm")
            sess.commit()

            probe = cds.get_paradigm_content(c2)
            ans = "new paradigm"
            self.assertEqual(probe, ans)
Ejemplo n.º 11
0
    def test_get_examples(self):
        import LanguageDeck.session_tools.session_scope as scp
        with scp.session_scope(self.session) as sess:
            cv1 = Cards.LanguageBVocab(text="allerdings", g_type="prep")
            ce1 = Cards.LanguageBExample(text="Es ist allerdings moeglich")
            ce2 = Cards.LanguageBExample(text="allerdings, du bist verklapt.")

            sess.add_all([cv1, ce1, ce2])
            sess.commit()

            probe = cds.get_examples(cv1)
            ans = []
            self.assertEqual(probe, ans)

            cv1.examples.append(ce1)
            cv1.examples.append(ce2)

            sess.commit()

            probe = cds.get_examples(cv1)
            ans = [ce1, ce2]
            self.assertEqual(probe, ans)
Ejemplo n.º 12
0
    def test_add_examples(self):
        import LanguageDeck.session_tools.session_scope as scp
        with scp.session_scope(self.session) as sess:
            cvb = Cards.LanguageBVocab(text="lbv")
            cvb2 = Cards.LanguageBVocab(text="lbv2")
            cva = Cards.LanguageAVocab(text="lav")
            ceb = Cards.LanguageBExample(text="example lbv")
            cea = Cards.LanguageAExample(text="example lav")

            sess.add_all([cvb, cvb2, cva, ceb, cea])
            sess.commit()

            cds.add_example(cvb, ceb)
            sess.commit()
            probe = cds.get_examples(cvb)
            ans = [ceb]
            self.assertEqual(probe, ans)

            cds.add_example(cvb2, ceb)
            sess.commit()
            probe = cds.get_examples(cvb2)
            ans = [ceb]
            self.assertEqual(probe, ans)

            cds.add_example(cva, cea)
            sess.commit()
            probe = cds.get_examples(cva)
            ans = [cea]
            self.assertEqual(probe, ans)

            cds.add_example(cvb, ceb)
            cds.add_example(cvb, ceb)
            sess.commit()
            probe = cds.get_examples(cvb)
            ans = [ceb]
            self.assertEqual(probe, ans)
Ejemplo n.º 13
0
    def __init__(self,
                 card,
                 map_type=None,
                 master=None,
                 report_dest=None,
                 session_factory=None):
        super().__init__(master, padding=5)
        self.session_factory = session_factory
        self.report_dest = report_dest
        self.card = card

        assert issubclass(type(report_dest),
                          CardView), "master must be cdview.CardView"

        self.card_id = card.id
        assert map_type in ["example", "translation"], "must specify type"

        if map_type == "example":
            self.card_type = maps.card_example_types.get(type(card))
            self.map_attribute = maps.card_example_fields[type(card)]
            maplist = getattr(card, maps.card_example_fields[type(card)], [])
        else:
            self.card_type = maps.card_translation_types.get(type(card))
            self.map_attribute = "translations"
            maplist = getattr(card, "translations", [])

        self.mapped = sorted([{
            t: k
            for (t, k) in zip(("id", "text", "type",
                               "tree_id"), (c.id, c.text, type(c),
                                            self.tree_id(c.text, c.id)))
        } for c in maplist],
                             key=lambda x: str.lower(x.get("text", "")))
        self.report = {i.get("id"): None for i in self.mapped}

        with session_scope(self.session_factory) as sess:
            self.card_pool = self.get_card_pool(sess, self.card_type)

        # Grid Self
        self.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S))
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        # Define Text Variables
        self.title_var = tk.StringVar()
        self.pool_title_var = tk.StringVar()
        self.map_title_var = tk.StringVar()

        # Define Frames
        self.title_frame = ttk.Frame(self,
                                     borderwidth=2,
                                     relief="solid",
                                     padding="2 2 2 5")
        self.content_frame = ttk.Frame(self,
                                       borderwidth=2,
                                       relief="solid",
                                       padding="2 5 2 2")
        self.view_frame = ttk.Frame(self,
                                    borderwidth=2,
                                    relief="solid",
                                    padding="2 2 2 2")
        self.pool_frame = ttk.Frame(self.content_frame,
                                    borderwidth=2,
                                    relief="solid",
                                    padding="2 2 2 2")
        self.button_frame = ttk.Frame(self.content_frame,
                                      borderwidth=2,
                                      relief="solid",
                                      padding="2 2 2 2")
        self.mapped_frame = ttk.Frame(self.content_frame,
                                      borderwidth=2,
                                      relief="solid",
                                      padding="2 2 2 2")

        # Define Widgets
        self.title = ttk.Label(self.title_frame, textvariable=self.title_var)
        self.pool_title = ttk.Label(self.pool_frame,
                                    textvariable=self.pool_title_var)
        self.pool = ttk.Treeview(self.pool_frame, selectmode="browse")
        self.pool_scroll = ttk.Scrollbar(self.pool_frame,
                                         orient=tk.VERTICAL,
                                         command=self.pool.yview)
        self.pool.configure(yscrollcommand=self.pool_scroll.set)
        self.add_button = ttk.Button(self.button_frame,
                                     text="Add Card >>>",
                                     command=self.add_button_call)
        self.remove_button = ttk.Button(self.button_frame,
                                        text="<<< Remove Card",
                                        command=self.remove_button_call)
        self.done_button = ttk.Button(self.button_frame,
                                      text="Done",
                                      command=self.done_call)
        self.map_title = ttk.Button(self.mapped_frame,
                                    textvariable=self.map_title_var)
        self.map = ttk.Treeview(self.mapped_frame)
        self.map_scroll = ttk.Scrollbar(self.mapped_frame,
                                        orient=tk.VERTICAL,
                                        command=self.map.yview)
        self.map.configure(yscrollcommand=self.map_scroll.set)

        # Grid Widgets
        self.title_frame.grid(column=0, row=0, sticky=tk.N)
        self.content_frame.grid(column=0, row=1, sticky=tk.N)
        self.view_frame.grid(column=0, row=2, sticky=tk.S)
        self.pool_frame.grid(column=0, row=0, sticky=(tk.N, tk.S))
        self.button_frame.grid(column=1, row=0, sticky=(tk.W, tk.E))
        self.mapped_frame.grid(column=2, row=0, sticky=(tk.N, tk.S))

        self.title.grid(column=0, row=0, sticky=tk.N)

        self.pool_title.grid(column=0, row=0, sticky=tk.N)
        self.pool.grid(column=0, row=1, sticky=tk.N)
        self.pool_scroll.grid(column=1, row=1, sticky=(tk.N, tk.S))

        self.add_button.grid(column=0, row=0, sticky=(tk.W, tk.E))
        self.remove_button.grid(column=0, row=1, sticky=(tk.W, tk.E))
        self.done_button.grid(column=0, row=2, sticky=(tk.W, tk.E))

        self.map_title.grid(column=0, row=0, sticky=tk.N)
        self.map.grid(column=0, row=1, sticky=tk.N)
        self.map_scroll.grid(column=1, row=1, sticky=(tk.N, tk.S))

        # Add view triggers
        self.pool.tag_bind("card", "<<TreeviewSelect>>", self.select_call)

        self.title_var.set(maps.card_example_fields[type(card)] + " for " +
                           card.text)
        self.pool_title_var.set("pool of " +
                                maps.card_example_fields[type(card)])
        self.map_title_var.set("mapped " +
                               maps.card_example_fields[type(card)])

        self.pool.insert("", "end", "pool", text="", open=True)
        self.map.insert("", "end", "map", text="", open=True)

        #populate lists
        self.update_lists()
Ejemplo n.º 14
0
    def update_self(self):
        with session_scope(self.sf) as sess:
            self._update_self(sess)

        for c in self.descendants:
            c.view_update()
Ejemplo n.º 15
0
 def select_translation_but(self):
     with session_scope(self.sf) as sess:
         self.root.new_card_view(sess, self.trns[self.trn_ind], self.sf)
Ejemplo n.º 16
0
 def select_example_but(self):
     with session_scope(self.sf) as sess:
         self.root.new_card_view(sess, self.examples[self.ex_ind], self.sf)
Ejemplo n.º 17
0
 def update(self):
     with sessc.session_scope(self.session_factory) as sess:
         self._update(sess)