예제 #1
0
 def build_location_option_widget(box, node, label, option):
     label_widget = g.Label(label)
     value_widget = g.Label()
     button = g.Button(stock=g.STOCK_FIND)
     box.may_add_tip(button, node)
 
     box.handlers[option] = (lambda: str(value_widget.get_label()), 
                             lambda: value_widget.set_label(option.value))
 
     def button_clicked(button):
         def dialog_response(dialog, response):
             if response == g.RESPONSE_ACCEPT:
                 selection = dialog.result_list.get_selection()
                 model, it = selection.get_selected()
                 if it:
                     code = model.get_value(it, 1)
                     if code:
                         name = str(model.get_value(it, 0))
                         value_widget.set_label("%s (%s)" % (str(code), name))
             dialog.destroy()
             box.check_widget(option)
         dialog = LocationSearchDialog()
         dialog.connect('response', dialog_response)
         dialog.show()
 
     button.connect('clicked', button_clicked)
 
     hbox = g.HBox(spacing = 5)
     hbox.pack_start(label_widget)
     hbox.pack_start(value_widget)
     hbox.pack_start(button)
 
     return [hbox]
예제 #2
0
def op_button(text, stock, command, message, dialog=None):
    button = g.Button()

    hbox = g.HBox(False, 0)
    button.add(hbox)

    image = g.Image()
    image.set_from_stock(stock, g.ICON_SIZE_BUTTON)
    hbox.pack_start(image, False, True, 4)

    label = g.Label('')
    label.set_text_with_mnemonic(text)
    label.set_alignment(0, 0.5)
    hbox.pack_start(label, True, True, 0)

    # No need for clickable buttons if no command is set
    tmp = command.strip()
    if tmp:

        def invoke(button):
            print >> sys.stderr, message
            os.system(command)
            if dialog:
                dialog.response(g.RESPONSE_ACCEPT)

        button.connect('clicked', invoke)
    else:
        button.set_sensitive(False)

    button.unset_flags(g.CAN_FOCUS)
    return button
예제 #3
0
    def build_filechooser(self, node, label, option):
        """<filechooser name='...' label='...'/>Tooltip</filechooser>.
		Lets the user choose a file (using a GtkFileChooser or by drag-and-drop).
		Note: requires GTK >= 2.6
		"""
        filebutton = g.FileChooserButton(label)
        eb = g.EventBox()
        eb.add(filebutton)
        self.may_add_tip(eb, node)

        clearbutton = g.Button(stock=g.STOCK_CLEAR)
        hbox = g.HBox(False, 4)
        if label:
            hbox.pack_start(g.Label(label + ":"), False, True, 0)
        hbox.pack_start(eb, True, True, 0)
        hbox.pack_start(clearbutton, False, True, 0)

        self.handlers[option] = (lambda: filebutton.get_filename(),
                                 lambda: filebutton.set_filename(option.value))
        filebutton.connect('selection-changed',
                           lambda w: self.check_widget(option))

        def clear(w):
            filebutton.set_filename("")
            self.check_widget(option)

        clearbutton.connect('clicked', clear)

        return [hbox or eb]
예제 #4
0
    def __init__(self, program, purpose, version, author, website):
        g.Dialog.__init__(self)
        self.website = website

        def close(iw, event=None, data=None):
            iw.hide()

        self.connect("delete_event", close)

        hbox = g.HBox()
        self.vbox.pack_start(hbox)
        hbox.show()

        try:
            path = os.path.join(rox.app_dir, '.DirIcon')
            pixbuf = g.gdk.pixbuf_new_from_file(path)
            icon = g.Image()
            icon.set_from_pixbuf(pixbuf)
            hbox.pack_start(icon)
            icon.show()
        except:
            #rox.report_exception()
            pass

        table = g.Table(5, 2)
        hbox.pack_start(table)

        label = g.Label("Program")
        table.attach(label, 0, 1, 0, 1)

        frame = g.Frame()
        frame.set_shadow_type(g.SHADOW_IN)
        table.attach(frame, 1, 2, 0, 1)

        label = g.Label(program or '')
        frame.add(label)

        label = g.Label("Purpose")
        table.attach(label, 0, 1, 1, 2)

        frame = g.Frame()
        frame.set_shadow_type(g.SHADOW_IN)
        table.attach(frame, 1, 2, 1, 2)

        label = g.Label(purpose or '')
        frame.add(label)

        label = g.Label("Version")
        table.attach(label, 0, 1, 2, 3)

        frame = g.Frame()
        frame.set_shadow_type(g.SHADOW_IN)
        table.attach(frame, 1, 2, 2, 3)

        label = g.Label(version or '')
        frame.add(label)

        label = g.Label("Authors")
        table.attach(label, 0, 1, 3, 4)

        frame = g.Frame()
        frame.set_shadow_type(g.SHADOW_IN)
        table.attach(frame, 1, 2, 3, 4)

        label = g.Label(author or '')
        frame.add(label)

        label = g.Label("Web site")
        table.attach(label, 0, 1, 5, 6)

        if website:
            button = g.Button(website)
            table.attach(button, 1, 2, 5, 6)

            def goto_website(widget, iw):
                webbrowser.open(iw.website)

            button.connect("clicked", goto_website, self)

        else:
            frame = g.Frame()
            frame.set_shadow_type(g.SHADOW_IN)
            table.attach(frame, 1, 2, 5, 6)

        hbox = self.action_area

        button = g.Button(stock=g.STOCK_CLOSE)
        hbox.pack_start(button)

        def dismiss(widget, iw):
            iw.hide()

        button.connect("clicked", dismiss, self)
        button.show()

        self.vbox.show_all()
예제 #5
0
파일: ShowAll.py 프로젝트: rox-desktop/memo
    def __init__(self):
        g.Dialog.__init__(self)
        self.set_title(_('All memos'))
        self.set_has_separator(FALSE)

        self.add_button(g.STOCK_CLOSE, g.RESPONSE_CANCEL)

        frame = g.Frame()
        self.vbox.pack_start(frame, TRUE, TRUE, 0)
        frame.set_shadow_type(g.SHADOW_IN)

        hbox = g.HBox(FALSE, 0)
        frame.add(hbox)

        scroll = g.VScrollbar()
        hbox.pack_end(scroll, FALSE, TRUE, 0)

        self.list = g.TreeView(memo_list)
        hbox.pack_start(self.list, TRUE, TRUE, 0)
        self.list.set_scroll_adjustments(None, scroll.get_adjustment())
        self.list.set_size_request(-1, 12)
        self.set_default_size(-1, 300)

        text = g.CellRendererText()

        toggle = g.CellRendererToggle()
        column = g.TreeViewColumn(_('Hide'), toggle, active=memos.HIDDEN)
        self.list.append_column(column)
        toggle.connect('toggled',
                       lambda t, path: memo_list.toggle_hidden(path))

        column = g.TreeViewColumn(_('Time'), text, text=memos.TIME)
        self.list.append_column(column)

        column = g.TreeViewColumn(_('Message'), text, text=memos.BRIEF)
        self.list.append_column(column)

        self.list.set_headers_visible(TRUE)

        sel = self.list.get_selection()
        sel.set_mode(g.SELECTION_MULTIPLE)

        def activate(view, path, column):
            memo = memo_list.get_memo_by_path(path)
            from EditBox import EditBox
            EditBox(memo).show()

        self.add_events(g.gdk.BUTTON_PRESS_MASK)
        self.list.connect('row-activated', activate)

        self.connect('response', self.response)

        self.set_default_response(g.RESPONSE_CANCEL)

        actions = g.HButtonBox()
        self.vbox.pack_start(actions, FALSE, TRUE, 0)
        actions.set_layout(g.BUTTONBOX_END)
        actions.set_border_width(5)
        actions.set_spacing(4)

        def new(b):
            from EditBox import EditBox
            EditBox().show()

        button = g.Button(stock=g.STOCK_NEW)
        actions.add(button)
        button.connect('clicked', new)

        def delete(b):
            sel = self.list.get_selection()
            memos = []
            for iter in memo_list:
                if sel.iter_is_selected(iter):
                    m = memo_list.get_memo_by_iter(iter)
                    memos.append(m)
            if not memos:
                rox.alert(_('You need to select some memos first!'))
                return
            l = len(memos)
            if l == 1:
                message = _("Really delete memo '%s'?") % memos[0].brief
            else:
                message = _('Really delete %d memos?') % l

            box = g.MessageDialog(None, 0, g.MESSAGE_QUESTION,
                                  g.BUTTONS_CANCEL, message)

            if rox.confirm(message, g.STOCK_DELETE):
                for m in memos:
                    memo_list.delete(m, update=0)
                memo_list.notify_changed()

        button = g.Button(stock=g.STOCK_DELETE)
        actions.add(button)
        button.connect('clicked', delete)

        def edit(b):
            sel = self.list.get_selection()
            memos = []
            for iter in memo_list:
                if sel.iter_is_selected(iter):
                    m = memo_list.get_memo_by_iter(iter)
                    memos.append(m)
            if len(memos) != 1:
                rox.alert(_('You need to select exactly one memo first!'))
                return
            from EditBox import EditBox
            EditBox(memos[0]).show()

        button = rox.ButtonMixed(g.STOCK_PROPERTIES, _('_Edit'))
        actions.add(button)
        button.connect('clicked', edit)

        self.show_all()
