コード例 #1
0
ファイル: search_events.py プロジェクト: Noori/starcal
 def __init__(self, showDesc=False):
     gtk.Window.__init__(self)
     self.initVars()
     ud.windowList.appendItem(self)
     ###
     self.set_title(_('Search Events'))
     self.connect('delete-event', self.closed)
     self.connect('key-press-event', self.keyPress)
     ###
     self.vbox = gtk.VBox()
     self.add(self.vbox)
     ######
     frame = TextFrame()
     frame.set_label(_('Text'))
     frame.set_border_width(5)
     pack(self.vbox, frame)
     self.textInput = frame
     ##
     hbox = gtk.HBox()
     self.textCSensCheck = gtk.CheckButton(_('Case Sensitive'))
     self.textCSensCheck.set_active(False) ## FIXME
     pack(hbox, self.textCSensCheck)
     pack(self.vbox, hbox)
     ######
     jd = core.getCurrentJd()
     year, month, day = jd_to_primary(jd)
     ######
     hbox = gtk.HBox()
     frame = gtk.Frame(_('Time'))
     frame.set_border_width(5)
     vboxIn = gtk.VBox()
     sgroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
     ####
     hboxIn = gtk.HBox()
     ##
     self.timeFromCheck = gtk.CheckButton(_('From'))
     sgroup.add_widget(self.timeFromCheck)
     pack(hboxIn, self.timeFromCheck)
     pack(hboxIn, gtk.Label('  '))
     ##
     self.timeFromInput = DateTimeButton()
     self.timeFromInput.set_value(((year, 1, 1), (0, 0, 0)))
     pack(hboxIn, self.timeFromInput)
     ##
     pack(vboxIn, hboxIn)
     ####
     hboxIn = gtk.HBox()
     ##
     self.timeToCheck = gtk.CheckButton(_('To'))
     sgroup.add_widget(self.timeToCheck)
     pack(hboxIn, self.timeToCheck)
     pack(hboxIn, gtk.Label('  '))
     ##
     self.timeToInput = DateTimeButton()
     self.timeToInput.set_value(((year+1, 1, 1), (0, 0, 0)))
     pack(hboxIn, self.timeToInput)
     ##
     pack(vboxIn, hboxIn)
     ##
     self.timeFromCheck.connect('clicked', self.updateTimeFromSensitive)
     self.timeToCheck.connect('clicked', self.updateTimeToSensitive)
     self.updateTimeFromSensitive()
     self.updateTimeToSensitive()
     ####
     vboxIn.set_border_width(5)
     frame.add(vboxIn)
     pack(hbox, frame)
     pack(hbox, gtk.Label(''), 1, 1)
     pack(self.vbox, hbox)
     ######
     hbox = gtk.HBox()
     hbox.set_border_width(5)
     self.modifiedFromCheck = gtk.CheckButton(_('Modified From'))
     pack(hbox, self.modifiedFromCheck)
     pack(hbox, gtk.Label('  '))
     self.modifiedFromInput = DateTimeButton()
     self.modifiedFromInput.set_value(((year, 1, 1), (0, 0, 0)))
     pack(hbox, self.modifiedFromInput)
     ##
     self.modifiedFromCheck.connect('clicked', self.updateModifiedFromSensitive)
     self.updateModifiedFromSensitive()
     pack(self.vbox, hbox)
     ######
     hbox = gtk.HBox()
     hbox.set_border_width(5)
     self.typeCheck = gtk.CheckButton(_('Event Type'))
     pack(hbox, self.typeCheck)
     pack(hbox, gtk.Label('  '))
     ##
     combo = gtk.combo_box_new_text()
     for cls in event_lib.classes.event:
         combo.append_text(cls.desc)
     combo.set_active(0)
     pack(hbox, combo)
     self.typeCombo = combo
     ##
     self.typeCheck.connect('clicked', self.updateTypeSensitive)
     self.updateTypeSensitive()
     pack(self.vbox, hbox)
     ######
     hbox = gtk.HBox()
     hbox.set_border_width(5)
     self.groupCheck = gtk.CheckButton(_('Group'))
     pack(hbox, self.groupCheck)
     pack(hbox, gtk.Label('  '))
     self.groupCombo = SingleGroupComboBox()
     pack(hbox, self.groupCombo)
     ##
     self.groupCheck.connect('clicked', self.updateGroupSensitive)
     self.updateGroupSensitive()
     pack(self.vbox, hbox)
     ######
     bbox = gtk.HButtonBox()
     bbox.set_layout(gtk.BUTTONBOX_START)
     bbox.set_border_width(5)
     searchButton = gtk.Button()
     searchButton.set_label(_('_Search'))
     searchButton.set_image(gtk.image_new_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_BUTTON))
     searchButton.connect('clicked', self.searchClicked)
     bbox.add(searchButton)
     pack(self.vbox, bbox)
     ######
     treev = gtk.TreeView()
     trees = gtk.TreeStore(int, int, str, gdk.Pixbuf, str, str)
     ## gid, eid, group_name, icon, summary, description
     treev.set_model(trees)
     treev.connect('row-activated', self.rowActivated)
     treev.set_headers_clickable(True)
     ###
     self.colGroup = gtk.TreeViewColumn(_('Group'), gtk.CellRendererText(), text=2)
     self.colGroup.set_resizable(True)
     self.colGroup.set_sort_column_id(2)
     treev.append_column(self.colGroup)
     ###
     self.colIcon = gtk.TreeViewColumn()
     cell = gtk.CellRendererPixbuf()
     pack(self.colIcon, cell)
     self.colIcon.add_attribute(cell, 'pixbuf', 3)
     #self.colIcon.set_sort_column_id(3)## FIXME
     treev.append_column(self.colIcon)
     ###
     self.colSummary = gtk.TreeViewColumn(_('Summary'), gtk.CellRendererText(), text=4)
     self.colSummary.set_resizable(True)
     self.colSummary.set_sort_column_id(4)
     treev.append_column(self.colSummary)
     ###
     self.colDesc = gtk.TreeViewColumn(_('Description'), gtk.CellRendererText(), text=5)
     self.colDesc.set_sort_column_id(5)
     self.colDesc.set_visible(showDesc)
     treev.append_column(self.colDesc)
     ###
     trees.set_sort_func(2, self.sort_func_group)
     ######
     swin = gtk.ScrolledWindow()
     swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
     swin.add(treev)
     ####
     vbox = gtk.VBox(spacing=5)
     vbox.set_border_width(5)
     ###
     topHbox = gtk.HBox()
     self.resultLabel = gtk.Label('')
     pack(topHbox, self.resultLabel)
     pack(topHbox, gtk.Label(''), 1, 1)
     pack(vbox, topHbox)
     ####
     columnBox = gtk.HBox(spacing=5)
     pack(columnBox, gtk.Label(_('Columns')+':    '))
     ##
     check = gtk.CheckButton(_('Group'))
     check.set_active(True)
     check.connect('clicked', lambda w: self.colGroup.set_visible(w.get_active()))
     pack(columnBox, check)
     ##
     check = gtk.CheckButton(_('Icon'))
     check.set_active(True)
     check.connect('clicked', lambda w: self.colIcon.set_visible(w.get_active()))
     pack(columnBox, check)
     ##
     check = gtk.CheckButton(_('Summary'))
     check.set_active(True)
     check.connect('clicked', lambda w: self.colSummary.set_visible(w.get_active()))
     pack(columnBox, check)
     ##
     check = gtk.CheckButton(_('Description'))
     check.set_active(showDesc)
     check.connect('clicked', lambda w: self.colDesc.set_visible(w.get_active()))
     pack(columnBox, check)
     ##
     pack(vbox, columnBox)
     ####
     pack(vbox, swin, 1, 1)
     ##
     frame = gtk.Frame(_('Search Results'))
     frame.set_border_width(10)
     frame.add(vbox)
     ##
     pack(self.vbox, frame, 1, 1)
     ###
     bbox2 = gtk.HButtonBox()
     bbox2.set_layout(gtk.BUTTONBOX_END)
     bbox2.set_border_width(10)
     closeButton = gtk.Button()
     closeButton.set_label(_('_Close'))
     closeButton.set_image(gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_BUTTON))
     closeButton.connect('clicked', self.closed)
     bbox2.add(closeButton)
     pack(self.vbox, bbox2)
     ######
     self.treev = treev
     self.trees = trees
     self.vbox.show_all()
コード例 #2
0
ファイル: search_events.py プロジェクト: Noori/starcal
class EventSearchWindow(gtk.Window, MyDialog, ud.IntegratedCalObj):
    def __init__(self, showDesc=False):
        gtk.Window.__init__(self)
        self.initVars()
        ud.windowList.appendItem(self)
        ###
        self.set_title(_('Search Events'))
        self.connect('delete-event', self.closed)
        self.connect('key-press-event', self.keyPress)
        ###
        self.vbox = gtk.VBox()
        self.add(self.vbox)
        ######
        frame = TextFrame()
        frame.set_label(_('Text'))
        frame.set_border_width(5)
        pack(self.vbox, frame)
        self.textInput = frame
        ##
        hbox = gtk.HBox()
        self.textCSensCheck = gtk.CheckButton(_('Case Sensitive'))
        self.textCSensCheck.set_active(False) ## FIXME
        pack(hbox, self.textCSensCheck)
        pack(self.vbox, hbox)
        ######
        jd = core.getCurrentJd()
        year, month, day = jd_to_primary(jd)
        ######
        hbox = gtk.HBox()
        frame = gtk.Frame(_('Time'))
        frame.set_border_width(5)
        vboxIn = gtk.VBox()
        sgroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
        ####
        hboxIn = gtk.HBox()
        ##
        self.timeFromCheck = gtk.CheckButton(_('From'))
        sgroup.add_widget(self.timeFromCheck)
        pack(hboxIn, self.timeFromCheck)
        pack(hboxIn, gtk.Label('  '))
        ##
        self.timeFromInput = DateTimeButton()
        self.timeFromInput.set_value(((year, 1, 1), (0, 0, 0)))
        pack(hboxIn, self.timeFromInput)
        ##
        pack(vboxIn, hboxIn)
        ####
        hboxIn = gtk.HBox()
        ##
        self.timeToCheck = gtk.CheckButton(_('To'))
        sgroup.add_widget(self.timeToCheck)
        pack(hboxIn, self.timeToCheck)
        pack(hboxIn, gtk.Label('  '))
        ##
        self.timeToInput = DateTimeButton()
        self.timeToInput.set_value(((year+1, 1, 1), (0, 0, 0)))
        pack(hboxIn, self.timeToInput)
        ##
        pack(vboxIn, hboxIn)
        ##
        self.timeFromCheck.connect('clicked', self.updateTimeFromSensitive)
        self.timeToCheck.connect('clicked', self.updateTimeToSensitive)
        self.updateTimeFromSensitive()
        self.updateTimeToSensitive()
        ####
        vboxIn.set_border_width(5)
        frame.add(vboxIn)
        pack(hbox, frame)
        pack(hbox, gtk.Label(''), 1, 1)
        pack(self.vbox, hbox)
        ######
        hbox = gtk.HBox()
        hbox.set_border_width(5)
        self.modifiedFromCheck = gtk.CheckButton(_('Modified From'))
        pack(hbox, self.modifiedFromCheck)
        pack(hbox, gtk.Label('  '))
        self.modifiedFromInput = DateTimeButton()
        self.modifiedFromInput.set_value(((year, 1, 1), (0, 0, 0)))
        pack(hbox, self.modifiedFromInput)
        ##
        self.modifiedFromCheck.connect('clicked', self.updateModifiedFromSensitive)
        self.updateModifiedFromSensitive()
        pack(self.vbox, hbox)
        ######
        hbox = gtk.HBox()
        hbox.set_border_width(5)
        self.typeCheck = gtk.CheckButton(_('Event Type'))
        pack(hbox, self.typeCheck)
        pack(hbox, gtk.Label('  '))
        ##
        combo = gtk.combo_box_new_text()
        for cls in event_lib.classes.event:
            combo.append_text(cls.desc)
        combo.set_active(0)
        pack(hbox, combo)
        self.typeCombo = combo
        ##
        self.typeCheck.connect('clicked', self.updateTypeSensitive)
        self.updateTypeSensitive()
        pack(self.vbox, hbox)
        ######
        hbox = gtk.HBox()
        hbox.set_border_width(5)
        self.groupCheck = gtk.CheckButton(_('Group'))
        pack(hbox, self.groupCheck)
        pack(hbox, gtk.Label('  '))
        self.groupCombo = SingleGroupComboBox()
        pack(hbox, self.groupCombo)
        ##
        self.groupCheck.connect('clicked', self.updateGroupSensitive)
        self.updateGroupSensitive()
        pack(self.vbox, hbox)
        ######
        bbox = gtk.HButtonBox()
        bbox.set_layout(gtk.BUTTONBOX_START)
        bbox.set_border_width(5)
        searchButton = gtk.Button()
        searchButton.set_label(_('_Search'))
        searchButton.set_image(gtk.image_new_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_BUTTON))
        searchButton.connect('clicked', self.searchClicked)
        bbox.add(searchButton)
        pack(self.vbox, bbox)
        ######
        treev = gtk.TreeView()
        trees = gtk.TreeStore(int, int, str, gdk.Pixbuf, str, str)
        ## gid, eid, group_name, icon, summary, description
        treev.set_model(trees)
        treev.connect('row-activated', self.rowActivated)
        treev.set_headers_clickable(True)
        ###
        self.colGroup = gtk.TreeViewColumn(_('Group'), gtk.CellRendererText(), text=2)
        self.colGroup.set_resizable(True)
        self.colGroup.set_sort_column_id(2)
        treev.append_column(self.colGroup)
        ###
        self.colIcon = gtk.TreeViewColumn()
        cell = gtk.CellRendererPixbuf()
        pack(self.colIcon, cell)
        self.colIcon.add_attribute(cell, 'pixbuf', 3)
        #self.colIcon.set_sort_column_id(3)## FIXME
        treev.append_column(self.colIcon)
        ###
        self.colSummary = gtk.TreeViewColumn(_('Summary'), gtk.CellRendererText(), text=4)
        self.colSummary.set_resizable(True)
        self.colSummary.set_sort_column_id(4)
        treev.append_column(self.colSummary)
        ###
        self.colDesc = gtk.TreeViewColumn(_('Description'), gtk.CellRendererText(), text=5)
        self.colDesc.set_sort_column_id(5)
        self.colDesc.set_visible(showDesc)
        treev.append_column(self.colDesc)
        ###
        trees.set_sort_func(2, self.sort_func_group)
        ######
        swin = gtk.ScrolledWindow()
        swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        swin.add(treev)
        ####
        vbox = gtk.VBox(spacing=5)
        vbox.set_border_width(5)
        ###
        topHbox = gtk.HBox()
        self.resultLabel = gtk.Label('')
        pack(topHbox, self.resultLabel)
        pack(topHbox, gtk.Label(''), 1, 1)
        pack(vbox, topHbox)
        ####
        columnBox = gtk.HBox(spacing=5)
        pack(columnBox, gtk.Label(_('Columns')+':    '))
        ##
        check = gtk.CheckButton(_('Group'))
        check.set_active(True)
        check.connect('clicked', lambda w: self.colGroup.set_visible(w.get_active()))
        pack(columnBox, check)
        ##
        check = gtk.CheckButton(_('Icon'))
        check.set_active(True)
        check.connect('clicked', lambda w: self.colIcon.set_visible(w.get_active()))
        pack(columnBox, check)
        ##
        check = gtk.CheckButton(_('Summary'))
        check.set_active(True)
        check.connect('clicked', lambda w: self.colSummary.set_visible(w.get_active()))
        pack(columnBox, check)
        ##
        check = gtk.CheckButton(_('Description'))
        check.set_active(showDesc)
        check.connect('clicked', lambda w: self.colDesc.set_visible(w.get_active()))
        pack(columnBox, check)
        ##
        pack(vbox, columnBox)
        ####
        pack(vbox, swin, 1, 1)
        ##
        frame = gtk.Frame(_('Search Results'))
        frame.set_border_width(10)
        frame.add(vbox)
        ##
        pack(self.vbox, frame, 1, 1)
        ###
        bbox2 = gtk.HButtonBox()
        bbox2.set_layout(gtk.BUTTONBOX_END)
        bbox2.set_border_width(10)
        closeButton = gtk.Button()
        closeButton.set_label(_('_Close'))
        closeButton.set_image(gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_BUTTON))
        closeButton.connect('clicked', self.closed)
        bbox2.add(closeButton)
        pack(self.vbox, bbox2)
        ######
        self.treev = treev
        self.trees = trees
        self.vbox.show_all()
        #self.maximize()## FIXME
    ## FIXME
    sort_func_group = lambda self, model, iter1, iter2: cmp(
        ui.eventGroups.index(model.get(iter1, 0)[0]),
        ui.eventGroups.index(model.get(iter2, 0)[0]),
    )
    def updateTimeFromSensitive(self, obj=None):
        self.timeFromInput.set_sensitive(self.timeFromCheck.get_active())
    def updateTimeToSensitive(self, obj=None):
        self.timeToInput.set_sensitive(self.timeToCheck.get_active())
    def updateModifiedFromSensitive(self, obj=None):
        self.modifiedFromInput.set_sensitive(self.modifiedFromCheck.get_active())
    def updateTypeSensitive(self, obj=None):
        self.typeCombo.set_sensitive(self.typeCheck.get_active())
    def updateGroupSensitive(self, obj=None):
        self.groupCombo.set_sensitive(self.groupCheck.get_active())
    def _do_search(self):
        if self.groupCheck.get_active():
            groupIds = [
                self.groupCombo.get_active()
            ]
        else:
            groupIds = ui.eventGroups.getEnableIds()
        ###
        conds = {}
        if self.textCSensCheck.get_active():
            conds['text'] = self.textInput.get_text()
        else:
            conds['text_lower'] = self.textInput.get_text().lower()
        if self.timeFromCheck.get_active():
            conds['time_from'] = self.timeFromInput.get_epoch(calTypes.primary)
        if self.timeToCheck.get_active():
            conds['time_to'] = self.timeToInput.get_epoch(calTypes.primary)
        if self.modifiedFromCheck.get_active():
            conds['modified_from'] = self.modifiedFromInput.get_epoch(calTypes.primary)
        if self.typeCheck.get_active():
            index = self.typeCombo.get_active()
            cls = event_lib.classes.event[index]
            conds['type'] = cls.name
        ###
        self.trees.clear()
        for gid in groupIds:
            group = ui.eventGroups[gid]
            for evData in group.search(conds):
                self.trees.append(None, (
                    group.id,
                    evData['id'],
                    group.title,
                    pixbufFromFile(evData['icon']),
                    evData['summary'],
                    evData['description'],
                ))
        self.resultLabel.set_label(_('Found %s events')%_(len(self.trees)))
    def searchClicked(self, obj=None):
        self.waitingDo(self._do_search)
    def rowActivated(self, treev, path, col):
        try:
            gid = self.trees[path][0]
            eid = self.trees[path][1]
        except:
            return
        group = ui.eventGroups[gid]
        event = group[eid]
        event = EventEditorDialog(
            event,
            title=_('Edit ')+event.desc,
            parent=self,
        ).run()
        if event is None:
            return
        ui.reloadGroups.append(gid)
        eventIter = self.trees.get_iter(path)
        self.trees.set_value(eventIter, 3, pixbufFromFile(event.icon))
        self.trees.set_value(eventIter, 4, event.summary)
        self.trees.set_value(eventIter, 5, event.getShownDescription())
    def clearResults(self):
        self.trees.clear()
        self.resultLabel.set_label('')
    def closed(self, obj=None, event=None):
        self.hide()
        self.clearResults()
        self.onConfigChange()
        return True
    def present(self):
        self.groupCombo.updateItems()
        gtk.Window.present(self)
    def keyPress(self, arg, gevent):
        kname = gdk.keyval_name(gevent.keyval).lower()
        if kname == 'escape':
            self.closed()
            return True
        return False