示例#1
0
 def videoviewer_config(self):
     from ifigure.utils.edit_list import DialogEditList
     l = [
         [
             "Interval(sec.)",
             str(float(self._playinterval) / 1000.), 0, {
                 'noexpand': True
             }
         ],
         ["Frame #", str(self.nframe), 0, {
             'noexpand': True
         }],
         [
             None, self._playloop, 3, {
                 "text": "Loop Movie",
                 "noindent": None
             }
         ],
         [
             None, self.sign == -1, 3, {
                 "text": "Use exp(-iwt)",
                 "noindent": None
             }
         ],
     ]
     value = DialogEditList(l,
                            parent=self,
                            title='Player Config.',
                            style=wx.DEFAULT_DIALOG_STYLE
                            | wx.RESIZE_BORDER)
     if not value[0]: return
     self._playinterval = int(float(value[1][0]) * 1000.)
     self._playloop = bool(value[1][2])
     self.sign = -1 if bool(value[1][3]) else 1
     self.nframe = int(value[1][1])
示例#2
0
def DlgFileimportmode(folder, parent = None, ask_copyorg=False):

    choices = ["auto", "abs", "home", "proj"]
    if folder.get_extfolderpath() is not None:
        choices.append(folder.get_extfolderpath())
    list6 = [[None,  [True, ['auto']], 127, 
             [{'text':'copy file to project'}, 
              {'elp':[['Select path mode', 'auto', 4,
                       {"style":wx.CB_READONLY,
                        "choices": choices}],]}], ],]
    if ask_copyorg:            
        list6.append( [None, False, 3, 
              {"text":"copy original to project as a separate file"}])
    value = DialogEditList(list6, modal = True, 
                 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
                 tip = None, 
                 parent=parent,)

    if not value[0]: return

#    print value[1]
#    ret = value[1][1]
    copy_file = value[1][0][0]
    path_modes = value[1][0][1]
    if str(path_modes[0]) == 'auto':
        path_modes = ['proj', 'home', 'abs']

    copy_org = False
    if ask_copyorg:
        copy_org = value[1][1]

    return copy_file, path_modes, copy_org
示例#3
0
 def onEditPoint(self, evt):
     x, y = self._eval_xy()
     if self._figc_hit < x.size:
         l = [
             ['x', str(x[self._figc_hit]), 0, None],
         ]
     else:
         l = [
             ['y', str(y[self._figc_hit - x.size]), 0, None],
         ]
     window = evt.GetEventObject().GetTopLevelParent()
     value = DialogEditList(l,
                            modal=True,
                            style=wx.DEFAULT_DIALOG_STYLE
                            | wx.RESIZE_BORDER,
                            tip=None,
                            parent=window)
     if value[0]:
         v = value[1]
     else:
         return
     x = self.getp('x').copy()
     y = self.getp('y').copy()
     if self._figc_hit < x.size:
         x[self._figc_hit] = float(v[0])
     else:
         y[self._figc_hit - x.size] = v[0]
     action = UndoRedoFigobjMethod(self._artists[0], 'data', (x, y))
     window = evt.GetEventObject().GetTopLevelParent()
     GlobalHistory().get_history(window).make_entry([action])
     return 1
示例#4
0
        def onHGcommit(self, evt):
            app = wx.GetApp().TopWindow
            list6 = [
                ["messsage", 'commit-#xxx', 0, None],
                #               ["user", os.getenv("USER"), 0, None]]
                ["user", usr, 0, None]
            ]

            value = DialogEditList(list6,
                                   modal=True,
                                   style=wx.DEFAULT_DIALOG_STYLE
                                   | wx.RESIZE_BORDER,
                                   tip=None,
                                   parent=app,
                                   title='HG commit')
            if not value[0]:
                return

            no_treedata = True if '.tree_data_hg' in self.getvar(
                'exclude') else False
            self.do_commit(str(value[1][0]),
                           user=str(value[1][1]),
                           no_treedata=no_treedata)
            self.hg_set_projtreeviewer_status()
            evt.Skip()
