Exemple #1
0
def remove_snapshots(host=None):
    ret, snapshotid_list = Snapshot.get_block_snapshot_ids(host)
    if ret == 0:
        for ssid in snapshotid_list:
            ret = Snapshot.delete_block_snapshot(ssid, host)
            if ret == 0:
                print "[Info] Succeed to remove snapshot %d." % ssid
            else:
                print "[Error] Failed to delete snapshot %d." % ssid
    else:
        print "[Error] Failed to get snapshot info."
    def SelectCell(self, col, row):
        """ Handle the selection of an individual cell in the Grid """
        # If we're in the "Time" column ...
        if col == 0:
            # ... determine the time of the selected item
            times = self.gridClips.GetCellValue(row, col).split('-')
            # ... and move to that time
            self.ControlObject.SetVideoStartPoint(Misc.time_in_str_to_ms(times[0]))
            # Retain the program focus in the Data Window
            self.gridClips.SetFocus()
        # If we're in the "ID" or "Keywords" column ...
        else:
            # ... if we have a Clip ...
            if self.gridClips.GetCellValue(row, 4) == 'Clip':
                # Load the Clip
                # Switched to CallAfter because of crashes on the Mac.
                wx.CallAfter(self.ControlObject.LoadClipByNumber, int(self.gridClips.GetCellValue(row, 3)))

                # NOTE:  LoadClipByNumber eliminates the EpisodeClipsTab, so no further processing can occur!!
                #        There used to be code here to select the Clip in the Database window, but it stopped
                #        working when I added multiple transcripts, so I moved it to the ControlObject.LoadClipByNumber()
                #        method.

            # ... if we have a Snapshot ...
            elif self.gridClips.GetCellValue(row, 4) == 'Snapshot':
                tmpSnapshot = Snapshot.Snapshot(int(self.gridClips.GetCellValue(row, 3)))
                # ... load the Snapshot
                self.ControlObject.LoadSnapshot(tmpSnapshot)
                # ... determine the time of the selected item
                times = self.gridClips.GetCellValue(row, 0).split('-')
                # ... and move to that time
                self.ControlObject.SetVideoStartPoint(Misc.time_in_str_to_ms(times[0]))
                # ... and set the program focus on the Snapshot
                self.ControlObject.SelectSnapshotWindow(tmpSnapshot.id, tmpSnapshot.number, selectInDataWindow=True)
Exemple #3
0
def parse(data_path): 
    with open(data_path) as f:
        lines = [line.rstrip() for line in f]

    snap = []
    for l in lines:
        with open(l) as s:
            next(s)
            snap.append([line.rstrip() for line in s])

    snapshot = []
    n = 0
    for s in snap:
        snapshot.append(Snapshot.Snapshot())
        for data in s:
            split_1 = data.split("\t")
            interaction = split_1[1]
            distance = float(split_1[3])
            energy = float(split_1[5])
            residue1 = (int(split_1[0].split(":")[1]), split_1[0].split(":")[0])
            residue2 = (int(split_1[2].split(":")[1]), split_1[2].split(":")[0])
            snapshot[n].addNode(residue1)
            snapshot[n].addNode(residue2)
            snapshot[n].addEdge(residue1, residue2, interaction, distance, energy)
            snapshot[n].addSimpleEdge(residue1, residue2)
            snapshot[n].addTypeEdge(residue1, residue2, interaction, energy)
        n += 1
    return snapshot
def loadPuzzle(puzzlefile):
    file = open(puzzlefile)
    newsnapshot = Snapshot.snapshot()
    rownumber = 0
    for line in file: # read lines
        newline = [int(x) for x in line.split()] 
        for columnnumber in range(9):
            newsnapshot.setCellVal(rownumber, columnnumber, newline[columnnumber])  
        rownumber +=1
    return newsnapshot
Exemple #5
0
def loadPuzzle(puzzlefile):
    file = open(puzzlefile)
    newsnapshot = Snapshot.snapshot()
    rownumber = 0
    
    for line in file: # read lines
        newline = [int(x) for x in line.split()] 
        for columnnumber in range(9):
            newsnapshot.setCellVal(rownumber, columnnumber, newline[columnnumber])  
        rownumber +=1
    return newsnapshot
 def diff_snapshot(snapshot_one, snapshot_two):
     snapshot_one_res = Snapshot.excluding_fields(snapshot_one.convert_to_dict(), ['timestamp'])
     snapshot_two_res = Snapshot.excluding_fields(snapshot_two.convert_to_dict(), ['timestamp'])
     snapshot_diff = Snapshot()
     snapshot_diff.timestamp = snapshot_two.timestamp - snapshot_one.timestamp
     for item_two in snapshot_two_res:
         for obj in snapshot_two_res[item_two]:
             if not obj in snapshot_one_res[item_two]:
                 snapshot_diff.add(obj, item_two, DiffObject(ADD, snapshot_two_res[item_two][obj]))
             elif snapshot_two_res[item_two][obj] != snapshot_one_res[item_two][obj]:
                 snapshot_diff.add(obj, item_two, DiffObject(CHANGE,
                                                             DiffValue(snapshot_one_res[item_two][obj],
                                                                       snapshot_two_res[item_two][obj])))
         for obj in snapshot_one_res[item_two]:
             if not obj in snapshot_two_res[item_two]:
                 snapshot_diff.add(obj, item_two, DiffObject(DELETE, snapshot_one_res[item_two][obj]))
     return snapshot_diff
Exemple #7
0
def load_puzzle(puzzle_file):
    file = open(puzzle_file)
    content = file.readlines()
    new_snapshot = Snapshot.Snapshot()

    for row_number in range(5):
        new_row = [int(x) for x in content[row_number].split()]
        for column_number in range(5):
            new_snapshot.set_cell_value(row_number, column_number,
                                        new_row[column_number])
    constraints = content[5:]
    for c in constraints:
        new_constraint = [int(x) for x in c.split()]
        new_snapshot.set_constraint(new_constraint)
    file.close()
    return new_snapshot
Exemple #8
0
def loadPuzzle(puzzlefile):
    file = open(puzzlefile)
    content = file.readlines()
    newsnapshot = Snapshot.snapshot()
    rownumber = 0

    for rownumber in range(5):
        newrow = [int(x) for x in content[rownumber].split()]
        for columnnumber in range(5):
            newsnapshot.setCellVal(rownumber, columnnumber,
                                   newrow[columnnumber])
    constraints = content[5:]
    for c in constraints:
        newconstraint = [int(x) for x in c.split()]
        newsnapshot.setConstraint(newconstraint)
    file.close()
    return newsnapshot
Exemple #9
0
def just_for_test_block(volume_num=1000,
                        volume_name_prefix="volume-",
                        volume_size_min=100,
                        volume_size_max=500,
                        snapshot_num=1000,
                        snapshot_name_prefix="snapshot-",
                        client_group_num=1000,
                        client_group_name_prefix="client-group",
                        access_path_num=2,
                        access_path_name_prefix="access_path",
                        host=None):
    if access_path_num < 2 or volume_num < 2 or snapshot_num < 2 or client_group_num < 2:
        print "[Error] The num of access path, volume, snapshot, client group should be larger than 2."
        return
    if volume_size_min < 0 or volume_size_max < 0 or volume_size_min > volume_size_max:
        print "[Error] Invalid parameters."
        return

    # create block volumes
    ret, pool_ids = Pool.get_pool_ids(host=host)
    if ret != 0 or len(pool_ids) < 1:
        print "[Error] Failed to get pool info or pool not exists."
        return
    for i in range(1, volume_num + 1):
        size = random.randint(volume_size_min, volume_size_max)
        pool_id = pool_ids[random.randint(0, len(pool_ids) - 1)]
        print BlockVolume.create_block_volume(volume_name_prefix + str(i),
                                              pool_id,
                                              str(size) + "G",
                                              host=host)

    # create block snapshots
    ret, volume_ids = BlockVolume.get_block_volume_ids(host=host)
    if ret != 0 or len(volume_ids) < 1:
        print "[Error] Failed to get volume info or volumes not exist."
        return
    for i in range(1, snapshot_num + 1):
        idx = random.randint(0, len(volume_ids) - 1)
        print Snapshot.create_block_snapshot(snapshot_name_prefix +
                                             str(uuid.uuid1()),
                                             volume_ids[idx],
                                             host=host)

    for i in range(1, client_group_num + 1):
        iqn = generate_iqn()
        print ClientGroup.create_client_group(client_group_name_prefix +
                                              str(i),
                                              "iSCSI",
                                              iqn,
                                              host=host)

    # create access paths
    for i in range(1, access_path_num + 1):
        print AccessPath.create_access_path(access_path_name_prefix + str(i),
                                            aptype="iSCSI",
                                            host=host)

    # create mapping groups
    ret, client_group_ids = ClientGroup.get_client_group_ids(host=host)
    if ret != 0:
        print "[Error] Failed to get client group info."
        return

    volume_ids.sort()
    client_group_ids.sort()

    cgid_len = len(client_group_ids)
    vid_len = len(volume_ids)

    for i in range(0, cgid_len / 2):
        cgid = client_group_ids[i]
        print MappingGroup.create_mapping_group(1,
                                                volume_ids[:vid_len / 2],
                                                cgid,
                                                host=host)

    for i in range(cgid_len / 2, cgid_len):
        cgid = client_group_ids[i]
        print MappingGroup.create_mapping_group(2,
                                                volume_ids[vid_len / 2:],
                                                cgid,
                                                host=host)
