示例#1
0
    def gui_add_channels(self):

        captions = (
            ('Prefix:', 'label', 'Prefix', 'entry'),
            ('Number:', 'label', 'Number', 'spinbutton'),
            ('In workspace:', 'label', 'workspace', 'combobox'),
        )

        w, b = Widgets.build_info(captions)
        b.prefix.set_text("Image")
        b.number.set_limits(1, 12, incr_value=1)
        b.number.set_value(1)

        cbox = b.workspace
        names = self.ds.get_wsnames()
        try:
            idx = names.index('channels')
        except:
            idx = 0
        for name in names:
            b.workspace.append_text(name)
        b.workspace.set_index(idx)
        dialog = Widgets.Dialog(title="Add Channels",
                                flags=0,
                                buttons=[['Cancel', 0], ['Ok', 1]],
                                parent=self.w.root)
        dialog.add_callback(
            'activated', lambda w, rsp: self.add_channels_cb(w, rsp, b, names))
        box = dialog.get_content_area()
        box.add_widget(w, stretch=0)

        self.ds.show_dialog(dialog)
示例#2
0
        def dialog(params, rows, pack):
            if len(self.toplevels) == 0:
                raise ValueError("Need a top-level window to parent a dialog")

            # any old top-level will do, for now...
            top_w = self.toplevels[0]
            widget = Widgets.Dialog(parent=top_w)
            container = widget.get_content_area()

            res = []
            for dct in rows:
                if isinstance(dct, dict):
                    stretch = dct.get('stretch', 1)
                    row = dct.get('row', None)
                else:
                    # assume a list defining the row
                    stretch = 1
                    row = dct
                if row is not None:
                    r = make(row,
                             lambda w: container.add_widget(w,
                                                            stretch=stretch))
                    r = dict(row=r, stretch=stretch)
                    res.append(r)

            process_common_params('dialog', widget, params)

            widget.show()
            return ['dialog', params] + res
示例#3
0
    def gui_add_channel(self, chname=None):
        if not chname:
            chname = self.make_channel_name("Image")

        captions = (
            ('New channel name:', 'label', 'channel_name', 'entry'),
            ('In workspace:', 'label', 'workspace', 'combobox'),
        )

        w, b = Widgets.build_info(captions, orientation='vertical')

        # populate values
        b.channel_name.set_text(chname)
        names = self.ds.get_wsnames()
        try:
            idx = names.index(self._lastwsname)
        except:
            idx = 0
        for name in names:
            b.workspace.append_text(name)
        b.workspace.set_index(idx)

        # build dialog
        dialog = Widgets.Dialog(title="Add Channel",
                                flags=0,
                                buttons=[['Cancel', 0], ['Ok', 1]],
                                parent=self.w.root)
        dialog.add_callback(
            'activated', lambda w, rsp: self.add_channel_cb(w, rsp, b, names))
        box = dialog.get_content_area()
        box.add_widget(w, stretch=0)

        self.ds.show_dialog(dialog)
示例#4
0
def popup_dialog(parent):
    dia = Widgets.Dialog(title="Dialog Title",
                         buttons=[('ok', 0), ('cancel', 1)],
                         parent=parent, modal=True)
    cntr = dia.get_content_area()
    cntr.add_widget(Widgets.Label("My Dialog Content"))
    dia.show()