示例#5
0
def ask_mdssetting(this=None):
    if this is not None:
        server = this.getvar("server")
        port = str(this.getvar("port"))
    else:
        server = "localhost"
        port = "10002"
    tree = "ANALYSIS"
    shot = "-1"
    list = [["", " " * 50, 2],
            #           ["Server", server, 0],
            #           ["Port", port, 0],
            ["MDSconnect", this.getvar('mdsplus_server'), 204, None],
            ["Tree", tree, 4, {"choices": ["ANALYSIS", "ELECTRONS",
                                           "SPECTROSCOPY", "XTOMO", "DNB", "RF",
                                           ]}],
            ["Shot", shot, 0]]

    flag, value = DialogEditList(list, parent=this.get_app())

    if flag:
        this.setvar('mdsplus_server', str(value[1]))
        this.setvar("tree", str(value[2]))
        this.setvar("shot", str(value[3]))
    return flag, value
示例#6
0
 def onImport(self, e):
     list = [["", "Enter Variable Name to Import", 2], 
             ["Name", "var", 0]]
     flag, value=DialogEditList(list)
     if flag:
         var = cbook.ReadFromMain(value[1])
         for key in var:
             self.setvar(key, var[key])
示例#7
0
 def onExport(self, e):
     d={}
     for key in self.eval_all_keys():
        d[key]=self.eval(key)
     list = [["", "Enter Variable Name to Export", 2], 
             ["Name", "var", 0]]
     flag, value=DialogEditList(list)
     if flag:
         self.write2shell(d,  value[1])
示例#8
0
        def onHGIncoming(self, evt):

            url, root, path = self.get_mercurial_url()
            if url is not None:
                root = root
                name = path
            else:
                root = None
                name = self._name
            app = wx.GetApp().TopWindow
            list6 = [
                ["root repository", root, 304,
                 dlg_s()],
                ["name", name, 0, None],
            ]

            value = DialogEditList(list6,
                                   modal=True,
                                   style=wx.DEFAULT_DIALOG_STYLE
                                   | wx.RESIZE_BORDER,
                                   tip=None,
                                   parent=app,
                                   title='HG incoming')
            if not value[0]:
                return

            url = rootpath2url(str(value[1][0]), str(value[1][1]))
            ocwd = os.getcwd()
            os.chdir(self.owndir())
            try:
                repo = hgapi.Repo(self.owndir())
                l1, l2 = self.hg_incoming_outgoing_changesets_list(repo, url)
                if len(l1) > 0:
                    self._status = '!'
                    out = repo.hg_command('incoming', url)
                    dialog.showtraceback(parent=app,
                                         txt=out,
                                         title='Incoming changeset',
                                         traceback=traceback.format_exc())
                else:
                    self._status = ''
                    dialog.showtraceback(parent=app,
                                         txt='No incoming change',
                                         title='Incoming changeset',
                                         traceback=traceback.format_exc())

            except:
                dialog.showtraceback(parent=app,
                                     txt='Failed to hg_command',
                                     title='Failed to hg_command',
                                     traceback=traceback.format_exc())
            os.chdir(ocwd)
            #           self.set_mercurial_url(str(value[1][0]), str(value[1][1]))
            self.hg_set_projtreeviewer_status(repo=repo)
            evt.Skip()
示例#9
0
        def onHGclone(self, evt):
            app = wx.GetApp().TopWindow
            name = self.getvar('mercurial_path')
            if name is None:
                name = self._name
            l2 = [
                ["commit message", '', 0, None],
            ]
            list6 = [
                ["root repository", None, 304,
                 dlg_s()],
                ["name", name, 0, None],
                #               [None, (False, ['change #1']),  27,
                #                      ({"text": 'commit modification'},
                #                      {"elp": l2},)],
                [
                    None, True, 3, {
                        "text": 'change source tree to the new clone'
                    }
                ]
            ]

            value = DialogEditList(list6,
                                   modal=True,
                                   style=wx.DEFAULT_DIALOG_STYLE
                                   | wx.RESIZE_BORDER,
                                   tip=None,
                                   parent=app,
                                   title='HG clone')
            if not value[0]:
                return
            if not self.update_hgsub():
                return
