예제 #1
0
    def test_store_and_delete(self):
        def lookup():
            bread = DBHandler.lookup_bread(0, 3, 1)

        DBHandler.store_bread(self.bread)
        DBHandler.delete_bread(0, 3, 1)
        self.assertRaises(DBLookupError, lookup)
예제 #2
0
    def test_store_and_delete(self):
        def lookup():
            bread = DBHandler.lookup_bread(0, 3, 1)

        DBHandler.store_bread(self.bread)
        DBHandler.delete_bread(0, 3, 1)
        self.assertRaises(DBLookupError, lookup)
예제 #3
0
    def callback_bread_delete(self, *args, **kwargs):
        flag_delete = tkMessageBox.askokcancel(
            'DailyBread',
            u'날짜 %04d.%02d.%02d의 양식을 정말로 삭제하시겠습니까? 양식을'
            u' 삭제하면 작성하신 소감이 저장소에서 삭제되며, 후에 양식을'
            u' 다시 열 때 인터넷 접속이 필요합니다.' % (
                self.bread.year, self.bread.month, self.bread.day
            )
        )

        if not flag_delete:
            self.write_status(u'양식 삭제가 취소되었습니다.')
            return

        try:
            DBHandler.delete_bread(
                self.bread.year, self.bread.month, self.bread.day
            )
        except DBDeleteError:
            self.write_status(u'에러가 발생했습니다.')
            self.raise_error(u'양식 삭제에 실패했습니다.')
            return

        self.write_status(
            u'날짜 %04d.%02d.%02d에 해당하는 양식을 저장소에서'
            u' 삭제했습니다.' % (
                self.bread.year, self.bread.month, self.bread.day
            )
        )
예제 #4
0
    def callback_bread_save(self, *args, **kwargs):
        self.bread.thoughts = self.text_thoughts.get('1.0', tk.END).strip()
        self.thoughts_prev = self.bread.thoughts

        try:
            DBHandler.store_bread(self.bread)
        except DBStoreError:
            self.write_status(u'에러가 발생했습니다.')

            self.raise_error(u'양식을 저장하는데에 실패했습니다. 저장소 파일'
                             u'(storage.db)이 손상되었을 수 있습니다.')

        self.write_status(u'양식을 저장소에 성공적으로 저장했습니다.')
예제 #5
0
    def callback_bread_save(self, *args, **kwargs):
        self.bread.thoughts = self.text_thoughts.get('1.0', tk.END).strip()
        self.thoughts_prev = self.bread.thoughts

        try:
            DBHandler.store_bread(self.bread)
        except DBStoreError:
            self.write_status(u'에러가 발생했습니다.')

            self.raise_error(
                u'양식을 저장하는데에 실패했습니다. 저장소 파일'
                u'(storage.db)이 손상되었을 수 있습니다.'
            )

        self.write_status(u'양식을 저장소에 성공적으로 저장했습니다.')
예제 #6
0
    def callback_bread_delete(self, *args, **kwargs):
        flag_delete = tkMessageBox.askokcancel(
            'DailyBread', u'날짜 %04d.%02d.%02d의 양식을 정말로 삭제하시겠습니까? 양식을'
            u' 삭제하면 작성하신 소감이 저장소에서 삭제되며, 후에 양식을'
            u' 다시 열 때 인터넷 접속이 필요합니다.' %
            (self.bread.year, self.bread.month, self.bread.day))

        if not flag_delete:
            self.write_status(u'양식 삭제가 취소되었습니다.')
            return

        try:
            DBHandler.delete_bread(self.bread.year, self.bread.month,
                                   self.bread.day)
        except DBDeleteError:
            self.write_status(u'에러가 발생했습니다.')
            self.raise_error(u'양식 삭제에 실패했습니다.')
            return

        self.write_status(u'날짜 %04d.%02d.%02d에 해당하는 양식을 저장소에서'
                          u' 삭제했습니다.' %
                          (self.bread.year, self.bread.month, self.bread.day))
예제 #7
0
    def update_bread(self, year, month, day):
        # try to load the bread from DB
        flag_stored = True

        try:
            bread = DBHandler.lookup_bread(year, month, day)
        except DBLookupError:
            bread = None  # for suppressing PyCharm warning
            flag_stored = False

        if flag_stored:
            self.write_status(
                u'저장소에서 날짜 %04d.%02d.%02d에 해당하는 양식을'
                u' 성공적으로 불러왔습니다.' % (year, month, day)
            )
            self.bread = bread
            self.thoughts_prev = self.bread.thoughts
            return

        # try to load the bread from the Internet
        try:
            bread = Downloader.get_bread(year, month, day)
        except ConnectionError:
            self.write_status(u'에러가 발생했습니다.')

            self.raise_error(
                u'웹사이트 연결에 실패했습니다. 인터넷 연결 상태를'
                u' 확인해 보십시오.'
            )

            return
        except InvalidDateError:
            self.write_status(u'에러가 발생했습니다.')

            self.raise_error(
                u'웹사이트에서 양식을 다운받는데에 실패했습니다.'
                u' 웹사이트에 아직 양식이 업데이트되지 않았을 수 있습니다.'
            )

            return

        self.bread = bread
        self.thoughts_prev = self.bread.thoughts

        self.write_status(
            u'인터넷에서 날짜 %04d.%02d.%02d에 해당하는 양식을 성공적으로'
            u' 불러왔습니다.' % (year, month, day)
        )
