EzDevInfo.com

wx

(minimalist) WeChat Middleware for Express.js WeiXin ๏ 微信应用框架

What to do when WxPerl class doesn't have some method?

I'm programming an application that uses WxPerl, but the Wx::Grid class is missing the method UseNativeColHeader. What can I do to call this method anyway?

What about event? The event EVT_GRID_COL_SORT is not implemented either in WxPerl. Is there a way to bypass the restriction in pure Perl?


Source: (StackOverflow)

How can I compile a GUI executable with ghc?

I ported a little Haskell program I wrote from Mac to Windows. It's a GUI application (wxHaskell, compiled with ghc 6.12.1), so it does not need the command prompt window to open. It does so, anyway, so my question: What must I do so that the program starts without opening a prompt window first? Is there some ghc switch for this?


Source: (StackOverflow)

Advertisements

Python ImportError: No module named wx

Im sorry to ask this question again. I have searched and found endles repeats of it both on stackoverflow and also on general google search. Unfortunatly I just cant get my system sorted.

I have the following:

C:\Python27\Lib\site-packages\wx-2.8-msw-unicode

this folder contains the wx folder and also wx & wxPython folders which each contain the _init_.py files

When I import wx I get the error message "no module named wx"

What do I need to do in order to get Python to find the relevant files to allow me to "import wx" succesfully


Source: (StackOverflow)

How to use AddSubclassFactory from wxPython?

I cant find any examples online on how to use this method. I think that It may be something that I will use. Can someone provide me an example on how to use this method?

http://wxpython.org/docs/api/wx.xrc.XmlResource-class.html


Source: (StackOverflow)

Why doesn't wxPerl draw my wxStaticBitmap when I run the program from a Windows shortcut?

I've made a wxPerl application which presents just a simple frame which only contains a wxMenuBar, wxPanel, wxTextCtrl and a wxStaticBitmap. The development and deployment platform is Windows XP and beyond.

The image is added to the form like this:

my $logoData = Wx::Bitmap->new(App::Resource::Images::getLogoPath(), wxBITMAP_TYPE_BMP);
my $logo = Wx::StaticBitmap->new($self, -1, $logoData);

I've had no problems displaying the image. I've made an installer with Inno Setup that adds a icon to the users' desktop. If the application gets started using that shortcut the window doesn't draw my wxStaticBitmap. Only when the application loses focus and some other window is being moved over it, only then will my wxStaticBitmap be drawn.

When starting the application from the start menu, quick start, or directly after compiling it with wxpar, or just with the perl interperter displays my wxStaticBitmap fine.

The only thing I've found is calling Refresh() and Update() on my wxFrame. After creating this wxFrame I call Show(1) and right after that Refresh() and Update(). But so far have had no luck with it.


Source: (StackOverflow)

I'm trying to make a wx.Frame with variable transparancy (based on the png mapped in the erase bk event)

I'm trying to make a special splash screen that is displayed while the application is loading, it outputs messages of the various components loading and features a progress bar.

The first job I am tackling is mapping a .png image to the frame that will host the splash screen.

import wx

class edSplash(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(410, 410), style=wx.NO_BORDER)
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.Center()
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        return

    def OnEraseBackground(self, evt):
        dc = evt.GetDC() 
        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)

        tempBrush = wx.Brush((0,0,0,0),wx.TRANSPARENT)
        print tempBrush
        dc.SetBackground(tempBrush)
        dc.SetBackgroundMode(wx.TRANSPARENT)
        #dc.Clear()
        img = wx.Image("splash.png", wx.BITMAP_TYPE_PNG, -1)
        bmp = wx.BitmapFromImage(img)
        dc.DrawBitmap(bmp, 0, 0, True)

    def PushMessage(self, mesage):
        print mesage


class edApp(wx.App):
    def OnInit(self):
        splash = edSplash(None, 'Ed')
        self.SetTopWindow(splash)
        splash.Show(True)
        return True

if __name__ == '__main__':
    edApp(redirect=False).MainLoop()

The problem is that dc.Clear() clears to an opaque rectangle, although i have set it's brush and mode to transparent (I think :D). Commenting out dc.Clear() gives me the desired variable transparency based on the .png's alpha channel but the window gathers image noise from the neighboring windows.

How could I get both the .png's transparency and have the background clearing to an transparent brush to keep from gathering image noise?


Source: (StackOverflow)

wxHaskell installation on windows

I stuck at installing wxHaskell on windows xp sp3

I installed MinGW, MSYS and wx-config

MinGW and MSYS with installer

wx-config with adding the directory to environment variable WXWIN

and wxWigets with installer

when I type

cabal install wx 

it says

generating: src/haskell/Graphics/UI/WXCore/WxcClassTypes.hs
reading class definitions:
parsing: src/include/wxc.h
parsing: src/include/wxc_types.h
parsing: src/include/wxc_glue.h
parsing: src/include/db.h
parsing: src/include/dragimage.h
parsing: src/include/graphicscontext.h
parsing: src/include/sound.h
parsing: src/include/managed.h
parsing: src/include/mediactrl.h
parsing: src/include/previewframe.h
parsing: src/include/printout.h
parsing: src/include/textstream.h
parsing: src/include/stc.h
parsing: src/include/stc_gen.h
generated 539 class definitions.
ok.
generating: src/haskell/Graphics/UI/WXCore/WxcClassInfo.hs
reading class definitions:
parsing: src/include/wxc.h
parsing: src/include/wxc_types.h
parsing: src/include/wxc_glue.h
parsing: src/include/db.h
parsing: src/include/dragimage.h
parsing: src/include/graphicscontext.h
parsing: src/include/sound.h
parsing: src/include/managed.h
parsing: src/include/mediactrl.h
parsing: src/include/previewframe.h
parsing: src/include/printout.h
parsing: src/include/textstream.h
parsing: src/include/stc.h
parsing: src/include/stc_gen.h
generated 381 class info definitions
ok.
parsing: src/include/wxc.h
parsing: src/include/wxc_types.h
parsing: src/include/wxc_glue.h
parsing: src/include/db.h
parsing: src/include/dragimage.h
parsing: src/include/graphicscontext.h
parsing: src/include/sound.h
parsing: src/include/managed.h
parsing: src/include/mediactrl.h
parsing: src/include/previewframe.h
parsing: src/include/printout.h
parsing: src/include/textstream.h
parsing: src/include/stc.h
parsing: src/include/stc_gen.h
ignore: parse error : //WXCOLORREF wxColour_GetPixel( TSelf(wxColour) _obj );
generating: src/haskell/Graphics/UI/WXCore/WxcClassesAL.hs
reading class definitions:
parsing: src/include/wxc.h
parsing: src/include/wxc_types.h
parsing: src/include/wxc_glue.h
parsing: src/include/db.h
parsing: src/include/dragimage.h
parsing: src/include/graphicscontext.h
parsing: src/include/sound.h
parsing: src/include/managed.h
parsing: src/include/mediactrl.h
parsing: src/include/previewframe.h
parsing: src/include/printout.h
parsing: src/include/textstream.h
parsing: src/include/stc.h
parsing: src/include/stc_gen.h
generated 1560 methods for 120 classes.
generating: src/haskell/Graphics/UI/WXCore/WxcClassesMZ.hs
generated 2184 methods for 123 classes.
generating: src/haskell/Graphics/UI/WXCore/WxcClasses.hs
generated 3744 total methods for 243 total classes.
ok.
parsing: src/eiffel/wxc_defs.e
parsing: src/eiffel/wx_defs.e
parsing: src/eiffel/stc.e
generating: src/haskell/Graphics/UI/WXCore/WxcDefs.hs
generated 2454 constant definitions
ok.

Please use the --prefix flag (as in wx-config --prefix=C:\wxWidgets)
or set the environment variable WXWIN (as in WXWIN=C:\wxWidgets)
to specify where is your installation of wxWidgets.
setup.exe: failed
cabal: Error: some packages failed to install:
wx-0.12.1.6 depends on wxcore-0.12.1.6 which failed to install.
wxcore-0.12.1.6 failed during the configure step. The exception was:
ExitFailure 1

help~

thanks!


Source: (StackOverflow)

Using wxOverlay ontop of widgets?

I have created a button in this rubberbands example. The rubber bands do not appear over the button, I would like the rubberbands to appear over the button.

import wx
print wx.version()

class TestPanel(wx.Panel):
     def __init__(self, *args, **kw):
         wx.Panel.__init__(self, *args, **kw)

         self.Bind(wx.EVT_PAINT, self.OnPaint)
         self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
         self.Bind(wx.EVT_MOTION, self.OnMouseMove)

         self.startPos = None
         self.overlay = wx.Overlay()
         self.b=wx.Button(self)

     def OnPaint(self, evt):
         # Just some simple stuff to paint in the window for an example
         dc = wx.PaintDC(self)
         coords = ((40,40),(200,220),(210,120),(120,300))
         dc.SetBackground(wx.Brush("sky blue"))
         dc.Clear()
         dc.SetPen(wx.Pen("red", 2))
         dc.SetBrush(wx.CYAN_BRUSH)
         dc.DrawPolygon(coords)
         dc.DrawLabel("Drag the mouse across this window to see \n"
                     "a rubber-band effect using wx.Overlay",
                     (140, 50, -1, -1))

     def OnLeftDown(self, evt):
         # Capture the mouse and save the starting posiiton for the
         # rubber-band
         self.CaptureMouse()
         self.startPos = evt.GetPosition()

     def OnMouseMove(self, evt):
         if evt.Dragging() and evt.LeftIsDown():
             rect = wx.RectPP(self.startPos, evt.GetPosition())

             # Draw the rubber-band rectangle using an overlay so it
             # will manage keeping the rectangle and the former window
             # contents separate.
             dc = wx.ClientDC(self)

             #***  This won't work because wx.GCDC is not a wx.WindowDC
             #dc = wx.GCDC(dc)

             odc = wx.DCOverlay(self.overlay, dc)
             odc.Clear()

             #***  This crashes on wxMac

             #dc = wx.GCDC(dc)

             dc.SetPen(wx.Pen("black", 2))
             if 'wxMac' in wx.PlatformInfo:
                 dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80)))
             else:
                 dc.SetBrush(wx.TRANSPARENT_BRUSH)
             dc.DrawRectangleRect(rect)

             del odc # work around a bug in the Python wrappers to make
                     # sure the odc is destroyed before the dc is.

     def OnLeftUp(self, evt):
         if self.HasCapture():
             self.ReleaseMouse()
         self.startPos = None

         # When the mouse is released we reset the overlay and it
         # restores the former content to the window.
         dc = wx.ClientDC(self)
         odc = wx.DCOverlay(self.overlay, dc)
         odc.Clear()
         del odc
         self.overlay.Reset()

app = wx.App(redirect=False)
frm = wx.Frame(None, title="wx.Overlay Test", size=(450,450))
pnl = TestPanel(frm)
frm.Show()
app.MainLoop()

Source: (StackOverflow)

How do I undo wx.grid.Grid.SetColAttr?

I have a grid application where a column can be, for instance, flagged as super-important. When this is done, I use Grid.SetColAttr to change the colour of the column. When the user removes the flag, however, I can't seem to undo the SetColAttr. Calling it again with None instead of an attribute object causes Python to mysteriously crash with no error message, and iterating over all the cells and calling SetAttr(row, col, None) has no effect on the color of the column. I guess that's because the column attribute overrides cell attributes when they are None.

So how do I undo the cell attribute change? I assume I'll have to call SetColAttr with the "default" grid attribute, but I don't even know if the grid has a default cell attribute or how to get it.


Source: (StackOverflow)

wxPython ,Change the background colour of a StyledTextCtrl

I tried (but nothing happens)

    self.txt.SetBackgroundColour ((255,0,0))

As said in the title I'm trying to change the background colour StyledTextCtrl. Does anyone know a method that could be used? I've checked the API docs but I couldn't seem to find one, http://wxpython.org/docs/api/wx.stc.StyledTextCtrl-class.html

(by background colour, I mean the whole writing area, of course)

Does anyone know a way I could do this?

EDIT:

The background doesn't change in the following code

import wx
import wx.stc

app = wx.App(redirect=True)
top = wx.Frame(None, title="StyledTXTCtrl", size=(300,200))
txt=wx.stc.StyledTextCtrl(top)
txt.SetBackgroundColour((255,255,0))
txt.Refresh()
top.Show()
app.MainLoop()

Source: (StackOverflow)

wxPython: Dragging a file into window to get file path

I want to drag a file into a window and get the file path. I've tried doing this:

class CSVDropper(wx.FileDropTarget):
  def __init__(self, data):
      wx.FileDropTarget.__init__(self)
      self.data = data

  def OnDropFiles(self, x, y, filenames):
      self.data = filenames
      print self.data

then in the main window:

    # Drag & Drop
    self.csv_path = None
    self.drop_table = CSVDropper(self.csv_path)

    self.SetDropTarget(self.drop_table)

But this does nothing. I've tried running this tutorial code, but it doesn't do anything either. How do I accomplish this?


Source: (StackOverflow)

Wx Python image viewer - atfer opening an image file menu is too tight

I use Python 2.7 and wx on Ubuntu 12.04.

I wrote a tiny, tiny image viewer in Python using wx. Everything works just great but I have problems with size of my app's main window.

When I open an ordinary-size picture, I see:

enter image description here

which is just fine.

But when I open another file, lets say sth like this (an image of a biiiiig graph):

enter image description here

my app window has a wrong width, I mean take a look at menu its .. too tight and you dont even see an "Edit" option properly.

How to fix it? I just started with wx in Python, so please, be patient :)

My code:

# -*- coding: utf-8 -*-
#!/usr/bin/env python

import wx
import os

class MyGUIApp(wx.App):

    def __init__(self, redirect=False, filename=None):

        wx.App.__init__(self, redirect, filename)
        self.frame = wx.Frame(None, title='MyGUIApp v0.2')
        self.panel = wx.Panel(self.frame)

        self.filename = ''
        self.dirname = ''
        width, height = wx.DisplaySize()
        self.pictureMaxSize = 500

        img = wx.EmptyImage(self.pictureMaxSize, self.pictureMaxSize)
        self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img))

        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.mainSizer.Add(self.imageCtrl, 0, wx.ALL|wx.CENTER, 5)
        self.panel.SetSizer(self.mainSizer)
        self.mainSizer.Fit(self.frame)

        self.createMenus()  
        self.connectItemsWithEvents()
        self.createKeyboardShortcuts()

        self.frame.SetMenuBar(self.menuBar)
        self.frame.Show()

    def connectItemsWithEvents(self) :
        self.Bind(wx.EVT_MENU, self.openEvent, self.openItem)
        self.Bind(wx.EVT_MENU, self.clearEvent, self.clearItem)

    def createKeyboardShortcuts(self) :
      self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('C'), self.clearItem.GetId()),
                                            (wx.ACCEL_CTRL, ord('O'), self.openItem.GetId()),
                                            ])
      self.frame.SetAcceleratorTable(self.accel_tbl)

    def createMenus(self) :
        self.menuBar = wx.MenuBar()
        self.menuFile = wx.Menu()

        self.menuBar.Append(self.menuFile, '&File')      
        self.openItem = wx.MenuItem(self.menuFile, wx.NewId(), u'&open ...\tCTRL+O')
        #self.openItem.SetBitmap(wx.Bitmap('images/document-open.png'))
        self.menuFile.AppendItem(self.openItem)

        self.menuEdit = wx.Menu()
        self.menuBar.Append(self.menuEdit, '&Edit')
        self.clearItem = wx.MenuItem(self.menuEdit, wx.NewId(), '&Clear\tCTRL+C')
        #self.clearItem.SetBitmap(wx.Bitmap('images/clear.png'))
        self.menuEdit.AppendItem(self.clearItem)


    def openEvent(self, event) :
        openDialog = wx.FileDialog(self.frame, u'Open file', "File", "", "*.*", wx.OPEN)
        if openDialog.ShowModal() == wx.ID_OK :
            self.filename = openDialog.GetFilename()
            self.dirname = openDialog.GetDirectory()
            self.draw(os.path.join(self.dirname, self.filename))
        openDialog.Destroy()

    def clearEvent(self, event) :
        img = wx.EmptyImage(self.pictureMaxSize, self.pictureMaxSize)
        self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img))
        self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
        self.frame.SetSize((self.pictureMaxSize, self.pictureMaxSize))
        self.filename = ''
        self.dirname = ''

    def draw(self, filename) :
        image_name = filename
        img = wx.Image(filename, wx.BITMAP_TYPE_ANY)
        W = img.GetWidth()
        H = img.GetHeight()
        if W > H:
            NewW = self.pictureMaxSize
            NewH = self.pictureMaxSize * H / W
        else:
            NewH = self.pictureMaxSize
            NewW = self.pictureMaxSize * W / H
        img = img.Scale(NewW,NewH)
        self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
        self.panel.Refresh()
        self.mainSizer.Fit(self.frame)

if __name__ == '__main__':
    app = MyGUIApp()
    app.MainLoop()

Source: (StackOverflow)

Remove horizontal grid lines only on wxgrid

On the wxwidgets docs, I only found the EnableGridLines, which is set to false, removes both the horizontal and vertical lines, what I wish, is to remove only the horizontal lines on the grid. Is there a possible way to do this?


Source: (StackOverflow)

Python WX - Returning user input from wx Dialog

I'm new to Python and WX. I created a simple test dialog shown below that prompts the user with a combobox. I would like to capture the value from the combox in my main program. How do I call it from my main program?

This is how I was purposing to call it that displays the dialog but does not currently capture the value from the combobox:

    import highlight
    highlight.create(self).Show(True)
    a = highlight.OnComboBox1Combobox(self)
    print a

The name of the Dialog file is "highlight". Below is the code:

#Boa:Dialog:Dialog2

import wx

def create(parent):
    return Dialog2(parent)

[wxID_DIALOG2, wxID_DIALOG2COMBOBOX1, wxID_DIALOG2STATICTEXT1, 
] = [wx.NewId() for _init_ctrls in range(3)]

class Dialog2(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG2, name='', parent=prnt,
              pos=wx.Point(264, 140), size=wx.Size(400, 485),
              style=wx.DEFAULT_DIALOG_STYLE, title='Dialog2')
        self.SetClientSize(wx.Size(384, 447))

        self.comboBox1 = wx.ComboBox(choices=['test1', 'test2'],
              id=wxID_DIALOG2COMBOBOX1, name='comboBox1', parent=self,
              pos=wx.Point(120, 16), size=wx.Size(130, 21), style=0,
              value=u'wining\n')
        self.comboBox1.SetToolTipString(u'comboBox1')
        self.comboBox1.SetLabel(u'wining\n')
        self.comboBox1.Bind(wx.EVT_COMBOBOX, self.OnComboBox1Combobox,
              id=wxID_DIALOG2COMBOBOX1)

        self.staticText1 = wx.StaticText(id=wxID_DIALOG2STATICTEXT1,
              label=u'test', name='staticText1', parent=self, pos=wx.Point(88,
              16), size=wx.Size(19, 13), style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)


        ##print get_selection
        ##print get_selection1

    def OnComboBox1Combobox(self, event):
        get_selection = self.comboBox1.GetValue()
        return get_selection

Source: (StackOverflow)

wxpython: Updating a dict or other appropriate data type from wx.lib.sheet.CSheet object

If I have a notebook with three spreadsheet widgets, what is the best way to have changes to the spreadsheet update a dictionary (or maybe an sqlite file?). Do all wx grid objects come with a built in dictionary related to the SetNumberRows and SetNumberCols? Basically I am looking for guidance on how to work with the user-input data from a spreadsheet widget, as in this example adapted from the tutorial on python.org:

class ExSheet(wx.lib.sheet.CSheet):
    def __init__(self, parent):
        sheet.CSheet.__init__(self, parent)
        self.SetLabelBackgroundColour('#CCFF66')
        self.SetNumberRows(50)
        self.SetNumberCols(50)

class Notebook(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM)
        self.sheet1 = ExSheet(nb)
        self.sheet2 = ExSheet(nb)
        self.sheet3 = ExSheet(nb)
        nb.AddPage(self.sheet1, "Sheet1")
        nb.AddPage(self.sheet2, "Sheet2")
        nb.AddPage(self.sheet3, "Sheet3")
        self.sheet1.SetFocus()
        self.StatusBar()

Source: (StackOverflow)