示例#5
0
    def gui_add_ws(self):

        chpfx = "Image"
        ws = self.get_current_workspace()
        if ws is not None:
            chpfx = ws.extdata.get('chpfx', chpfx)

        captions = (
            ('Workspace name:', 'label', 'Workspace name', 'entry'),
            ('Workspace type:', 'label', 'Workspace type', 'combobox'),
            ('In workspace:', 'label', 'workspace', 'combobox'),
            ('Channel prefix:', 'label', 'Channel prefix', 'entry'),
            ('Number of channels:', 'label', 'num_channels', 'spinbutton'),
            ('Share settings:', 'label', 'Share settings', 'entry'),
        )
        w, b = Widgets.build_info(captions)

        self.wscount += 1
        wsname = "ws%d" % (self.wscount)
        b.workspace_name.set_text(wsname)
        #b.share_settings.set_length(60)

        cbox = b.workspace_type
        cbox.append_text("Grid")
        cbox.append_text("Tabs")
        cbox.append_text("MDI")
        cbox.append_text("Stack")
        cbox.set_index(0)

        cbox = b.workspace
        names = self.ds.get_wsnames()
        names.insert(0, 'top level')
        try:
            idx = names.index('channels')
        except:
            idx = 0
        for name in names:
            cbox.append_text(name)
        cbox.set_index(idx)

        b.channel_prefix.set_text(chpfx)
        spnbtn = b.num_channels
        spnbtn.set_limits(0, 36, incr_value=1)
        spnbtn.set_value(4)

        dialog = Widgets.Dialog(title="Add Workspace",
                                flags=0,
                                buttons=[['Cancel', 0], ['Ok', 1]],
                                parent=self.w.root)
        dialog.add_callback('activated',
                            lambda w, rsp: self.add_ws_cb(w, rsp, b, names))
        box = dialog.get_content_area()
        box.add_widget(w, stretch=1)
        self.ds.show_dialog(dialog)
示例#6
0
    def gui_delete_window(self, tabname):
        lbl = Widgets.Label("Really delete window '%s' ?" % (tabname))
        dialog = Widgets.Dialog(title="Delete Window",
                                flags=0,
                                buttons=[['Cancel', 0], ['Ok', 1]],
                                parent=self.w.root)
        dialog.add_callback('activated',
                            lambda w, rsp: self.delete_tab_cb(w, rsp, tabname))

        box = dialog.get_content_area()
        box.add_widget(lbl, stretch=0)

        self.ds.show_dialog(dialog)
示例#7
0
    def finish_gui(self, p_info, vbox):
        # add container to workspace
        # TODO: how to figure out the appropriate size for top-levels?
        wd, ht = vbox.get_size()

        try:
            in_ws = p_info.spec.get('workspace', None)
            if in_ws is None:
                # to be deprecated
                in_ws = p_info.spec.ws

            if in_ws == 'in:toplevel':
                topw = vbox.get_app().make_window()
                topw.add_callback('close',
                                  lambda *args: self.deactivate(p_info.name))
                topw.resize(wd, ht)
                topw.set_widget(vbox)
                p_info.widget = topw
                p_info.is_toplevel = True
                topw.show()

            elif in_ws == 'in:dialog':
                dialog = Widgets.Dialog(title=p_info.name,
                                        flags=0,
                                        buttons=[],
                                        parent=self.fv.w.root)
                dialog.resize(wd, ht)
                box = dialog.get_content_area()
                box.add_widget(vbox, stretch=1)
                p_info.widget = dialog
                p_info.is_toplevel = True
                # TODO: need to add callback to remove from Desktop
                # dialog list?
                self.ds.show_dialog(dialog)

            else:
                bnch = self.ds.add_tab(in_ws, vbox, 2, p_info.tabname,
                                       p_info.tabname)
                bnch.plugin_info = p_info

                ws = self.ds.get_ws(in_ws)
                ws.add_callback('page-close', self.tab_closed_cb)

                ws_w = self.ds.get_nb(in_ws)
                ws_w.add_callback('page-switch', self.tab_switched_cb)
                p_info.widget = vbox
                p_info.is_toplevel = False

        except Exception as e:
            self.fv.show_error("Error finishing plugin UI for '%s': %s" %
                               (p_info.name, str(e)))