예제 #8
0
    def update_bread(self, year, month, day):
        # try to load the bread from DB
        flag_stored = True

        try:
            bread = DBHandler.lookup_bread(year, month, day)
        except DBLookupError:
            bread = None  # for suppressing PyCharm warning
            flag_stored = False

        if flag_stored:
            self.write_status(u'저장소에서 날짜 %04d.%02d.%02d에 해당하는 양식을'
                              u' 성공적으로 불러왔습니다.' % (year, month, day))
            self.bread = bread
            self.thoughts_prev = self.bread.thoughts
            return

        # try to load the bread from the Internet
        try:
            bread = Downloader.get_bread(year, month, day)
        except ConnectionError:
            self.write_status(u'에러가 발생했습니다.')

            self.raise_error(u'웹사이트 연결에 실패했습니다. 인터넷 연결 상태를' u' 확인해 보십시오.')

            return
        except InvalidDateError:
            self.write_status(u'에러가 발생했습니다.')

            self.raise_error(u'웹사이트에서 양식을 다운받는데에 실패했습니다.'
                             u' 웹사이트에 아직 양식이 업데이트되지 않았을 수 있습니다.')

            return

        self.bread = bread
        self.thoughts_prev = self.bread.thoughts

        self.write_status(u'인터넷에서 날짜 %04d.%02d.%02d에 해당하는 양식을 성공적으로'
                          u' 불러왔습니다.' % (year, month, day))
예제 #9
0
 def lookup():
     bread = DBHandler.lookup_bread(0, 3, 1)
예제 #10
0
 def test_store_and_lookup(self):
     DBHandler.store_bread(self.bread)
     bread = DBHandler.lookup_bread(0, 3, 1)
     self.assertEqual(bread.month, 3)
     self.assertEqual(bread.day, 1)
예제 #11
0
    def test_get_dates(self):
        DBHandler.store_bread(Bread(year=0, month=2, day=1))
        DBHandler.store_bread(Bread(year=0, month=4, day=2))
        DBHandler.store_bread(Bread(year=0, month=6, day=3))

        list_dates = DBHandler.get_dates()

        self.assertIn((0, 2, 1), list_dates)
        self.assertIn((0, 4, 2), list_dates)
        self.assertIn((0, 6, 3), list_dates)

        DBHandler.delete_bread(0, 2, 1)
        DBHandler.delete_bread(0, 4, 2)
        DBHandler.delete_bread(0, 6, 3)
예제 #12
0
 def lookup():
     bread = DBHandler.lookup_bread(0, 3, 1)
예제 #13
0
 def test_store_and_lookup(self):
     DBHandler.store_bread(self.bread)
     bread = DBHandler.lookup_bread(0, 3, 1)
     self.assertEqual(bread.month, 3)
     self.assertEqual(bread.day, 1)
예제 #14
0
    def __init__(self, root=None):
        self.root = root
        self.style = Data.style['selector']
        self.image_icon = tk.PhotoImage(data=Data.icon)

        super(Selector, self).__init__(self.root)

        self.root.wm_title(u'양식 찾기')
        self.root.protocol('WM_DELETE_WINDOW', self.callback_quit)
        self.root.resizable(0, 0)

        # -----------------------------------------------
        # frames

        self.frame_calendar = tk.Frame(self)
        self.frame_control = tk.Frame(self)

        self.frame_calendar.pack()
        self.frame_control.pack(pady=3)

        self.frame_header = tk.Frame(self.frame_calendar)
        self.frame_board = tk.Frame(self.frame_calendar)

        self.frame_header.pack(expand=tk.YES, fill=tk.BOTH)
        self.frame_board.pack()

        # -----------------------------------------------
        # header

        self.label_header = tk.Label(self.frame_header, text=u'0000년 00월')

        self.button_prev = tk.Button(self.frame_header,
                                     text=u'\u25C0',
                                     command=self.callback_prev)

        self.button_next = tk.Button(self.frame_header,
                                     text=u'\u25B6',
                                     command=self.callback_next)

        self.button_prev.pack(side=tk.LEFT, padx=10)
        self.label_header.pack(side=tk.LEFT, expand=tk.YES, fill=tk.BOTH)
        self.button_next.pack(side=tk.RIGHT, padx=10)

        # -----------------------------------------------
        # board

        self.canvas_board = tk.Canvas(self.frame_board)
        self.canvas_board.pack()

        # -----------------------------------------------
        # control

        self.button_ok = tk.Button(self.frame_control,
                                   text=u'     확인     ',
                                   command=self.callback_ok)

        self.button_cancel = tk.Button(self.frame_control,
                                       text=u'     취소     ',
                                       command=self.callback_cancel)

        self.button_ok.pack(side=tk.LEFT, padx=15)
        self.button_cancel.pack(side=tk.RIGHT, padx=15)

        # -----------------------------------------------
        # configuration

        self.frame_header.configure(bg=self.style['label']['header']['bg'])

        self.label_header.configure(
            height=2,
            font=(self.style['label']['header']['font'],
                  self.style['label']['header']['size'],
                  self.style['label']['header']['style']),
            bg=self.style['label']['header']['bg'],
            fg=self.style['label']['header']['fg'])

        self.canvas_board.configure(
            width=self.style['canvas']['board']['cell_width'] * 7,
            height=self.style['canvas']['board']['cell_height'] * 7,
            highlightthickness=0)

        # -----------------------------------------------
        # canvas items

        map_weekdays = [u'일', u'월', u'화', u'수', u'목', u'금', u'토']

        self.bg_weekdays = [None] * 7
        self.str_weekdays = [None] * 7
        self.bg_days = [[None] * 7 for i in xrange(6)]
        self.str_days = [[None] * 7 for i in xrange(6)]
        self.bg_checks = [[None] * 7 for i in xrange(6)]

        w = self.style['canvas']['board']['cell_width']
        h = self.style['canvas']['board']['cell_height']

        for i in xrange(7):
            self.bg_weekdays[i] = self.canvas_board.create_rectangle(
                w * i,
                0,
                w * (i + 1),
                h,
                fill=self.style['item']['weekdays']['bg'],
                outline='')

            self.str_weekdays[i] = self.canvas_board.create_text(
                w * i + w / 2,
                h / 2,
                text=map_weekdays[i],
                font=(self.style['item']['weekdays']['font'],
                      self.style['item']['weekdays']['size'],
                      self.style['item']['weekdays']['style']),
                fill=self.style['item']['weekdays']['fg'])

        for i in xrange(6):
            for j in xrange(7):
                self.bg_days[i][j] = self.canvas_board.create_rectangle(
                    w * j,
                    h * (i + 1),
                    w * (j + 1),
                    h * (i + 2),
                    fill=self.style['item']['days']['bg'],
                    outline='')

                self.bg_checks[i][j] = (
                    self.canvas_board.create_line(
                        w * j + w / 4,
                        h * (i + 1) + (h * 3) / 8,
                        w * j + w / 2,
                        h * (i + 1) + (h * 3) / 4,
                        fill=self.style['item']['checks']['bg'],
                        width=3),
                    self.canvas_board.create_line(
                        w * j + w / 2,
                        h * (i + 1) + (h * 3) / 4,
                        w * j + (w * 3) / 4,
                        h * (i + 1) + h / 4,
                        fill=self.style['item']['checks']['bg'],
                        width=3))

                self.str_days[i][j] = self.canvas_board.create_text(
                    w * j + w / 2,
                    h * (i + 1) + h / 2,
                    text='00',
                    font=(self.style['item']['days']['font'],
                          self.style['item']['days']['size'],
                          self.style['item']['days']['style']),
                    fill=self.style['item']['days']['fg'])

        # -----------------------------------------------
        # bindings

        self.canvas_board.bind('<ButtonPress-1>', self.callback_select)

        self.root.bind('<Return>', self.callback_ok)
        self.root.bind('<Escape>', self.callback_quit)

        self.root.bind('<Left>', self.callback_move_left)
        self.root.bind('<Right>', self.callback_move_right)
        self.root.bind('<Up>', self.callback_move_up)
        self.root.bind('<Down>', self.callback_move_down)

        # -----------------------------------------------
        # initialization

        try:
            self.dates_checked = DBHandler.get_dates()
        except DBKeyListError:
            tkMessageBox.showerror(
                'DailyBread', u'저장소에 저장된 날짜 목록을 불러오는데에 실패했습니다.'
                u' 저장소 파일(storage.db)이 손상되었을 수 있습니다.')

        self.year, self.month, self.day = Timetools.get_today()
        self.table_days = [[0] * 7 for i in xrange(6)]
        self.coor_selected = (0, 0)
        self.result = None

        self.update_table()
        self.update_header()
        self.update_board()

        self.select_day(*self.get_ij(self.day))
예제 #15
0
    def test_get_dates(self):
        DBHandler.store_bread(Bread(year=0, month=2, day=1))
        DBHandler.store_bread(Bread(year=0, month=4, day=2))
        DBHandler.store_bread(Bread(year=0, month=6, day=3))

        list_dates = DBHandler.get_dates()

        self.assertIn((0, 2, 1), list_dates)
        self.assertIn((0, 4, 2), list_dates)
        self.assertIn((0, 6, 3), list_dates)

        DBHandler.delete_bread(0, 2, 1)
        DBHandler.delete_bread(0, 4, 2)
        DBHandler.delete_bread(0, 6, 3)
예제 #16
0
 def tearDown(self):
     DBHandler.run_command(
         'DELETE FROM storage WHERE SUBSTR(date, 1, 4)=\'0000\''
     )
예제 #17
0
 def tearDown(self):
     DBHandler.run_command(
         'DELETE FROM storage WHERE SUBSTR(date, 1, 4)=\'0000\'')