Search Results

Search found 10298 results on 412 pages for 'self teaching'.

Page 3/412 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Python - help on custom wx.Python (pyDev) class

    - by Wallter
    I have been hitting a dead end with this program. I am trying to build a class that will let me control the BIP's of a button when it is in use. so far this is what i have (see following.) It keeps running this weird error TypeError: 'module' object is not callable - I, coming from C++ and C# (for some reason the #include... is so much easier) , have no idea what that means, Google is of no help so... I know I need some real help with sintax and such - anything woudl be helpful. Note: The base code found here was used to create a skeleton for this 'custom button class' Custom Button import wx from wxPython.wx import * class Custom_Button(wx.PyControl): # The BMP's # AM I DOING THIS RIGHT? - I am trying to get empty 'global' # variables within the class Mouse_over_bmp = None #wxEmptyBitmap(1,1,1) # When the mouse is over Norm_bmp = None #wxEmptyBitmap(1,1,1) # The normal BMP Push_bmp = None #wxEmptyBitmap(1,1,1) # The down BMP Pos_bmp = wx.Point(0,0) # The posisition of the button def __init__(self, parent, NORM_BMP, PUSH_BMP, MOUSE_OVER_BMP, pos, size, text="", id=-1, **kwargs): wx.PyControl.__init__(self,parent, id, **kwargs) # The conversions, hereafter, were to solve another but. I don't know if it is # necessary to do this since the source being given to the class (in this case) # is a BMP - is there a better way to prevent an error that i have not # stumbled accost? # Set the BMP's to the ones given in the constructor self.Mouse_over_bmp = wx.Bitmap(wx.Image(MOUSE_OVER_BMP, wx.BITMAP_TYPE_ANY).ConvertToBitmap()) self.Norm_bmp = wx.Bitmap(wx.Image(NORM_BMP, wx.BITMAP_TYPE_ANY).ConvertToBitmap()) self.Push_bmp = wx.Bitmap(wx.Image(PUSH_BMP, wx.BITMAP_TYPE_ANY).ConvertToBitmap()) self.Pos_bmp = self.pos self.Bind(wx.EVT_LEFT_DOWN, self._onMouseDown) self.Bind(wx.EVT_LEFT_UP, self._onMouseUp) self.Bind(wx.EVT_LEAVE_WINDOW, self._onMouseLeave) self.Bind(wx.EVT_ENTER_WINDOW, self._onMouseEnter) self.Bind(wx.EVT_ERASE_BACKGROUND,self._onEraseBackground) self.Bind(wx.EVT_PAINT,self._onPaint) self._mouseIn = self._mouseDown = False def _onMouseEnter(self, event): self._mouseIn = True def _onMouseLeave(self, event): self._mouseIn = False def _onMouseDown(self, event): self._mouseDown = True def _onMouseUp(self, event): self._mouseDown = False self.sendButtonEvent() def sendButtonEvent(self): event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, self.GetId()) event.SetInt(0) event.SetEventObject(self) self.GetEventHandler().ProcessEvent(event) def _onEraseBackground(self,event): # reduce flicker pass def _onPaint(self, event): dc = wx.BufferedPaintDC(self) dc.SetFont(self.GetFont()) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() dc.DrawBitmap(self.Norm_bmp) # draw whatever you want to draw # draw glossy bitmaps e.g. dc.DrawBitmap if self._mouseIn: # If the Mouse is over the button dc.DrawBitmap(self, self.Mouse_over_bmp, self.Pos_bmp, useMask=False) if self._mouseDown: # If the Mouse clicks the button dc.DrawBitmap(self, self.Push_bmp, self.Pos_bmp, useMask=False) Main.py import wx import Custom_Button from wxPython.wx import * ID_ABOUT = 101 ID_EXIT = 102 class MyFrame(wx.Frame): def __init__(self, parent, ID, title): wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, wxSize(400, 400)) self.CreateStatusBar() self.SetStatusText("Program testing custom button overlays") menu = wxMenu() menu.Append(ID_ABOUT, "&About", "More information about this program") menu.AppendSeparator() menu.Append(ID_EXIT, "E&xit", "Terminate the program") menuBar = wxMenuBar() menuBar.Append(menu, "&File"); self.SetMenuBar(menuBar) self.Button1 = Custom_Button(self, parent, -1, "D:/Documents/Python/Normal.bmp", "D:/Documents/Python/Clicked.bmp", "D:/Documents/Python/Over.bmp", wx.Point(200,200), wx.Size(300,100)) EVT_MENU(self, ID_ABOUT, self.OnAbout) EVT_MENU(self, ID_EXIT, self.TimeToQuit) def OnAbout(self, event): dlg = wxMessageDialog(self, "Testing the functions of custom " "buttons using pyDev and wxPython", "About", wxOK | wxICON_INFORMATION) dlg.ShowModal() dlg.Destroy() def TimeToQuit(self, event): self.Close(true) class MyApp(wx.App): def OnInit(self): frame = MyFrame(NULL, -1, "wxPython | Buttons") frame.Show(true) self.SetTopWindow(frame) return true app = MyApp(0) app.MainLoop() Errors (and traceback) /home/wallter/python/Custom Button overlay/src/Custom_Button.py:8: DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained. Please switch to the wx package as soon as possible. I have never been able to get this to go away whenever using wxPython any help? from wxPython.wx import * Traceback (most recent call last): File "/home/wallter/python/Custom Button overlay/src/Main.py", line 57, in <module> app = MyApp(0) File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 7978, in __init__ self._BootstrapApp() File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 7552, in _BootstrapApp return _core_.PyApp__BootstrapApp(*args, **kwargs) File "/home/wallter/python/Custom Button overlay/src/Main.py", line 52, in OnInit frame = MyFrame(NULL, -1, "wxPython | Buttons") File "/home/wallter/python/Custom Button overlay/src/Main.py", line 32, in __init__ wx.Point(200,200), wx.Size(300,100)) TypeError: 'module' object is not callable I have tried removing the "wx.Point(200,200), wx.Size(300,100))" just to have the error move up to the line above. Have I declared it right? help?

    Read the article

  • wxPython - ListCrtl and SQLite3

    - by Dunwitch
    I'm trying to get a SQLite3 DB to populate a wx.ListCrtl. I can get it to print to stdout/stderr without any problem. I just can't seem to figure out how to display the data in the DataWindow/DataList? I'm sure I've made some code mistakes, so any help is appreciated. Main.py import wx import wx.lib.mixins.listctrl as listmix from database import * import sys class DataWindow(wx.Frame): def __init__(self, parent = None): wx.Frame.__init__(self, parent, -1, 'DataList', size=(640,480)) self.win = DataList(self) self.Center() self.Show(True) class DataList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin): def __init__(self, parent = DataWindow): wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES) #building the columns self.InsertColumn(0, "Location") self.InsertColumn(1, "Address") self.InsertColumn(2, "Subnet") self.InsertColumn(3, "Gateway") self.SetColumnWidth(0, 100) self.SetColumnWidth(1, 150) self.SetColumnWidth(2, 150) self.SetColumnWidth(3, 150) class MainWindow(wx.Frame): def __init__(self, parent = None, id = -1, title = "MainWindow"): wx.Frame.__init__(self, parent, id, title, size = (800,600), style = wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER)) # StatusBar self.CreateStatusBar() # Filemenu filemenu = wx.Menu() # Filemenu - About menuitem = filemenu.Append(-1, "&About", "Information about this application") self.Bind(wx.EVT_MENU, self.onAbout, menuitem) #Filemenu - Data menuitem = filemenu.Append(-1, "&Data", "Get data") self.Bind(wx.EVT_MENU, self.onData, menuitem) # Filemenu - Seperator filemenu.AppendSeparator() #Filemenu - Exit menuitem = filemenu.Append(-1, "&Exit", "Exit the application") self.Bind(wx.EVT_MENU, self.onExit, menuitem) # Menubar menubar = wx.MenuBar() menubar.Append(filemenu, "&File") self.SetMenuBar(menubar) # Show self.Show(True) self.Center() def onAbout(self, event): pass def onData(self, event): DataWindow(self) callDb = Database() sql = "SELECT rowid, address, subnet, gateway FROM pod1" records = callDb.select(sql) for v in records: print "How do I get the records on the DataList?" #print "%s%s%s" % (v[1],v[2],v[3]) #for v in records: #DataList.InsertStringItem("%s") % (v[0], v[1], v[2]) def onExit(self, event): self.Close() self.Destroy() def onSave(self, event): pass if __name__ == '__main__': app = wx.App() frame = MainWindow(None, -1) frame.Show() app.MainLoop() database.py import os import sqlite3 class Database(object): def __init__(self, db_file="data/data.sqlite"): database_allready_exists = os.path.exists(db_file) self.db = sqlite3.connect(db_file) if not database_allready_exists: self.setupDefaultData() def select(self,sql): cursor = self.db.cursor() cursor.execute(sql) records = cursor.fetchall() cursor.close return records def insert(self,sql): newID = 0 cursor = self.db.cursor() cursor.execute(sql) newID = cursor.lastrowid self.db.commit() cursor.close() return newID def save(self,sql): cursor = self.db.cursor() cursor.execute(sql) self.db.commit() cursor.close() def setupDefaultData(self): pass

    Read the article

  • Is there any self-improving compiler around?

    - by JohnIdol
    I am not aware of any self-improving compiler, but then again I am not much of a compiler-guy. Is there ANY self-improving compiler out there? Please note that I am talking about a compiler that improves itself - not a compiler that improves the code it compiles. Any pointers appreciated! Side-note: in case you're wondering why I am asking have a look at this post. Even if I agree with most of the arguments I am not too sure about the following: We have programs that can improve their code without human input now — they’re called compilers. ... hence my question.

    Read the article

  • Running the same code for get(self) as post(self)

    - by Peter Farmer
    Its been mentioned in other answers about getting the same code running for both the def get(self) and the def post(self) for any given request. I was wondering what techniques people use, I was thinking of: class ListSubs(webapp.RequestHandler): def get(self): self._run() def post(self): self._run() def _run(self): self.response.out.write("This works nicely!")

    Read the article

  • Hopcroft–Karp algorithm in Python

    - by Simon
    I am trying to implement the Hopcroft Karp algorithm in Python using networkx as graph representation. Currently I am as far as this: #Algorithms for bipartite graphs import networkx as nx import collections class HopcroftKarp(object): INFINITY = -1 def __init__(self, G): self.G = G def match(self): self.N1, self.N2 = self.partition() self.pair = {} self.dist = {} self.q = collections.deque() #init for v in self.G: self.pair[v] = None self.dist[v] = HopcroftKarp.INFINITY matching = 0 while self.bfs(): for v in self.N1: if self.pair[v] and self.dfs(v): matching = matching + 1 return matching def dfs(self, v): if v != None: for u in self.G.neighbors_iter(v): if self.dist[ self.pair[u] ] == self.dist[v] + 1 and self.dfs(self.pair[u]): self.pair[u] = v self.pair[v] = u return True self.dist[v] = HopcroftKarp.INFINITY return False return True def bfs(self): for v in self.N1: if self.pair[v] == None: self.dist[v] = 0 self.q.append(v) else: self.dist[v] = HopcroftKarp.INFINITY self.dist[None] = HopcroftKarp.INFINITY while len(self.q) > 0: v = self.q.pop() if v != None: for u in self.G.neighbors_iter(v): if self.dist[ self.pair[u] ] == HopcroftKarp.INFINITY: self.dist[ self.pair[u] ] = self.dist[v] + 1 self.q.append(self.pair[u]) return self.dist[None] != HopcroftKarp.INFINITY def partition(self): return nx.bipartite_sets(self.G) The algorithm is taken from http://en.wikipedia.org/wiki/Hopcroft%E2%80%93Karp_algorithm However it does not work. I use the following test code G = nx.Graph([ (1,"a"), (1,"c"), (2,"a"), (2,"b"), (3,"a"), (3,"c"), (4,"d"), (4,"e"),(4,"f"),(4,"g"), (5,"b"), (5,"c"), (6,"c"), (6,"d") ]) matching = HopcroftKarp(G).match() print matching Unfortunately this does not work, I end up in an endless loop :(. Can someone spot the error, I am out of ideas and I must admit that I have not yet fully understand the algorithm, so it is mostly an implementation of the pseudo code on wikipedia

    Read the article

  • GAE Datastore Put()

    - by Ivan Slaughter
    def post(self): update = self.request.get('update') if users.get_current_user(): if update: personal = db.GqlQuery("SELECT * FROM Personal WHERE __key__ = :1", db.Key(update)) personal.name = self.request.get('name') personal.gender = self.request.get('gender') personal.mobile_num = self.request.get('mobile_num') personal.birthdate = int(self.request.get('birthdate')) personal.birthplace = self.request.get('birthplace') personal.address = self.request.get('address') personal.geo_pos = self.request.get('geo_pos') personal.info = self.request.get('info') photo = images.resize(self.request.get('img'), 0, 80) personal.photo = db.Blob(photo) personal.put() self.redirect('/admin/personal') else: personal= Personal() personal.name = self.request.get('name') personal.gender = self.request.get('gender') personal.mobile_num = self.request.get('mobile_num') personal.birthdate = int(self.request.get('birthdate')) personal.birthplace = self.request.get('birthplace') personal.address = self.request.get('address') personal.geo_pos = self.request.get('geo_pos') personal.info = self.request.get('info') photo = images.resize(self.request.get('img'), 0, 80) personal.photo = db.Blob(photo) personal.put() self.redirect('/admin/personal') else: self.response.out.write('I\'m sorry, you don\'t have permission to add this LP Personal Data.') Should this will update the existing record if the 'update' is querystring containing key datastore key. I try this but keep adding new record/entity. Please give me some sugesstion to correctly updating the record/entity. Correction? : def post(self): update = self.request.get('update') if users.get_current_user(): if update: personal = Personal.get(db.Key(update)) personal.name = self.request.get('name') personal.gender = self.request.get('gender') personal.mobile_num = self.request.get('mobile_num') personal.birthdate = int(self.request.get('birthdate')) personal.birthplace = self.request.get('birthplace') personal.address = self.request.get('address') personal.geo_pos = self.request.get('geo_pos') personal.info = self.request.get('info') photo = images.resize(self.request.get('img'), 0, 80) personal.photo = db.Blob(photo) personal.put() self.redirect('/admin/personal') else: personal= Personal() personal.name = self.request.get('name') personal.gender = self.request.get('gender') personal.mobile_num = self.request.get('mobile_num') personal.birthdate = int(self.request.get('birthdate')) personal.birthplace = self.request.get('birthplace') personal.address = self.request.get('address') personal.geo_pos = self.request.get('geo_pos') personal.info = self.request.get('info') photo = images.resize(self.request.get('img'), 0, 80) personal.photo = db.Blob(photo) personal.put() self.redirect('/admin/personal') else: self.response.out.write('I\'m sorry, you don\'t have permission to add this LP Personal Data.')

    Read the article

  • Objective-C I can access self.view but not self.view.frame

    - by user292896
    I can access and show self.view and see the frame in the log but when I try to access self.view.frame I get null. Below is the log output of NSLog(@"Show self.view:%@",self.view); NSLog(@"Show self.view.frame:%@",self.view.frame); - 2010-03-28 11:08:43.373 vivmed_CD_Tab[20356:207] Show self.view:<UITableView: 0x4001600; frame = (0 0; 320 583); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x3b21270>> 2010-03-28 11:08:43.373 vivmed_CD_Tab[20356:207] Show self.view.frame:(null) Can anyone explain why self.view.frame is null but self.view shows a frame? May Goal is to change the frame size. Cheers, Grant

    Read the article

  • App Engine webapp.RequestHandler child instances has no self.request during __init__

    - by grucha
    i use modified webapp.RequestHandler for handling requests in my app: class MyRequestHandler(webapp.RequestHandler): """ Request handler with some facilities like user. self.out is the dictionary to pass to templates """ def __init__(self, *args, **kwargs): super(MyRequestHandler, self).__init__(*args, **kwargs) self.out = { 'user': users.get_current_user(), 'logout_url': users.create_logout_url(self.request.uri) } def render(self, template_name): """ Shortcut to render templates """ self.response.out.write(template.render(template_name, self.out)) class DeviceList(MyRequestHandler): def get(self): self.out['devices'] = GPSDevice.all().fetch(1000) self.render('templates/device_list.html') but I get an exception: line 28, in __init__ self.out['logout_url'] = users.create_logout_url(self.request.uri) AttributeError: 'DeviceList' object has no attribute 'request' When the code causing exception is moved out of __init__ everything's fine: class MyRequestHandler(webapp.RequestHandler): """ Request handler with some facilities like user. self.out is the dictionary to pass to templates and initially it contains user object for example """ def __init__(self, *args, **kwargs): super(MyRequestHandler, self).__init__(*args, **kwargs) self.out = { 'user': users.get_current_user(), } def render(self, template_name): """ Shortcut to render templates """ self.out['logout_url'] = users.create_logout_url(self.request.uri) self.response.out.write(template.render(template_name, self.out)) Whi is that? Why there's no self.request after parent's (i.e. webapp.RequestHandler's) __init__ was executed?

    Read the article

  • Jack of all trades, master of none [closed]

    - by Rope
    I've got a question similar to this one: Is looking for code examples constantly a sign of a bad developer? though not entirely. I got off college 2 years ago and I'm currently struggling with a University study. Most likely I'll have to drop out and start working within the next couple of months. Now here's the pickle. I have no speciality what so ever. When I got out of college I had worked with C, C++ and Java. I had had an internship at NEC-Philips and got familiar with C# (.NET) and I taught myself how it worked. After college I started working with PHP, HTML,SQL, MySQL Javascript and Jquery. I'm currently teaching myself Ruby on Rails and thus Ruby. At my university I also got familiar with MATLAB. As you can see I've got a broad scope of languages and frameworks I'm familiar with, but none I know inside-out. So I guess this kinda applies to me: "Jack of all trades, master of none.". I've been looking for jobs and I've noticed that most of them require some years of experience with a certain language and some specifications that apply to that language. My question is: How do I pick a speciality? And how do I know if I'll actually enjoy it? As I've worked with loads of languages how would I be able to tell this is right for me? I don't like being tied down to a specific role and I quite like being a generalist. But in order to make more money I would need a specialisation. How would I pick something that goes against my nature? Thanks in advance, Rope.

    Read the article

  • How do I create a self referential association (self join) in a single class using ActiveRecord in Rails?

    - by Daniel Chang
    I am trying to create a self join table that represents a list of customers who can refer each other (perhaps to a product or a program). I am trying to limit my model to just one class, "Customer". The schema is: create_table "customers", force: true do |t| t.string "name" t.integer "referring_customer_id" t.datetime "created_at" t.datetime "updated_at" end add_index "customers", ["referring_customer_id"], name: "index_customers_on_referring_customer_id" My model is: class Customer < ActiveRecord::Base has_many :referrals, class_name: "Customer", foreign_key: "referring_customer_id", conditions: {:referring_customer_id => :id} belongs_to :referring_customer, class_name: "Customer", foreign_key: "referring_customer_id" end I have no problem accessing a customer's referring_customer: @customer.referring_customer.name ... returns the name of the customer that referred @customer. However, I keep getting an empty array when accessing referrals: @customer.referrals ... returns []. I ran binding.pry to see what SQL was being run, given a customer who has a "referer" and should have several referrals. This is the SQL being executed. Customer Load (0.3ms) SELECT "customers".* FROM "customers" WHERE "customers"."id" = ? ORDER BY "customers"."id" ASC LIMIT 1 [["id", 2]] Customer Exists (0.2ms) SELECT 1 AS one FROM "customers" WHERE "customers"."referring_customer_id" = ? AND "customers"."referring_customer_id" = 'id' LIMIT 1 [["referring_customer_id", 3]] I'm a bit lost and am unsure where my problem lies. I don't think my query is correct -- @customer.referrals should return an array of all the referrals, which are the customers who have @customer.id as their referring_customer_id.

    Read the article

  • How to replace a Widget with another using Qt ?

    - by Natim
    Hi, I have an QHBoxLayout with a QTreeWidget on the left, a separator on the middle and a widget on the right. When I click on the QTreeWidget, I want to change the widget on the right to modify the QTreeWidgetItem I tried to do this with this code : def new_rendez_vous(self): self.ui.horizontalLayout_4.removeWidget(self.ui.editionFormWidget) del self.ui.editionFormWidget self.ui.editionFormWidget = RendezVousManagerDialog(self.parent) self.ui.editionFormWidget.show() self.ui.horizontalLayout_4.addWidget(self.ui.editionFormWidget) self.connect(self.ui.editionFormWidget, QtCore.SIGNAL('saved'), self.scheduleTreeWidget.updateData) def edit(self, category, rendez_vous): self.ui.horizontalLayout_4.removeWidget(self.ui.editionFormWidget) del self.ui.editionFormWidget self.ui.editionFormWidget = RendezVousManagerDialog(self.parent, category, rendez_vous) self.ui.editionFormWidget.show() self.ui.horizontalLayout_4.addWidget(self.ui.editionFormWidget) self.connect(self.ui.editionFormWidget, QtCore.SIGNAL('saved'), self.scheduleTreeWidget.updateData) def edit_category(self, category): self.ui.horizontalLayout_4.removeWidget(self.ui.editionFormWidget) del self.ui.editionFormWidget self.ui.editionFormWidget = CategoryManagerDialog(self.parent, category) self.ui.editionFormWidget.show() self.ui.horizontalLayout_4.addWidget(self.ui.editionFormWidget) self.connect(self.ui.editionFormWidget, QtCore.SIGNAL('saved'), self.scheduleTreeWidget.updateData) But it doesn't work and all the widgets are stacked up on each other : . Do you know how I can remove the old widget and next display the new one ?

    Read the article

  • Edit of self referencing HABTM in cakephp works, sometimes

    - by Odegard
    I'm using a self referencing HABTM model with Participants. You sign up for an event and when you log in to your reservation/profile you see a list of other participants and you can choose to add yourself and others into various groups; share hotel room, share transportation from airport etc. What I've managed so far: 1) In my profile I see the list of all other participants with checkboxes. Great so far. 2) Adding another participant works fine. Next time I edit, the participant I added is shown as checked. 3) Removing another participant works fine too as long as you still have checked participants before you submit! Again, with words: There are 3 participants. I'm logged in as one of them, and I see the 2 other people on the participants list. I choose to check both of them. This works fine (always). Later I choose to remove one of them (by unchecking the checkbox and hitting submit). This also works fine (always). If I want to remove the last checkbox... nothing is updated (always!). What's curious is that I can add and remove any odd combination of participants and it will always work UNLESS I choose to remove every participants in one go (removing a one and only participant is a special case of "remove all checked participants"). As far as I know, HABTMs work by first deleting all relations, then re-saving them. I can see that in my tables when I remove, add, remove, add the same participant over and over again - the id on the HABTM table is always increasing. When I deselect all participants at once, however, the relations are not updated. The ids stay the same, so it's like the save never happened. This behaviour is so specific and peculiar, I have a feeling I'm missing something obvious here. Anyway, here's the relevant code: Model class Participant extends AppModel { var $hasAndBelongsToMany = array( 'buddy' = array( 'className' = 'Participant', 'joinTable' = 'participants_participants', 'foreignKey' = 'participant_id', 'associationForeignKey' = 'buddy_id', 'unique' = true, ) ); Controller function edit($id = null) { if (!$id && empty($this-data)) { $this-Session-setFlash(__('Invalid Participant', true)); $this-redirect(array('action'='index')); } if (!empty($this-data)) { if ($this-Participant-saveAll($this-data)) { $this-Session-setFlash(__('The Participant has been saved', true)); $this-redirect(array('action'='index')); } else { $this-Session-setFlash(__('The Participant could not be saved. Please, try again.', true)); } } if (empty($this-data)) { $this-data = $this-Participant-read(null, $id); } // Fetching all participants except yourself $allParticipants = $this-Participant-find('list', array('conditions' = array('participant.id ' = $id))); // Fetching every participant that has added you to their list $allBuddies = $this-Participant-ParticipantsParticipant-find('list', array( 'conditions' = array('buddy_id' = $id), 'fields' = 'ParticipantsParticipant.participant_id', 'order' = 'ParticipantsParticipant.participant_id ASC' )); $this-set(compact('allParticipants','allBuddies')); } View echo $form-create('Participant'); echo $associations-habtmCheckBoxes($allParticipants, $this-data['buddy'], 'buddy', 'div', '\'border: 1px solid #000;\'', '\'border: 1px solid #000;\''); echo $form-end('Submit'); I'm using a slightly modified helper, habtmCheckBoxes, found here: http://cakeforge.org/snippet/detail.php?type=snippet&id=190 It works like this: function habtmCheckBoxes($rows=array(), $selectedArr=array(), $modelName, $wrapTag='p', $checkedDiv, $uncheckedDiv) {}

    Read the article

  • Utility that helps in file locking - expert tips wanted

    - by maix
    I've written a subclass of file that a) provides methods to conveniently lock it (using fcntl, so it only supports unix, which is however OK for me atm) and b) when reading or writing asserts that the file is appropriately locked. Now I'm not an expert at such stuff (I've just read one paper [de] about it) and would appreciate some feedback: Is it secure, are there race conditions, are there other things that could be done better … Here is the code: from fcntl import flock, LOCK_EX, LOCK_SH, LOCK_UN, LOCK_NB class LockedFile(file): """ A wrapper around `file` providing locking. Requires a shared lock to read and a exclusive lock to write. Main differences: * Additional methods: lock_ex, lock_sh, unlock * Refuse to read when not locked, refuse to write when not locked exclusivly. * mode cannot be `w` since then the file would be truncated before it could be locked. You have to lock the file yourself, it won't be done for you implicitly. Only you know what lock you need. Example usage:: def get_config(): f = LockedFile(CONFIG_FILENAME, 'r') f.lock_sh() config = parse_ini(f.read()) f.close() def set_config(key, value): f = LockedFile(CONFIG_FILENAME, 'r+') f.lock_ex() config = parse_ini(f.read()) config[key] = value f.truncate() f.write(make_ini(config)) f.close() """ def __init__(self, name, mode='r', *args, **kwargs): if 'w' in mode: raise ValueError('Cannot open file in `w` mode') super(LockedFile, self).__init__(name, mode, *args, **kwargs) self.locked = None def lock_sh(self, **kwargs): """ Acquire a shared lock on the file. If the file is already locked exclusively, do nothing. :returns: Lock status from before the call (one of 'sh', 'ex', None). :param nonblocking: Don't wait for the lock to be available. """ if self.locked == 'ex': return # would implicitly remove the exclusive lock return self._lock(LOCK_SH, **kwargs) def lock_ex(self, **kwargs): """ Acquire an exclusive lock on the file. :returns: Lock status from before the call (one of 'sh', 'ex', None). :param nonblocking: Don't wait for the lock to be available. """ return self._lock(LOCK_EX, **kwargs) def unlock(self): """ Release all locks on the file. Flushes if there was an exclusive lock. :returns: Lock status from before the call (one of 'sh', 'ex', None). """ if self.locked == 'ex': self.flush() return self._lock(LOCK_UN) def _lock(self, mode, nonblocking=False): flock(self, mode | bool(nonblocking) * LOCK_NB) before = self.locked self.locked = {LOCK_SH: 'sh', LOCK_EX: 'ex', LOCK_UN: None}[mode] return before def _assert_read_lock(self): assert self.locked, "File is not locked" def _assert_write_lock(self): assert self.locked == 'ex', "File is not locked exclusively" def read(self, *args): self._assert_read_lock() return super(LockedFile, self).read(*args) def readline(self, *args): self._assert_read_lock() return super(LockedFile, self).readline(*args) def readlines(self, *args): self._assert_read_lock() return super(LockedFile, self).readlines(*args) def xreadlines(self, *args): self._assert_read_lock() return super(LockedFile, self).xreadlines(*args) def __iter__(self): self._assert_read_lock() return super(LockedFile, self).__iter__() def next(self): self._assert_read_lock() return super(LockedFile, self).next() def write(self, *args): self._assert_write_lock() return super(LockedFile, self).write(*args) def writelines(self, *args): self._assert_write_lock() return super(LockedFile, self).writelines(*args) def flush(self): self._assert_write_lock() return super(LockedFile, self).flush() def truncate(self, *args): self._assert_write_lock() return super(LockedFile, self).truncate(*args) def close(self): self.unlock() return super(LockedFile, self).close() (the example in the docstring is also my current use case for this) Thanks for having read until down here, and possibly even answering :)

    Read the article

  • Teaching "web design/development" to high-school home-school group. Good sources?

    - by anonymous coward
    I may soon begin teaching a "web design and development" class for a home-school co-op group. Any suggestions for "course" material? My first thought was to work through the Opera Web Standards Curriculum, but am interested in hearing about possible alternatives or suggestions that better cover the "very basics" of getting started with designing and developing web pages. Not necessarily looking for topics, so much as existing resources. Thanks so much for your input!

    Read the article

  • Teaching coworkers LINQ...

    - by cyberzed
    I have set myself upon a journey to educate my coworkers (all have accepted my mission, even the boss). Every day I seem to find a piece of code that could have been less error prone if my coworkers knew more about the framework, better-know-framework (in courtesy of DNR ;)) is part two of my teaching process. First part is teaching my coworkers about LINQ, what it can do for them and how it is written. My big question is where are all the good basic resources for LINQ education, everything if find is tightly coupled to Linq2Sql or all other sorts of material. Neither have I been able to find a tutorial for the actual linq syntax (except a specification of it all). (I hope this haven't been asked before but if it has please say so, cause then my searching skills have failed ;) )

    Read the article

  • A toolset for self improvement and learning [closed]

    - by Sebastian
    Possible Duplicate: I’m having trouble learning I've been working as an IT consultant for 1½ years and I am very passionate about programming. Before that I studied MSc Software Engineering and had both a part time job as a developer for a big telecom company. During that time I also took extra courses and earned a SCJP certificate. I have been continuously reading a lot of books during the last 3½ years. Now to my problem. I want to continue learning and become a really, really good developer. Apart from my daytime job as a full time java developer I have taken university courses in, for me, new languages and paradigms. Most recently, android game development and then functional programming with Scala. I've read books, went to conferences and had a couple of presentations for internal training purposes in our local office. I want to have some advice from other people who have previously been in my situation or currently are. What are you guys doing to keep improving yourselves? Here is some things that I have found are working for me: Reading books I've mostly read books about best practices for programming, OO-design, refactoring, design patterns, tdd. Software craftmanship if you like. I keep a reading list and my current book is Apprenticeship patterns. Taking courses In my country we have a really good system for taking online distance courses. I have also taken one course at coursera.org and a highly recommend that platform. Ive looked at courses at oreilly.com, industriallogic, javaspecialists.eu and they seem to be okay. If someone gives these type of courses a really good review, I can probably convince my boss. Workshops that span over a couple of days would probably be harder, but Ive seen that uncle Bob will have one about refactoring and tdd in 6months not far from here.. :) Are their possibly some online learning platforms that I dont know about? Educational videos I've bought uncle bobs videos from cleancoders.com and I highly recommend them. The only thing I dont like is that they are quite expensive and that he talks about astronomy for ~10 minutes in every episode. Getting certified I had a lot of fun and learned a lot when I studied for the SCJP. I have also done some preparation for the microsoft equivalent but never went for it. I think it is a good when selling yourself as a newly graduated student and also will boost your knowledge if your are interested in it. Now I would like others to start sharing their experiences and possibly give me some advice! BR Sebastian

    Read the article

  • Time management and self improvement

    - by Filip
    Hi, I hope I can open a discussion on this topic as this is not a specific problem. It's a topic I hope to get some ideas on how people in similar situation as mine manage their time. OK, I'm a single developer on a software project for the last 6-8 months. The project I'm working on uses several technologies, mainly .net stuff: WPF, WF, NHibernate, WCF, MySql and other third party SDKs relevant for the project nature. My experience and knowledge vary, for example I have a lot of experience in WPF but much less in WCF. I work full time on the project and im curios on how other programmers which need to multi task in many areas manage their time. I'm a very applied type of person and prefer to code instead of doing research. I feel that doing research "might" slow down the progress of the project while I recognize that research and learning more in areas which I'm not so strong will ultimately make me more productive. How would you split up your daily time in productive coding time and time to and experiment, read blogs, go through tutorials etc. I would say that Im coding about 90%+ of my day and devoting some but very little time in research and acquiring new knowledge.

    Read the article

  • Time management and self improvement

    - by Filip
    I hope I can open a discussion on this topic as this is not a specific problem. It's a topic I hope to get some ideas on how people in similar situation as mine manage their time. OK, I'm a single developer on a software project for the last 6-8 months. The project I'm working on uses several technologies, mainly .net stuff: WPF, WF, NHibernate, WCF, MySql and other third party SDKs relevant for the project nature. My experience and knowledge vary, for example I have a lot of experience in WPF but much less in WCF. I work full time on the project and im curios on how other programmers which need to multi task in many areas manage their time. I'm a very applied type of person and prefer to code instead of doing research. I feel that doing research "might" slow down the progress of the project while I recognize that research and learning more in areas which I'm not so strong will ultimately make me more productive. How would you split up your daily time in productive coding time and time to and experiment, read blogs, go through tutorials etc. I would say that Im coding about 90%+ of my day and devoting some but very little time in research and acquiring new knowledge. Thanks for your replies. I think I will adopt a gradual transition to Dominics block parts. I kinda knew that coding was taking up way to much of my time but it feels good having a first version of the project completed and ready. With a few months of focused hard work behind me I hope to get more time to experiment and expand my knowlegde. Now I only hope my boss will cut me some slack and stop pressuring me for features...

    Read the article

  • Self Service Reporting With PowerPivot

    - by blakmk
    There are so many cool new features in Sql 2008 release 2 it was difficult for me to pick a topic for T-SQL Tuesday . But the one that I am now a secret fan of, I once resented for its creation. Let me explain, for years I have encountered reporting systems cobbled together in tools like Access and Excel built by "database hobbyists" who had no formal training in database design or best practices. They would take their monstrosities as far as they could go before ultimatley it stopped working or the person that wrote it left the company. At that point it would become the resident DBA's problem to support it as a Live application. So when I first heard of Power Pivot, a sense of Deja Vu overtook me and I felt like the guy in the Ausin Powers movie , knowing the inevitable is coming but somehow unsure how to get out of the way. But when I eventually saw it in action, I quickly realised that it is a very powerful tool. It has a much smaller "time to market" than traditional BI architectures. Combined with the new features of Excel, some pretty impressive dashboards can be produced.Of course PowerPivot is not a magic bullet and along with potential scalability issues there are the usual issues such as master data management and data quality that cannot be overcome easily with power pivot. As a tool though, it has potential. Traditional BI is expensive, both in terms of time and the amount of resources it takes to deliver the system. The time lag between an analyst or a commercial accountant requesting reports and the report being delivered can make a huge commercial difference. I have observed companies where empowered end users become extremely productive when allowed to plough in to various disperate datasets. It may not be the correct way or the most sustainable but its cheap and quick. In these times when budgets are being slashed and we are forced to deliver more with less, why not empower the end user in a tool that is designed for exactly this task.... @blakmk  

    Read the article

  • How to clear wxpython frame content when dragging a panel?

    - by aF
    Hello, I have 3 panels and I want to make drags on them. The problem is that when I do a drag on one this happens: How can I refresh the frame to happear its color when the panel is no longer there? This is the code that I have to make the drag: def onMouseMove(self, event): (self.pointWidth, self.pointHeight) = event.GetPosition() (self.width, self.height) = self.GetSizeTuple() if (self.pointWidth>100 and self.pointWidth<(self.width-100) and self.pointHeight < 15) or self.parent.dragging: self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) """implement dragging""" if not event.Dragging(): self.w = 0 self.h = 0 return self.CaptureMouse() if self.w == 0 and self.h == 0: (self.w, self.h) = event.GetPosition() else: (posw, posh) = event.GetPosition() displacement = self.h - posh self.SetPosition( self.GetPosition() - (0, displacement)) else: self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) def onDraggingDown(self, event): if self.pointWidth>100 and self.pointWidth<(self.width-100) and self.pointHeight < 15: self.parent.dragging = 1 self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) self.SetBackgroundColour('BLUE') self.parent.SetTransparent(220) self.Refresh() def onDraggingUp(self, event): self.parent.dragging = 0 self.parent.SetTransparent(255) self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) and this are the binds for this events: self.Bind(wx.EVT_MOTION, self.onMouseMove) self.Bind(wx.EVT_LEFT_DOWN, self.onDraggingDown) self.Bind(wx.EVT_LEFT_UP, self.onDraggingUp) With this, if I click on the top of the panel, and move down or up, the panel position changes (I drag the panel) to the position of the mouse.

    Read the article

  • How to learn programming for a medium scale project form a beginner? [closed]

    - by Lin Xiangyu
    I study programming by myself.I have learn servel programming languages. but I never write a project more than 1000 lines. I know the best way to improve programming skills is practise. The problem is many books, just talk about the programming language, or talk about build a project from a high level. Fews of books will teach how to build a middle scale project. For example, I want to build a simple HTTP Server(Nor like Apache or just a simple listenr to a port), a Markdown Parser, or a download tools just like emule or wget. I don't know what to do. I may found peaces of code in the web, or found familiar project in the Github. I don't know how to read the code. I want to some tutorial that can told me how to build the project step by step, teacher me how to write thousands lines of code. Any suggest?

    Read the article

  • Audiobooks for programmers?

    - by Zoot
    I'm a programmer with a two-hour round trip commute to work each day. I'd like to fill some of that time with audiobooks about software development. Any audiobooks that would help me become a better programmer would be appreciated. I'm thinking that books about design patterns and non-fiction about computing history might be good here, but I'm open to anything. Keeping in mind that I will be listening to this in a car, what are the best audiobooks that I can listen to? EDIT: Many people have also suggested podcasts. This is appreciated, but since podcasts arrive in a constantly arriving stream of data rather than as a finite amount of data, ways to juggle all of these different content streams would also be appreciated. To be more specific to my situation, my commuting vehicle has an MP3 CD player, USB input for MP3 files, and AUX input. I own Android and webOS devices that can be plugged into the AUX input.

    Read the article

  • Learning and Developing with PHP [closed]

    - by KyelJmD
    I am here to ask you What is a good PHP Book that doesn't contain too much details but it is compose of all necessary information to develop in PHP such as (OO PHP, Handling Forms, Database etc etc) This may be subjective but I've tried to look php book recomendations here at Stackoverflow but I cannot find any. Next is What are the things I need to know in learning a PHp framework? specifically I want to learn CAKEPHP. NOTE I do not need those lenghty books that discuss loops and such I already have experience programming with java and C#.

    Read the article

  • Could someone break this nasty habit of mine please?

    - by MimiEAM
    I recently graduated in cs and was mostly unsatisfied since I realized that I received only a basic theoretical approach in a wide range of subjects (which is what college is supposed to do but still...) . Anyway I took the habit of spending a lot of time looking for implementations of concepts and upon finding those I will used them as guides to writing my own implementation of those concepts just for fun. But now I feel like the only way I can fully understand a new concept is by trying to implement from scratch no matter how unoptimized the result may be. Anyway this behavior lead me to choose by default the hard way, that is time consuming instead of using a nicely written library until I hit my head again a huge wall and then try to find a library that works for my purpose.... Does anyone else do that and why? It seems so weird why would anyone (including me) do that ? Is it a bad practice ? and if so how can i stop doing that ?

    Read the article

  • Doing practice jobsearch/technical interviews?

    - by Beekguk
    I graduated college last year & I've never gone through the interview process - my current programming position evolved out of projects I did in school, but in a few months I'm making a clean break and moving across the country so I'm going to have to face a "grown-up" jobsearch. I'm kind of scared of technical interviews - I think I'm pretty good at my job and my hobby programming projects ... but what if it turns out I'm part of that group that thinks they're qualified, but really just cause despair at the state of education in the hearts of interviewers? So, I'm thinking of doing a "practice" job hunt in my current city to get an idea of what it's like and what kind of experience/expertise employers are really looking for. Is this a dick move ethically (applying to/interviewing for jobs I can't take)? If so, is there another good way to prepare for technical interviews, especially those little trick puzzle-type questions?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >