473,233 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

wxPython Drag and Drop

12
i need a source code in python for example to make application with drag and drop fiture,i can't understand learning from wxPython2.6 docs,Thank for help
Sep 12 '07 #1
5 8702
bartonc
6,596 Expert 4TB
From wxPyton in Action Noel Rappin and Robin Dunn
Expand|Select|Wrap|Line Numbers
  1. import wx
  2.  
  3. class DragController(wx.Control):
  4.     """
  5.     Just a little control to handle dragging the text from a text
  6.     control.  We use a separate control so as to not interfere with
  7.     the native drag-select functionality of the native text control.
  8.     """
  9.     def __init__(self, parent, source, size=(25,25)):
  10.         wx.Control.__init__(self, parent, -1, size=size,
  11.                             style=wx.SIMPLE_BORDER)
  12.         self.source = source
  13.         self.SetMinSize(size)
  14.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  15.         self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
  16.  
  17.     def OnPaint(self, evt):
  18.         # draw a simple arrow
  19.         dc = wx.BufferedPaintDC(self)
  20.         dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
  21.         dc.Clear()
  22.         w, h = dc.GetSize()
  23.         y = h/2
  24.         dc.SetPen(wx.Pen("dark blue", 2))
  25.         dc.DrawLine(w/8,   y,  w-w/8, y)
  26.         dc.DrawLine(w-w/8, y,  w/2,   h/4)
  27.         dc.DrawLine(w-w/8, y,  w/2,   3*h/4)
  28.  
  29.     def OnLeftDown(self, evt):
  30.         text = self.source.GetValue()
  31.         data = wx.TextDataObject(text)
  32.         dropSource = wx.DropSource(self)
  33.         dropSource.SetData(data)
  34.         result = dropSource.DoDragDrop(wx.Drag_AllowMove)
  35.  
  36.         # if the user wants to move the data then we should delete it
  37.         # from the source
  38.         if result == wx.DragMove:
  39.             self.source.SetValue("")
  40.  
  41. class MyFrame(wx.Frame):
  42.     def __init__(self):
  43.         wx.Frame.__init__(self, None, title="Drop Source")
  44.         p = wx.Panel(self)
  45.  
  46.         # create the controls
  47.         label1 = wx.StaticText(p, -1, "Put some text in this control:")
  48.         label2 = wx.StaticText(p, -1,
  49.            "Then drag from the neighboring bitmap and\n"
  50.            "drop in an application that accepts dropped\n"
  51.            "text, such as MS Word.")
  52.         text = wx.TextCtrl(p, -1, "Some text")
  53.         dragctl = DragController(p, text)
  54.  
  55.         # setup the layout with sizers
  56.         sizer = wx.BoxSizer(wx.VERTICAL)
  57.         sizer.Add(label1, 0, wx.ALL, 5)
  58.         hrow = wx.BoxSizer(wx.HORIZONTAL)
  59.         hrow.Add(text, 1, wx.RIGHT, 5)
  60.         hrow.Add(dragctl, 0)
  61.         sizer.Add(hrow, 0, wx.EXPAND|wx.ALL, 5)
  62.         sizer.Add(label2, 0, wx.ALL, 5)
  63.         p.SetSizer(sizer)
  64.         sizer.Fit(self)
  65.  
  66.  
  67. app = wx.PySimpleApp()
  68. frm = MyFrame()
  69. frm.Show()
  70. app.MainLoop()
  71.  
Sep 12 '07 #2
bartonc
6,596 Expert 4TB
i need a source code in python for example to make application with drag and drop fiture,i can't understand learning from wxPython2.6 docs,Thank for help
By the way, it's best to stay current with releases. The current version on 2.8.4.
Sep 12 '07 #3
ndoe
12
By the way, it's best to stay current with releases. The current version on 2.8.4.
thanks for your help's but i have a new problem, i want make some application like pySketch but GUI use Boa Constructor and it's not same like i use python modul,can somebody help me? It's hard to me i use python just 1 months but my task making editing tool
Sep 14 '07 #4
bartonc
6,596 Expert 4TB
thanks for your help's but i have a new problem, i want make some application like pySketch but GUI use Boa Constructor and it's not same like i use python modul,can somebody help me? It's hard to me i use python just 1 months but my task making editing tool
Using Boa Constructor, you are still allowed to edit the files in many ways. You can even change the parameters to create() and __init__(), as this snippet shows:
Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:StationReportDialog
  2.  
  3. import wx
  4.  
  5. from DatabaseNames import *
  6. from DBGridPanels import StationReportPanel
  7.  
  8.  
  9. def BitmapPrintout(src_dc, w, h):
  10.     pDialog = wx.PrintDialog(None)       # Declare Printer Dialog.
  11.     result = pDialog.ShowModal()        # Store dialog result after showing it.
  12.     pData = pDialog.GetPrintDialogData() # Get resutlts from Printer Dialog.
  13.     dc = pDialog.GetPrintDC()           # Get DC data from Printer Dialog.
  14.  
  15. #    EmptyBitmap(int width, int height, int depth=-1) -> Bitmap
  16.     bmp = wx.EmptyBitmap(w, h)
  17. ##    bmpDC = wx.MemoryDC()
  18.  
  19.     dc.SetDeviceOrigin(400,1000)       # Set the origin of the printed bitmap on the paper.
  20.     dc.SetUserScale(10,10)             # Set printer scale: if (1,1), each pixel will correspond to a dot
  21.         # on the printer; so, if your printer prints at 300 DPI, a 300 pixel
  22.         # wide image will be printed 1 inch wide.
  23.  
  24.     dc.StartDoc("printing...")         # Begin new document to be printed.
  25.     dc.StartPage()                     # Begin new page to be printed.
  26. ##    src_dc.SelectObject(bmp)           # "Enable" bitmap for "blitting".
  27.     dc.Blit(0, 0, 0, 0, src_dc, 0, 0)     # Copy bitmap into printer DC.
  28. ##    bmpDC.SelectObject(wx.NullBitmap)   # "Free" bitmap.
  29.     dc.EndPage()
  30.     dc.EndDoc()
  31.  
  32.  
  33.  
  34. def create(parent, dbServer, tableName, whereDict):
  35.     return StationReportDialog(parent, dbServer, tableName, whereDict)