#           if value[1][2][0]:
#               if not self.do_commit(str(value[1][2][1])): return
            url = rootpath2url(str(value[1][0]), str(value[1][1]))

            ocwd = os.getcwd()
            os.chdir(self.owndir())
            try:
                repo = hgapi.Repo(self.owndir())
                if not url.startswith('ssh://'):
                    # for local repo, check if directory exists
                    dirname = os.path.dirname(url)
                    if not os.path.exists(dirname):
                        os.makedirs(dirname)
                repo.hg_clone('.', url)
            except:
                dialog.showtraceback(parent=app,
                                     txt='Failed to clone subtree to ' + url,
                                     title='Failed to clone',
                                     traceback=traceback.format_exc())
            if value[1][2]:
                self.set_mercurial_url(str(value[1][0]), str(value[1][1]))
            os.chdir(ocwd)
示例#10
0
 def edit_setting(self):
     list6 = self._elp_panel_list()
     value = DialogEditList(
         list6,
         modal=True,
         style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
         tip=None,
         parent=None,
     )
     if value[0] is True:
         self._elp_process_panelvalue(value[1])
示例#11
0
        def onHGDiff(self, evt=None):
            app = wx.GetApp().TopWindow
            repo = self.get_repo()
            latest = repo.revisions(slice(-1, -1))[0].rev
            current = repo.hg_rev()
            ll = [
                [None, 'Enter revision numbers to compare', 2, None],
                ["revision (older)", str(current), 0, None],
                ["revision (newer)", str(latest), 0, None],
                [None, 'newer == "", diff against working dir.', 2, None],
                [
                    None,
                    'older == newer, diff between the latest and current', 2,
                    None
                ],
            ]

            value = DialogEditList(ll,
                                   modal=True,
                                   style=wx.DEFAULT_DIALOG_STYLE
                                   | wx.RESIZE_BORDER,
                                   tip=None,
                                   parent=app,
                                   title='HG diff')
            if not value[0]:
                return
            a = str(value[1][1])
            b = str(value[1][2])
            if b == '':
                args = (str(a), )
            elif int(a) != int(b):
                args = (
                    str(a),
                    str(b),
                )
            elif int(a) == int(b):
                args = tuple()
            try:
                res = repo.hg_diff(*args)
            except:
                dialog.showtraceback(parent=app,
                                     txt='Failed to hg_diff',
                                     title='Failed to hg_diff',
                                     traceback=traceback.format_exc())
            if globals()['diffwindow'] is not None:
                try:
                    globals()['diffwindow'].Destroy()
                except PyDeadObjectError:
                    pass
                globals()['diffwindow'] = None
            from ifigure.widgets.hgdiff_window import HGDiffWindow
            globals()['diffwindow'] = HGDiffWindow(res, wx.GetApp().TopWindow)
示例#12
0
    def OnMoveItemTo(self, evt):
        from ifigure.utils.edit_list import DialogEditList
        import ifigure.widgets.dialog as dialog

        if self.tree.GetSelection() is None:
            return

        indices = self.tree.GetIndexOfItem(self.tree.GetSelection())
        mm = self.model.GetItem(indices)
        p = mm.parent
        names = list(p._contents)
        idx = names.index(mm.name())

        list6 = [
            ["New parent", p.name(), 0],
            ["Index (0-base)", str(idx), 0],
        ]
        value = DialogEditList(list6,
                               modal=True,
                               style=wx.DEFAULT_DIALOG_STYLE
                               | wx.RESIZE_BORDER,
                               tip=None,
                               parent=self,
                               title='Move item to...')
        if not value[0]:
            return

        if value[1][0] != p.name():
            try:
                assert False, "Moving under diffent parent is not supported"
            except AssertionError:
                dialog.showtraceback(
                    parent=self,
                    txt='Moving under diffent parent is not supported',
                    title='Error',
                    traceback=traceback.format_exc())
                return

        new_idx = int(value[1][1])
        names = list(p._contents)
        new_idx = max([0, new_idx])
        new_idx = min([len(names) - 1, new_idx])

        idx = names.index(mm.name())
        new_names = self.MoveItemInList(names, idx, new_idx)
        p._contents = OrderedDict((k, p._contents[k]) for k in new_names)
        self.tree.RefreshItems()

        indices = self.tree.GetIndexOfItem(self.tree.GetSelection())
        mm = self.model.GetItem(indices)
        self.show_panel(mm)
