samedi 27 juin 2015

how to get value from another class in python by hit button

I have some problem, i want get value from database in another class by hit button. I used methode string matching, when user input string and after taht user press button. System will matching what user input to database. what i want now is, i want the output in another form and absoluty in another class. I create some code like this.

class MyFrame(wx.Frame):
  def __init__(self, parent):
    wx.Frame.__init__(self, parent)
    wx.StaticText(self, -1, "Asking", pos=(20, 50))
    self.inpt = wx.TextCtrl(self, -1, pos=(10, 70), size=(250, 20), style= wx.EXPAND)
    wx.StaticText(self, -1, "Link", pos=(20, 135))
    self.opt = wx.ListBox(self, -1, pos=(10, 160), size=(480, 250), style= wx.TE_MULTILINE | wx.BORDER_SUNKEN)

    img = "search.png"
    image1 = wx.Image(img, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    self.btn1 = wx.BitmapButton(pan1, id=-1, bitmap=image1, pos=(85, 105), size = (image1.GetWidth()+5, image1.GetHeight()+5))

    self.btn1.Bind(wx.EVT_BUTTON, self.OnEnter, self.btn1)

    self.klik = self.opt.Bind(wx.EVT_LISTBOX_DCLICK, self.playVideo)

def playVideo(self, event):
    data = event.GetClientObject()
    link = data[0]
    ex = data[1]

    self.player.Load(link)
    self.pjs.Clear()
    self.pjs.AppendText(ex)

  def OnEnter(self, event):
    self.opt.SetLabel(self.PatMatch())

  def PatMatch(self):
    self.opt.Clear()
    con = lite.connect('media.db')  
    with con:
        cur = con.cursor()
        for row in cur.execute("select * from baru"):
            self.klmt = self.inpt.GetValue()
            if row[1] in self.klmt.lower():
                self.opt.Append(row[2], [row[4], row[3]])

class Kmp(wx.Frame):
  def __init__(self, parent, *args, **kwds):
      kwds["style"] = (wx.DEFAULT_FRAME_STYLE) & ~ (wx.RESIZE_BORDER|wx.RESIZE_BOX)
      wx.Frame.__init__(self,parent,title='Informasi', size=(500, 500), *args, **kwds)

      km2 = wx.StaticText(self, label='Word', pos=(20, 70))
      ttk2 = wx.StaticText(self, label=':', pos=(200,70))
      txt1 = wx.TextCtrl(self, -1, pos=(220, 70), size=(200, 30), style= wx.EXPAND)
      txt1.SetEditable(False)

      km3 = wx.StaticText(self, label='Total word', pos=(20, 110))
      ttk3 = wx.StaticText(self, label=':', pos=(200,110))
      txt2 = wx.TextCtrl(self, -1, pos=(220, 110), size=(200, 30), style= wx.EXPAND)
      txt2.SetEditable(False)

      km4 = wx.StaticText(self, label='POsisition Word', pos=(20,145))
      ttk4 = wx.StaticText(self, label=':', pos=(200,145))
      txt3 = wx.TextCtrl(self, -1, pos=(220, 150), size=(200, 30), style= wx.EXPAND)
      txt3.SetEditable(False)

      btn2 = wx.Button(self, -1, 'Exit', pos=(200, 200))

    def data(self):
        dt = MyFrame(self)
        klm = selt.inpt.GetValue()
        re.findall(r"[\w']+", klm)      

    def compute_prefix(word):
        word_length = len(word)
        prefix = [0] * word_length
        k = 0

        for q in xrange(1, word_length):
            while k > 0 and word[k] != word[q]:
                k = prefix[k - 1]

            if word[k + 1] == word[q]:
                k = k + 1
            prefix[q] = k
        return prefix

    def search(self, string, word):
        word_length = len(word)
        string_length = len(string)
        offsets = []
        if word_length > string_length:
            return offsets

        prefix = compute_prefix(word)
        q = 0
        for index, letter in enumerate(string):
            while q > 0 and word[q] != letter:
                q = prefix[q - 1]
            if word[q] == letter:
                q += 1
            if q == word_length:
                offsets.append(index - word_length + 1)
                q = prefix[q - 1]
        return offsets

    word = ""
    string = "" 

    def pro(self, event):
        pp = MyFrame(self)
        self.opt.SetLabel(self.PatMatch())

my database:

id  word        name_link   explain     link
--- ------      ----------- ---------   --------
1   python      Video1      test        C:\Users\Ihsan\Downloads\Video1.MP4
2   python      Video2      test1       C:\Users\Ihsan\Downloads\Video2.MP4
3   python      Video3      test2       C:\Users\Ihsan\Downloads\Video3.MP4

Aucun commentaire:

Enregistrer un commentaire