Beispiel #1
0
def read_today_all_entries(con, dt=conv.today_isodt()):
    where = """
        (entry_type IN (0, 1) AND entry_createdt = :dt) OR
        (entry_type = 2 AND :dt BETWEEN entry_startdt AND entry_enddt) OR
        (entry_type = 3 AND :dt BETWEEN entry_startdt AND entry_enddt)
    """
    orderby = "entry_type desc, entry_enddt, entry_startdt, entry_id"
    parms = {"dt": dt}

    return read_entries(con, where, orderby, parms)
Beispiel #2
0
    def __init__(self, con, **opts):
        """
        opts:
            dt              = iso date string of date param to pass to read_fn function
            read_fn         = function returning entries
            heading         = text heading to appear
            on_sel_entry    = function to call when entry item selected
            show_preview    = bool whether to show preview pane
        """
        dt = opts.get("dt", conv.today_isodt())
        read_fn = opts.get("read_fn", db.read_today_all_entries)
        heading = opts.get("heading", "")
        on_sel_entry = opts.get("on_sel_entry")
        show_preview = opts.get("show_preview", False)

        entries_lb = Gtk.ListBox()

        def on_sel(lb, row):
            if not row:
                return
            entry_id = row.entry_id
            entry = db.read_entry(self._con, entry_id)
            if not entry:
                return
            if self._preview:
                self._preview.load_entry(entry)
            if on_sel_entry:
                on_sel_entry(entry)
        entries_lb.connect("row-selected", on_sel)
        sw = ui.scrollwindow(entries_lb)

        preview = None
        if show_preview:
            preview = EntryPreview()
            vpane = Gtk.VPaned()
            vpane.add1(sw)
            vpane.add2(preview.widget())
            vpane.set_position(400)
            frame = ui.frame(vpane, "")
        else:
            frame = ui.frame(sw, "")

        self._con = con
        self._dt = dt
        self._frame = frame
        self._heading_lbl = frame.heading_lbl
        self._entries_lb = entries_lb
        self._preview = preview
        self._read_fn = read_fn
        self._heading = heading

        self.refresh()
Beispiel #3
0
def add_entry(con, entry):
    cur = con.cursor()

    entry_id = entry.get("id")
    entry_type = entry.get("type", EntryType.LOG)
    createdt = entry.get("createdt", conv.today_isodt())
    body = entry.get("body", "")
    startdt = entry.get("startdt")
    enddt = entry.get("enddt")
    status = entry.get("status", 0)
    topic_id = entry.get("topic_id", 0)

    if entry_type == EntryType.EVENT or entry_type == EntryType.TASK:
        if not startdt and not enddt:
            startdt = enddt = createdt
        elif not startdt:
            startdt = enddt
        elif not enddt:
            enddt = startdt

    sql = "INSERT OR REPLACE INTO entry (entry_id, entry_type, entry_createdt, entry_body, entry_startdt, entry_enddt, entry_status, topic_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
    cur.execute(sql, (entry_id, entry_type, createdt, body, startdt, enddt,
                      status, topic_id))
Beispiel #4
0
def read_recent_notes(con, dt=conv.today_isodt()):
    where = "entry_type = 1"
    orderby = "entry_createdt desc limit 10"
    parms = {}
    return read_entries(con, where, orderby, parms)
Beispiel #5
0
def read_today_tasks(con, dt=conv.today_isodt()):
    where = "entry_type = 3 AND :dt BETWEEN entry_startdt AND entry_enddt"
    orderby = "entry_enddt, entry_startdt, entry_id"
    parms = {"dt": dt}
    return read_entries(con, where, orderby, parms)
Beispiel #6
0
def read_today_logs(con, dt=conv.today_isodt()):
    where = "entry_type IN (0) AND entry_createdt = :dt"
    orderby = "entry_type, entry_id"
    parms = {"dt": dt}

    return read_entries(con, where, orderby, parms)
Beispiel #7
0
    def __init__(self, con, dt=None, entrytype=None, on_save=None, on_cancel=None):
        self._con = con
        if not dt:
            dt = conv.today_isodt()
        self._dt = dt

        if not entrytype:
            entrytype = db.EntryType.LOG

        frame = Gtk.Frame()
        grid = Gtk.Grid()
        grid.props.margin = 2
        grid.set_row_spacing(2)
        grid.set_column_spacing(0)
        frame.add(grid)

        heading_lbl = Gtk.Label("[New Entry]")
        heading_lbl.set_xalign(0)
        grid.attach(heading_lbl, 0,0, 1,1)

        type_cb = Gtk.ComboBoxText()
        type_cb.append_text("log")
        type_cb.append_text("note")
        type_cb.append_text("event")
        type_cb.append_text("task")
        type_cb.set_active(entrytype)
        type_cb.set_halign(Gtk.Align.END)
        grid.attach(type_cb, 4,0, 1,1)

        y = 1

        body_tv = Gtk.TextView()
        body_tv.set_wrap_mode(Gtk.WrapMode.WORD)
        sw = ui.scrollwindow(body_tv)
        grid.attach(sw, 0,y, 5,1)
        y += 1

        startdt_chk = Gtk.CheckButton("Start on")
        startdt_entry = Gtk.Entry()
        grid.attach(startdt_chk, 0,y, 1,1)
        grid.attach(startdt_entry, 1,y, 1,1)
        y += 1

        enddt_chk = Gtk.CheckButton("End on")
        enddt_entry = Gtk.Entry()
        grid.attach(enddt_chk, 0,y, 1,1)
        grid.attach(enddt_entry, 1,y, 1,1)
        y += 1

        status_lbl = Gtk.Label("Status")
        status_lbl.set_xalign(0)
        status_cb = Gtk.ComboBoxText()
        status_cb.append_text("Open")
        status_cb.append_text("Closed")
        status_cb.set_active(0)
        grid.attach(status_lbl, 0,y, 1,1)
        grid.attach(status_cb, 1,y, 1,1)
        y += 1

        lbl = Gtk.Label("Assign to topic")
        lbl.set_xalign(0)
        topic_cb = Gtk.ComboBoxText.new_with_entry()
        topic_cb.append_text("Unassigned")
        topic_cb.append_text("Cats")
        topic_cb.append_text("The Blog")
        topic_cb.set_active(0)
        grid.attach(lbl, 0,y, 1,1)
        grid.attach(topic_cb, 1,y, 1,1)
        y += 1

        save = Gtk.Button("Save")
        cancel = Gtk.Button("Cancel")
        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
        hbox.pack_start(save, False, False, 0)
        hbox.pack_start(cancel, False, False, 0)
        grid.attach(hbox, 0,y, 5,1)
        y += 1

        def show_chk_entry(chk, entry):
            if chk.get_active():
                entry.set_sensitive(True)
            else:
                entry.set_sensitive(False)

        show_chk_entry(startdt_chk, startdt_entry)
        show_chk_entry(enddt_chk, enddt_entry)

        type_cb.connect("changed", self.show_visible_widgets)
        startdt_chk.connect("toggled", show_chk_entry, startdt_entry) 
        enddt_chk.connect("toggled", show_chk_entry, enddt_entry) 

        def on_save_clicked(w):
            entry = self.get_entry()
            db.add_entry(self._con, entry)
            db.commit(self._con)
            self.clear()

            if self.on_save:
                self.on_save(entry)
        save.connect("clicked", on_save_clicked)

        def on_cancel_clicked(w):
            if self.on_cancel:
                self.on_cancel()
        cancel.connect("clicked", on_cancel_clicked)

        self._frame = frame
        self._grid = grid

        self._entry_id = None
        self._type_cb = type_cb
        self._heading_lbl = heading_lbl
        self._body_tv = body_tv
        self._startdt_chk = startdt_chk
        self._enddt_chk = enddt_chk
        self._startdt_entry = startdt_entry
        self._enddt_entry = enddt_entry
        self._status_lbl = status_lbl
        self._status_cb = status_cb
        self._topic_cb = topic_cb
        self.savebtn = save
        self.cancelbtn = cancel
        self.on_save = on_save
        self.on_cancel = on_cancel

        self.refresh_heading()