Пример #1
0
    def OnCoreDataClick(self, event):
        """ Method for when Core Data button is clicked """
        # If no items are currently selected ...
        if (self.fname_lb.GetCount() > 0) and (len(self.fname_lb.GetSelections()) == 0):
            # ... then select the first item
            self.fname_lb.Select(0)
        
        # We can only edit Core Data once the Media Filename has been selected in the file list and the file must exist
        if (self.fname_lb.GetStringSelection() != '') and os.path.exists(self.fname_lb.GetStringSelection()):
            # Extract the path-less File Name from the full-path Media File Name for the selected item in the filename list
            (path, filename) = os.path.split(self.fname_lb.GetStringSelection())

            # Determine if the appropriate record exists in the database
            try:
                # Load the record if it exists, raises an exception if it does not
                coreData = CoreData.CoreData(filename)
                # If the record exists, lock it.
                coreData.lock_record()
            # If the record does not exist, a RecordNotFoundError exception is raised.
            except RecordNotFoundError:
                # Create an empty CoreData Object
                coreData = CoreData.CoreData()
                # Specify the path-less filename as the Identifier
                coreData.id = filename
            except RecordLockedError, e:
                ReportRecordLockedException(_('Core Data record'), coreData.id, e)
                # If we get a record lock error, we don't need to display the Core Data Properties form
                return
            # If a different exception is raised, report it and pass it on.
            except:
Пример #2
0
    def __init__(self, parent, id, title, ep_object):
        # Make the Keyword Edit List resizable by passing wx.RESIZE_BORDER style
        Dialogs.GenForm.__init__(self, parent, id, title, (550,435), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                                 useSizers = True, HelpContext='Episode Properties')
        # Remember the Parent Window
        self.parent = parent
        self.obj = ep_object

        # Create the form's main VERTICAL sizer
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        # Create a HORIZONTAL sizer for the first row
        r1Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v1 = wx.BoxSizer(wx.VERTICAL)
        # Episode ID
        self.id_edit = self.new_edit_box(_("Episode ID"), v1, self.obj.id, maxLen=100)
        # Add the element to the sizer
        r1Sizer.Add(v1, 1, wx.EXPAND)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r1Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Create a HORIZONTAL sizer for the next row
        r2Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v2 = wx.BoxSizer(wx.VERTICAL)
        # Library ID layout
        series_edit = self.new_edit_box(_("Library ID"), v2, self.obj.series_id)
        # Add the element to the sizer
        r2Sizer.Add(v2, 2, wx.EXPAND)
        series_edit.Enable(False)

        # Add a horizontal spacer to the row sizer        
        r2Sizer.Add((10, 0))

        # Dialogs.GenForm does not provide a Masked text control, so the Date
        # Field is handled differently than other fields.
        
        # Create a VERTICAL sizer for the next element
        v3 = wx.BoxSizer(wx.VERTICAL)
        # Date [label]
        date_lbl = wx.StaticText(self.panel, -1, _("Date (MM/DD/YYYY)"))
        v3.Add(date_lbl, 0, wx.BOTTOM, 3)

        # Date
        # Use the Masked Text Control (Requires wxPython 2.4.2.4 or later)
        # TODO:  Make Date autoformat localizable
        self.dt_edit = wx.lib.masked.TextCtrl(self.panel, -1, '', autoformat='USDATEMMDDYYYY/')
        v3.Add(self.dt_edit, 0, wx.EXPAND)
        # If a Date is know, load it into the control
        if (self.obj.tape_date != None) and (self.obj.tape_date != '') and (self.obj.tape_date != '01/01/0'):
            self.dt_edit.SetValue(self.obj.tape_date)
        # Add the element to the sizer
        r2Sizer.Add(v3, 1, wx.EXPAND)

        # Add a horizontal spacer to the row sizer        
        r2Sizer.Add((10, 0))

        # Create a VERTICAL sizer for the next element
        v4 = wx.BoxSizer(wx.VERTICAL)
        # Length
        self.len_edit = self.new_edit_box(_("Length"), v4, self.obj.tape_length_str())
        # Add the element to the sizer
        r2Sizer.Add(v4, 1, wx.EXPAND)
        self.len_edit.Enable(False)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r2Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Media Filename(s) [label]
        txt = wx.StaticText(self.panel, -1, _("Media Filename(s)"))
        mainSizer.Add(txt, 0, wx.BOTTOM, 3)

        # Create a HORIZONTAL sizer for the next row
        r3Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Media Filename(s)
        # If the media filename path is not empty, we should normalize the path specification
        if self.obj.media_filename == '':
            filePath = self.obj.media_filename
        else:
            filePath = os.path.normpath(self.obj.media_filename)
        # Initialize the list of media filenames with the first one.
        self.filenames = [filePath]
        # For each additional Media file ...
        for vid in self.obj.additional_media_files:
            # ... add it to the filename list
            self.filenames.append(vid['filename'])
        self.fname_lb = wx.ListBox(self.panel, -1, wx.DefaultPosition, wx.Size(180, 60), self.filenames)
        # Add the element to the sizer
        r3Sizer.Add(self.fname_lb, 5, wx.EXPAND)
        self.fname_lb.SetDropTarget(ListBoxFileDropTarget(self.fname_lb))
        
        # Add a horizontal spacer to the row sizer        
        r3Sizer.Add((10, 0))

        # Create a VERTICAL sizer for the next element
        v4 = wx.BoxSizer(wx.VERTICAL)
        # Add File button layout
        addFile = wx.Button(self.panel, wx.ID_FILE1, _("Add File"), wx.DefaultPosition)
        v4.Add(addFile, 0, wx.EXPAND | wx.BOTTOM, 3)
        wx.EVT_BUTTON(self, wx.ID_FILE1, self.OnBrowse)

        # Remove File button layout
        removeFile = wx.Button(self.panel, -1, _("Remove File"), wx.DefaultPosition)
        v4.Add(removeFile, 0, wx.EXPAND | wx.BOTTOM, 3)
        wx.EVT_BUTTON(self, removeFile.GetId(), self.OnRemoveFile)

        if TransanaConstants.proVersion:
            # SynchronizeFiles button layout
            synchronize = wx.Button(self.panel, -1, _("Synchronize"), wx.DefaultPosition)
            v4.Add(synchronize, 0, wx.EXPAND)
            synchronize.Bind(wx.EVT_BUTTON, self.OnSynchronize)

        # Add the element to the sizer
        r3Sizer.Add(v4, 1, wx.EXPAND)
        # If Mac ...
        if 'wxMac' in wx.PlatformInfo:
            # ... add a spacer to avoid control clipping
            r3Sizer.Add((2, 0))

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r3Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Create a HORIZONTAL sizer for the next row
        r4Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v5 = wx.BoxSizer(wx.VERTICAL)
        # Comment
        comment_edit = self.new_edit_box(_("Comment"), v5, self.obj.comment, maxLen=255)
        # Add the element to the sizer
        r4Sizer.Add(v5, 1, wx.EXPAND)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r4Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))
        
        # Create a HORIZONTAL sizer for the next row
        r5Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v6 = wx.BoxSizer(wx.VERTICAL)
        # Keyword Group [label]
        txt = wx.StaticText(self.panel, -1, _("Keyword Group"))
        v6.Add(txt, 0, wx.BOTTOM, 3)

        # Keyword Group [list box]

        kw_groups_id = wx.NewId()
        # Create an empty Keyword Group List for now.  We'll populate it later (for layout reasons)
        self.kw_groups = []
        self.kw_group_lb = wx.ListBox(self.panel, kw_groups_id, wx.DefaultPosition, wx.DefaultSize, self.kw_groups)
        v6.Add(self.kw_group_lb, 1, wx.EXPAND)

        # Add the element to the sizer
        r5Sizer.Add(v6, 1, wx.EXPAND)

        self.kw_list = []
        wx.EVT_LISTBOX(self, kw_groups_id, self.OnGroupSelect)

        # Add a horizontal spacer
        r5Sizer.Add((10, 0))

        # Create a VERTICAL sizer for the next element
        v7 = wx.BoxSizer(wx.VERTICAL)
        # Keyword [label]
        txt = wx.StaticText(self.panel, -1, _("Keyword"))
        v7.Add(txt, 0, wx.BOTTOM, 3)

        # Keyword [list box]
        self.kw_lb = wx.ListBox(self.panel, -1, wx.DefaultPosition, wx.DefaultSize, self.kw_list, style=wx.LB_EXTENDED)
        v7.Add(self.kw_lb, 1, wx.EXPAND)

        wx.EVT_LISTBOX_DCLICK(self, self.kw_lb.GetId(), self.OnAddKW)

        # Add the element to the sizer
        r5Sizer.Add(v7, 1, wx.EXPAND)

        # Add a horizontal spacer
        r5Sizer.Add((10, 0))

        # Create a VERTICAL sizer for the next element
        v8 = wx.BoxSizer(wx.VERTICAL)
        # Keyword transfer buttons
        add_kw = wx.Button(self.panel, wx.ID_FILE2, ">>", wx.DefaultPosition)
        v8.Add(add_kw, 0, wx.EXPAND | wx.TOP, 20)
        wx.EVT_BUTTON(self.panel, wx.ID_FILE2, self.OnAddKW)

        rm_kw = wx.Button(self.panel, wx.ID_FILE3, "<<", wx.DefaultPosition)
        v8.Add(rm_kw, 0, wx.EXPAND | wx.TOP, 10)
        wx.EVT_BUTTON(self, wx.ID_FILE3, self.OnRemoveKW)

        kwm = wx.BitmapButton(self.panel, wx.ID_FILE4, TransanaImages.KWManage.GetBitmap())
        v8.Add(kwm, 0, wx.EXPAND | wx.TOP, 10)
        # Add a spacer to increase the height of the Keywords section
        v8.Add((0, 60))
        kwm.SetToolTipString(_("Keyword Management"))
        wx.EVT_BUTTON(self, wx.ID_FILE4, self.OnKWManage)

        # Add the element to the sizer
        r5Sizer.Add(v8, 0)

        # Add a horizontal spacer
        r5Sizer.Add((10, 0))

        # Create a VERTICAL sizer for the next element
        v9 = wx.BoxSizer(wx.VERTICAL)

        # Episode Keywords [label]
        txt = wx.StaticText(self.panel, -1, _("Episode Keywords"))
        v9.Add(txt, 0, wx.BOTTOM, 3)

        # Episode Keywords [list box]
        
        # Create an empty ListBox
        self.ekw_lb = wx.ListBox(self.panel, -1, wx.DefaultPosition, wx.DefaultSize, style=wx.LB_EXTENDED)
        v9.Add(self.ekw_lb, 1, wx.EXPAND)
        
        self.ekw_lb.Bind(wx.EVT_KEY_DOWN, self.OnKeywordKeyDown)

        # Add the element to the sizer
        r5Sizer.Add(v9, 2, wx.EXPAND)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r5Sizer, 5, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))
        
        # Create a sizer for the buttons
        btnSizer = wx.BoxSizer(wx.HORIZONTAL)

        # Core Data button layout
        CoreData = wx.Button(self.panel, -1, _("Core Data"))
        # If Mac ...
        if 'wxMac' in wx.PlatformInfo:
            # ... add a spacer to avoid control clipping
            btnSizer.Add((2, 0))
        btnSizer.Add(CoreData, 0)
        wx.EVT_BUTTON(self, CoreData.GetId(), self.OnCoreDataClick)

        # Add the buttons
        self.create_buttons(sizer=btnSizer)
        # Add the button sizer to the main sizer
        mainSizer.Add(btnSizer, 0, wx.EXPAND)
        # If Mac ...
        if 'wxMac' in wx.PlatformInfo:
            # ... add a spacer to avoid control clipping
            mainSizer.Add((0, 2))

        # Set the PANEL's main sizer
        self.panel.SetSizer(mainSizer)
        # Tell the PANEL to auto-layout
        self.panel.SetAutoLayout(True)
        # Lay out the Panel
        self.panel.Layout()
        # Lay out the panel on the form
        self.Layout()
        # Resize the form to fit the contents
        self.Fit()

        # Get the new size of the form
        (width, height) = self.GetSizeTuple()
        # Reset the form's size to be at least the specified minimum width
        self.SetSize(wx.Size(max(550, width), max(435, height)))
        # Define the minimum size for this dialog as the current size
        self.SetSizeHints(max(550, width), max(435, height))
        # Center the form on screen
        TransanaGlobal.CenterOnPrimary(self)

        # We need to set some minimum sizes so the sizers will work right
        self.kw_group_lb.SetSizeHints(minW = 50, minH = 20)
        self.kw_lb.SetSizeHints(minW = 50, minH = 20)
        self.ekw_lb.SetSizeHints(minW = 50, minH = 20)

        # We populate the Keyword Groups, Keywords, and Clip Keywords lists AFTER we determine the Form Size.
        # Long Keywords in the list were making the form too big!

        self.kw_groups = DBInterface.list_of_keyword_groups()
        for keywordGroup in self.kw_groups:
            self.kw_group_lb.Append(keywordGroup)

        # Load the parent Library in order to determine the default Keyword Group
        tempLibrary = Library.Library(self.obj.series_id)
        # Select the Library Default Keyword Group in the Keyword Group list
        if (tempLibrary.keyword_group != '') and (self.kw_group_lb.FindString(tempLibrary.keyword_group) != wx.NOT_FOUND):
            self.kw_group_lb.SetStringSelection(tempLibrary.keyword_group)
        # If no Default Keyword Group is defined, select the first item in the list
        else:
            # but only if there IS a first item in the list.
            if len(self.kw_groups) > 0:
                self.kw_group_lb.SetSelection(0)
        if self.kw_group_lb.GetSelection() != wx.NOT_FOUND:
            self.kw_list = \
                DBInterface.list_of_keywords_by_group(self.kw_group_lb.GetStringSelection())
        else:
            self.kw_list = []
        for keyword in self.kw_list:
            self.kw_lb.Append(keyword)

        # Populate the ListBox
        for episodeKeyword in self.obj.keyword_list:
            self.ekw_lb.Append(episodeKeyword.keywordPair)

        self.id_edit.SetFocus()
Пример #3
0
 def __init__(self, parent, id):
     # Create a blank Core Data Object
     obj = CoreData.CoreData()
     CoreDataPropertiesForm.__init__(self, parent, id, _("Add Core Data"), obj)