示例#13
0
        def onHGpush(self, evt):
            app = wx.GetApp().TopWindow
            url, root, path = self.get_mercurial_url()
            if url is not None:
                root = root
                name = path
            else:
                root = None
                name = self._name

            list6 = [
                ["root repository", root, 304,
                 dlg_s()],
                ["name", name, 0, None],
                [None, True, 3, {
                    "text": 'Perform HG update'
                }],
            ]

            value = DialogEditList(list6,
                                   modal=True,
                                   style=wx.DEFAULT_DIALOG_STYLE
                                   | wx.RESIZE_BORDER,
                                   tip=None,
                                   parent=app,
                                   title='HG push')
            if not value[0]:
                return
            if not self.update_hgsub():
                return
            url = rootpath2url(str(value[1][0]), str(value[1][1]))

            ocwd = os.getcwd()
            os.chdir(self.owndir())
            try:
                urlbk, rootbk, pathbk = self.get_mercurial_url()
                repo = hgapi.Repo(self.owndir())
                self.set_mercurial_url(str(value[1][0]), str(value[1][1]))
                repo.hg_push(url)
                if value[1][2] and not url.startswith('ssh'):
                    repo2 = hgapi.Repo(url)
                    latest = repo2.revisions(slice(-1, -1))[0].rev
                    repo2.hg_update(int(latest))
            except:
                dialog.showtraceback(parent=app,
                                     txt='Failed to push',
                                     title='Failed to push',
                                     traceback=traceback.format_exc())
            self.set_mercurial_url(rootbk, pathbk)
            os.chdir(ocwd)
示例#14
0
    def send_file(self, file, parent=None):
        if parent is None:
            parent = self.parent
        if self.passwd is None:
            self.ask_passwd(parent=parent)
        if self.passwd is None:
            return

        list6 = [
            ["To:", self.setting["default_to"], 0, None],
            ["Subject:", self.setting["default_title"], 0, None],
            [None, self.setting["default_message"], 35, {
                'nlines': 10
            }],
        ]

        #                 ["mail server", self.setting["server"], 0, None],
        #                 ["use ssl", self.setting["use_ssl"], 1, {"values":["on", "off"]}],
        #                 ["ssl port", str(self.setting["ssl_port"]), 0, None],]

        value = DialogEditList(list6,
                               modal=True,
                               style=wx.DEFAULT_DIALOG_STYLE
                               | wx.RESIZE_BORDER,
                               tip=None,
                               title='Edit Message for Send File',
                               parent=parent,
                               size=(400, -1))

        if value[0] is True:
            to = str(value[1][0])
            subject = str(value[1][1])
            message = str(value[1][2])

        else:
            return

        passwd = binascii.a2b_hex(self.passwd).decode(coding)

        sendMail([to],
                 subject,
                 message,
                 files=[file],
                 server=self.setting["server"],
                 ssl=(self.setting["use_ssl"] == "on"),
                 ssl_port=int(self.setting["ssl_port"]),
                 ssl_username=self.username,
                 ssl_passwd=passwd)
示例#15
0
def ask_field(self, dest):
    vars = self.td.data.getvar()
    list6 = [
        ["", "Select field to convert", 2],
        [None, None, 36, {
            'col': 4,
            'labels': list(vars.keys())
        }],
    ]
    value = DialogEditList(list6,
                           modal=True,
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                           tip=None,
                           title="Convert to " + dest,
                           parent=self.td.get_app())
    checked = [x for x, b in value[1][1] if b]
    return value[0], checked
示例#16
0
    def onEditPoint(self, evt):
        def add_list(l, name, self, idx):
            value = self.getp(name)
            l.append([name, str(value[idx]), 0, None])

        from ifigure.utils.edit_list import DialogEditList
        l = []
        names = ['x', 'y']
        if self.getp('xerr') is not None:
            names.append('xerr')
        if self.getp('yerr') is not None:
            names.append('yerr')
        for name in names:
            add_list(l, name, self, self._figc_hit)

        window = evt.GetEventObject().GetTopLevelParent()
        value = DialogEditList(l, modal=True,
                               style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                               tip=None,
                               parent=window)
        if value[0]:
            v = value[1]
        else:
            return
        x = _copy(self.getp('x'))
        x[self._figc_hit] = v[names.index('x')]
        y = _copy(self.getp('y'))
        y[self._figc_hit] = v[names.index('y')]
        yerr = _copy(self.getp('yerr'))
        if yerr is not None:
            yerr[self._figc_hit] = v[names.index('yerr')]
        xerr = _copy(self.getp('xerr'))
        if xerr is not None:
            xerr[self._figc_hit] = v[names.index('xerr')]

        actions = [UndoRedoFigobjMethod(self._artists[0],
                                        'data', (x, y)), ]
        if self._mpl_cmd != 'plot':
            actions.append(UndoRedoFigobjMethod(self._artists[0],
                                                'errdata', (xerr, yerr)))
        window = evt.GetEventObject().GetTopLevelParent()
        GlobalHistory().get_history(window).make_entry(actions)
        return 1
示例#17
0
        def onHGpull(self, evt):
            url, root, path = self.get_mercurial_url()
            if url is not None:
                root = root
                name = path
            else:
                root = None
                name = self._name
            app = wx.GetApp().TopWindow
            list6 = [
                ["root repository", root, 304,
                 dlg_s()],
                ["name", name, 0, None],
            ]

            value = DialogEditList(list6,
                                   modal=True,
                                   style=wx.DEFAULT_DIALOG_STYLE
                                   | wx.RESIZE_BORDER,
                                   tip=None,
                                   parent=app,
                                   title='HG pull')
            if not value[0]:
                return

            url = rootpath2url(str(value[1][0]), str(value[1][1]))

            ocwd = os.getcwd()
            os.chdir(self.owndir())
            try:
                repo = hgapi.Repo(self.owndir())
                repo.hg_pull(url)
            except:
                dialog.showtraceback(parent=app,
                                     txt='Failed to pull',
                                     title='Failed to pull',
                                     traceback=traceback.format_exc())
            os.chdir(ocwd)
            self.set_mercurial_url(str(value[1][0]), str(value[1][1]))
            self.hg_set_projtreeviewer_status(repo=repo)
            #           self.setvar('mercurial_url', url
            evt.Skip()
示例#18
0
    def onGoToFrame(self, evt):
        from ifigure.utils.edit_list import DialogEditList
        list6 = [
            ("Frame number (1-" + str(self.num_page()) + ")",
             str(self._video_page), 0, None),
        ]
        value = DialogEditList(
            list6,
            modal=True,
            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
            tip=None,
            parent=self,
        )

        if value[0] is True:
            ipage = long(value[1][0])
        else:
            return
        self.goto_frame(ipage)
        self.property_editor.onTD_ShowPage(evt)
示例#19
0
    def onSetLevel(self, evt):
        import wx
        from ifigure.utils.edit_list import DialogEditList

        diag = evt.GetEventObject().GetTopLevelParent()

        list6 = [
            ["New level", self.grid_level, 0],
        ]
        value = DialogEditList(list6,
                               modal=True,
                               style=wx.DEFAULT_DIALOG_STYLE
                               | wx.RESIZE_BORDER,
                               tip=None,
                               parent=diag,
                               title='Set level...')
        if not value[0]:
            return

        self.grid_level = int(value[1][0])
示例#20
0
def scale_p(self, factor=None):

    td = self.td
    if factor is None:
        list = [["", "Enter P Scale Factor", 2], ["P sclae", str(1), 0]]

        flag, value = DialogEditList(list)
        if flag:
            factor = float(value[1])
        else:
            return

    print(('Pres scale by', str(factor)))
    td[:]["table"]["pres"] *= factor
    td[:]["table"]["pressmid"] *= np.abs(factor)
    td[:]["table"]["pressrz"] *= factor
    td[:]["table"]["pprime"] *= factor
    add_extra_data(td[:]["table"])
    print('Updating g-file')
    self.onUpdateFile()
