Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. # generated by wxGlade 0.6.5 on Tue Jun 18 16:55:32 2013
  4.  
  5. from threading import Thread
  6. import wx
  7. from mega import Mega
  8. import os
  9. from decimal import Decimal
  10. # begin wxGlade: extracode
  11. # end wxGlade
  12.  
  13. class MyFrame2(wx.Frame):
  14. def __init__(self, *args, **kwds):
  15. # begin wxGlade: MyFrame2.__init__
  16. kwds["style"] = wx.DEFAULT_FRAME_STYLE
  17. wx.Frame.__init__(self, *args, **kwds)
  18. self.notebook_1 = wx.Notebook(self, -1, style=0)
  19. self.notebook_1_pane_1 = wx.Panel(self.notebook_1, -1)
  20. self.button_1 = wx.Button(self.notebook_1_pane_1, -1, "Upload File")
  21. self.gauge_1 = wx.Gauge(self.notebook_1_pane_1, -1, 1)
  22. self.button_3 = wx.Button(self.notebook_1_pane_1, -1, "Upload Directory")
  23. self.notebook_1_pane_2 = wx.Panel(self.notebook_1, -1)
  24.  
  25. self.__set_properties()
  26. self.__do_layout()
  27.  
  28. self.Bind(wx.EVT_BUTTON, self.upload_file, self.button_1)
  29. self.Bind(wx.EVT_BUTTON, self.upload_directory, self.button_3)
  30. # end wxGlade
  31.  
  32. def __set_properties(self):
  33. # begin wxGlade: MyFrame2.__set_properties
  34. self.SetTitle(u"Główne menu")
  35. self.SetSize((447, 362))
  36. self.gauge_1.SetMinSize((200, 28))
  37. self.button_3.Enable(False)
  38. # end wxGlade
  39.  
  40. def __do_layout(self):
  41. # begin wxGlade: MyFrame2.__do_layout
  42. grid_sizer_2 = wx.GridSizer(1, 1, 0, 0)
  43. grid_sizer_3 = wx.GridSizer(3, 2, 0, 0)
  44. grid_sizer_3.Add(self.button_1, 0, 0, 0)
  45. grid_sizer_3.Add(self.gauge_1, 0, 0, 0)
  46. grid_sizer_3.Add(self.button_3, 0, 0, 0)
  47. self.notebook_1_pane_1.SetSizer(grid_sizer_3)
  48. self.notebook_1.AddPage(self.notebook_1_pane_1, "tab1")
  49. self.notebook_1.AddPage(self.notebook_1_pane_2, "tab2")
  50. grid_sizer_2.Add(self.notebook_1, 1, wx.EXPAND, 0)
  51. self.SetSizer(grid_sizer_2)
  52. self.Layout()
  53. self.SetSize((447, 362))
  54. # end wxGlade
  55.  
  56.  
  57. def myupdater(self, current, total):
  58.  
  59. m = (Decimal(current)/Decimal(total))
  60. print "uploaded {0}/{1} so far".format(current, total)
  61. self.gauge_1.SetValue(m)
  62. print(m)
  63. print (self.gauge_1.GetValue)
  64. wx.Yield()
  65. print"----------------------"
  66.  
  67.  
  68. def upload_file(self, event): # wxGlade: MyFrame2.<event_handler>
  69. dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.*", wx.OPEN)
  70. if dlg.ShowModal() == wx.ID_OK:
  71. path = dlg.GetPath()
  72. mypath = os.path.basename(path)
  73. self.button_1.Enable(False)
  74. mega.upload(path, callback=self.myupdater)
  75. self.button_1.Enable(True)
  76. #t.start()
  77. #dlg.Destroy()
  78.  
  79. def upload_directory(self, event): # wxGlade: MyFrame2.<event_handler>
  80. print "Event handler `upload_directory' not implemented"
  81. event.Skip()
  82.  
  83.  
  84.  
  85. # end of class MyFrame2
  86. class MyFrame(wx.Frame):
  87. def __init__(self, *args, **kwds):
  88. # begin wxGlade: MyFrame.__init__
  89. kwds["style"] = wx.DEFAULT_FRAME_STYLE
  90. wx.Frame.__init__(self, *args, **kwds)
  91. self.label_1 = wx.StaticText(self, -1, "Login", style=wx.ALIGN_CENTRE)
  92. self.label_2 = wx.StaticText(self, -1, u"Hasło\n", style=wx.ALIGN_CENTRE)
  93. self.panel_1 = wx.Panel(self, -1)
  94. self.text_ctrl_1 = wx.TextCtrl(self, -1, "")
  95. self.text_ctrl_2 = wx.TextCtrl(self, -1, "", style=wx.TE_PASSWORD)
  96. self.panel_2 = wx.Panel(self, -1)
  97. self.panel_3 = wx.Panel(self, -1)
  98. self.panel_4 = wx.Panel(self, -1)
  99. self.button_2 = wx.Button(self, -1, "Logowanie")
  100.  
  101. self.__set_properties()
  102. self.__do_layout()
  103.  
  104. self.Bind(wx.EVT_BUTTON, self.Login, self.button_2)
  105. # end wxGlade
  106.  
  107. def __set_properties(self):
  108. # begin wxGlade: MyFrame.__set_properties
  109. self.SetTitle("Logowanie")
  110. self.label_1.SetBackgroundColour(wx.Colour(242, 241, 240))
  111. self.label_2.SetBackgroundColour(wx.Colour(242, 241, 240))
  112. self.panel_1.SetBackgroundColour(wx.Colour(242, 241, 240))
  113. self.panel_2.SetBackgroundColour(wx.Colour(242, 241, 240))
  114. self.panel_3.SetBackgroundColour(wx.Colour(242, 241, 240))
  115. self.panel_4.SetBackgroundColour(wx.Colour(242, 241, 240))
  116. # end wxGlade
  117.  
  118. def __do_layout(self):
  119. # begin wxGlade: MyFrame.__do_layout
  120. grid_sizer_1 = wx.GridSizer(3, 3, 0, 0)
  121. grid_sizer_1.Add(self.label_1, 0, 0, 0)
  122. grid_sizer_1.Add(self.label_2, 0, 0, 0)
  123. grid_sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
  124. grid_sizer_1.Add(self.text_ctrl_1, 0, 0, 0)
  125. grid_sizer_1.Add(self.text_ctrl_2, 0, 0, 0)
  126. grid_sizer_1.Add(self.panel_2, 1, wx.EXPAND, 0)
  127. grid_sizer_1.Add(self.panel_3, 1, wx.EXPAND, 0)
  128. grid_sizer_1.Add(self.panel_4, 1, wx.EXPAND, 0)
  129. grid_sizer_1.Add(self.button_2, 0, 0, 0)
  130. self.SetSizer(grid_sizer_1)
  131. grid_sizer_1.Fit(self)
  132. self.Layout()
  133. # end wxGlade
  134.  
  135. def Quit(self, event): # wxGlade: MyFrame.<event_handler>
  136. dlg = wx.MessageDialog(self,"Do you really want to close this application?","Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
  137. result = dlg.ShowModal()
  138. if result == wx.ID_OK:
  139. self.Destroy()
  140.  
  141. def Login(self, event): # wxGlade: MyFrame.<event_handler>
  142. udalosie=0
  143. m = mega.login(self.text_ctrl_1.GetValue(), self.text_ctrl_2.GetValue())
  144. if(m):
  145. print("Zalogowany")
  146. self.button_2.Disable()
  147.  
  148. frame_1.Close(1)
  149. frame_2.Show()
  150.  
  151. # end of class MyFrame
  152. if __name__ == "__main__":
  153. mega = Mega({'verbose': True})
  154. app = wx.PySimpleApp(0)
  155. wx.InitAllImageHandlers()
  156. frame_1 = MyFrame(None, -1, "")
  157. frame_2 = MyFrame2(None, -1, "")
  158. app.SetTopWindow(frame_1)
  159. frame_1.Show()
  160. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement