示例#1
0
    def set_dm(self, num):
        """
        Make GUI changes based on data model num.
        Get info from WD in appropriate format.
        Called by self.get_dm_and_wd
        """
        #enable or disable self.btn1a
        if self.data_model_num == 3:
            self.btn1a.Enable()
        else:
            self.btn1a.Disable()
        #
        # set pmag_gui_dialogs
        global pmag_gui_dialogs
        if self.data_model_num == 2:
            pmag_gui_dialogs = pgd2
            #wx.CallAfter(self.get_wd_data2)
        elif self.data_model_num == 3:
            pmag_gui_dialogs = pgd3
            #wx.CallAfter(self.get_wd_data)

        # do / re-do menubar
        menubar = pmag_gui_menu.MagICMenu(self,
                                          data_model_num=self.data_model_num)
        self.SetMenuBar(menubar)
示例#2
0
    def __init__(self, WD=None, dmodel=None):
        """
        Input working directory, and data model object (optional).
        """
        wx.Frame.__init__(self, None, wx.ID_ANY, self.title, name='pmag_gui mainframe')

        #set icon
        self.icon = wx.Icon()
        icon_path = os.path.join(PMAGPY_DIRECTORY, 'programs', 'images', 'PmagPy.ico')
        if os.path.isfile(icon_path):
            self.icon.CopyFromBitmap(wx.Bitmap(icon_path, wx.BITMAP_TYPE_ANY))
            self.SetIcon(self.icon)
        else:
            print("-I- PmagPy icon file not found -- skipping")

        self.data_model = dmodel
        self.FIRST_RUN = True

        self.panel = wx.Panel(self, name='pmag_gui main panel')
        self.InitUI()

        # if not specified on the command line,
        # make the user choose their working directory
        if WD:
            self.WD = WD
        else:
            self.get_dir()

        self.get_wd_data()
        # use realpath
        self.WD = os.path.realpath(self.WD)
        # set data model and read in data
        self.dir_path.SetValue(self.WD)

        # for use as module:
        self.resource_dir = os.getcwd()

        # set some things
        self.HtmlIsOpen = False
        self.Bind(wx.EVT_CLOSE, self.on_menu_exit)

        # if specified directory doesn't exist, try to make it
        try:
            if not os.path.exists(self.WD):
                os.mkdir(self.WD)
                pw.simple_warning("New directory: {}\nwill be created".format(self.WD))
        except FileNotFoundError:
            pw.simple_warning("You have provided a directory that does not exist and cannot be created.\n Please pick a different directory.")
            print("-W- You have provided a directory that does not exist and cannot be created.\n    Please pick a different directory.")

        # do menubar
        menubar = pmag_gui_menu.MagICMenu(self)
        self.SetMenuBar(menubar)
        self.menubar = menubar
示例#3
0
    def InitUI(self):
        """
        Build the mainframe
        """
        menubar = pmag_gui_menu.MagICMenu(self,
                                          data_model_num=self.data_model_num)
        self.SetMenuBar(menubar)

        #pnl = self.panel

        #---sizer logo ----

        #start_image = wx.Image("/Users/ronshaar/PmagPy/images/logo2.png")
        #start_image = wx.Image("/Users/Python/simple_examples/001.png")
        #start_image.Rescale(start_image.GetWidth(), start_image.GetHeight())
        #image = wx.BitmapFromImage(start_image)
        #self.logo = wx.StaticBitmap(self.panel, -1, image)

        #---sizer 0 ----

        bSizer0 = wx.StaticBoxSizer(
            wx.StaticBox(self.panel, wx.ID_ANY,
                         "Choose MagIC project directory"), wx.HORIZONTAL)
        self.dir_path = wx.TextCtrl(self.panel,
                                    id=-1,
                                    size=(600, 25),
                                    style=wx.TE_READONLY)
        self.change_dir_button = buttons.GenButton(self.panel,
                                                   id=-1,
                                                   label="change directory",
                                                   size=(-1, -1))
        self.change_dir_button.SetBackgroundColour("#F8F8FF")
        self.change_dir_button.InitColours()
        self.Bind(wx.EVT_BUTTON, self.on_change_dir_button,
                  self.change_dir_button)
        bSizer0.Add(self.change_dir_button, wx.ALIGN_LEFT)
        bSizer0.AddSpacer(40)
        bSizer0.Add(self.dir_path, wx.ALIGN_CENTER_VERTICAL)

        # not fully implemented method for saving/reverting WD
        # last saved: []
        #bSizer0_1 = wx.StaticBoxSizer( wx.StaticBox( self.panel, wx.ID_ANY, "Save MagIC project directory in current state or revert to last-saved state" ), wx.HORIZONTAL )
        #saved_label = wx.StaticText(self.panel, -1, "Last saved:", (20, 120))
        #self.last_saved_time = wx.TextCtrl(self.panel, id=-1, size=(100,25), style=wx.TE_READONLY)
        #now = datetime.datetime.now()
        #now_string = "{}:{}:{}".format(now.hour, now.minute, now.second)
        #self.last_saved_time.write(now_string)
        #self.save_dir_button = buttons.GenButton(self.panel, id=-1, label = "save dir", size=(-1, -1))
        #self.revert_dir_button = buttons.GenButton(self.panel, id=-1, label = "revert dir", size=(-1, -1))

        #self.Bind(wx.EVT_BUTTON, self.on_revert_dir_button, self.revert_dir_button)
        #self.Bind(wx.EVT_BUTTON, self.on_save_dir_button, self.save_dir_button)

        #bSizer0_1.Add(saved_label, flag=wx.RIGHT, border=10)
        #bSizer0_1.Add(self.last_saved_time, flag=wx.RIGHT, border=10)
        #bSizer0_1.Add(self.save_dir_button,flag=wx.ALIGN_LEFT|wx.RIGHT, border=10)
        #bSizer0_1.Add(self.revert_dir_button,wx.ALIGN_LEFT)

        #
        #---sizer 1 ----
        bSizer1 = wx.StaticBoxSizer(
            wx.StaticBox(self.panel, wx.ID_ANY,
                         "Import data to working directory"), wx.HORIZONTAL)

        text = "1. Convert magnetometer files to MagIC format"
        self.btn1 = buttons.GenButton(self.panel,
                                      id=-1,
                                      label=text,
                                      size=(450, 50),
                                      name='step 1')
        self.btn1.SetBackgroundColour("#FDC68A")
        self.btn1.InitColours()
        self.Bind(wx.EVT_BUTTON, self.on_convert_file, self.btn1)

        text = "2. (optional) Calculate geographic/tilt-corrected directions"
        self.btn2 = buttons.GenButton(self.panel,
                                      id=-1,
                                      label=text,
                                      size=(450, 50),
                                      name='step 2')
        self.btn2.SetBackgroundColour("#FDC68A")
        self.btn2.InitColours()
        self.Bind(wx.EVT_BUTTON, self.on_btn_orientation, self.btn2)
        text = "3. (optional) Add MagIC metadata for uploading data to MagIC "
        self.btn3 = buttons.GenButton(self.panel,
                                      id=-1,
                                      label=text,
                                      size=(450, 50),
                                      name='step 3')
        self.btn3.SetBackgroundColour("#FDC68A")
        self.btn3.InitColours()
        self.Bind(wx.EVT_BUTTON, self.on_btn_metadata, self.btn3)

        text = "Unpack txt file downloaded from MagIC"
        self.btn4 = buttons.GenButton(self.panel,
                                      id=-1,
                                      label=text,
                                      size=(330, 50))
        self.btn4.SetBackgroundColour("#FDC68A")
        self.btn4.InitColours()
        self.Bind(wx.EVT_BUTTON, self.on_btn_unpack, self.btn4)

        text = "Convert directory to 3.0. format (legacy data only)"
        self.btn1a = buttons.GenButton(self.panel,
                                       id=-1,
                                       label=text,
                                       size=(330, 50),
                                       name='step 1a')
        self.btn1a.SetBackgroundColour("#FDC68A")
        self.btn1a.InitColours()
        self.Bind(wx.EVT_BUTTON, self.on_btn_convert_3, self.btn1a)

        #str = "OR"
        OR = wx.StaticText(self.panel, -1, "or", (20, 120))
        font = wx.Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL)
        OR.SetFont(font)

        #bSizer0.Add(self.panel,self.btn1,wx.ALIGN_TOP)
        bSizer1_1 = wx.BoxSizer(wx.VERTICAL)
        bSizer1_1.AddSpacer(20)
        bSizer1_1.Add(self.btn1, wx.ALIGN_TOP)
        bSizer1_1.AddSpacer(20)
        bSizer1_1.Add(self.btn2, wx.ALIGN_TOP)
        bSizer1_1.AddSpacer(20)
        bSizer1_1.Add(self.btn3, wx.ALIGN_TOP)
        bSizer1_1.AddSpacer(20)

        bSizer1.Add(bSizer1_1, wx.ALIGN_CENTER, wx.EXPAND)
        bSizer1.AddSpacer(20)

        bSizer1.Add(OR, 0, wx.ALIGN_CENTER, 0)
        bSizer1.AddSpacer(20)

        bSizer1_2 = wx.BoxSizer(wx.VERTICAL)
        spacing = 60  #if self.data_model_num == 3 else 90
        bSizer1_2.AddSpacer(spacing)

        bSizer1_2.Add(self.btn4, 0, wx.ALIGN_CENTER, 0)
        bSizer1_2.AddSpacer(20)
        bSizer1_2.Add(self.btn1a, 0, wx.ALIGN_CENTER, 0)
        bSizer1_2.AddSpacer(20)

        bSizer1.Add(bSizer1_2)
        bSizer1.AddSpacer(20)

        #---sizer 2 ----
        bSizer2 = wx.StaticBoxSizer(
            wx.StaticBox(self.panel, wx.ID_ANY, "Analysis and plots"),
            wx.HORIZONTAL)

        text = "Demag GUI"
        self.btn_demag_gui = buttons.GenButton(self.panel,
                                               id=-1,
                                               label=text,
                                               size=(300, 50),
                                               name='demag gui')
        self.btn_demag_gui.SetBackgroundColour("#6ECFF6")
        self.btn_demag_gui.InitColours()
        self.Bind(wx.EVT_BUTTON, self.on_btn_demag_gui, self.btn_demag_gui)

        text = "Thellier GUI"
        self.btn_thellier_gui = buttons.GenButton(self.panel,
                                                  id=-1,
                                                  label=text,
                                                  size=(300, 50),
                                                  name='thellier gui')
        self.btn_thellier_gui.SetBackgroundColour("#6ECFF6")
        self.btn_thellier_gui.InitColours()
        self.Bind(wx.EVT_BUTTON, self.on_btn_thellier_gui,
                  self.btn_thellier_gui)

        bSizer2.AddSpacer(20)
        bSizer2.Add(self.btn_demag_gui, 0, wx.ALIGN_CENTER, 0)
        bSizer2.AddSpacer(20)
        bSizer2.Add(self.btn_thellier_gui, 0, wx.ALIGN_CENTER, 0)
        bSizer2.AddSpacer(20)

        #---sizer 3 ----
        bSizer3 = wx.StaticBoxSizer(
            wx.StaticBox(self.panel, wx.ID_ANY,
                         "Create file for upload to MagIC database"),
            wx.HORIZONTAL)

        text = "Create MagIC txt file for upload"
        self.btn_upload = buttons.GenButton(self.panel,
                                            id=-1,
                                            label=text,
                                            size=(300, 50))
        self.btn_upload.SetBackgroundColour("#C4DF9B")
        self.btn_upload.InitColours()

        bSizer3.AddSpacer(20)
        bSizer3.Add(self.btn_upload, 0, wx.ALIGN_CENTER, 0)
        bSizer3.AddSpacer(20)
        self.Bind(wx.EVT_BUTTON, self.on_btn_upload, self.btn_upload)

        #---arange sizers ----

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.AddSpacer(5)
        #vbox.Add(self.logo,0,wx.ALIGN_CENTER,0)
        vbox.AddSpacer(5)
        vbox.Add(bSizer0, 0, wx.ALIGN_CENTER, 0)
        vbox.AddSpacer(10)
        #vbox.Add(bSizer0_1, 0, wx.ALIGN_CENTER, 0)
        #vbox.AddSpacer(10)
        vbox.Add(bSizer1, 0, wx.ALIGN_CENTER, 0)
        vbox.AddSpacer(10)
        vbox.Add(bSizer2, 0, wx.ALIGN_CENTER, 0)
        vbox.AddSpacer(10)
        vbox.Add(bSizer3, 0, wx.ALIGN_CENTER, 0)
        vbox.AddSpacer(10)
        hbox.AddSpacer(10)
        hbox.Add(vbox, 0, wx.ALIGN_CENTER, 0)
        hbox.AddSpacer(5)

        self.panel.SetSizer(hbox)
        hbox.Fit(self)