Exemple #10
0
    def db_delete(self, use_transactions=1):
        """Delete this object record from the database.  Raises
        RecordLockedError exception if the record is locked and unable to
        be deleted."""
        result = 1
        try:
            # Initialize delete operation, begin transaction if necessary
            (db, c) = self._db_start_delete(use_transactions)
            if (db == None):
                return  # Abort delete

            # Delete all Collection-based Filter Configurations
            #   Delete Collection Clip Data Export records
            DBInterface.delete_filter_records(4, self.number)
            #   Delete Collection Report records
            DBInterface.delete_filter_records(12, self.number)
            # Delete Collection Map records
            DBInterface.delete_filter_records(16, self.number)

            # Detect, Load, and Delete all Collection Notes
            notes = self.get_note_nums()
            for note_num in notes:
                note = Note.Note(note_num)
                result = result and note.db_delete(0)
                del note
            del notes

            # Delete Clips, which in turn will delete Clip transcripts/notes/kws
            clips = DBInterface.list_of_clips_by_collection(
                self.id, self.parent)
            for (clipNo, clip_id, collNo) in clips:
                clip = Clip.Clip(clipNo)
                result = result and clip.db_delete(0)
                del clip
            del clips

            # Delete Quotes, which in turn will delete Quote notes/kws
            quotes = DBInterface.list_of_quotes_by_collectionnum(self.number)
            for (quoteNo, quote_id, collNo, sourceDocNo) in quotes:
                quote = Quote.Quote(num=quoteNo)
                result = result and quote.db_delete(0)
                del quote
            del quotes

            # Delete Snapshots, which in turn will delete Snapshot Coding and Keywords
            snapshots = DBInterface.list_of_snapshots_by_collectionnum(
                self.number)
            for (snapshotNo, snapshotID, collNo) in snapshots:
                # Since we intend to delete the snapshot, we can suppress the error message about missing Episodes
                snapshot = Snapshot.Snapshot(snapshotNo,
                                             suppressEpisodeError=True)
                result = result and snapshot.db_delete(0)
                del snapshot
            del snapshots

            # Delete all Nested Collections
            for (collNo, collID,
                 parentCollNo) in DBInterface.list_of_collections(self.number):
                tempCollection = Collection(collNo)
                result = result and tempCollection.db_delete(0)
                del tempCollection

            # Delete the actual record
            self._db_do_delete(use_transactions, c, result)

            # Cleanup
            c.close()
            self.clear()
        except RecordLockedError, e:

            if DEBUG:
                print "Collection: RecordLocked Error", e

            # if a sub-record is locked, we may need to unlock the Collection record (after rolling back the Transaction)
            if self.isLocked:
                # c (the database cursor) only exists if the record lock was obtained!
                # We must roll back the transaction before we unlock the record.
                c.execute("ROLLBACK")

                if DEBUG:
                    print "Collection: roll back Transaction"

                c.close()

                self.unlock_record()

                if DEBUG:
                    print "Collection: unlocking record"

            raise e
    def DisplayCells(self, TimeCode):
        """ Get data from the database and populate the Episode Clips / Selected Clips Grid """
        # Get clip data from the database
        clipData = DBInterface.list_of_clips_by_episode(self.episodeObj.number, TimeCode)
        if TransanaConstants.proVersion:
            # Get the snapshot data from the database
            snapshotData = DBInterface.list_of_snapshots_by_episode(self.episodeObj.number, TimeCode)

        # Combine the two lists
        cellData = {}
        # For each Clip ...
        for clip in clipData:
            # load the Clip
            tmpObj = Clip.Clip(clip['ClipNum'])
            # add the Clip to the cellData
            cellData[(clip['ClipStart'], clip['ClipStop'], tmpObj.GetNodeString(True).upper())] = tmpObj
        if TransanaConstants.proVersion:
            # for each Snapshot ...
            for snapshot in snapshotData:
                # load the Snapshot
                tmpObj = Snapshot.Snapshot(snapshot['SnapshotNum'])
                # add the Snapshot to the cellData
                cellData[(snapshot['SnapshotStart'], snapshot['SnapshotStop'], tmpObj.GetNodeString(True).upper())] = tmpObj

        # Get the Keys for the cellData
        sortedKeys = cellData.keys()
        # Sort the keys for the cellData into the right order
        sortedKeys.sort()
        
        # Add rows to the Grid to accomodate the amount of data returned, or delete rows if we have too many
        if len(cellData) > self.gridClips.GetNumberRows():
            self.gridClips.AppendRows(len(cellData) - self.gridClips.GetNumberRows(), False)
        elif len(cellData) < self.gridClips.GetNumberRows():
            self.gridClips.DeleteRows(numRows = self.gridClips.GetNumberRows() - len(cellData))

        # Initialize the Row Counter
        loop = 0
        # Add the data to the Grid
        for keyVals in sortedKeys:
            # If we have a Clip ...
            if isinstance(cellData[keyVals], Clip.Clip):
                # ... get the start, stop times and the object type
                startTime = cellData[keyVals].clip_start
                stopTime = cellData[keyVals].clip_stop
                objType = 'Clip'
                # Initialize the string for all the Keywords to blank
                kwString = unicode('', 'utf8')
                # Initialize the prompt for building the keyword string
                kwPrompt = '%s'
            # If we have a Snapshot ...
            elif isinstance(cellData[keyVals], Snapshot.Snapshot):
                # ... get the start, stop times and the object type
                startTime = cellData[keyVals].episode_start
                stopTime = cellData[keyVals].episode_start + cellData[keyVals].episode_duration
                objType = 'Snapshot'
                # if there are whole snapshot keywords ...
                if len(cellData[keyVals].keyword_list) > 0:
                    # ... initialize the string for all the Keywords to indicate this
                    kwString = unicode(_('Whole:'), 'utf8') + '\n'
                # If there are NOT whole snapshot keywords ...
                else:
                    # ... initialize the string for all the Keywords to blank
                    kwString = unicode('', 'utf8')
                # Initialize the prompt for building the keyword string
                kwPrompt = '  %s'
            # For each Keyword in the Keyword List ...
            for kws in cellData[keyVals].keyword_list:
                # ... add the Keyword to the Keyword List
                kwString += kwPrompt % kws.keywordPair
                # If we have a Clip ...
                if isinstance(cellData[keyVals], Clip.Clip):
                    # After the first keyword, we need a NewLine in front of the Keywords.  This accompishes that!
                    kwPrompt = '\n%s'
                # If we have a Snapshot ...
                elif isinstance(cellData[keyVals], Snapshot.Snapshot):
                    # After the first keyword, we need a NewLine in front of the Keywords.  This accompishes that!
                    kwPrompt = '\n  %s'

            # If we have a Snapshot, we also want to display CODED Keywords in addition to the WHOLE Snapshot keywords
            # we've already included
            if isinstance(cellData[keyVals], Snapshot.Snapshot):
                # Keep a list of the coded keywords we've already displayed
                codedKeywords = []
                # Modify the template for additional keywords
                kwPrompt = '\n  %s : %s'
                # For each of the Snapshot's Coding Objects ...
                for x in range(len(cellData[keyVals].codingObjects)):
                    # ... if the Coding Object is visible and if it is not already in the codedKeywords list ...
                    if (cellData[keyVals].codingObjects[x]['visible']) and \
                      (not (cellData[keyVals].codingObjects[x]['keywordGroup'], cellData[keyVals].codingObjects[x]['keyword']) in codedKeywords):
                        # ... if this is the FIRST Coded Keyword ...
                        if len(codedKeywords) == 0:
                            # ... and if there WERE Whole Snapshot Keywords ...
                            if len(kwString) > 0:
                                # ... then add a line break to the Keywords String ...
                                kwString += '\n'
                            # ... add the indicator to the Keywords String that we're starting to show Coded Keywords
                            kwString += unicode(_('Coded:'), 'utf8')
                        # ... add the coded keyword to the Keywords String ...
                        kwString += kwPrompt % (cellData[keyVals].codingObjects[x]['keywordGroup'], cellData[keyVals].codingObjects[x]['keyword'])
                        # ... add the keyword to the Coded Keywords list
                        codedKeywords.append((cellData[keyVals].codingObjects[x]['keywordGroup'], cellData[keyVals].codingObjects[x]['keyword']))

            # Insert the data values into the Grid Row
            # Start and Stop time in column 0
            self.gridClips.SetCellValue(loop, 0, "%s -\n %s" % (Misc.time_in_ms_to_str(startTime), Misc.time_in_ms_to_str(stopTime)))
            # Node String (including Item name) in column 1
            self.gridClips.SetCellValue(loop, 1, cellData[keyVals].GetNodeString(True))
            # make the Collection / Item ID line auto-word-wrap
            self.gridClips.SetCellRenderer(loop, 1, grid.GridCellAutoWrapStringRenderer())
            # Keywords in column 2
            self.gridClips.SetCellValue(loop, 2, kwString)
            # Item Number (hidden) in column 3.  Convert value to a string
            self.gridClips.SetCellValue(loop, 3, "%s" % cellData[keyVals].number)
            # Item Type (hidden) in column 4
            self.gridClips.SetCellValue(loop, 4, "%s" % objType)
            # Auto-size THIS row
            self.gridClips.AutoSizeRow(loop, True)
            # Increment the Row Counter
            loop += 1
        # Select the first cell
        self.gridClips.SetGridCursor(0, 0)