示例#21
0
    def send_message(self, message='', parent=None):
        if parent is None:
            parent = self.parent
        if self.passwd is None:
            self.ask_passwd(parent=parent)
        if self.passwd is None:
            return

        list6 = [
            ["subject", self.setting["default_title"], 0, None],
            ["to", self.setting["default_to"], 0, None],
        ]
        #                 ["mail server", self.setting["server"], 0, None],
        #                 ["use ssl", self.setting["use_ssl"], 1, {"values":["on", "off"]}],
        #                 ["ssl port", str(self.setting["ssl_port"]), 0, None],]

        value = DialogEditList(
            list6,
            modal=True,
            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
            tip=None,
            parent=parent,
        )

        if value[0] is True:
            subject = str(value[1][0])
            message = message
            to = str(value[1][1])
        else:
            return

        passwd = binascii.a2b_hex(self.passwd)
        sendMail([to],
                 subject,
                 message,
                 files=[],
                 server=self.setting["server"],
                 ssl=(self.setting["use_ssl"] == "on"),
                 ssl_port=int(self.setting["ssl_port"]),
                 ssl_username=self.username,
                 ssl_passwd=passwd)
示例#22
0
 def onAddYSpan(self, evt):
     l = [['y1', 0, 400, None],
          ['y2', 1, 400, None],]
     window = evt.GetEventObject().GetTopLevelParent()
     value = DialogEditList(l, modal = True, 
                  style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
                  tip = None, 
                  parent  = window)
     if value[0]: 
         v = value[1]
     else: 
         return
     x = self.getp('x').copy()
     y = self.getp('y').copy()
     y = np.array([xx for xx in y] + [v])
     action = UndoRedoFigobjMethod(self._artists[0], 
                                      'data', 
                                       (x, y))
     window = evt.GetEventObject().GetTopLevelParent()
     GlobalHistory().get_history(window).make_entry([action], menu_name = 'add span')
     return 1
示例#23
0
def scale_b(self, factor=None):

    td = self.td
    if factor is None:
        list = [["", "Enter Bt Scale Factor", 2], ["Bt sclae", str(1), 0]]

        flag, value = DialogEditList(list)
        if flag:
            factor = float(value[1])
        else:
            return

    print(('Bt scale by', str(factor)))

    td[:]["table"]["ffprim"] *= factor * factor
    td[:]["table"]["fpol"] *= factor
    td[:]["table"]["qpsi"] *= np.abs(factor)
    td[:]["table"]["bcentr"] *= factor
    add_extra_data(td[:]["table"])
    print('Updating g-file')
    self.onUpdateFile()
示例#24
0
def scale_i(self, factor=None):

    td = self.td
    if factor is None:
        list = [["", "Enter Ip Scale Factor", 2], ["Ip sclae", str(1), 0]]

        flag, value = DialogEditList(list)
        if flag:
            factor = float(value[1])
        else:
            return

    print(('Ip scale by', str(factor)))

    td[:]["table"]["psirz"] *= factor
    td[:]["table"]["qpsi"] *= np.abs(1. / factor)
    td[:]["table"]["cpasma"] *= factor
    td[:]["table"]["ssibry"] *= factor
    td[:]["table"]["ssibdry"] *= factor
    td[:]["table"]["ssimag"] *= factor
    add_extra_data(td[:]["table"])
    print('Updating g-file')
    self.onUpdateFile()
示例#25
0
 def videoviewer_config(self):
     from ifigure.utils.edit_list import DialogEditList
     l = [
         [
             "Interval(sec.)",
             str(float(self._playinterval) / 1000.), 0, {
                 'noexpand': True
             }
         ],
         [None, self._playloop, 3, {
             "text": "Loop",
             "noindent": None
         }],
     ]
     value = DialogEditList(l,
                            parent=self,
                            title='Player Config.',
                            style=wx.DEFAULT_DIALOG_STYLE
                            | wx.RESIZE_BORDER)
     if not value[0]: return
     interval = min([50, int(float(value[1][0]) * 1000.)])
     self._playinterval = interval
     self._playloop = bool(value[1][1])
示例#26
0
def setup(package='',
          root='',
          path='setup_scripts',
          del_scripts=True,
          model=None):

    from ifigure.mto.hg_support import load_subtree_hg, dlg_s
    from ifigure.events import SendSelectionEvent

    app = wx.GetApp().TopWindow
    proj = app.proj
    name = 'setup_scritps'

    if root == '' or path == '':
        if path == '':
            path = 'setup_scripts'
        list6 = [
            ["root repository", None, 404,
             dlg_s()],
            ["source ", path, 0],
        ]
        value = DialogEditList(list6,
                               modal=True,
                               style=wx.DEFAULT_DIALOG_STYLE
                               | wx.RESIZE_BORDER,
                               tip=None,
                               parent=app,
                               title='Select Setup Scripts Repo.')
        if not value[0]:
            return
        root = str(value[1][0])
        path = str(value[1][1])

    if not proj.has_owndir():
        proj.mk_owndir()

    if proj.has_child(name):
        name = proj.get_next_name(name)
    obj = load_subtree_hg(proj,
                          root=root,
                          path=path,
                          name=name,
                          overwrite=False,
                          run_setup=False,
                          launch_gui=False)  # , src = 'setup_scripts')

    separator = '---------'
    if package == '':
        names = obj.get_childnames()
        names = sorted(names)
        names.extend([separator, 'setup scripts'])
        setting = {"style": wx.CB_READONLY, "choices": names}
        list6 = [
            [None, "Select scripts to run ", 2, None],
            ["setup scripts", names[0], 4, setting],
        ]
        #             [None, del_scripts, 3, {"text":'Delete scripts folder after the run'}],]

        value = DialogEditList(list6,
                               modal=True,
                               style=wx.DEFAULT_DIALOG_STYLE
                               | wx.RESIZE_BORDER,
                               tip=None,
                               parent=app,
                               title='Select Setup Scripts')
        if not value[0]:
            if del_scripts:
                obj.destroy()
            else:
                app.proj_tree_viewer.update_widget()
                SendSelectionEvent(obj)
            return
        package = str(value[1][1])
#        del_scripts = value[1][2]

    if (package != 'setup scripts') and (package != separator):
        script = obj.get_child(name=package)
        if model is None:
            model = proj.onAddModel()
        new_model = script(model)

        if del_scripts:
            obj.destroy()

        app.proj_tree_viewer.update_widget()
        if new_model is not None:
            SendSelectionEvent(new_model)
        return model
    else:
        app.proj_tree_viewer.update_widget()
        SendSelectionEvent(obj)
        return obj
示例#27
0
    def load_subtree_hg(parent,
                        root='',
                        path='',
                        name='',
                        overwrite=False,
                        run_setup=False,
                        launch_gui=False):
        app = wx.GetApp().TopWindow
        if root == '':
            list6 = [
                ["root repository", None, 304,
                 dlg_s()],
                ["source ", path, 0],
                ["destination", '', 0],
                [None, True, 3, {
                    "text": 'Run setup script'
                }],
            ]

            value = DialogEditList(list6,
                                   modal=True,
                                   style=wx.DEFAULT_DIALOG_STYLE
                                   | wx.RESIZE_BORDER,
                                   tip=None,
                                   parent=app,
                                   title='retrieve subtree from HG repo.')
            if not value[0]: return
            if not parent.has_owndir(): parent.mk_owndir()

            #           url = rootpath2url(
            root = str(value[1][0])
            path = str(value[1][1])
            name = str(value[1][2])
            run_setup = value[1][3]
            if name.strip() == '':
                name = value[1][1].split('/')[-1]
        else:
            if not parent.has_owndir(): parent.mk_owndir()
            if name == '':
                name = path.split('/')[-1]

        if parent.has_child(name):
            if overwrite:
                parent.get_child(name=name).destroy()
            else:
                print(parent.get_full_path() + '.' + name + ' already exists.')
                obj = parent.get_child(name=name)
                _add_include_exclude(obj)
                return obj
        if path.startswith('/'): path = path[1:]
        url = rootpath2url(root, path)
        dpath = os.path.join(parent.owndir(), name)
        repo = hgapi.Repo(parent.owndir())
        try:
            repo2 = repo.hg_clone(url, dpath)
        except:
            print url, dpath
            dialog.showtraceback(parent=app,
                                 txt='Failed to clone subtree from ' + url,
                                 title='Failed to clone',
                                 traceback=traceback.format_exc())

            return

        load_fpath = True
        fpath = os.path.join(dpath, ".tree_data_hg")
        if not os.path.exists(fpath):
            fpath = os.path.join(dpath, ".tree_data")
            if not os.path.exists(fpath):
                #
                #  In this case, it makes a containing folder
                #  and gather *.py to make PyScript
                #  I should be handling other files here too?
                #

                td = handle_pure_file_repo(parent, name, dpath)
                load_fpath = False
            else:
                dlg = wx.MessageDialog(
                    None,
                    'HG update succeeded but .tree_data_hg is not found.',
                    'Old style for HG repo', wx.OK)
                ret = dlg.ShowModal()
                dlg.Destroy()
                del_old_treedata = True
        else:
            del_old_treedata = False
        if load_fpath:
            fid = open(fpath, 'rb')
            td, olist, nlist = TreeDict().load(fid, keep_zorder=True)
            fid.close()
            parent.add_child(name, td, keep_zorder=True)

            ### for sub repo
            subrepos = []
            for name, child in td.get_children():
                #           print child
                for obj in child.walk_tree():
                    if has_repo(obj):
                        #print 'subrepo', obj
                        load_repo_treedata(obj)

            if del_old_treedata:
                os.remove(fpath)

            for obj in td.walk_tree():
                obj.init_after_load(olist, nlist)

        td.set_mercurial_url(root, path)

        for name, child in td.get_children():
            #           print child
            for obj in child.walk_tree():
                if has_repo(obj):
                    r = hgapi.Repo(obj.owndir())
                    latest = r.revisions(slice(-1, -1))[0].rev
                    current = r.hg_rev()
                    if latest > current:
                        dprint1('updating ' + str(obj) + ' ' +
                                str(r.hg_rev()) + '->' + str(latest))
                        obj.onHGupdate(evt=None, m=latest)

        if run_setup:
            #           try:
            if (td.has_child("scripts") and td.scripts.has_child("setup")):
                #               wx.CallAfter(td.scripts.setup.Run)
                td.scripts.setup.Run()
