def add_row(data):
     try:
         _mysql.add(ExampleModel(**data))
         _mysql.commit()
     except Exception:
         _mysql.rollback()
         raise
     finally:
         _mysql.close()
예제 #2
0
	def __init__(self, *args, **kwds):
		kwds["style"] = wx.DEFAULT_FRAME_STYLE
		wx.Frame.__init__(self, *args, **kwds)

		self.panel = wx.Panel(self, -1)
		#self.lv = ObjectListView(self.panel, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
		self.lv = olv.GroupListView(
		    self.panel, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER)
		#self.lv = FastObjectListView(self.panel, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)

		sizer_2 = wx.BoxSizer(wx.VERTICAL)
		sizer_2.Add(self.lv, 1, wx.ALL | wx.EXPAND, 4)
		self.panel.SetSizer(sizer_2)
		self.panel.Layout()

		sizer_1 = wx.BoxSizer(wx.VERTICAL)
		sizer_1.Add(self.panel, 1, wx.EXPAND)
		self.SetSizer(sizer_1)
		self.Layout()

		musicImage = self.lv.AddImages(
		    ExampleImages.Music16.GetBitmap(),
		    ExampleImages.Music32.GetBitmap())
		artistImage = self.lv.AddImages(
		    ExampleImages.User16.GetBitmap(),
		    ExampleImages.User32.GetBitmap())

		self.lv.SetColumns([
		    olv.ColumnDefn(
		        "Title", "left", 200, "title",
		        imageGetter=musicImage),
		    olv.ColumnDefn(
		        "Artist", "left", 150, "artist",
		        imageGetter=artistImage),
		    olv.ColumnDefn(
		        "Last Played", "left", 100, "lastPlayed"),
		    olv.ColumnDefn(
		        "Size", "center", 100, "sizeInBytes"),
		    olv.ColumnDefn(
		        "Rating", "center", 100, "rating"), ])

		# self.lv.CreateCheckStateColumn()
		self.lv.SetSortColumn(self.lv.columns[2])
		self.lv.SetObjects(ExampleModel.GetTracks())

		# use CallLater so preview shows up after OLV
		wx.CallLater(50, self.run)
예제 #3
0
    def CreateDb(self, path):
        CREATE_STMT = "CREATE TABLE tracks (trackId int, title text, artist text, album text, sizeInBytes int, rating int, PRIMARY KEY (trackId))"
        INSERT_STMT = "INSERT INTO tracks VALUES(?, ?, ?, ?, ?, ?)"
        NUMBER_OF_ROWS = 10000

        connection = sqlite.connect(path)
        connection.execute(CREATE_STMT)
        connection.commit()

        start = time.clock()
        i = 0
        while i < NUMBER_OF_ROWS:
            for x in ExampleModel.GetTracks():
                connection.execute(INSERT_STMT, [i, x.title + str(i), x.artist, x.album, x.sizeInBytes, x.rating])
                i += 1
        connection.commit()
        #print "Building database of %d rows took %2f seconds." % (NUMBER_OF_ROWS, time.clock() - start)

        return connection
예제 #4
0
 def InitModel(self):
     self.songs = ExampleModel.GetTracks()