Sep 14 '07 #5
ndoe
12
Using Boa Constructor, you are still allowed to edit the files in many ways. You can even change the parameters to create() and __init__(), as this snippet shows:
Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:StationReportDialog
  2.  
  3. import wx
  4.  
  5. from DatabaseNames import *
  6. from DBGridPanels import StationReportPanel
  7.  
  8.  
  9.   def BitmapPrintout(src_dc, w, h):
  10.     pDialog = wx.PrintDialog(None)       # Declare Printer Dialog.
  11.     result = pDialog.ShowModal()        # Store dialog result after showing it.
  12.     pData = pDialog.GetPrintDialogData() # Get resutlts from Printer Dialog.
  13.     dc = pDialog.GetPrintDC()           # Get DC data from Printer Dialog.
  14.  
  15. #    EmptyBitmap(int width, int height, int depth=-1) -> Bitmap
  16.     bmp = wx.EmptyBitmap(w, h)
  17. ##    bmpDC = wx.MemoryDC()
  18.  
  19.     dc.SetDeviceOrigin(400,1000)       # Set the origin of the printed bitmap on the paper.
  20.     dc.SetUserScale(10,10)             # Set printer scale: if (1,1), each pixel will correspond to a dot
  21.         # on the printer; so, if your printer prints at 300 DPI, a 300 pixel
  22.         # wide image will be printed 1 inch wide.
  23.  
  24.     dc.StartDoc("printing...")         # Begin new document to be printed.
  25.     dc.StartPage()                     # Begin new page to be printed.
  26. ##    src_dc.SelectObject(bmp)           # "Enable" bitmap for "blitting".
  27.     dc.Blit(0, 0, 0, 0, src_dc, 0, 0)     # Copy bitmap into printer DC.
  28. ##    bmpDC.SelectObject(wx.NullBitmap)   # "Free" bitmap.
  29.     dc.EndPage()
  30.     dc.EndDoc()
  31.  
  32.  
  33.  
  34. def create(parent, dbServer, tableName, whereDict):
  35.     return StationReportDialog(parent, dbServer, tableName, whereDict)
hello bartonc may i ask again? i use one button and one panel to show a bitmap to panel and would drag a bitmap in a panel,to show a bitmap it successful but to drag is still not working here's a part of the code,
Expand|Select|Wrap|Line Numbers
  1. def OnButton1Button(self, event):
  2.         bmp1 = wx.Bitmap(u'sector1.bmp')
  3.         panel= self.panel1
  4.         pos = 10
  5.         wx.StaticBitmap(panel, -1, bmp1, (10, pos),         (bmp1.GetWidth(),bmp1.GetHeight()))
  6.         bmp = wx.Bitmap(u'sector1.bmp')
  7.         shape = DragShape(bmp) 
  8.         shape.fullscreen = True
  9.         #shape.pos = (200, 5)
  10.         self.shapes.append(shape)
  11.  
how to drag a bitmap with a panel as a parent? and i follow the python 2.6 docs
for referension for this i hope you know where's the error for draging.thanks :D
Sep 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: James Goldwater | last post by:
I'm starting a new hopfully-commercial project soon, and I face a dilemma about whether Python with wxPython would be appropriate. The project has 3 main areas: a) manipulation of lists and...
15
by: Grant Edwards | last post by:
Can anybody recommend a good book on wxPython? Are there any books on wxPython? I've been trying to learn wxPython and/or wax for a few weeks, and I'm just not getting it. wxWindows seems...
3
by: marco | last post by:
I've got a wxpython application and when i drag'n' drop files from(linux) rox/nautilus/konqueror to my app i've got strange chars in filenames (on win32 : it works well) example: - my dir "my...
2
by: Emiliano Molina | last post by:
This has been driving me crazy for a couple of days and I have finally narrowed it down to the following code. If the commented section is uncommented the drag and drop handler is never called. I...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
2
by: praveen0437 | last post by:
hi is there is any IDE which provides drag &drop facility for designing wxpython
4
by: stef | last post by:
hello, I'm trying to move from Delphi to Python (move from MatLab to Python already succeeded, also thanks to this discussion group). From the discussions in this list about "the best" GUI for...
44
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file...
1
by: Eric von Horst | last post by:
Hi, I need some advice on Drag&Drop. What I want to achieve is the following: - I have a window that is divided in two : on the left hand I have a wx.TreeCtlr and on the other hand a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.