#           except:
#               dialog.showtraceback(parent = td.get_root_parent().app,
#                                    txt='Failed to run setup script',
#                                    title='Setup script failced',
#                                    traceback=traceback.format_exc())
        _add_include_exclude(td)
        return td
示例#28
0
def onSetting(self, e=None):
    import ifigure.mdsplus.mdsscope
    s = self.td.getvar('setting')
    host = s['connection'][0]['server']
    port = s['connection'][0]['port']

    if s['connection_type'] == 'direct': txt = 'off'
    else: txt = 'on'

    list6 = [
        ["Use Proxy", txt, 1, {
            "values": ["on", "off"]
        }],
        ["Root Tree", "cmod", 0, None],
        ["Proxy Server", str(host), 0, None],
        ["Port", str(port), 0, None],
        ["NumWorker",
         str(ifigure.mdsplus.mdsscope.mds_num_worker), 0, None],
        #           ["Worker", s['worker'], 4, {'style':wx.CB_READONLY, 'choices':['mp', 'th', 'sp']}]]
        [
            "Worker", s['worker'], 4, {
                'style': wx.CB_READONLY,
                'choices': ['mp', 'th']
            }
        ]
    ]

    value = DialogEditList(list6,
                           modal=True,
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                           tip=None,
                           parent=self.td.get_app())

    if value[0]:
        v = value[1]
    else:
        return
    if str(v[0]) == 'on':
        t = 'proxy'
    else:
        t = 'direct'
    onum = ifigure.mdsplus.mdsscope.mds_num_worker
    ifigure.mdsplus.mdsscope.mds_num_worker = long(v[4])
    w = str(v[5])
    #    w = 'mp' ## always use mp worker
    port = str(v[3])
    host = str(v[2])
    restart = False
    if (s['connection_type'] != t or s['worker'] != w
            or onum != ifigure.mdsplus.mdsscope.mds_num_worker
            or s['connection'][0]['server'] != host
            or long(s['connection'][0]['port']) != long(port)):
        restart = True
    s['connection_type'] = t
    s['worker'] = w
    s['connection'][0]['server'] = host
    s['connection'][0]['port'] = long(port)
    if restart:
        self.onReset()
        self.onStartWorker()

    self.td.setvar('setting', s)