예제 #6
0
파일: Window.py 프로젝트: rox-desktop/memo
	def __init__(self, memo_list):
		rox.Window.__init__(self)
		MenuWindow.__init__(self)
		self.set_wmclass('Memo', 'Memo')
		self.set_title('Memo')
		self.set_resizable(False)
		if hasattr(self, 'set_deletable'):
			self.set_deletable(False)
		#self.set_type_hint(g.gdk.WINDOW_TYPE_HINT_DIALOG)

		self.tips = g.Tooltips()

		if main_sticky.int_value:
			self.stick()

		self.memo_list = memo_list
		self.last_day = None
		self.prime_in_progress = False

		vbox = g.VBox(FALSE, 0)
		self.add(vbox)

		hbox = g.HBox(False, 0)
		vbox.pack_start(hbox, expand = False)

		self.time_label = g.Label('')
		self.time_button = g.Button()
		self.time_button.add(self.time_label)
		self.time_button.unset_flags(g.CAN_FOCUS)
		hbox.pack_start(self.time_button, expand = True)

		hbox.pack_start(timer.TimerButton(), expand = False)

		self.list = g.TreeView(memo_list.visible)
		vbox.pack_start(self.list, expand = TRUE)
		self.list.unset_flags(g.CAN_FOCUS)

		cell = g.CellRendererText()
		column = g.TreeViewColumn('Time', cell, text = 0)
		cell.set_property('xalign', 1)
		self.list.append_column(column)

		cell = g.CellRendererText()
		column = g.TreeViewColumn('Message', cell, text = 1)
		self.list.append_column(column)

		self.list.set_headers_visible(FALSE)
		
		sel = self.list.get_selection()
		sel.set_mode(g.SELECTION_NONE)

		def activate(view, path, column):
			memo = memo_list.visible.get_memo_by_path(path)
			from EditBox import EditBox
			EditBox(memo).show()
		
		self.add_events(g.gdk.BUTTON_PRESS_MASK)
		self.list.connect('button-press-event', self.button_press)
		self.list.connect('row-activated', activate)
		self.time_button.add_events(g.gdk.BUTTON1_MOTION_MASK)
		self.time_button.connect('button-press-event', self.button_press)
		self.time_button.connect('motion-notify-event', self.button_motion)
		self.time_button.connect('clicked', self.time_button_clicked)

		self.update()
		gobject.timeout_add(10000, self.update)	# Update clock

		self.timeout = None	# For next alarm
		self.alert_box = None
		self.show_all_box = None
		self.save_box = None
		self.prime()

		# If we had more than one window, we'd need a remove too...
		memo_list.connect("MemoListChanged", self.prime)
		app_options.add_notify(self.options_changed)
		
		vbox.show_all()
예제 #7
0
    def build_varlist(self, node, label, option):
        """<varlist name='...' label='...' edit='yes|no' extend='yes|no' selection='single|none|multiple'>Tooltip</varlist>"""
        edit = bool_attr(node, 'edit')
        reorder = bool_attr(node, 'reorder')
        extend = bool_attr(node, 'extend')
        select = str_attr(node, 'selection', 'single')

        cont = rox.g.VBox(False, 4)
        cont._rox_lib_expand = True

        if label:
            label_wid = rox.g.Label(label)
            cont.pack_start(label_wid, False, True, 0)
            label_wid.show()

        swin = g.ScrolledWindow()
        swin.set_border_width(4)
        swin.set_policy(g.POLICY_NEVER, g.POLICY_ALWAYS)
        swin.set_shadow_type(g.SHADOW_IN)
        #swin.set_size_request(-1, 128)
        cont.pack_start(swin, True, True, 0)

        model = g.ListStore(str, str)
        view = g.TreeView(model)
        swin.add(view)

        selection = view.get_selection()
        if select == 'none':
            selection.set_mode(g.SELECTION_NONE)
        elif select == 'multiple':
            selection.set_mode(g.SELECTION_MULTIPLE)
        else:
            selection.set_mode(g.SELECTION_SINGLE)
            select = 'single'

        if reorder:
            view.set_reorderable(True)

        def cell_edited(ell, path, new_text, col):
            if col == 0 and new_text.find('=') >= 0:
                return
            iter = model.get_iter_from_string(path)
            model.set(iter, col, new_text)
            self.check_widget(option)

        cell = g.CellRendererText()
        column = g.TreeViewColumn('Variable', cell, text=0)
        view.append_column(column)
        if edit:
            cell.set_property('editable', True)
            cell.connect('edited', cell_edited, 0)

        cell = g.CellRendererText()
        column = g.TreeViewColumn('Value', cell, text=1)
        view.append_column(column)
        if edit:
            cell.set_property('editable', True)
            cell.connect('edited', cell_edited, 1)

        def add(widget, box):
            iter = model.append()
            model.set(iter, 0, 'newvar', 1, 'new value')
            if select == 'single':
                view.get_selection().select_iter(iter)
            box.check_widget(option)

        if extend:
            hbox = g.HBox(False, 2)
            cont.pack_start(hbox, False)

            but = g.Button(stock=g.STOCK_ADD)
            but.connect('clicked', add, self)
            hbox.pack_start(but, False)

        self.may_add_tip(swin, node)

        def get():
            v = []
            iter = model.get_iter_first()
            while iter:
                var = model.get_value(iter, 0)
                val = model.get_value(iter, 1)
                v.append(var + '=' + val)

                iter = model.iter_next(iter)
            return v

        def set():
            model.clear()
            for v in option.list_value:
                var, val = v.split('=', 1)
                iter = model.append()
                model.set(iter, 0, var, 1, val)

        self.handlers[option] = (get, set)

        return [cont]