Daily Archives

Articles indexed Sunday December 9 2012

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

  • How to create contracts in python

    - by recluze
    I am just moving to python from Java and have a question about the way the two do things. My question relates to contracts. An example: an application defines an interface that all plugins must implement and then the main application can call it. In Java: public interface IPlugin { public Image modify(Image img); } public class MainApp { public main_app_logic() { String pluginName = "com.example.myplugin"; IPlugin x = (IPlugin) Class.forName(pluginName); x.modify(someimg); } } The plugin implements the interface and we use reflection in main app to call it. That way, there's a contract between the main app and the plugin that both can refer to. How does one go about doing something similar in Python? And also, which approach is better? p.s. I'm not posting this on SO because I'm much more concerned with the philosophy behind the two approaches.

    Read the article

  • Using PDO with MVC

    - by mister martin
    I asked this question at stackoverflow and received no response (closed as duplicate with no answer). I'm experimenting with OOP and I have the following basic MVC layout: class Model { // do database stuff } class View { public function load($filename, $data = array()) { if(!empty($data)) { extract($data); } require_once('views/header.php'); require_once("views/$filename"); require_once('views/footer.php'); } } class Controller { public $model; public $view; function __construct() { $this->model = new Model(); $this->view = new View(); // determine what page we're on $page = isset($_GET['view']) ? $_GET['view'] : 'home'; $this->display($page); } public function display($page) { switch($page) { case 'home': $this->view->load('home.php'); break; } } } These classes are brought together in my setup file: // start session session_start(); require_once('Model.php'); require_once('View.php'); require_once('Controller.php'); new Controller(); Now where do I place my database connection code and how do I pass the connection onto the model? try { $db = new PDO('mysql:host='.DB_HOST.';dbname='.DB_DATABASE.'', DB_USERNAME, DB_PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $err) { die($err->getMessage()); } I've read about Dependency Injection, factories and miscellaneous other design patterns talking about keeping SQL out of the model, but it's all over my head using abstract examples. Can someone please just show me a straight-forward practical example?

    Read the article

  • How do I improve my logic in general and programming in particular?

    - by Dinesh Venkata
    I'm good with understanding technology and implementing it. At least that is what I feel. But it seems that when I come across experienced programmers they point out that my logic is weak. I feel that I would need some time with real programming to improve it. But nobody is ready to give that time to me. I'm just about starting my carer and it often feels disheartening to hear this. I want know how can I improve my logic and also does this sort of thing happens to others too?

    Read the article

  • OO Design, how to model Tonal Harmony?

    - by David
    I have started to write a program in C++ 11 that would analyse chords, scales, and harmony. The biggest problem I am having in my design phase, is that the note 'C' is a note, a type of chord (Cmaj, Cmin, C7, etc), and a type of key (the key of Cmajor, Cminor). The same issue arises with intervals (minor 3rd, major 3rd). I am using a base class, Token, that is the base class for all 'symbols' in the program. so for example: class Token { public: typedef shared_ptr<Token> pointer_type; Token() {} virtual ~Token() {} }; class Command : public Token { public: Command() {} pointer_type execute(); } class Note : public Token; class Triad : public Token; class MajorTriad : public Triad; // CMajorTriad, etc class Key : public Token; class MinorKey : public Key; // Natural Minor, Harmonic minor,etc class Scale : public Token; As you can see, to create all the derived classes (CMajorTriad, C, CMajorScale, CMajorKey, etc) would quickly become ridiculously complex including all the other notes, as well as enharmonics. multiple inheritance would not work, ie: class C : public Note, Triad, Key, Scale class C, cannot be all of these things at the same time. It is contextual, also polymorphing with this will not work (how to determine which super methods to perform? calling every super class constructors should not happen here) Are there any design ideas or suggestions that people have to offer? I have not been able to find anything on google in regards to modelling tonal harmony from an OO perspective. There are just far too many relationships between all the concepts here.

    Read the article

  • Finding back to an old project that was turned upside-down by the developer. Your workflow?

    - by Kreativrandale
    after some time I'm asked to work on a heavy web-project I did (layout, html/css) about a year ago. There are some changes that have to be made, basically some css and js stuff. By now the whole project was turned upside down by the developer. It gives me a hard time to connect to the work of him, especially because my old files and file-structure won't work anymore. Thats why I need a up-to-date working-environment, but I don't want to change the files on the server directly. Need some testing and improving while doing this. So, what is your workflow in such a case? Thought about copying the whole/parts of the server to a own homeserver. But even that will be a big task for me (I'm more the front-end-guy). Would be great if theres a way to shrink it down (php, mysql,...), since I only need to change some css/html javascript. Are there any tools available? Love to hear how you handle such situations. Thanks a lot!

    Read the article

  • Separating merged array of arithmetic and geometric series [closed]

    - by user1814037
    Possible Duplicate: Separating merged array of arithmetic and geometric series My friend asked me an interseting question. Given an array of positive integers in increasing order. Seperate them in two series, an arithmetic sequence and geometric sequence. The given array is such that a solution do exist. The union of numbers of the two sequence must be the given array. Both series can have common elements i.e. series need not to be disjoint. The ratio of the geometric series can be fractional. Example: Given series : 2,4,6,8,10,12,25 AP: 2,4,6,8,10,12 GP: 4,10,25 I tried taking few examples but could not reach a general way. Even tried some graph implementation by introducing edges if they follow a particular sequence but could not reach solution.

    Read the article

  • Mouse disables on key press, but touchpad doesn't

    - by Dan
    My mouse cursor disables for 1-2 seconds when the keyboard is used. This can make gaming especially difficult. The touchpad is fine; I can use it at the same time as the keyboard. Doing some forum searching, I can see that going to mouse and touchpad touchpad disable touchpad when typing works for the touchpad, but I still have the problem when using the mouse. I've tried using synaptiks, and setting the 'automatically switch off touchpad on keyboard activity' time to 0 seconds doesn't seem to work either. I'd appreciate any help.

    Read the article

  • Bluetooth light not turned on and bluetooth also not working on vostro 1014

    - by Dinesh Kumar
    after running following command dmesg | grep -i bluetooth [ 17.106250] Bluetooth: Core ver 2.16 [ 17.107845] Bluetooth: HCI device and connection manager initialized [ 17.107847] Bluetooth: HCI socket layer initialized [ 17.107849] Bluetooth: L2CAP socket layer initialized [ 17.107857] Bluetooth: SCO socket layer initialized [ 18.853255] Bluetooth: BNEP (Ethernet Emulation) ver 1.3 [ 18.853260] Bluetooth: BNEP filters: protocol multicast [ 18.859350] Bluetooth: RFCOMM TTY layer initialized [ 18.859355] Bluetooth: RFCOMM socket layer initialized [ 18.859357] Bluetooth: RFCOMM ver 1.11 [14998.338293] init: bluetooth main process ended, respawning

    Read the article

  • Bandwidth Problem in Terminal?

    - by Rob Barker
    I'm trying to install the Mac cursors to Ubuntu 12.04 but i get this error when using the wget command in Terminal. ubuntu@ubuntu:~$ wget -O mac-cursors.zip http://dl.dropbox.com/u/53319850/NoobsLab.com/mac-cursors.zip --2012-12-09 16:31:17-- http://dl.dropbox.com/u/53319850/NoobsLab.com/mac-cursors.zip Resolving dl.dropbox.com (dl.dropbox.com)... 23.21.195.136, 23.23.139.153, 107.20.134.231, ... Connecting to dl.dropbox.com (dl.dropbox.com)|23.21.195.136|:80... connected. HTTP request sent, awaiting response... 509 Bandwidth Error 2012-12-09 16:31:18 ERROR 509: Bandwidth Error. Can someone tell me what this means please, and a possible workaround? Thanks very much.

    Read the article

  • How to manually set color of Unity Panel?

    - by JamesTheAwesomeDude
    I was just wondering if there's a way to set the color of the Unity panel manually, as opposed to having it derived from smooshing all the colors of the wallpaper together. (the launcher on the left side of the screen that comes default in Ubuntu is the Unity Panel, right? If not, please correct me on my terminology.) The reason I want this is because I have this cool wallpaper I found on DeviantArt, and I used GIMP to make Dawn, Dusk, and Midnight versions of it. Then, I set them with a transition effect, so that the lighting changes over the course of the day. Unfortunately, the Unity Panel turns a sickly sewer green at night (it could also be said to look like radioactive barf.) Either way, I don't like my launcher thingy looking like that. I'd prefer to stay away from programs that let you customise the Unity Panel (I'm fine with using sudo nano to edit system config files,) but I would if it were the only option. Here are some screenshots, one with a grey-themed wallpaper, one with lots of red, and the hill at night, (the one that makes the unity panel look like radioactive barf.): http://imgur.com/a/0Gqcd

    Read the article

  • Ubuntu not selectable in boot menu

    - by user113630
    Im trying to dual boot windows 7 and Ubuntu 12.10. i created a partition in windows 7, booted the Ubuntu cd, installed Ubuntu and created a swap space(following all instructions detailed in various video tutorials). after restarting and taking out the disk my computer boots directly into windows. also, in the boot menu where you select what os to boot, Ubuntu doesn't show up, just windows 7. i didn't want to screw around with any settings and figured the community could figure out my problem faster than i could :p any help is greatly appreciated!

    Read the article

  • How do I specify a string to display in the Ubuntu software-center when creating a package with dpkg-deb?

    - by TomMKV
    When I open *.deb packages downloaded from the internet in the Ubuntu software-center, it displays a "nice" name for the package (including upper- and lowercase, spaces, special characters, ...). When I create a *.deb package from binaries only using dpkg-deb -b, Ubuntu Software Center displays the "technical" package name (the one specified at the Package: field in the control file, limited to lowercase only, no spaces, ...). Is there any way to provide a string different from the "technical" package name (including upper- and lowercase, spaces, special characters, ...) for display in the Ubuntu software Center? Unfortunately, this can not be done via the short description (that is displayed below the "technical" name, but not replacing it).

    Read the article

  • Can't open Software Center or Update Manager

    - by Albert
    When I try to (not from terminal) the following error message opens up: An unresolvable problem occurred while initializing the package information. Please report this bug against the 'update-manager' package and include the following error message: 'E:Malformed line 60 in source list /etc/apt/sources.list (dist parse)' Using Ubuntu 12.04, thanks. Edit: Went to line 60, this is what I found: deb http://archive.canonical.com/precise partner

    Read the article

  • White screen on webcam site using Flash Player

    - by glenn
    I browsed a webcam site with flash player 10 and it works perfectly. But there is a private chat section and when I enter it I see a big white rectangle where the webcam and chat box should be. What is the problem - it is definitely the flash player, as the page does not prompt me to download the latest flash player... The site was working fine until last week. Does anybody know how to Re-install flash player?

    Read the article

  • Language support problems

    - by oadams
    I'm running 11.04. I want the system language to be in German. When I go to Language Support and Install/Remove Languages, I check the German box and Apply Changes. However I'm told that the package is already installed and that there isn't any need for an installation. Expanding the Details shows: Package [dbus.String(u'libreoffice-gnome')] is already installed However, German doesn't appear in the Language for menus and windows list. How should I resolve this? The problem is the same when I tried Esperanto and Afrikaans.

    Read the article

  • core.* files eating up server space (~50MB)

    - by skytreader
    I'm renting server space from someone and, upon logging in my control panel after quite sometime, noticed an abnormal spike (~50MB) in the disk usage. Upon investigating, I found a lot of core.* files scattered around my public_html directory. Each one is more than 5MB in size but no more than 6MB. The * part is all numbers (in programming regex, that should be core\.\d+). I downloaded one and checked the contents. There was a lot of balderdash characters (NUL mostly, but also a scattering of ETB, ETX, STX) but there's this block of readable text which says: This text is part of the internal format of your mail folder, and is not a real message. It is created automatically by the mail system software. If deleted, important folder data will be lost, and it will be re-created with the data reset to initial values. Pretty self-explanatory. A few blocks above the text are some more readable messages that look like logs but is sandwiched in between non printable characters. I've extracted some below. Scan not valid for mh mailboxes Bogus character 0x%x in news state Can't rewrite news state %.80s Error closing backup news state %.80s No state for newsgroup %.80s found Now, a few concerns: Am I under attack? The messages seem to be about my webmail but I don't use my personal webmail that much---only for a vanity email address and an inbox for an outdated comments system. However, lately, I seem to notice a spike in the spam for my vanity mail. (Note: the comments system is covered by a captcha but every now and then some get through. My vanity email has a spam filter but it isn't as good as I'd like). Next, if this is a feature, can I turn it off? Is it advisable to? I've only 150MB so you see why I'm fretting over a 50MB spike. Some final details: my only server-side scripts are in PHP. The directory which accumulated the most number of these core files is the one containing the Wordpress-managed subdomain of my site. I manage my server through CPanel. Lastly, I decided to delete this files and after some checking nothing seems amiss in my websites nor in my mail. They are indeed the ones responsible for the ~50MB spike as my disk space usage is back to expected.

    Read the article

  • What dangers await if I block non-standard, non-major-usa search engine bots from my USA only website?

    - by Ryan
    I noticed tons of bandwidth being used by non-USA search engine bots, so I began blocking them in an effort to save bandwidth and cpu cycles for actual users and the search engines they come from (Google, Bing, Yahoo, Ask, etc.). Other than potentially losing some international traffic (which isn't really important to us since all of our content is very USA-centric), what additional dangers should I be concerned about? I'm using a modified version of Jeff Starr's User Agent Blocklist

    Read the article

  • What are the statements in XNA?

    - by Katie Hajduk
    A hypothetical game called “AlienShooter” needs to be able to work on Windows and on the Xbox. In the Windows version, the keyboard will handle firing at alien spaceships, and this functionality is contained within a method called “KeyboardSupport()”. In the Xbox version of the game, the gamepad will be used for shooting, and this functionality is contained within a method called “GamepadSupport()”. Write the statement(s) that must be added so that the appropriate code is used in the each version of the game.

    Read the article

  • World orientation in OpenGLES clarification

    - by Dev2rights
    I have a 3d tile map made up of individual billboards in OpenGLES. Each is a 2 triangles mesh and has a 3D Vector to determine its position and another defining its rotation from the origin at (0,0,0). Im trying to work out how to rotate the entire tile map around a point be that the origin or some arbitrary point in space. Im guessing i need to set up a Model Matrix instead for each tile. Then set up a world matrix for the world. Then on updating i would translate the world matrix and change the orientation and multiply it with each model matrix before rendering. Is this correct ?

    Read the article

  • Animate multiple entities

    - by Robert
    I'm trying to animate multiple(3) entities using one model(IQM format). It's working but performance is really bad because I'm calling animate function for each entity in my game loop (I think problem is there). What's the best way to animate multiple entities (with different animation ofc) in OpenGL? I think I can try build one VBO / entity for better performances but I don't think it's the best way to do it.

    Read the article

  • OBJ model loaded in LWJGL has a black area with no texture

    - by gambiting
    I have a problem with loading an .obj file in LWJGL and its textures. The object is a tree(it's a paid model from TurboSquid, so I can't post it here,but here's the link if you want to see how it should look like): http://www.turbosquid.com/FullPreview/Index.cfm/ID/701294 I wrote a custom OBJ loader using the LWJGL tutorial from their wiki. It looks like this: public class OBJLoader { public static Model loadModel(File f) throws FileNotFoundException, IOException { BufferedReader reader = new BufferedReader(new FileReader(f)); Model m = new Model(); String line; Texture currentTexture = null; while((line=reader.readLine()) != null) { if(line.startsWith("v ")) { float x = Float.valueOf(line.split(" ")[1]); float y = Float.valueOf(line.split(" ")[2]); float z = Float.valueOf(line.split(" ")[3]); m.verticies.add(new Vector3f(x,y,z)); }else if(line.startsWith("vn ")) { float x = Float.valueOf(line.split(" ")[1]); float y = Float.valueOf(line.split(" ")[2]); float z = Float.valueOf(line.split(" ")[3]); m.normals.add(new Vector3f(x,y,z)); }else if(line.startsWith("vt ")) { float x = Float.valueOf(line.split(" ")[1]); float y = Float.valueOf(line.split(" ")[2]); m.texVerticies.add(new Vector2f(x,y)); }else if(line.startsWith("f ")) { Vector3f vertexIndicies = new Vector3f(Float.valueOf(line.split(" ")[1].split("/")[0]), Float.valueOf(line.split(" ")[2].split("/")[0]), Float.valueOf(line.split(" ")[3].split("/")[0])); Vector3f textureIndicies = new Vector3f(Float.valueOf(line.split(" ")[1].split("/")[1]), Float.valueOf(line.split(" ")[2].split("/")[1]), Float.valueOf(line.split(" ")[3].split("/")[1])); Vector3f normalIndicies = new Vector3f(Float.valueOf(line.split(" ")[1].split("/")[2]), Float.valueOf(line.split(" ")[2].split("/")[2]), Float.valueOf(line.split(" ")[3].split("/")[2])); m.faces.add(new Face(vertexIndicies,textureIndicies,normalIndicies,currentTexture.getTextureID())); }else if(line.startsWith("g ")) { if(line.length()>2) { String name = line.split(" ")[1]; currentTexture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/" + name + ".png")); System.out.println(currentTexture.getTextureID()); } } } reader.close(); System.out.println(m.verticies.size() + " verticies"); System.out.println(m.normals.size() + " normals"); System.out.println(m.texVerticies.size() + " texture coordinates"); System.out.println(m.faces.size() + " faces"); return m; } } Then I create a display list for my model using this code: objectDisplayList = GL11.glGenLists(1); GL11.glNewList(objectDisplayList, GL11.GL_COMPILE); Model m = null; try { m = OBJLoader.loadModel(new File("res/untitled4.obj")); } catch (Exception e1) { e1.printStackTrace(); } int currentTexture=0; for(Face face: m.faces) { if(face.texture!=currentTexture) { currentTexture = face.texture; GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTexture); } GL11.glColor3f(1f, 1f, 1f); GL11.glBegin(GL11.GL_TRIANGLES); Vector3f n1 = m.normals.get((int) face.normal.x - 1); GL11.glNormal3f(n1.x, n1.y, n1.z); Vector2f t1 = m.texVerticies.get((int) face.textures.x -1); GL11.glTexCoord2f(t1.x, t1.y); Vector3f v1 = m.verticies.get((int) face.vertex.x - 1); GL11.glVertex3f(v1.x, v1.y, v1.z); Vector3f n2 = m.normals.get((int) face.normal.y - 1); GL11.glNormal3f(n2.x, n2.y, n2.z); Vector2f t2 = m.texVerticies.get((int) face.textures.y -1); GL11.glTexCoord2f(t2.x, t2.y); Vector3f v2 = m.verticies.get((int) face.vertex.y - 1); GL11.glVertex3f(v2.x, v2.y, v2.z); Vector3f n3 = m.normals.get((int) face.normal.z - 1); GL11.glNormal3f(n3.x, n3.y, n3.z); Vector2f t3 = m.texVerticies.get((int) face.textures.z -1); GL11.glTexCoord2f(t3.x, t3.y); Vector3f v3 = m.verticies.get((int) face.vertex.z - 1); GL11.glVertex3f(v3.x, v3.y, v3.z); GL11.glEnd(); } GL11.glEndList(); The currentTexture is an int - it contains the ID of the currently used texture. So my model looks absolutely fine without textures: (sorry I cannot post hyperlinks since I am a new user) i.imgur.com/VtoK0.png But look what happens if I enable GL_TEXTURE_2D: i.imgur.com/z8Kli.png i.imgur.com/5e9nn.png i.imgur.com/FAHM9.png As you can see an entire side of the tree appears to be missing - and it's not transparent, since it's not in the colour of the background - it's rendered black. It's not a problem with the model - if I load it using Kanji's OBJ loader it works fine(but the thing is,that I need to write my own OBJ loader) i.imgur.com/YDATo.png this is my OpenGL init section: //init display try { Display.setDisplayMode(new DisplayMode(Support.SCREEN_WIDTH, Support.SCREEN_HEIGHT)); Display.create(); Display.setVSyncEnabled(true); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } GL11.glLoadIdentity(); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glClearColor(1.0f, 0.0f, 0.0f, 1.0f); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LESS); GL11.glDepthMask(true); GL11.glEnable(GL11.GL_NORMALIZE); GL11.glMatrixMode(GL11.GL_PROJECTION); GLU.gluPerspective (90.0f,800f/600f, 1f, 500.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glCullFace(GL11.GL_BACK); //enable lighting GL11.glEnable(GL11.GL_LIGHTING); ByteBuffer temp = ByteBuffer.allocateDirect(16); temp.order(ByteOrder.nativeOrder()); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip()); GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS,(int)material_shinyness); GL11.glLight(GL11.GL_LIGHT2, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse2).flip()); // Setup The Diffuse Light GL11.glLight(GL11.GL_LIGHT2, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition2).flip()); GL11.glLight(GL11.GL_LIGHT2, GL11.GL_AMBIENT,(FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip()); GL11.glLight(GL11.GL_LIGHT2, GL11.GL_SPECULAR,(FloatBuffer)temp.asFloatBuffer().put(lightDiffuse2).flip()); GL11.glLightf(GL11.GL_LIGHT2, GL11.GL_CONSTANT_ATTENUATION, 0.1f); GL11.glLightf(GL11.GL_LIGHT2, GL11.GL_LINEAR_ATTENUATION, 0.0f); GL11.glLightf(GL11.GL_LIGHT2, GL11.GL_QUADRATIC_ATTENUATION, 0.0f); GL11.glEnable(GL11.GL_LIGHT2); Could somebody please help me?

    Read the article

  • How to make a checkbox list that is also explorer tree?

    - by Loclip
    Lets say we have 3 categories Car Airplanes Bikes Each category have other categories for example car have: BMW Toyota Mercedes Each of these categories have cars (no more categories) Car, airplane, bikes will be items in the listbox that can be explored and checked. Now lets say we explore car there will be BMW, Toyota, Mercedes that can be only checked. So if I check car all car will be checked, if i check bmw only the bmw from cars will be checked.. How I can do that?

    Read the article

  • MySQL SELECT where if stores have X, show me everything that they have

    - by tnt0932
    I have a MYSQL table like this: STORES (SPID, StoreID, ProductID); And data like this: { 1 | s1 | p2 } { 2 | s1 | p7 } { 3 | s1 | p8 } { 4 | s2 | p1 } { 5 | s2 | p3 } { 6 | s2 | p6 } { 7 | s2 | p9 } { 8 | s3 | p2 } { 9 | s3 | p5 } And I would like to: Use a MYSQL SELECT query to get results, where if a store has a certain product, then a list of all of the products at that store will be returned. For example, if I were looking for "p2", then I would like to know that "s1" has "p2, p7, p8" and "s3" has "p2, p5". Please let me know if you require any more information. I'm not sure what is required to solve this issue (Which is probably why I can't search and find the answer!) Thank you.

    Read the article

  • Length-1 arrays can be converted to python scalars error? python

    - by Randy
    from numpy import * from pylab import * from math import * def LogisticMap(a,x): return 4.*a*x*(1.-x) def CosineMap(a,x): return a*cos(x/(2.*pi)) def TentMap(a,x): if x>= 0 or x<0.5: return 2.*a*x if x>=0.5 or x<=1.: return 2.*a*(1.-x) a = 0.98 N = 40 xaxis = arange(0.0,N,1.0) Func = CosineMap subplot(211) title(str(Func.func_name) + ' at a=%g and its second iterate' %a) ylabel('X(n+1)') # set y-axis label plot(xaxis,Func(a,xaxis), 'g', antialiased=True) subplot(212) ylabel('X(n+1)') # set y-axis label xlabel('X(n)') # set x-axis label plot(xaxis,Func(a,Func(a,xaxis)), 'bo', antialiased=True) My program is supposed to take any of the three defined functions and plot it. They all take in a value x from the array xaxis from 0 to N and then return the value. I want it to plot a graph of xaxis vs f(xaxis) with f being any of the three above functions. The logisticmap function works fine, but for CosineMap i get the error "only length-1 arrays can be converted to python scalars" and for TentMap i get error "The truth value of an array with more than one element is ambiguous, use a.any() or a.all()". My tent map function is suppose to return 2*a*x if 0<=x<0.5 and it's suppose to return 2*a*(1-x) if 0.5<=0<=1.

    Read the article

  • What is the best strategy for populating a TableView from a service?

    - by alrutherford
    I have an application which has a potentially long running background process. I want this process to populate a TableView as results objects are generated. The results objects are added to an observableList and have properties which are bound to the columns in the usual fashion for JavaFX. As an example of this consider the following sample code Main Application import java.util.LinkedList; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class DataViewTest extends Application { private TableView<ServiceResult> dataTable = new TableView<ServiceResult>(); private ObservableList<ServiceResult> observableList; private ResultService resultService; public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { observableList = FXCollections.observableArrayList(new LinkedList<ServiceResult>()); resultService = new ResultService(observableList); Button refreshBtn = new Button("Update"); refreshBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { observableList.clear(); resultService.reset(); resultService.start(); } }); TableColumn<ServiceResult, String> nameCol = new TableColumn<ServiceResult, String>("Value"); nameCol.setCellValueFactory(new PropertyValueFactory<ServiceResult, String>("value")); nameCol.setPrefWidth(200); dataTable.getColumns().setAll(nameCol); // productTable.getItems().addAll(products); dataTable.setItems(observableList); Scene scene = new Scene(new Group()); stage.setTitle("Table View Sample"); stage.setWidth(300); stage.setHeight(500); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); vbox.getChildren().addAll(refreshBtn, dataTable); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.show(); } } Service public class ResultService extends Service<Void> { public static final int ITEM_COUNT = 100; private ObservableList<ServiceResult> observableList; /** * Construct service. * */ public ResultService(ObservableList<ServiceResult> observableList) { this.observableList = observableList; } @Override protected Task<Void> createTask() { return new Task<Void>() { @Override protected Void call() throws Exception { process(); return null; } }; } public void process() { for (int i = 0; i < ITEM_COUNT; i++) { observableList.add(new ServiceResult(i)); } } } Data public class ServiceResult { private IntegerProperty valueProperty; /** * Construct property object. * */ public ServiceResult(int value) { valueProperty = new SimpleIntegerProperty(); setValue(value); } public int getValue() { return valueProperty.get(); } public void setValue(int value) { this.valueProperty.set(value); } public IntegerProperty valueProperty() { return valueProperty; } } Both the service and the TableView share a reference to the observable list? Is this good practise in JavaFx and if not what is the correct strategy? If you hit the the 'Update' button the list will not always refresh to the ITEM_COUNT length. I believe this is because the observableList.clear() is interfering with the update which is running in the background thread. Can anyone shed some light on this?

    Read the article

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