Exemple #12
0
    def __init__(self, parent, id, title, note_object):
        # Make the Keyword Edit List resizable by passing wx.RESIZE_BORDER style
        Dialogs.GenForm.__init__(self, parent, id, title, size=(400, 260), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                                 useSizers = True, HelpContext='Notes')  # 'Notes' is the Help Context for Notes.  There is no entry for Note Properties at this time

        self.obj = note_object
        seriesID = ''
        episodeID = ''
        transcriptID = ''
        collectionID = ''
        clipID = ''
        snapshotID = ''
        documentID = ''
        quoteID = ''
        if (self.obj.series_num != 0) and (self.obj.series_num != None):
            tempLibrary = Library.Library(self.obj.series_num)
            seriesID = tempLibrary.id
        elif (self.obj.episode_num != 0) and (self.obj.episode_num != None):
            tempEpisode = Episode.Episode(self.obj.episode_num)
            episodeID = tempEpisode.id
            tempLibrary = Library.Library(tempEpisode.series_num)
            seriesID = tempLibrary.id
        elif (self.obj.transcript_num != 0) and (self.obj.transcript_num != None):
            # To save time here, we can skip loading the actual transcript text, which can take time once we start dealing with images!
            tempTranscript = Transcript.Transcript(self.obj.transcript_num, skipText=True)
            transcriptID = tempTranscript.id
            tempEpisode = Episode.Episode(tempTranscript.episode_num)
            episodeID = tempEpisode.id
            tempLibrary = Library.Library(tempEpisode.series_num)
            seriesID = tempLibrary.id
        elif (self.obj.collection_num != 0) and (self.obj.collection_num != None):
            tempCollection = Collection.Collection(self.obj.collection_num)
            collectionID = tempCollection.GetNodeString()
        elif (self.obj.clip_num != 0) and (self.obj.clip_num != None):
            # We can skip loading the Clip Transcript to save load time
            tempClip = Clip.Clip(self.obj.clip_num, skipText=True)
            clipID = tempClip.id
            tempCollection = Collection.Collection(tempClip.collection_num)
            collectionID = tempCollection.GetNodeString()
        elif (self.obj.snapshot_num != 0) and (self.obj.snapshot_num != None):
            tempSnapshot = Snapshot.Snapshot(self.obj.snapshot_num)
            snapshotID = tempSnapshot.id
            tempCollection = Collection.Collection(tempSnapshot.collection_num)
            collectionID = tempCollection.GetNodeString()
        elif (self.obj.document_num != 0) and (self.obj.document_num != None):
            tempDocument = Document.Document(self.obj.document_num)
            documentID = tempDocument.id
            tempLibrary = Library.Library(tempDocument.library_num)
            seriesID = tempLibrary.id
        elif (self.obj.quote_num != 0) and (self.obj.quote_num != None):
            tempQuote = Quote.Quote(num=self.obj.quote_num, skipText=True)
            quoteID = tempQuote.id
            tempCollection = Collection.Collection(tempQuote.collection_num)
            collectionID = tempCollection.GetNodeString()
            
        # 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)
        # Note ID
        id_edit = self.new_edit_box(_("Note 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
        seriesID_edit = self.new_edit_box(_("Library ID"), v2, seriesID)
        # Add the element to the row sizer
        r2Sizer.Add(v2, 1, wx.EXPAND)
        seriesID_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))

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

        if TransanaConstants.proVersion:
            # Create a VERTICAL sizer for the next element
            v9 = wx.BoxSizer(wx.VERTICAL)
            # Document ID
            documentID_edit = self.new_edit_box(_("Document ID"), v9, documentID)
            # Add the element to the row sizer
            r3Sizer.Add(v9, 1, wx.EXPAND)
            documentID_edit.Enable(False)

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

        # Create a VERTICAL sizer for the next element
        v3 = wx.BoxSizer(wx.VERTICAL)
        # Episode ID
        episodeID_edit = self.new_edit_box(_("Episode ID"), v3, episodeID)
        # Add the element to the row sizer
        r3Sizer.Add(v3, 1, wx.EXPAND)
        episodeID_edit.Enable(False)

        # 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)
        # Transcript ID
        transcriptID_edit = self.new_edit_box(_("Transcript ID"), v4, transcriptID)
        # Add the element to the row sizer
        r3Sizer.Add(v4, 1, wx.EXPAND)
        transcriptID_edit.Enable(False)

        # 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
        r5Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v5 = wx.BoxSizer(wx.VERTICAL)
        # Collection ID
        collectionID_edit = self.new_edit_box(_("Collection ID"), v5, collectionID)
        # Add the element to the row sizer
        r5Sizer.Add(v5, 2, wx.EXPAND)
        collectionID_edit.Enable(False)

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

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

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

        if TransanaConstants.proVersion:
            # Create a VERTICAL sizer for the next element
            v7 = wx.BoxSizer(wx.VERTICAL)
            # Quote ID
            quoteID_edit = self.new_edit_box(_("Quote ID"), v7, quoteID)
            # Add the element to the row sizer
            r6Sizer.Add(v7, 1, wx.EXPAND)
            quoteID_edit.Enable(False)

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

        # Create a VERTICAL sizer for the next element
        v6 = wx.BoxSizer(wx.VERTICAL)
        # Clip ID
        clipID_edit = self.new_edit_box(_("Clip ID"), v6, clipID)
        # Add the element to the row sizer
        r6Sizer.Add(v6, 1, wx.EXPAND)
        clipID_edit.Enable(False)

        if TransanaConstants.proVersion:
            # Add a horizontal spacer to the row sizer        
            r6Sizer.Add((10, 0))

            # Create a VERTICAL sizer for the next element
            v8 = wx.BoxSizer(wx.VERTICAL)
            # Snapshot ID
            snapshotID_edit = self.new_edit_box(_("Snapshot ID"), v8, snapshotID)
            # Add the element to the row sizer
            r6Sizer.Add(v8, 1, wx.EXPAND)
            snapshotID_edit.Enable(False)

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

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

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

        # Create a VERTICAL sizer for the next element
        v8 = wx.BoxSizer(wx.VERTICAL)
        # Comment layout
        noteTaker_edit = self.new_edit_box(_("Note Taker"), v8, self.obj.author, maxLen=100)
        # Add the element to the row sizer
        r8Sizer.Add(v8, 2, wx.EXPAND)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r8Sizer, 0, 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)
        # 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(400, width), height))
        # Define the minimum size for this dialog as the current size, and define height as unchangeable
        self.SetSizeHints(max(400, width), height, -1, height)
        # Center the form on screen
        TransanaGlobal.CenterOnPrimary(self)
        
        # Set focus to the Note ID
        id_edit.SetFocus()
 def create_snapshot(self):
     snapshot = Snapshot()
     for snapshot_class in self.list_subclass:
         snapshot.union(snapshot_class.create_snapshot())
     return snapshot