示例#8
0
    def ask_action_images(self, action):

        images = self.get_selected()
        if len(images) == 0:
            self.fv.show_error("Please select some images first")
            return

        l_img = list(map(lambda tup: "%s/%s" % (tup[0], tup[1].imname),
                         images))

        verb = action.capitalize()
        l_img.insert(0, "%s images\n" % (verb))

        # build dialog
        dialog = Widgets.Dialog(title="%s Images" % (verb),
                                flags=0,
                                buttons=[['Cancel', 0], ['Ok', 1]],
                                parent=self.treeview)
        box = dialog.get_content_area()
        box.set_border_width(6)
        if len(l_img) < 12:
            text = Widgets.Label("\n".join(l_img))
        else:
            text = Widgets.TextArea(wrap=None)
            text.set_text("\n".join(l_img))
        box.add_widget(text, stretch=1)

        if action != 'remove':
            hbox = Widgets.HBox()
            hbox.add_widget(Widgets.Label("To channel: "))
            chnl = Widgets.ComboBox()
            for chname in self.chnames:
                chnl.append_text(chname)
            hbox.add_widget(chnl)
            hbox.add_widget(Widgets.Label(''), stretch=1)
            box.add_widget(hbox)
        else:
            chnl = None

        dialog.add_callback('activated',
                            lambda w, rsp: self.action_images_cb(w, rsp,
                                                                 chnl,
                                                                 images,
                                                                 action))

        self.fv.ds.show_dialog(dialog)
示例#9
0
    def gui_delete_channel(self, chname=None):
        channel = self.get_channelInfo(chname=chname)
        if (len(self.get_channelNames()) == 0) or (channel is None):
            self.show_error("There are no more channels to delete.")
            return

        chname = channel.name
        lbl = Widgets.Label("Really delete channel '%s' ?" % (chname))
        dialog = Widgets.Dialog(title="Delete Channel",
                                flags=0,
                                buttons=[['Cancel', 0], ['Ok', 1]],
                                parent=self.w.root)
        dialog.add_callback(
            'activated', lambda w, rsp: self.delete_channel_cb(w, rsp, chname))
        box = dialog.get_content_area()
        box.add_widget(lbl, stretch=0)

        self.ds.show_dialog(dialog)
示例#10
0
    def workspace_closed_cb(self, ws):
        self.logger.debug("workspace requests close")
        children = list(ws.nb.get_children())
        if len(children) > 0:
            self.show_error(
                "Please close all windows in this workspace first!",
                raisetab=True)
            return

        # TODO: this will prompt the user if we should close the workspace
        lbl = Widgets.Label("Really delete workspace '%s' ?" % (ws.name))
        dialog = Widgets.Dialog(title="Delete Workspace",
                                flags=0,
                                buttons=[['Cancel', 0], ['Ok', 1]],
                                parent=self.w.root)
        dialog.add_callback(
            'activated', lambda w, rsp: self.delete_workspace_cb(w, rsp, ws))
        box = dialog.get_content_area()
        box.add_widget(lbl, stretch=0)

        self.ds.show_dialog(dialog)
示例#11
0
    menu.add_name('Moe').add_callback('activated',
                                      lambda w: logger.info("chose Moe"))
    menu = w.add_menu('Menu Type 2', mtype='mbar')
    menu.add_name('Frank')
    menu.add_name('Dean')
    menu.add_name('Sammy')
    w.add_widget(Widgets.Button('A Button'))
    w.add_separator()
    w.add_action("Toggle me", toggle=True)
    w.add_action(None, iconpath=os.path.join(icondir, 'hand_48.png'))
    vbox.add_widget(w)
    vbox.add_widget(Widgets.Label("App content"), stretch=1)

elif wname == 'dialog':
    dia = Widgets.Dialog(title="Dialog Title",
                         buttons=[('ok', 0), ('cancel', 1)],
                         parent=top,
                         modal=False)
    dia.add_callback('activated', lambda w, rsp: logger.info("user chose %s" %
                                                             (rsp)))
    cntr = dia.get_content_area()
    cntr.add_widget(Widgets.Label("My Dialog Content"))

    # add some content to main app widget
    w = Widgets.Label("Hello World label")
    vbox.add_widget(w, stretch=1)
    hbox = Widgets.HBox()
    w = Widgets.Button("Open Dialog")
    w.add_callback('activated', lambda w: dia.show())
    hbox.add_widget(w)
    w = Widgets.Button("Close Dialog")
    w.add_callback('activated', lambda w: dia.hide())