Exemple #14
0
    def OnDisplay(self, reportText):
        """ This method, required by TextReport, populates the TextReport.  The reportText parameter is
            the wxSTC control from the TextReport object.  It needs to be in the report parent because
            the TextReport doesn't know anything about the actual data.  """
        # Determine if we need to populate the Filter Lists.  If it hasn't already been done, we should do it.
        # If it has already been done, no need to do it again.
        if self.filterList == []:
            populateFilterList = True
        else:
            populateFilterList = False
        # Make the control writable
        reportText.SetReadOnly(False)
        # Set the font for the Report Title
        reportText.SetTxtStyle(fontFace='Courier New',
                               fontSize=16,
                               fontBold=True,
                               fontUnderline=True,
                               parAlign=wx.TEXT_ALIGNMENT_CENTER,
                               parSpacingAfter=12)
        # Add the Report Title
        reportText.WriteText(self.title)
        # Turn off underlining and bold
        reportText.SetTxtStyle(fontBold=False, fontUnderline=False)
        reportText.Newline()

        if self.searchText != None:
            # ...  add a subtitle
            if 'unicode' in wx.PlatformInfo:
                # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
                prompt = unicode(_("Search Text: %s"), 'utf8')
            else:
                prompt = _("Search Text: %s")
            self.subtitle = prompt % self.searchText
            # ... set the font for the subtitle ...
            reportText.SetTxtStyle(fontSize=10)
            # ... and insert the spacer and the subtitle.
            reportText.WriteText(self.subtitle)
            reportText.Newline()

        if self.configName != '':
            # ...  add a subtitle
            if 'unicode' in wx.PlatformInfo:
                # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
                prompt = unicode(_("Filter Configuration: %s"), 'utf8')
            else:
                prompt = _("Filter Configuration: %s")
            self.configLine = prompt % self.configName
            # ... set the font for the subtitle ...
            reportText.SetTxtStyle(fontSize=10)
            # ... and insert the subtitle.
            reportText.WriteText(self.configLine)
            reportText.Newline()

        # If a Root Node flag is passed in ...
        if self.reportType == 'RootNode':
            # ... we want to group notes by category.  (They will be alphabetical within each category.)
            majorList = DBInterface.list_of_all_notes(
                reportType='LibraryNode', searchText=self.searchText)
            if TransanaConstants.proVersion:
                majorList += DBInterface.list_of_all_notes(
                    reportType='DocumentNode', searchText=self.searchText)
            majorList += DBInterface.list_of_all_notes(
                reportType='EpisodeNode', searchText=self.searchText)
            majorList += DBInterface.list_of_all_notes(
                reportType='TranscriptNode', searchText=self.searchText)
            majorList += DBInterface.list_of_all_notes(
                reportType='CollectionNode', searchText=self.searchText)
            if TransanaConstants.proVersion:
                majorList += DBInterface.list_of_all_notes(
                    reportType='QuoteNode', searchText=self.searchText)
            majorList += DBInterface.list_of_all_notes(
                reportType='ClipNode', searchText=self.searchText)
            if TransanaConstants.proVersion:
                majorList += DBInterface.list_of_all_notes(
                    reportType='SnapshotNode', searchText=self.searchText)
        # if a specific Node flag is passed in ...
        else:
            # ... and use the Notes from the requested Report Type for the majorList.
            majorList = DBInterface.list_of_all_notes(
                reportType=self.reportType, searchText=self.searchText)

        # Initialize the initial data structure that will be turned into the report
        self.data = []
        # We need a list of all checked NoteNums to apply the Filter.  Initialize it here.
        checkedRecords = []
        # Now populate it based on the Filter List.  (The filterList will be empty if not populate yet, but that's OK.)
        # Iterate through the filter list ...
        for noteRecord in self.filterList:
            # ... pull out the filter list record elements.
            (noteNum, noteID, noteParent, checked) = noteRecord
            # If an item is checked ...
            if checked:
                # ... add it to the list of checked items!
                checkedRecords.append(noteNum)

        # Iterate through the major list
        for noteRecord in majorList:
            # If the current item from the Major List is in the list of checked records from the filter dialog
            # OR if we're going through the list for the first time (populateFilterList == True) ....
            if (noteRecord['NoteNum'] in checkedRecords) or populateFilterList:
                # ... load each note ...
                tempNote = Note.Note(noteRecord['NoteNum'])
                # Turn bold on.
                reportText.SetTxtStyle(fontBold=True,
                                       fontSize=12,
                                       parAlign=wx.TEXT_ALIGNMENT_LEFT,
                                       parLeftIndent=0,
                                       parSpacingBefore=36,
                                       parSpacingAfter=12)
                # Add the note ID to the report
                reportText.WriteText('%s' % tempNote.id)
                reportText.Newline()

                # Initialize all temporary objects to None so we can detect their presence or absence
                tempLibrary = None
                tempDocument = None
                tempEpisode = None
                tempTranscript = None
                tempCollection = None
                tempQuote = None
                tempClip = None
                tempSnapshot = None
                # If we have a Library Note ...
                if tempNote.series_num > 0:
                    # ... load the Library data
                    tempLibrary = Library.Library(tempNote.series_num)
                    noteParent = unicode(_('Libraries'),
                                         'utf8') + ' ' + tempLibrary.id
                # If we have a Document Note ...
                elif tempNote.document_num > 0:
                    # ... load the Document and Library data
                    tempDocument = Document.Document(tempNote.document_num)
                    tempLibrary = Library.Library(tempDocument.library_num)
                    noteParent = unicode(
                        _('Document'), 'utf8'
                    ) + ' ' + tempLibrary.id + ' > ' + tempDocument.id
                # If we have an Episode Note ...
                elif tempNote.episode_num > 0:
                    # ... load the Episode and Library data
                    tempEpisode = Episode.Episode(tempNote.episode_num)
                    tempLibrary = Library.Library(tempEpisode.series_num)
                    noteParent = unicode(
                        _('Episode'),
                        'utf8') + ' ' + tempLibrary.id + ' > ' + tempEpisode.id
                # If we have a Transcript Note ...
                elif tempNote.transcript_num > 0:
                    # ... load the Transcript, Episode, and Library data
                    # To save time here, we can skip loading the actual transcript text, which can take time once we start dealing with images!
                    tempTranscript = Transcript.Transcript(
                        tempNote.transcript_num, skipText=True)
                    tempEpisode = Episode.Episode(tempTranscript.episode_num)
                    tempLibrary = Library.Library(tempEpisode.series_num)
                    noteParent = unicode(
                        _('Transcript'), 'utf8'
                    ) + ' ' + tempLibrary.id + ' > ' + tempEpisode.id + ' > ' + tempTranscript.id
                # If we have a Collection Note ...
                elif tempNote.collection_num > 0:
                    # ... load the Collection data
                    tempCollection = Collection.Collection(
                        tempNote.collection_num)
                    noteParent = unicode(
                        _('Collection'),
                        'utf8') + ' ' + tempCollection.GetNodeString()
                # If we have a Quote Note ...
                elif tempNote.quote_num > 0:
                    # ... load the Quote and Collection data.  We can skip loading the Quote text to save load time
                    tempQuote = Quote.Quote(tempNote.quote_num, skipText=True)
                    tempCollection = Collection.Collection(
                        tempQuote.collection_num)
                    noteParent = unicode(
                        _('Quote'),
                        'utf8') + ' ' + tempCollection.GetNodeString(
                        ) + ' > ' + tempQuote.id
                # If we have a Clip Note ...
                elif tempNote.clip_num > 0:
                    # ... load the Clip and Collection data.  We can skip loading the Clip Transcript to save load time
                    tempClip = Clip.Clip(tempNote.clip_num, skipText=True)
                    tempCollection = Collection.Collection(
                        tempClip.collection_num)
                    noteParent = unicode(
                        _('Clip'),
                        'utf8') + ' ' + tempCollection.GetNodeString(
                        ) + ' > ' + tempClip.id
                # If we have a Snapshot Note ...
                elif tempNote.snapshot_num > 0:
                    # ... load the Snapshot and Collection data.
                    tempSnapshot = Snapshot.Snapshot(tempNote.snapshot_num)
                    tempCollection = Collection.Collection(
                        tempSnapshot.collection_num)
                    noteParent = unicode(
                        _('Snapshot'),
                        'utf8') + ' ' + tempCollection.GetNodeString(
                        ) + ' > ' + tempSnapshot.id

                # If we have Library data ...
                if tempLibrary != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontSize=10,
                                           fontBold=True,
                                           parLeftIndent=63,
                                           parSpacingBefore=0,
                                           parSpacingAfter=0)
                    # Add the note ID to the report
                    reportText.WriteText(_('Library: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Library ID
                    reportText.WriteText('%s' % tempLibrary.id)
                    reportText.Newline()
                # If we have Document data ...
                if tempDocument != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Document: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Document ID
                    reportText.WriteText('%s' % tempDocument.id)
                    reportText.Newline()
                # If we have Episode data ...
                if tempEpisode != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Episode: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Episode ID
                    reportText.WriteText('%s' % tempEpisode.id)
                    reportText.Newline()
                # If we have Transcript data ...
                if tempTranscript != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Transcript: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Transcript ID
                    reportText.WriteText('%s' % tempTranscript.id)
                    reportText.Newline()
                # If we have Collection data ...
                if tempCollection != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontSize=10,
                                           fontBold=True,
                                           parLeftIndent=63,
                                           parSpacingBefore=0,
                                           parSpacingAfter=0)
                    # Add the note ID to the report
                    reportText.WriteText(_('Collection: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Collection ID
                    reportText.WriteText('%s' % tempCollection.GetNodeString())
                    reportText.Newline()
                # If we have Quote data ...
                if tempQuote != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Quote: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Quote ID
                    reportText.WriteText('%s' % tempQuote.id)
                    reportText.Newline()
                # If we have Clip data ...
                if tempClip != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Clip: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Clip ID
                    reportText.WriteText('%s' % tempClip.id)
                    reportText.Newline()
                # If we have Snapshot data ...
                if tempSnapshot != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Snapshot: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Snapshot ID
                    reportText.WriteText('%s' % tempSnapshot.id)
                    reportText.Newline()

                # If we're going through the list for the first time and need to populate the filter list ...
                if populateFilterList:
                    # ... add the note number, note ID, note parent info, and checked=True to the filter list.
                    self.filterList.append(
                        (tempNote.number, tempNote.id, noteParent, True))

                # Turn bold on.
                reportText.SetTxtStyle(fontBold=True)
                # Add the note ID to the report
                reportText.WriteText(_('Note Taker: '))
                # Turn bold off.
                reportText.SetTxtStyle(fontBold=False)
                # Add the Note's author
                reportText.WriteText('%s' % tempNote.author)
                reportText.Newline()
                # Turn bold on.
                reportText.SetTxtStyle(fontBold=True)
                # Add the note ID to the report
                reportText.WriteText(_('Note Text:'))
                reportText.Newline()
                # Turn bold off.
                reportText.SetTxtStyle(fontBold=False, parLeftIndent=127)
                # Add the note text to the report (rstrip() prevents formatting problems when notes end with blank lines)
                reportText.WriteText('%s' % tempNote.text.rstrip())
                reportText.Newline()

        # Make the control read only, now that it's done
        reportText.SetReadOnly(True)
Exemple #15
0
c.ViewObject.Visibility=False

ss=App.activeDocument().addObject("Part::MultiCommon","Common")
ss.Shapes = [b,c]
ss.ViewObject.Visibility=False

FreeCADGui.ActiveDocument.ActiveView.setAnimationEnabled(False)
FreeCAD.ActiveDocument.recompute()
FreeCADGui.SendMsgToActiveView("ViewFit")
FreeCADGui.updateGui() 
 

r=Placer.createPlacer("BoxPlacer",b)
to=Toucher.createToucher("Touch Common",b)

s=Snapshot.createSnapshot("Snaps ",'T',ss)
v=Snapshot.createViewSequence('VS','T')

m=createManager()
m2=createManager()

m.intervall = 30
m.sleeptime = 0
m.addObject(r)
m.addObject(to)
m.addObject(s)
m.Proxy.run()


m2.intervall = 30
m2.sleeptime = 0.1