Go to QuArK Web Site
QuarkX
Updated 24 Dec 2021
Upper levels:
QuArK Information Base
4. The Source Code

 4.8. QuarkX

 [ Prev - Up - Next ] 

 Index


 What QuArK expects to find from Python

Armin Rigo - 05 Apr 2018   [ Top ] 

When QuArK starts, it initializes the Python interpreter and loads the package called  quarkpy . This should be a subdirectory in the directory that contains  quark.exe . Once this package (i.e. the file  quarkpy\__init__.py ) has been loaded, QuArK calls its function  RunQuArK() . See the file  __init__.py  for more details about the start-up process.

To answer to user actions, QuArK needs to call Python code. This is usually done by setting some variables that QuArK knows how to read so that they point to a Python function. In some cases, however, this is not possible; these cases are handled by the module  qmacro.py  which contains functions with special names, all beginning with  MACRO_ . See below for a list of all macros that QuArK expects to find there.

QuArK exposes all its features to Python code through the built-in module  quarkx . Constant values and various utilities are found in the Python modules  qutils.py  and  qeditor.py .

For examples about all the following stuff, see the  .py  files included with QuArK.


 QuArK-specific functions of the module quarkx

Armin Rigo - 07 Aug 2021   [ Top ] 
Setup1(...) Must be called at start-up for initialization only. See  quark.py .
action() Starts an undoable user action. Returns a copy of the  undo  module described below.
getchangednames() Returns a list with, one or more, tuple lists  (oldname, newname)  inside it, each consisting of two string items that give the old and new names of an object that was renamed. Do not call this function directly or it will clear the list, call it using a variable to be set by it.
For example:
changednames = quarkx.getchangednames()

Then use the variable to work with. If nothing has been renamed then this function will only return  None , but not as a string item.
undostate(obj) Returns a tuple  (undostr, redostr)  with two strings that give the next operation that can be undone (resp. redone) on the object  obj .  undostr  and  redostr  are set to  None  if there is no operation to undo (resp. redo).
boundingboxof(list) Returns a bounding box  (vmin, vmax)  for the given  list  of map objects, or  None .  vmin  and  vmax  are 3D vector objects. The list may also contain (non-projected) 3D vector objects that will be included in the returned bounding box.
texturesof(list) Returns a sorted list of all texture names used in the given  list  of map objects.
extendcoplanar(list, lookin)
extendcoplanar(list, lookin, side)
 list  should be a list of polyhedron faces. This routine searches for faces in the objects in the list  lookin  that are coplanar and adjacent to the given faces, and appends them to  list . All given faces must already be coplanar.  side  controls whether two faces of opposite normal vector match;  1  must be the same direction,  -1  must be opposite,  0  (default) both. Note that the resulting  list  may contain a face more than once if it is shared by several polyhedron or if it was originally both in  list  and  lookin .
forms()
forms(1)
forms(2)
Returns a list of all opened windows. Note that this is currently not very useful, because only Python-controlled windows are included. In the second form of the call, Floating windows are included as well. In the 3rd form of the call, non-Python windows are included as  None  in the list, and the order is such as the first item in the list represents the active window.
newform() Opens a new window. Don’t use this. To create floating toolbox windows, see  newfloating() .
update()
update(form)
Updates the window  form , or all windows if not specified. Menu bars, toolbars, and buttons are updated. See below for more information.
opentoolbox(toolbox)
opentoolbox(toolbox, select)
Opens the toolbox given by name. If  toolbox  is empty ex:  quarkx.opentoolbox("") , this function opens the texture browser. If  select  is the actual texture object (see quarkpy\mdlbtns.py texturebrowser function for code example), attempts to find and select this Internal object in the toolbox. If  select  is  None , and if some objects were previously selected in the toolbox, they are unselected.
findtoolboxes()
findtoolboxes(tb)
Find all toolbox data objects. Returns a list of couples  ("toolbox name", rootofdata) . If  tb  is specified, it must be a string and  findtoolboxes  will only return data for this toolbox.
openconfigdlg()
openconfigdlg(path)
openconfigdlg(caption, obj, newobjlist)
Opens the Configuration dialog box. If  path  is given, the corresponding folder or subfolder is opened, e.g. " Map:Options ", or " : " for the current game’s configuration page. In the third form,  obj  is a  :config  object that gives alternate configuration data to display, and  caption  is the window caption. In this case, the dialog box is modal and  openconfigdlg  returns  1  or  0  to let you know if the user clicked on Ok or Cancel.  newobjlist  is a list of objects that the user can insert from buttons, or  None  if no editing of the object hierarchy is allowed.
globalaccept()
globalaccept(ok)
Ends pending user editing (e.g. in yellow edit boxes). If  ok  is  True  or omitted, the changes are accepted; otherwise, they are cancelled.

 Functions of the module quarkx that build special objects

Armin Rigo - 05 Aug 2020   [ Top ] 
loadtexture(name)
loadtexture(name, altsrc)
Loads the texture name from the texture browser. Returns None if the texture is not found. altsrc is an optional parameter specifying an alternate place to look for textures first (for .bsp files, it is the .bsp’s own texture list). Note that the returned texture is often just a link to the actual texture in the Quake directory; see the textures' disktexture attribute.
maptextures(list, op)
maptextures(list, op, altsrc)
Loads a list of textures given by name. If the list contains animated textures, and some animation sequence are not complete, they are completed. Returns a list of all loaded textures, as loaded with loadtexture. If op is 1, this function writes all the textures to the tmpQuArK directory. If op is 2, extra files are written, too, as specified by ExtraFiles in Defaults.qrk. If op is 0, no file is written to the disk.
vect(x,y,z)
vect(x,y,z,s,t)
vect((x,y,z))
vect((x,y,z,s,t))
vect(string)
Returns a 3D (resp. 5D) vector object with coordinates x,y,z (resp. x,y,z,s,t) specified either as three (resp. five) parameters, as a single tuple parameter, or textually in a string as three (not 5, not supported, sorry) numbers separated with whitespaces.
quaternion(string) Returns a quaternion object. string textually contains 4 numbers separated with whitespaces (no parenthesis). As with vect above, instead of calling quaternion with three arguments, you can call it with a single tuple argument.
matrix(v1,v2,v3)
matrix((a,b,c), (d,e,f), (g,h,i))
matrix(string)
Returns a matrix object. v1,v2,v3 are 3D vectors that are used as columns of the matrix. (a,b,c),(d,e,f),(g,h,i) is the line-by- line description of the 9 floats to put into the matrix. string textually contains 9 numbers separated with whitespaces (no parenthesis). As with vect above, instead of calling matrix with three arguments, you can call it with a single tuple argument.
newobj(name) Creates a new Internal QuArK object called name. See below for a description of Internal QuArK objects.
newfileobj(name) Idem, but builds an Internal QuArK file object.
openfileobj(filename) Opens an existing file and returns an Internal QuArK file object.
savefileobj(obj,FM_SaveAsFile,0,None,0) Opens a 'Save File' window and saves any selected fileobject such as a texture image (Internal QuArK file object) or md2 file to any location.
obj the selected object in QuArK, FM_SaveAsFile enter as shown here (see others below), 0 to specify type of file to save as (see others below), None (default setting) specifies as dialog form, will not save the file until dialog closed, 0 this setting stops the saved file from showing up on the Recent files menu list, setting the argument to 1 will place the name on the list.
other settings available  :
2nd argument:
FM_Save           = 1
FM_SaveAsFile     = 2
FM_SaveIfModif    = 3
FM_SaveTagOnly    = 4
3rd argument
0       = (default setting), any file type *.*
1 - N   = as shown in source code (look for the various TestConversionType functions)
The values of the third argument depend on the object type. For example, for images 1=QPcx, 2=QTga, 3=QDDS, 4=QBmp, 5=QJPeg, 6=QPng, 7=QM32, 8=QFTX, 9=QVTF, 10=QIWI, but for map-files 1=QQkm and 2 is gamemode dependent (6DX: Hmf, HL2: VMF, Sylphis: QCMapFile, else: QQuakeMapFile).
setupsubset()
setupsubset(i)
setupsubset(i,subset)
Returns an Internal object from the Configuration dialog box. i is one of the SS_xxx constants, and subset is the name of the subset. If unspecified, returns the set SS_xxx. If i is unspecified, too, returns the subset corresponding to the current game.
copyobj(list) Copy all QuArK objects in the list into the clipboard. The previous clipboard content is cleared.
pasteobj()
pasteobj(1)
With no argument, or with a False argument, returns 1 if there is one or several Internal object in the clipboard ready to be pasted, and 0 otherwise. With a True argument, returns a list of all objects from the clipboard, which will be empty if there is no such object.
getqctxlist()
getqctxlist(type)
getqctxlist(type, name)
Builds a list of objects from all .qctx objects found in Defaults.qrk and in the currently registered add-ons. If parameters are given, returns a list of objects within .qctx objects that match the specified criteria: they must have the correct type and, if specified, the correct name.
loadimages(filename)
loadimages(fn, width)
loadimages(fn, width, (x,y))
Loads an image list from a .bmp file. Each image in the list has the given width (default 16), and all pixels of the same color as the one at coordinates (x,y), if specified, are considered to be transparent. See Image List objects below. If width is a floating-point number, it represents the ratio width/height instead of a pixel count.
newfaceex(vertices) Makes a new polyhedron face with the given vertices list. Not for building polyhedrons!! Only for special uses!! The resulting face should only be used to check for intersection with other polyhedrons or to be displayed (with a "broken face" cyan border).
needgamefile(file)
needgamefile(file, base)
Loads a file from the current game's data. The file path should be specified in a .pak-style fashion, e.g. "maps/base1.bsp". If base is present, QuArK only looks in this base directory; otherwise, it looks in all configured base directories, just like the game itself. Returns an Internal File Object. Raises quarkx.error if not found.

 Logging functions of the module quarkx

DanielPharos - 05 Apr 2018   [ Top ] 

The default filename for the main log file is 'QUARK.LOG'.
The default filename for the console log file is 'Console.txt'.

log(string [, level]) Writes a line of text to the main log file. It'll be marked with 'PythonLog'.  level  is the loglevel used for this output.
startconsolelog() Opens the console log file. Console output is automatically written to the log file if it is open.
stopconsolelog() Closes the console log file. This stops any console output from being written to it.
clearconsolelog() Deletes the console log file. Should be used with caution!

 Texture functions of the module quarkx

cdunde - 24 Dec 2021   [ Top ] 

Functions for actually changing a texture image, weather it be in the Model Editor as a skin texture or the Map Editor as a face texture (not implemented yet). These can also be used to set and apply dialog pen colors to change a texture or in conjunction with a view's Canvas objects to set their various color functions.

In addition, other useful related functions can be found in the quarkpy\qutils.py file Texture and Color Utilities section such as:
RGBToColor(RGB) : Converts separate Red, Green, Blue color components into a long integer color.
ColorToRGB(Color) : Converts long integer color number into separate color components Red Green Blue (RGB).

As well as specific functions for the Model Editor in its quarkpy/mdlutils.py file for:
TexturePixelLocation(editor, view, x, y, triangleface) : To get the u, v texture position of any triangle where the cursor is pointing in any view.

Argument Definitions and examples to use for these functions:
texshortname = editor.Root.currentcomponent.currentskin.shortname (be SURE to use the shortname and not name or the function breaks!)
texparent = editor.Root.currentcomponent.currentskin.parent
pixU, pixV = The texture u, v location in a view (get by using the mdlutils.py TexturePixelLocation function).
PalIndex = An actual integer palette number, not the string equivalent of an integer value.
paintcolor = As a palette index intiger, hex number, or Long intiger for ex:
      PalIndex = int(quarkx.setupsubset(SS_MODEL, "Colors")["Paint_PalettePenColor"]) # 8 bit texture PalIndex number.
      hex2longint = MapColor("Paint_RGBPenColor", SS_MODEL) # 24 bit texture, as a hex number converted to a long int.
      longint = 13283574

getpixel(texshortname, texparent, pixU, pixV) This is NOT the same function as the view.canvas() getpixel function. which is a pixel of a view that can be distorted, inaccurate, not a true texture pixel.
If the texture being sent is a palette texture, such as a .pcx texture, then the function returns the PalIndex number as an integer (not a string of an integer).
If the texture being sent is a 24 bit texture, such as a .tga texture which do not use a palette - only RGB colors, then the color's long integer number is returned.

If an RBG color, returns a long integer of that pixel, this can be used for the setpixelpal function below to paint (change) that texture.
Use example:
      paintcolor = quarkx.getpixel(texshortname, texparent, pixU, pixV)
getpixelpal(texshortname, texparent, PalIndex) Returns the color of the PalIndex as an RGB long integer. Used to set RGB pen color from a palette color.
Use example:
      paintcolor = quarkx.getpixelpal(texshortname, texparent, PalIndex)
getpixelalpha(texshortname, texparent, pixU, pixV) This function is an RGB function ONLY! And ONLY works with OpenGL in QuArK. Returns the "alphavalue" as a long integer.
Use example:
      alphavalue = quarkx.getpixelalpha(texshortname, texparent, pixU, pixV)
setpixel(texshortname, texparent, pixU, pixV, integer) Changes the actual texture image color to the new Palette integer color, or for RGB colors the hex2longint or longint. (does the color painting)
Use examples:
      quarkx.setpixel(texshortname, texparent, pixU, pixV, PalIndex)        or
      quarkx.setpixel(texshortname, texparent, pixU, pixV, hex2longint)   or
      quarkx.setpixel(texshortname, texparent, pixU, pixV, longint)
setpixelpal(texshortname, texparent, PalIndex, paintcolor) Used to CHANGE a model's palette color to ANY RGB color, to be saved with the model file. It actually changes the model's palette.
Use example:
      quarkx.setpixelpal(texshortname, texparent, PalIndex, paintcolor)
setpixelalpha(texshortname, texparent, pixU, pixV, alphavalue) This function is an RGB function ONLY! And ONLY works with OpenGL in QuArK. Changes the actual alpha color alphavalue of a texture, to the new alphavalue.
(does the alpha painting, the alphavalue, comes from getpixelalpha function above)
Use example:
      quarkx.setpixelalpha(texshortname, texparent, pixU, pixV, alphavalue)

 Various general-purpose functions of the module quarkx

Armin Rigo - 12 Dec 2021   [ Top ] 
lines2list(string) Convert a string with $0D end-of-line characters (as found in .qrk files) into a list of strings, one for each line.
list2lines(list) lines2list’s inverse operation.
truncstr(string) Returns the string up to but not including the first null character.
settimer(callback, info, delay) Set up a timer. QuArK will call the function callback with the single user-specified argument info after delay milliseconds have elapsed. To set a repetitive timer, callback can return a number, which is the number of milliseconds until it should be called again. If callback returns None, the timer stops. To cancel a pending timer, call settimer with exactly the same (as the operator “ is ” would tell) callback and info and with a delay of 0.
rnd(float) Rounds float to the nearest integer. Values that are almost exactly an integer and a half are rounded down, e.g. 2.49999, 2.5 and 2.50001 are all rounded to 2.
middlecolor(c1,c2,frac) Returns a color interpolated between c1 and c2. frac is usually between 0 (which returns c2) and 1 (which returns c1) but can be outside this range; in this case, the R-G-B components are clamped to the valid range.
keydown(key) Checks the state of the keyboard. See qkeys.py for a list of all keys. Returns 1 if the key is down, -1 if the key is up but has been pressed after the previous same call to keydown, and 0 otherwise.
setpoolobj(tagname, anything) Stores anything into the pool under the name tagname. The pool is like a dictionary, but objects that are put there will be periodically freed if they are not referenced any more by other variables. Use it to store complex memory-consuming objects that can be quickly rebuilt when necessary. This lets you use the same object from several places. If tagname is the empty string, the stored object cannot be retrieved from the pool any more, but it guarantees that the object won’t be freed immediately (e.g. use it to store objects that take some time to be freed).
poolobj(tagname) Returns the pool object called tagname, or None.
listfileext() Returns a list of all known file types, each of the form (extension, description).
filedialogbox(...) Opens an Open or Save dialog box. See the .py files for examples.
screenrect() Returns the screen size minus the task bar (left,top,right,bottom).
seticons(i, icon)
seticons(i, ico1, ico2)
Assigns the given icon to the objects of kind i. See qutils.py for a complete list. If two icons are given, the second one is used when the object is not selected. The icon parameter(s) can be each either an item of an image list, or a function that QuArK will call whenever it needs the icon. The function has the actual Internal object as parameter, and must return an item of an image list.
msgbox(msg, typ, btn) Displays a message box. See qutils.py for a list of available MT_ flags for typ and MB_ for btn.
textbox(msg, text, typ) Displays a text box form. See qutils.py for a list of available MT_ flags for typ.
Note : Each line of the text must end with both \r\n and not just \n or improper marks will be displayed instead.
beep()
beep(kind)
Beeps. Use  kind  with  SOUND_*  constants to change the kind of beep-noise made.
wait()
wait(delay)
wait(delay, origin)
Waits delay milliseconds (0 if unspecified) and returns the current time, computed in milliseconds. If origin is specified, the delay is computed from the start time origin. This lets you make an animation at a given speed no matter how long it takes to display one image.
exit() Exits QuArK.
progressbar(txt,count) Sets up a new progressbar module. The progress bar displays the text qdictionnary.Strings[txt] (txt must be an integer, not a string!) and it reaches 100% after count steps. Returns a new copy a the progressbar module (see below).
ftos(float) Returns a string representing the given float with at most one decimal. If float is almost an integer, the string contains no decimal part.
clipline(p1,p2) Clips the line between the points p1 and p2 to its part before the camera. Returns a couple of points that represents the new line, or (None, None) if the line is completely behind the camera. The two returned points are computed so that their x and y coordinates can be used (i.e. the visible attribute of the points are True). clipline is automatically called by the line method of canvases. See below for more information about projected 3D points.
runprogram(cmdline, currentdir)
runprogram(cmdline, currentdir, stdout)
runprogram(cmdline, currentdir, stdout, stderr)
Runs the program given by cmdline. currentdir is the new program’s current directory. runprogram returns a process object, as described below. If the program is a console program, and if stdout is specified, it will use this console object instead of running in its own console. If stderr is omitted, it defaults to stdout.
Code example:
cmdline = "psp.exe"
currentdir = "C:\Programs\PSP"
quarkx.runprogram(cmdline, currentdir)
# runs the program
# sets the programs directory
console()
console(visible)
Shows or hides the QuArK console. console() or console(1) shows it and console(0) hides it.
writeconsole(src, text) Writes the text in the console. src should be an object of class qconsole.console. See the file qconsole.py for details.
getquakedir() Returns the Quake dir. This is the directory containing the game's executable file.
getgamedir() Returns the Game dir. This is the directory containing the pak files (note: can be different for mods!).
gettmpquark() Returns the tmpquark dir. This is the directory QuArK outputs files to.
getbasedir() Returns the base dir. This is the directory containing the game's (official) pak files.
outputfile(pathandname) Expands pathandname into a complete path and name. pathandname is a name as seen by Quake, e.g. maps/xyz.bsp. The returned path is in the directory tmpQuArK. The directories are created if they don’t already exist. If the directory to Quake has not been set in the Configuration dialog box, outputfile warns the user and raises quarkx.abort.
outputpakfile()
outputpakfile(1)
Returns the file path and name of the .PAK file that should be created before running Quake, or None. outputpakfile never returns None if a True parameter is given.
getfileattr(filename) Returns the file attributes, or -1 if the file doesn’t exist. See qutils.py for the list of attributes.
setfileattr(filename, attr) Sets the file attributes. Use it to either clear a file’s archive attribute, or to delete the file by specifying -1 as attr. Raises quarkx.error if the file doesn’t exist.
reloadsetup() Reload the settings of QuArK from the Setup objects.
htmldoc(url)
htmldoc(filename)
Opens the given HTML file or URL in the default browser. filename must give the full path, and may end with #section to jump directly to the specified section in the file.
helppopup(text) Displays a pop-up window with the given help text.
helpmenuitem(text) Adds an item into the '?' menu. Selecting this items call the MACRO_helpmenu macro.
getshorthint(hint) Returns the "short" part of a hint string, that is, everything before the first "|". This is the part of the hint that will be displayed in a small pop-up window when you leave the mouse over the control.
getlonghint(hint) Returns the "long" part of a hint string. If there is a "|" in the string, this "long" part is everything after this bar. This is usually a longer description for the control action, suitable to be displayed with quarkx.helppopup.
listmapviews() Returns a list with all currently opened map views in QuArK.
menuname(s) Returns the string s with all '&' signs doubled (required for menu items in which the '&' sign should occur as is and not as a prefix for shortcut).
searchforholes(polys, startpoints) Search for holes between the given list of polys, starting the search from the given list of startpoints. Returns a line going "through" the hole as a list of points, or None if no hole is found. startpoints may contain 3D vectors and/or Quake entities.

 Read-only variables of the module quarkx

Armin Rigo - 05 Aug 2020   [ Top ] 
error The exception type raised by all routines of QuArK when something goes wrong. The full name of the exception is quarkx.error.
aborted Another exception, raised when there is not really an error but rather the operation must be aborted for some reason. This exception is not displayed in the console with a traceback; it is a “ silent ” exception.
version Version of the executable (QUARK.EXE).
exepath Complete directory to QUARK.EXE, with a trailing backslash.
toolboxmenu The Toolboxes menu item, to put in menu bars.
helpmenu The ‘?’ menu item. It is automatically added to menu bars.
clickform The Window object in which the last menu or button click occurred.
window_type
toolbar_type
imagelist_type
image1_type
panel_type
object_type
explorer_type
dataform_type
floating_type
mapview_type
imagectrl_type
btnpanel_type
vector_type
quaternion_type
matrix_type
canvas_type
process_type
Types of all the built-in Python object types.

 Read-write variables of the module quarkx

Armin Rigo - 05 Apr 2018   [ Top ] 
editshortcuts List of strings describing keys and shortcuts that are normally assigned to edit boxes. When the cursor is in an edit box, all the keys listed here are sent to the edit box instead of being used as a menu shortcut (this is particularly important for clipboard keys Ctrl-X, Ctrl-V,...)
setupchanged Set by Python code to a function called whenever the configuration (from the Configuration dialog box) is changed. The function takes one parameter, which you can ignore for now.
redlinesicons A tuple of 6 icons to use with the map editor red lines (top, topfocus, topmouse, bottom, bottomfocus, bottommouse).
buildmodes A list of strings describing the available build modes for the big "GO!" button.

 Internal QuArK objects

Armin Rigo - 05 Apr 2018   [ Top ] 

Internal Objects are all the objects that QuArK works with, stores in files, and displays in tree views. Each Internal object has a name, which usually contains an extension like files. The extension is called the type of the object, and the part of the name before the extension is the shortname. Internal File Objects are the Internal Objects that correspond directly to a file, e.g. BSP or QRK files. Such objects have the file extension as type, e.g. " .bsp " or " .qrk ". Non-File Objects are internals to a file, and cannot be stored into their own file. For example, polyhedrons and entities are Non-File. Such objects have a type that starts with " : " instead of " . ", e.g. " :p " for polyhedrons.

Besides this, all Internal Objects have a list of Specifics/Arg, much like Quake entities, as well as sub-items, as displayed in tree views. See 'QObjects' for more information.


 Attributes common to all Internal objects

Armin Rigo - 01 Aug 2020   [ Top ] 
classes Tuple of all class names implemented into this object. For example, .bmp file objects returns ("Object", "FileObject", "Image", "Bmp").
dictitems A dictionary of all subitems with the format name:item. Modifying this dictionary has no effect on the actual subitems of the object.
dictspec A read-only dictionary with all Specific/Arg pairs.
Note: known to cause memory leaks in older versions of QuArK, see: 'Using dicts'.
flags OF_XXX flags. See qutils.py.
itemcount Number of subitems.
name Full name. Read-only.
parent Object owning this object as subitem, or None.
selected Is the object selected by the user?
shortname Short name. Read-write. (writing to shortname was buggy in QuArK 5.0.c2 and 5.0.c3)
subitems List of subitems. Read-only.
type Type (extension).
treeparent Like parent but is None if the parent is outside the scope of the tree view that displays the object, i.e. if the object is a root of its tree view.
subitem(i) Returns the ith subitem.
appenditem(obj) Appends the Internal object obj to the end of the subitems of the current object.
insertitem(i, ob) Inserts ob at position i in the list of subitems.
removeitem(i)
removeitem(obj)
Removes a subitem specified by position or directly.
findname(name) Finds the first subitems with the given name, or None.
findshortname(shortname) Finds the first subitems with the given shortname, or None.
...[spec] Like dictionaries, use this notation to read or set a Specific. The values that can take a Specific are: None if not set, a string (that may be void), or a tuple of floats. To store an integer, either convert it from/to a string, or use the methods getint and setint below. As a special case, when using the " [ ] " notation to write an integer value, setint is called. However, when reading the same value, " [ ] " will return the packed string, not the integer. (QuArK 5.0.c2: you cannot set a Specific to None to delete it. All versions: setting a Specific to an empty string will delete it, although Specifics can exist with an empty Arg.)
getint(spec) Reads the Specific spec and returns it as an integer. The Arg must not be a string describing an integer ("5") but a packed string of zero to four bytes ("\005").
setint(spec, int) Sets the value of the Specific to the packed string that represents the integer int.
togglesel() selected = not selected
copy()
copy(1)
Builds a copy of the object and all its subitems. The new copy has no parent. In the first form of the call, the new copies are initially unselected; in the second form of the call, the selection status is copied as well.
copyalldata(src) Copies all Specifics and sub-items of the object from the ones of source. To make temporary changes on obj, do backup=obj.copy(), make the changes, and when done, call obj.copyalldata(backup).
acceptitem(ob) Returns 1 if and only if the object ob can reasonably be inserted into the list of subitems. For example, it is not reasonable to insert a bitmap in an entity. Although it is possible, you should not try to do so.
nextingroup() Returns the next object in the parent, or  None .
findallsubitems(name, type)
findallsubitems(name, type, browsetype)
Returns a list of all objects that match the given name and type. If name is empty, all names are matched. Objects that can be returned include the object itself, all its subitems, all their own subitems, and so on, unless browsetype is set; in this case, only items whose type match browsetype are recursively looked into.
loadtext(fulltxt) Loads a textual representation of the object from the string fulltxt, whose format should be the same as in full-text .QRK files. All Specifics and sub-items loaded are added to the object.
geticon()
geticon(selected)
Returns the icon used in tree views for this object. If selected is True, returns the selected version of the icon; otherwise, returns the unselected one. selected defaults to the current value of the object's attribute selected.

Note that Internal Objects implement none of the operations like +,*,not, etc. Trying to use them, or even using an Internal Object in a boolean operation, will likely raise an Access Violation error. To test if a function returned an actual object or  None , don’t write if obj:... but write if obj is not None:...


 Attributes common to Internal File objects

Armin rigo - 01 Aug 2020   [ Top ] 

All Internal File Objects have the following additional attributes.

filename Name of the file, if this object has been loaded directly from a file or if it will be stored in a file. Should include the full path.
tempfilename Name of a temporary file where this data can be saved (for Auto-Save). The file name is based on the pointer address of the object: multiple reads of  tempfilename  will return the same value, and different objects will never have the same  tempfilename .
savefile()
savefile(path)
savefile(path,astext)
Saves the file. If no argument is given,  filename  must be set before. If  path  is specified, saves a copy of the file into  path  (which should be a full path and file name). If  astext  is specified, it overrides the current file format and specifies whether the file must be saved in full-text or binary format.
conversion()
conversion(type)
Conversion between different object types. Mostly used for conversions between textures and images. With no argument, returns a list of all types this object can be converted to, including the current type (each one is a string giving the extension of the corresponding files with the dot); with a type argument, it attempts to convert the object to the given type.

Subclasses of Internal File Objects don’t have more attributes. Most information is stored as Specifics-Args pairs and in subitems. Three exceptions:

  1. .BSP file objects have a few attributes required to load them in the map editor. See  mapeditor.py  for more information.
  2. .PAK and .PAKFOLDER file objects have a method  extract , which extracts all files and subfolders into the directory given as parameter, which is created if required, as well as a method  getfolder  that creates a given path inside the .PAK file and returns the resulting .PAKFOLDER object.
  3. Textures have an attribute  disktexture  that loads and returns an actual texture object if the first texture were just a link.

 Attributes common to Internal objects of class "3DObject"

Armin Rigo - 01 Aug 2020   [ Top ] 

Here are the additional attributes of Internal objects with "3DObject" in their class tuple. The Internal 3D Objects are the ones that have some kind of 3D position or shape. All objects present in the map editor’s tree view are Internal 3D Objects. This includes groups because you can move and resize whole groups.

origin The origin point for the object, as a read-only 3D Vector.
translate(v)
translate(v, grid)
Translates (moves) the object by adding the vector  v . If  grid  is set and is not zero, the origin of all objects is then forced to this grid. Note that the vector  v  does not have to be on the grid. To move an object by a distance which is a multiple of the grid step, first round  v  to the grid and then call  translate  with no  grid  argument.
forcetogrid(grid) Forces the object to the grid. If the object is a group, all objects in this group are individually forced to the grid.
linear(v, m) Applies the linear operation given by the matrix  m  by using the point  v  as center (fixed). See  qeditor.py  for functions that build matrices for common operations such as rotations.
inflate(z) Inflates the polyhedron(s) by  z  pixels.  z  can be negative. When applied to a single face, the face is simply scrolled by  z  pixels perpendicularly to its plane.

 Attributes common to Internal objects of class "TreeMap"

Armin Rigo - 01 Aug 2020   [ Top ] 

Here are the additional attributes of Internal objects with "TreeMap" in their class tuple. All objects present in the map editor’s tree view are TreeMap objects, and no other one.

replacetex(tx1, tx2)
replacetex(tx1, tx2, undomode)
Replaces all textures named tx1 with the texture tx2. If tx1 is empty, all textures are replaced. If undomode is specified and is True, this function does not change the textures in the polyhedron faces themselves, but creates a copy of each modified face and put it into the active undo operation list (see below). Returns the number of modified textures.
rebuildall() Forces all polyhedrons to build themselves from their face objects. This is required in some circumstances, for example to know whether a polyhedron would be valid with a given set of planes as faces. Note that polyhedrons that are already built are not rebuilt (the name of the function is not well chosen). Returns a tuple (p,f) where p is the number of invalid polyhedrons and f is the number of unused faces (as shown by the " broken " versions of the polyhedron and face icons).

 Attributes of Internal objects of class "Polyhedron"

Armin Rigo - 05 Apr 2018   [ Top ] 

Note: the class name "Polyhedron" is new in 5.0.c3. In version 5.0.c2, the name was in french, "Polyedre".

error A string describing the error, if the polyhedron is invalid (e.g. no interior).
faces A list of all faces really used by the polyhedron. This can include faces outside the polyhedron (see the section about faces below). The list is empty if the polyhedron is invalid.
vertices List of vertices (3D points). The list is empty if the polyhedron is invalid.
subtractfrom(list) Subtracts the polyhedron from all polyhedrons in the given list. Returns a list with the resulting polyhedrons. Polyhedrons that don’t intersect the subtracting one are returned unchanged; other polyhedrons are replaced by zero or more pieces. New pieces are not attached to any parent, but it is invalid to read their parent attribute, which may return a wrong non-None value.
pieceof Right after a subtraction, new pieces have this attribute set to the polyhedron they are a piece of. This is reset to None as soon as the piece is inserted into a group. Note that this attribute does not count for a reference, so it could become invalid if the original polyhedron is freed too early. A way to avoid that is to keep the original list of polyhedrons given to subtractfrom in a local variable until all pieceof attributes have been checked. If you give in the list of subtractfrom a polyhedron whose pieceof attribute is not None, and if the polyhedron is itself broken into pieces, the value of pieceof will be set as the new pieces’ pieceof, too. This lets you call subtractfrom several times with various subtracters and check the pieceof attributes only once.
broken True or False depending on whether the polyhedron is broken or not.
intersects(poly)
intersects(face)
intersects(poly, face)
True or False depending on whether the polyhedron intersects or not the given polyhedron poly or the given face. If two arguments are given, face must be a face of poly and the intersection with this face of the polyhedron only is computed.
changedfaces() Makes the Delphi code add + sign to poly in the tree-view without going through undo code.

 Attributes of Internal objects of class "Face"

Armin Rigo - 05 Apr 2018   [ Top ] 

These objects are polyhedron faces. They are often found within Polyhedron objects, but use the polyhedron’s  faces  attribute instead of its  subitem  method to find them, because:

  1. Polyhedrons don’t always use all their faces
  2. Faces may lie outside polyhedrons, in which case they could be part of all polyhedrons within the group
  3. In some cases, faces may be used in other contexts, e.g. as BSP faces.

faceof List of all objects that this is a face of. Usually contains a single polyhedron. This list is never empty: if the face is not used at all,  faceof  will contain the face itself.
vertices Vertices for each object that this is a face of. This is a list of lists of points. It is not simply a list of points! (You should generally use  verticesof  instead of  vertices )
normal
dist
Plane containing the face, defined by a  normal  vector and its  dist ance to origin. The plane contains all points  p  for which we have  p*normal==dist . These attributes are read-only; to move the plane, either use the  translate  method common to all "3DObject", or set the face’s " v " Specific, or call  distortion  below.
texturename The name of the texture.
verticesof(obj) List of vertices of this face, as used by the object  obj , which must be in the  faceof  list.
threepoints(tex)
threepoints(2,texsrc)
Returns the three points defining the plane that contains the face.  tex  can be  0 ,  1  or  2 . If  tex  is  0 , the points  p1,p2,p3  are set so that the cross product  (p2-p1)^(p3-p1)  points towards the outside of the polyhedron. If  tex  is  1  or  3 ,  p2  and  p3  may be exchanged to reflect the texture mapping, i.e.  p1  maps to texture coordinates (0,0),  p2  maps to texture coordinates (128,0), and  p3  maps to (0,128). If  tex  is  2 , the points are moved to reflect the real texture size (if it can be loaded; otherwise a 64x64 texture is assumed) and so that they lie near the center of the face.  texsrc  tells where to load the texture from (see  quarkx.loadtexture ).
setthreepoints((p1,p2,p3), tex)
setthreepoints((p1,p2,p3), 2, texsrc)
Sets the three points defining the plane that contains the face. The position of the points also determines how the texture is mapped on the face. The second argument  tex  and the optional third argument  texsrc  are the same as for the method  threepoints  above.
 setthreepoints  must not be called with  tex>=2  to change the plane containing the face, but only to move the texture on the face. This is the difference between  tex==1  and  tex==3 .
axisbase() returns normalized vectors in the plane paralell to the face, the first one horizontal (makes nice coordinate system for positioning textures, etc.)
distortion(newnormal, fixpt) Distort the face (actually it just rotates it) so that  normal  becomes  newnormal . The rotation is done around the fixed point  fixpt .
broken  True  or  False  depending on whether the face is broken or not.
swapsides() Exchanges the inner and outer sides of the face ( normal = -normal ).
extrudeprism(obj) Returns a list of faces that make an infinite prism over the given face.  obj  has the same meaning as in the  verticesof  method.

 Attributes of Internal objects of class "Duplicator"

Armin Rigo - 01 Aug 2020   [ Top ] 

Here is the additional attribute of Internal objects with " Duplicator " in their class tuple.

images List of all images built by the Duplicator.

 Attributes of Internal objects of class "TreeMapBrush"

Armin Rigo - 01 Aug 2020   [ Top ] 

TreeMapBrush objects are all Quake's "Brush entities", that is, all entities with associated brushes. The top-level object worldspawn is a TreeMapBrush, and so are all doors, plats, etc. These objects have three additional read-only attributes.

listpolyhedrons List of all polyhedrons within this brush entity. Operations of Diggers, negative polyhedrons, and Duplicators are computed, so the returned polyhedrons are not necessarily all found in the map tree. Polyhedrons from sub-brush-entities are not included, that is, if you apply listpolyhedrons to worldspawn, you will not get the polyhedrons from doors, plats, etc. listpolyhedron does exactly the same work as QuArK does when it should write the .MAP file section corresponding to a brush entity. This function returns polyhedrons with wrong texture positioning in the case of Quake 2 rotating objects; use Q2offset below.
listentities List of all entities and brush entities within this brush entity, including the ones created by Duplicators, if any, and including the given brush entity itself.
listbeziers List of all bezier patches within this brush entity, including the ones created by Duplicators, if any.
Q2offset Relevant only in Quake 2 mode, and if the given entity is not worldspawn. Returns the texture offset computed from the "origin" brush in the entity, as with rotating doors. (Not implemented yet, ask me if you need this)

 Attributes of Internal objects of class "Bezier"

Armin Rigo - 05 Apr 2018   [ Top ] 

These objects are Bezier patches (for Quake 3). They can actually represent any "quilt" of  m  times  n  joined quadratic Bezier patches, where  m  or  n  can be zero (for Bezier lines).

For more information about Bezier patches see 'Bezier.pas'.

cp This read/write attribute lists all control points of the Bezier face. It is a tuple of tuples of 5D vectors, making a rectangular array of control points. Both dimensions of the rectangle are odd numbers. When writing to this attribute, the following rules apply: the tuples can be replaced by lists, and the vectors can be 3D only (in which case the old texture coordinates are not modified).
texturename The name of the texture.

 Macros expected by QuArK in the module qmacro.py

Armin Rigo - 05 Apr 2018   [ Top ] 
MACRO_displaymap(self) Called by QuArK when there is a map to display. self is the map as an Internal File Object. This is not the root of the map (“ worldspawn ”). See mapeditor.py for more information.
MACRO_displaybsp(self) Called by QuArK when there is a BSP file to display. self is an Internal File Object. This is not the root of the map (“ worldspawn ”). See qmacro.py for more information.
MACRO_displaymdl(self) Called by QuArK when there is a Model to display. self is an Internal File Object. This is not the root of the Model.
MACRO_duplicator(dup) Called by QuArK to build the images of the Duplicator dup. Must return a list of new map objects. See qduplicator.py for more information.
MACRO_applylinear(entity, matrix) Called whenever a linear operation is applied on an entity or a Duplicator. This lets Python code change Specifics accordingly. For example, upon rotation, the angle Specific of entities should be modified so that the entity appears to rotate.
MACRO_hint(form)
MACRO_hint(form, text)
Called to set or retrive the current help text.
MACRO_buildmaps(maps, mode, extracted [,cfgfile[,defaultbsp]]) Called to build maps and run Quake. maps is a list of Internal File Objects, each as the parameter self of MACRO_displaymap. mode is an integer describing the type of build required, as an index in the list quarkx.buildmodes. extracted is the list of all files already extracted: maps that would produce .BSP files with the corresponding names need not be rebuilt. cfg is the content of the configuration file to produce. The last parameter defaultbsp is the name of the first bsp found, if before a map. The last two parameters may be omitted.
MACRO_helpmenu(text) Called when the user selects an item in the '?' menu. text is the string describing this item.
externaledit(obj) A special quarkx function call allowing any (obj) object, such as text or a texture image, to be passed to it causing that object to be opened in an external editor, and would be used like this:
    obj = quarkx.newfileobj("temp.txt")
    obj['Data'] = editor.Root.currentcomponent.dictspec['mesh_shader']
    quarkx.externaledit(obj)
This can be used in conjunction with a form button of Typ "P" which uses its Macro = "the macro name" to call the def macro_the macro name(btn) that contains the quarkx.externaledit(obj) function call. This def of the macro is then registered with the quarkpy\qmacro.py file attaching itself to the other macros in that file, that code looks like this:
quarkpy.qmacro.MACRO_opentexteditor = macro_opentexteditor
For the complete code of the above examples see the plugins\ie_md5_import.py file.

 3D Vector objects

Armin Rigo - 01 Aug 2020   [ Top ] 

3D Vector Objects are created with the function  quarkx.vect . Vectors are immutable in the Python sense. Vector Objects usually represent 3D points or 3D vectors, but in some cases they are projections on a map view. See the second table below for the additional attributes that apply to projected vectors only. All vectors have a few attributes you can read, and you can use the arithmetic operations described below:

v+w
v-w
-v
Sum, difference, negation of vectors
v*float
float*v
v/float
Multiplication or division of a vector by a float
v*w Dot product
v^w Cross product
abs(v) Norm (length) of a vector
boolean value A vector is considered  False  if it is zero or almost zero, to accommodate for small computation errors.
str(v) String representation.  quarkx.vect(string)  is the inverse operation.
v.copy A copy of the vector (note: no " () "). Probably not useful, as vectors are immutable anyway.
v.normalized A normalized copy of length 1 of the vector.
v.tuple A tuple  (x,y,z)  with the vector coordinates.
v.x
v.y
v.z
The individual coordinates.

Note: do not compare two vectors with " v=w "! Instead, make their difference and check if the result is  True  or  False  with a boolean operation.

About projected vectors: their  x  and  y  coordinates are pixels in the window, and the  z  coordinate represents the depth. Depending on the projection type, flat or perspective, the  z  coordinate has various meanings. You cannot tell which point is nearer by comparing their  z  values; instead, use the compare operators on the vectors themselves:

v<w
v=w
v>w
Compares the depth of vectors.  v<w  if  v  is nearer than  w .
v.visible  1  or  0  depending on whether the original 3D point was in a visible screen region or not. It is  0  if, projected from a perspective view, the point was behind the camera. In this case, don’t use the values  v.x  and  v.y  to draw something! You would draw it somewhere in the middle of the window, where there is actually nothing.  v.visible  is  -1  if v is not a projected point.
v.offscreen  0  if the point is really on-screen, and neither too far or too near.  offscreen  is actually a combination of flags that tell whether the point is too much to the left, too far, and so on.

The control points of Bezier patches use an extension of the 3D vectors: 5D vectors. These vectors have two additional coordinates, representing the texture coordinates. 5D vectors have the same Python type as 3D vectors, and all operations you can do with 3D vectors can be done with 5D vectors too; here is the new stuff:

v+w
v-w
v*float
float*v
v/float
These operations apply on all 5 coordinates. Note that adding or subtracting a 3D and a 5D vector together will produce a 5D vector as expected.
v.tex_s
v.tex_t
The two additional coordinates of 5D vectors.
v.tex The tuple  (v.tex_s, v.tex_t) .

 Quaternion objects

DanielPharos - 05 Aug 2020   [ Top ] 

Quaternions are four values that together represent a rotation in 3D space and a scaling. Use quarkx.quaternion to create quaternion. They are not immutable objects, because you can change values in individual cases, but in general they should be considered as immutable.

q1+q2
q1-q2
-q
Sum, difference, or negation of quaternions
q1*q2 Quaternion product
q*v Product of a quaternion and a vector
float*q
q*float
q/float
Product of a quaternion and a float, or division of a quaternion by a float
q1/q2 Product of q1 and the inverse of q2
float/q Product of a float and the inverse of q
~q Inverted quaternion (1/q)
abs(q) Norm of a quaternion
boolean value False if zero or almost zero
m[i] The value (i) of the quaternion, where i isin the range 1 to 4.
str(q) String representation. quarkx.quaternion(string) is the inverse operation.
q.copy A copy of the quaternion (note: no " () ")
q.normalized A normalized copy of norm 1 of the quaternion.
q.tuple A tuple of the four values.

 Matrix objects

Armin Rigo - 05 Apr 2018   [ Top ] 

3x3 matrices are used to represent linear mappings. Use quarkx.matrix to create matrices. They are not immutable objects, because you can change values in individual cases, but in general they should be considered as immutable.

m+n
m-n
-m
Sum, difference, or negation of matrices
m*n Matrix product
m*v Product of a matrix and a vector
float*m
m*float
m/float
Product of a matrix and a float, or division of a matrix by a float
m/n Product of m and the inverse of n
float/m Product of a float and the inverse of n
~m Inverted matrix (1/m)
abs(m) Det of a matrix
boolean value False if zero or almost zero
m[i,j] The value (i,j) of the matrix, where i and j are in the range 1 to 3.
str(m) String representation. quarkx.matrix(string) is the inverse operation.
m.copy A copy of the matrix (note: no " () ")
m.cols A tuple of three vectors whose value are the three columns of the matrix
m.transposed copy of m, transposed (rows<->columns))
m.tuple A tuple of three tuples of three values each: all nine values, line-by-line

 The undo module

Armin Rigo - 05 Apr 2018   [ Top ] 

As a general rule, you must never directly modify map objects. This would prevent the user from undoing his actions. Instead, when you have changes to make, you must call quarkx.action() which returns a module object where you will find the functions described in the next table. Duplicate the objects you want to change using their copy() method, make changes in the copies, and use the following functions to give the new objects to QuArK’s undo mechanism.

To finalize the undo call and action you must use the undo.ok(base, text) call. The base is the main object such as editor.Root and text is the string text message that will be posted to the editor's Undo / Redo list. One option does exist for this ok call for the text. In rare cases, the ability of the undo module to activate code that other functions do not, such as invlaidateallviews, the undo function can be called as described and finalized with its text argument like this undo.ok(base, "") giving no text within the two double quotes. This will still allow the acceptance of the undo action but will NOT post anything to the editor's Undo / Redo list.

put(parent, new)
put(parent, new, insertbefore)
Operation that puts the new object into the group parent. It is inserted at the end of the subitems list, unless insertbefore is specified. insertbefore must be an existing subitem of parent.
exchange(old, new) Operation that replaces the old object with the new one. If new is None, the old object is simply deleted.
setspec(obj, spec, arg)
setspec(obj, spec, arg, position)
Operation that sets a Specific/Arg pair in the object obj. spec is a string, and arg can be a string, a tuple of floats, or an integer, as the command obj[spec]=arg would do. If position is specified, it controls the position relative to other Specifics.
rename(obj, name) Operation that changes the shortname of an object.
move(obj, target)
move(obj, target, insertbefore)
Operation that moves the object obj into the group target, inserting it before the item insertbefore. Don’t use this to move objects outside the tree view they belong to, or even between roots of this tree view (tree view with multiple roots may be found in toolboxes, for example).
end(root, text) Operations are queued and applied only when you call this function. root is any object belonging to the tree view where changes where made (usually, you will pass the root, hence the name of the parameter). text is a short string describing the action. This string is displayed in the Edit menu as well as in the Undo/Redo window. Once you called end, you cannot continue to use other functions of the module.
cancel() Cancels all operations. You don’t really have to call this if you choose to cancel the action; it simply lets QuArK free associated memory immediately instead of when the next call to quarkx.action is made.

 The progressbar module

Armin Rigo - 05 Apr 2018   [ Top ] 

You create a progress bar by calling quarkx.progressbar(txt,count), which returns a copy of the module described in the following table.

progress() Makes the bar go one step forward. When you called this function count time, the bar is at 100%. If the user clicked on the “ cancel ” button, progress() will raise an exception quarkx.aborted.
close() Closes the progressbar module. This is very important! You should always use try...finally to make sure that close() is called.
count() Returns the value of count given to quarkx.progressbar.
changecount(new) Changes the value of count. Do this only if you really can’t compute the exact value at the beginning, because calling changecount can make the bar jump forward or backward!

 Built-in process objects

Armin Rigo - 05 Apr 2018   [ Top ] 

A process object lets you know the state of a program executed by  quarkx.runprogram . It has the following attributes:

exitcode If the program is still running, exitcode is None; otherwise, it is the program’s exit code (as checked with MS-DOS’ "if errorvalue xx" command).
onexit(proc) Set a callback function that is called when the program terminates, or immediately if the program is already terminated. If several callbacks are set, they will all be called, but in random order. The callbacks take a single argument, the process object itself.

Note that this object might become obsolete in a future version of QuArK. Don’t rely on it. The stdout and stderr mechanism can be used to know when console processes terminate.


 Image List objects

Armin Rigo - 05 Apr 2018   [ Top ] 

Image Lists are built with the function quarkx.loadimages. They are similar to immutable sequences of icons, but only the following operations are defined on them:

len(imagelist) The length (how many images the list contains)
imagelist[i] The ith image, starting at 0

Do not use Image List objects in places where a sequence could normally be used, e.g. in for. Instead of

for icon in imagelist:
  ...
write
for i in range(0, len(imagelist)):
  icon = imagelist[i]
  ...


 Icon objects

Armin Rigo - 05 Apr 2018   [ Top ] 

Icon Objects are the individual items of Image Lists.

icon.size The (x,y) size of the icon. This is the same for all icons of an image list.
icon.disabledimage The disabled (grayed out) version of the icon, returned as another icon.

 Windows (forms)

Armin Rigo - 07 Aug 2021   [ Top ] 

Window Objects (commonly called “ forms ”) are the Python objects with which you can control a window’s aspect. In the current versions, only the map and model editors are Window objects; other windows cannot be accessed from Python. Here are the attributes of Window objects.

begincolor
endcolor
The colors used for the gradient caption. begincolor is the color at the left and endcolor is the color at the right. Please follow the convention that begincolor represents the window type (blue for editors, black for toolboxes,...) and endcolor represents the file type (black for maps,...)
fileobject The Internal File Object displayed in this window
mainpanel The main panel. See below for more information on Panel objects.
windowrect The window position (left,top,right,bottom) in screen coordinates
windowstate Window state: maximized, minimized, or normal. See qutils.py.
info Any data for Python code use
menubar
shortcuts
numshortcuts
The menu bar and the key shortcuts. See Menus below.
focus The control currently focused inside this window, if any. (read-only, ask me if you need it to be writeable)
macro(cmd) Fires a macro command. Returns False if the macro failed or True otherwise. See the file TECHINFO.TXT in the tech info package for a list of macros. Note that macros are more or less obsolete now that QuArK supports Python.
newtoolbar(caption, buttons, canclose) Makes a new floating tool bar. See below for more information on Toolbar objects. All parameters are optional; caption defaults to "tool bar" and canclose defaults to False. If canclose is True, when the toolbar is not docked (padded along a border of the window), it has a close box that hides it. The user should have a way to make the toolbar reappear, for example from the menus.
toolbars() Returns a list of all toolbars in this window.
allbuttons() Returns a list of all buttons used in this window, either on toolbars or on button panels.
newfloating(flags, caption) Makes a new floating window attached to this window. See below for more information. Parameters are optional: flags default to 0 and caption defaults to "". See qutils.FWF_XXX for flags values.
floatings() Returns a list of floating windows attached to this window.
openfullscreen(root, caption) Opens a new fullscreen window, with  root  the object to display and  caption  is the window caption.
choosecolor(color) Displays a color picking dialog box. color is the default color. Returns the chosen color or None if the user cancelled the dialog box.

 Introduction to screen controls and panels

Armin Rigo - 01 Aug 2020   [ Top ] 

Screen controls are the various units of a window design with which users interact. All screen controls - - map views, tree views, image displayers, data-entry forms, floating windows, etc. - - are distinct built-in object types, but they share common attributes. Note that toolbars are not screen controls in QuArK 5.0.c2, so they don’t have all these attributes, but this may change in a future version.

Controls are not positioned on screen by setting coordinates. They are put into panels, which are screen controls themselves. Panels are dummy gray rectangles that can contains other screen controls and that know how to set their position. Usually, panels are nested, starting from the main panel, which covers the whole window except its border, its caption, and its menu bar. For example, in the map editor’s Classical layout, the main panel contains three controls: the two map view and a left-aligned panel, which in turn contains other panels, and so on.

Panels are the only kind of screen controls that can contain other screen controls. Each panel knows how to align its own controls. There are two kinds of alignments a panel can perform: " full-size sections " and " padded to a border ". Within a panel, only subpanels can be padded to a border; other controls are always full-sized.

A panel can be divided into sections, i.e. rows and columns, like a table. By default, there is only one row and one column, taking up the whole panel size. For each subcontrols, you choose in which section it goes, and it takes the whole size of the section. Row and column size is given with a percentage of the total width or height. This keeps the same proportions when the window is resized. The user can manually resize the sections.

Panels can also contain border-padded subpanels. These subpanels are aligned so that they go along the whole left, top, right or bottom border. For left- and right-padded subpanels, you choose only the panel width, in pixels; for top- and bottom-padded subpanels, you choose only the panel height. The user can also resize these panels. The sizes are given in pixels and don’t change when the window is resized. Border-padded subpanels shrink the screen space allocated to sections.


 Attributes common to all screen controls

Armin Rigo - 01 Aug 2020   [ Top ] 
owner The Window that owns this control (read-only)
parent The Panel that owns this control, or None for the main panel (read-only)
visible To show or hide the control
section If the parent Panel has several sections, this is the section for this control. Format: (column, row) where column and row range between 0 included and the total number of columns (resp. rows) of the parent Panel, excluded.
clientarea The (x,y) size of the control (read-only). If the control has a border around it, it is excluded from this size.
hint A string that pops up when the user leaves the mouse over the control
info Reserved for Python code use
type String describing the control type. (read-only)
close() Closes (destroys) the control. You cannot use it any longer once it has been closed, much like you cannot use Python files any longer once you called their close() method.
show() visible = 1
hide() visible = 0
invalidate() invalidate(rebuild) Forces a control to display itself again. For map views in textured mode, this also forces a rebuild of the scene if rebuild is present and not egual to 0. (note that this default behavior is new from QuArK 5.9.) The control is not repainted immediately.
invalidaterect
(ULx, ULy, LRx, LRy)
Forces a control (view area) to display (redraw) itself again within the given max. and min. rectangle area positions
(upper left x , upper left y , lower right x , lower right y).
repaint() Repaint the control immediately.
update() Immediately repaint the regions of the control that needs to be, if any.
popupmenu(list) popupmenu(list,dblclk) popupmenu(list,x, y) Displays a pop-up menu with the items of the list. If x,y are specified, they give the position of the pop-up menu within the screen control. The default position is at the current mouse location. If only a second argument dblclk is specified, and is non-zero, the menu is not displayed, and its default item (if any) is clicked instead.
ondrop Callback function. Called when the user drops objects on the screen control, with 5 arguments: the screen control itself, a list of objects dropped (which you should copy, not use directly), the x,y coordinates of the drop, and the source control or button. Note that the ondrop of Tree Views differs from this one. Also note that, when dropping objects onto a button, QuArK will call that button's ondrop callback instead if it has one.

 Additional attributes of Panel controls

Armin Rigo - 05 Apr 2018   [ Top ] 
sections The sections: (columns, rows) where rows and columns are two tuples of floats giving the position of the separation between adjacent rows (resp. columns). For example, (0.1,0.8) means three columns, the first one between 0% and 10% of the width, the second one between 10% and 80% of the width, and the third one between 80% and 100% of the width. Be careful about tuples with a single value: when there are exactly two columns or two rows, don’t write (0.6) because Python interprets this as a float; instead, write (0.6,). The default value for one row and one column is ((),()). Use negative floats to prevent the user from resizing himself the sections.
size The width or the height of the panel, in pixels, if it is border-padded.
align A string giving the padding mode: "left", "right", "top", "bottom", or "full" if not border-padded. You can switch between the four first modes by changing this attribute.
controls() Returns a list of the controls within this panel.
newleftpanel(size)
newleftpanel(size,resizable)
Makes and returns a new left-padded panel with width size. resizable defaults to True; if it is False, the user cannot resize the panel himself.
newrightpanel(..)
newtoppanel(..)
newbottompanel(..)
See newleftpanel(..).
newfullpanel() Returns a new subpanel that is not border-padded.
newexplorer() Returns a new Explorer control (a tree view).
newdataform() Returns a new Data Form control.
newmapview() Returns a new Map View control.
newimagectrl()
newimagectrl(icon)
Returns a new Image Displayer control. If specified, icon is the initial value of the image attribute.
newbtnpanel()
newbtnpanel(btns)
Returns a new Button Panel control. If specified, btns is the initial value of the buttons attribute.

 Menu bars, pop-up menus and keyboard shortcuts

Armin Rigo - 01 Aug 2020   [ Top ] 

Menus are not yet another type of built-in objects. Instead, they are completely defined with classic Python objects, and QuArK reads these objects’ attributes when it needs them to build the menu.

A menu bar or a pop-up menu is a list of one Python class instance for each item. The items need not really be class instances, but QuArK expects them to have a few attributes, and instances of classes are, with modules, the only kind of object you can give the attributes you want.  qmenu.py  defines two classes, one for normal menu items and one for menu items that open pop-up menus. I recommend to always use instances of these classes to populate your menus. Please refer to  qmenu.py  for more information about the expected attributes.

You set a Window’s menu bar by storing a list of instances of  qmenu.popup  into its menubar attribute. You can also assign keyboard shortcuts to menu items; however, this is not done by setting an attribute (e.g. shortcut) to the instances of the class  qmenu.item . All shortcuts for a Window must be grouped in a dictionary that must be assigned to the Window’s shortcuts attribute. The dictionary should contain pairs "shortcutkey":menuitem, where "shortcutkey" is a string describing the key (e.g. "Ctrl+X") and menuitem is the item whose onclick attribute should be called. Although not required, I recommend that this menuitem appear somewhere in the menu bar, too. If it is the case, QuArK adds the shortcut key string to the right of the item in the menu. New in QuArK 5.5: a shortcut can be a number (a "virtual key code") as obtained in the configuration dialog box (page Map, Keys). These shortcuts must be put in the attribute numshortcuts.


 Callback functions in Python and Warning about circular references

Armin Rigo - 01 Aug 2020   [ Top ] 

At a lot of places, QuArK expects to find a callable Python object. For example, each menu item must have an attribute onclick that, if not  None , will be called by QuArK. The arguments that the function should accept varies from case to case; for example, the menu item’s onclick is called with a single argument, which is the menu item itself. The call is made by simulating the Python command apply(onclick, args). This means that onclick doesn’t need to be a function; it can be anything that is valid to call with the arguments args. In the current Python code, it is often a method instead of a function: if you give onclick the value someobject.mymethod, that method will be called with one additional argument (often called self) before the normal ones given by QuArK: the object someobject itself.

This is pretty useful in all cases where the arguments given by QuArK are not enough to really know what occurred. Typically, onclick will point to a method of the MapEditor object, so that we immediately know in which MapEditor instance we are. However, be careful about circular references: this technique makes a reference from the menu item’s onclick member to the given MapEditor instance, which in turn is likely to somehow reference the menu item through a pointer to the whole menu. In this kind of situation, neither the MapEditor instance nor the menu item will ever be freed from memory. This situation is allowed if you take care of breaking them: that’s why, when the MapEditor window is closed, a lot of its attributes are reset to  None . This would free the menu, which in turn would let the MapEditor be freed.


 Floating toolbars, Toolbar panels, and Buttons

Armin Rigo - 01 Aug 2020   [ Top ] 

Floating Toolbars correspond to a built-in type. You create toolbars with the method newtoolbar of Window objects. The user can move Floating toolbars and either dock them (put them along the border of the window) or make them float (appear as a small stand-alone window). Note that Toolbars are not screen controls, as mentionned above. Here are all their attributes.

buttons List of the buttons displayed on the toolbar. See below.
caption Caption displayed above the buttons when the toolbar is not docked.
dock Current dock position: "topdock", "leftdock", "rightdock", "bottomdock", or None. (Note: because of bug in QuArK 5.0.c2, you cannot set dock to None; instead, set it to "floating".)
dockpos
dockrow
Position and row within the dock. (If they are several toolbars on the same dock, they can be organized in several rows.)
floatrect Position of the toolbar when it is floating. (left,top,right,bottom). Changes to floatrect have no effect until the next dock=None.
visible Is the toolbar visible?
update() Refresh the toolbar buttons. (Was equivalent to buttons=buttons in previous versions, but now the recreation of buttons is not done immediately because it was causing some serious troubles). Required in some cases because QuArK doesn’t know, if you modify a single button, that it must update the displayed buttons. See also quarkx.update().
close() Closes (destroys) the control. You cannot use it any longer once it has been closed, much like you cannot use Python files any longer once you called their close() method.
show() visible = 1
hide() visible = 0
ondrop Same as ondrop for screen controls. (not implemented in 5.0.c4)

Individual buttons are, like menu items, not built-in types, but rather instances of a standard Python class. See  qtoolbar.py  for more information.

Besides Floating Toolbars, buttons can also be displayed on fixed panels. Such panels are called Button Panels, and are created with a panel’s newbtnpanel() method. They are screen controls, with a few additional attributes:

buttons List of the buttons displayed on the panel.
margins Extra space between buttons, (x,y). Default (2,2).
update() See the method update() of Floating toolbars.

Button panels have additional formatting capabilities: by inserting special values in the list of buttons, you can create gaps between buttons, pad buttons to the right, or force a new button row to begin. See  qtoolbar.py .


 Additional attributes of Floating Windows controls

Armin Rigo - 01 Aug 2020   [ Top ] 

Floating windows are created by a window’s newfloating() method. They are screen controls, and as all screen controls are, they are attached to their owner window. Unlike other screen controls, however, they can float anywhere on the screen and are never automatically aligned by a parent panel. In fact, their parent attribute is always None.

caption Window caption.
begincolor
endcolor
The colors used for the gradient caption. See the begincolor and endcolor attributes of Window Objects for more info.
mainpanel The main panel. (read-only)
rect The same as clientarea, that is, the (x,y) size of the window without its border. The difference is that rect is not read-only.
windowrect The position and size of the whole window, in screen coordinates. (left,top,right,bottom)
onmove Callback function. Called when the window is moved or resized. Takes one parameter: the window itself.
onclose Callback function. Called when the window is closed. Takes one parameter: the window itself. This is not called if the window is only hidden.
close() Closes the window.

 Additional attributes of Tree view controls (Explorers)

Armin Rigo - 01 Aug 2020   [ Top ] 

Tree views are created by a panel’s newexplorer() method. They are screen controls that display a hierarchical view of Internal QuArK Objects. Any number of objects in a tree view can be selected (they appear in blue), but only one can have the focus (a rectangle of dots around it). Note that if the object with the focus is in a closed group, the group itself will be displayed with the rectangle of dots, but the focus stays on the correct object. Objects are not considered selected themselves if they are into a group that is already selected; in this case, they are displayed with a blue border instead of a blue background.

focus This is the object that has the focus. (read-write)
focussel This is the same as focus, but only if this object is selected. An object can have the focus without being selected. In this case, focussel is None. (read-only)
sellist List of selected objects. (read-write)
uniquesel The unique selected object, if exactly one is selected. Setting uniquesel to an object will unselect all the other objects. Setting uniquesel to None will unselect everything.
flags Flags. See qeditor.EF_XXX
onselchange Callback function. Called whenever the list of selected items changes. Single argument: the tree view object itself.
onrootchange Callback function. Called as onrootchange(treeview, old, new) when a root (top-level) object changes, in response to direct actions or undo or redo. old is the old root, and new is the root that replaces it. We can have old==new if, for example, only the name changed.
onmenu A menu (list of menu items) or a callback function. This is the pop-up menu to display when the user right-click on an object. If set to a callback function (which is recommended), it is called with the tree view as single argument, and should examine the tree view’s sellist to return a menu corresponding to the currently selected objects.
ondrop Callback function. Called as ondrop(treeview, newlist, text) to drop the objects given in the list newlist into the tree view. text is the description of the action, as displayed in the Undo/Redo box. If the items cannot be dropped, the function should return 0 (which makes QuArK beep); otherwise, it should return 1.
oninsert Callback function. Called when the user drops objects on the tree view with the mouse to prepare the new objects for the drop. Called with two arguments: the tree view and the list of new objects. The callback function can modify the list if it wishes. It can return 0 to cancel the operation.
clear() Clears the tree view contents.
addroot(obj) Adds a root to the tree view contents. Tree views may have multiple roots, like in the New Items toolbox.
selchanged() Informs the tree view that some of its items where selected or unselected. This is only required if you change the selection state of the objects with their own attributes, e.g. selected or togglesel(). In response to selchanged(), the tree view will repaint itself and call onselchange.
expand(obj) expand(obj,0) Expands (resp. collapses) the group object obj.

 Additional attributes of Data form controls

Armin Rigo - 01 Aug 2020   [ Top ] 

Data Forms are created by a panel’s  newdataform()  method. They are screen controls that display a list of object parameters, like on the Specific/Args page, or like all pages of the Configuration dialog box.

setdata(objs)
setdata(objs, formobj)
Select the object(s) whose Specifics/Args are to be displayed in the data form.  objs  can be either a single “ objspec ” or a list of “ objspecs ”. An “ objspec ” is either a single object or a tuple of two objects: the actual object and another one with default values. If a Specific is not found in the object, the data form displays the one from its default value. The optional argument  formobj  gives a  :form  Internal object to use.
allowedit Allow editing of the Specific themselves, or only the Args?
addremaining If the object has more Specifics than given in the  formobj , should they be also displayed?
actionchanging
actiondeleting
actionrenaming
Texts for the actions of editing or deleting Specifics/Args, or renaming the object, resp. Note: in QuArK 5.0.c2, these are not strings, but numbers for the dictionary  qdictionnary.Strings .
bluehint Should hints be displayed on a blue background, and stay longer than normal hints? (for entities Specifics/Args only)
editnames If this string is not empty, the user can edit the name of the object, which is usually not a Specific from QuArK’s point of view.  editnames  gives the text to display as if it where the Specific, e.g. " classname ".
flags Flags. See  qeditor.DF_XXX 
form The last value given to  formobj  in  setdata . (read-only)
linkedobjects List of the objects given in the last call to  setdata . Does not include the objects giving the default values.
noheader Do not display columns headers? (must be set before a call to  setdata )
nospecifics Do not enable the specifics add/delete menu-options.
sep Separation position between the two columns. Either a percentage (between 0.0 and 1.0) or, if negative, a pixel count for the size of the left column. The user can always resize the columns unless no headers are displayed.
onchange Callback function. Called when data is modified in the form. Single argument: the data form object itself.
bitspec(spec, bitmask) Read the value of a single bit in the object’s Specifics, or in all the object’s Specifics if you gave several objects to  setdata .  spec  is the Specific to read, and  bitmask  is the value of the bit(s) to test. Returns  1  if all the objects have at least one of the bits of  bitmask  set,  0  if none has any of these bits set, or  None  if some objects have one of these bits set and others don’t.
togglebitspec(spec, bitmask)
togglebitspec(spec, bitmask, clearzero)
Simulates a click on a check box that would correspond to the Specific  spec  with the bit value  bitmask . If  clearzero  is  True  (which is the default), and if the resulting Arg value would be zero, the Specific is completely removed.
useraction(n) Simulates a click on the  n th item of the popup menu. The following values are currently valid:  0  to add a Specific, and  1  to delete the selected Specific.

Note: internally, data forms have other routines to read and set values of various types of data, but only the bit-spec ones are exposed to Python code now because I didn’t need the other ones yet. Just ask if you do.


 Additional attributes of Image Displayer controls

Armin Rigo - 01 Aug 2020   [ Top ] 

Image Displayers are created by a panel’s newimagectrl() method. They are screen controls that display an image. Additional drawings can be painted over the image by Python code.

image The image to display. It is an " icon " (although it might be of any size) as found in Image Lists.
color The color to fill the control with. Used if there is no image or if the image is smaller than the control.
canvas() Returns a Canvas object to draw a picture over the image or over the uniform background. See Canvas objects below.
ondraw Callback function. Called with the Image displayer itself as single argument whenever the image need to be repainted. If needed, this function should call canvas() and draw in it.
onclick Callback function. Called as onclick(imagedisplayer, x, y, flags) when a mouse button is clicked. x,y are the coordinates of the click. flags is a combination of qeditor.MB_XXX constants. If the callback returns 1, QuArK will continue to call onclick if the mouse is dragged over the image.

 Canvas objects

Armin Rigo - 05 Apr 2018   [ Top ] 

Canvas Objects let you draw dots and lines from Python code. You obtain a Canvas object by calling a screen control’s canvas() method. Currently, only Image Displayers and Map Views have a canvas() method. You cannot create off-screen bitmaps currently.

Note that the Canvas returned by such an object should be considered as temporary: only use it right after you called canvas(). Don’t store it into something else than a local variable.

brushcolor
brushstyle
Color and style of the brush (to fill the background of drawings). See qeditor.BS_XXX for styles.
pencolor
penwidth
penstyle
Color, width, and style of the pen. See qeditor.PS_XXX for styles. The width is normally set to zero to mean “ as thin as possible ” (although this is generally the same as setting it to 1).
fontcolor
fontname
fontsize
fontbold
fontitalic
fontunderline
transparent
Properties of the font used by textout and textsize.
line(p1,p2)
line(x1,y1,x2,y2)
Draws a line between two points. The first form is preffered for map views if the two points are projections of 3D points. This lets QuArK clip the line if one point is before and the other point is behind the camera. In this situation, line(p1.x,p1.y,p2.x,p2.y) would be incorrect.
rectangle(x1,y1, x2,y2) Draws a filled rectangle and its border. To draw an empty rectangle, set brushstyle to BS_CLEAR. To draw the interior only, set penstyle to PS_CLEAR.
ellipse(x1,y1, x2,y2) Draws a filled ellipse and its border inside the rectangle (x1,y1,x2,y2). To draw an empty ellipse, set brushstyle to BS_CLEAR. To draw the interior only, set penstyle to PS_CLEAR. To draw a circle, set (x1,y1,x2,y2) to a square. (Note: this function will produce incorrect results if called with values of (x1,y1,x2,y2) too large (above 8192) on Windows 95).
polygon(listxy)
polygon(listpt,ccw)
Draws a filled polygon using the points in the list. The list can contain either tuples (x,y) or projected vector objects. The same remark as for line applies. If the list contains projected vectors, ccw (counterclockwise) must be True or False to give the orientation of the points in the list.
setpixel(x,y, color) Gives the color color to the pixel x,y, and returns the previous color of the pixel. (Note: don’t draw complex images with this, it would be horribly slow!)
getpixel(x,y) Reads the color of the pixel x,y. (Note: because of a bug in QuArK 5.0.c2, getpixel expects a third integer parameter, which is ignored. Set it to 0.)
draw(icon,x,y) Draws the icon at the location x,y.
painttexture(tex, rect)
painttexture(tex, rect, gradient)
Fills the specified area with the texture object tex, which must have been loaded by a function like loadtexture. rect is the area to fill (left,top,right,bottom). gradient (default 1) specifies the light gradient direction: the image is brighter at left or right if gradient is positive or negative. There is no gradient if gradient is set to 0.
textout(x,y,text) Writes a string of text.
textsize(text) Returns the (width,height) of the text, in pixels.
reset() Resets the default pen and brush color and styles. Returns the canvas itself.

There are of course other drawing methods that could be implemented, e.g. polylines, arcs, and so on. Ask me if you need them.


 Methods of Map View controls

Armin Rigo - 05 Apr 2018   [ Top ] 

Map Views are the most important type of screen control in QuArK. Each Map View can display 3D objects under various projection types. Objects can be displayed in wireframe, solid, or textured.

setprojmode("3D")
setprojmode("2D", matrix)
setprojmode("2D", matrix, range)
Sets the projection type. In 3D (perspective), display parameters like the field of view are controlled by the current setup (see the attribute setup below). In 2D (flat), you must give the matrix used for projection. In this mode, proj(vect) is the same as matrix*vect, but a little more efficient. There are functions to build standard projection matrices in the module qeditor.py. The matrix must have a positive determinant, or else you will get a quarkx.error with message Invalid floating point operation. If range is specified and is False, the scroll bar range and position is left unchanged (see setrange and screencenter).
proj(vect)
proj(x,y,z)
Projects a point in 3D space onto the map view surface using the current projection attributes. The result is a “ projected vector ”. See above for more informations about projected vectors. Important: you must not use the resulting vector’s x and y attributes to make drawings before you check that the point is really visible (i.e. in front of the camera) by reading the vector’s visible attribute.
space(vect)
space(x,y,z)
Reverse operation. Returns the 3D point that would be projected to the screen coordinates x,y,z.
vector(from) Returns a vector based on the current projection mode: if from is a point in 3D space (as a vector object), this function returns a vector from this point in the direction of the camera. If from is a string, it can be one of: "x": returns a vector in the direction of the screen x axis "y": returns a vector in the direction of the screen y axis "z": returns vector(quarkx.vect(0,0,0)), which is the screen z axis on 2D (non-perspective) views "0": returns the null vector
setdepth(min,max) Sets the minimum and maximum depth that are considered visible. Depending on the drawing mode, the parts of the map that are outside these limits may be grayed out or hidden. The values must be given as projected points’ z coordinates. In perspective mode, these values cannot be changed: the minimum depth is fixed to “ very near the camera ”, and the maximum depth corresponds to the “ far distance ”. setdepth calls invalidate() unless you specify the same values as the ones already set.
drawmap(obj)
drawmap(obj, flags)
drawmap(obj, flags, color)
Draws the object obj and all its sub-objects. How the objects are really drawn depends on the flags, listed in qeditor.DM_XXX. See qeditor.py and mapeditor.py for more information about drawing map parts.
solidimage()
solidimage(texsrc)
In solid and textured modes, the map parts drawn with drawmap are stored in a buffer and the image is only really computed and displayed when solidimage() is called. Call this after you have drawn the solid map parts but before you draw the wireframe ones. texsrc is an optional alternate place to look for textures (e.g. in the opened .BSP file).
canvas() Returns a Canvas in which you can draw. This lets you add lines and pictures over the usual map display. Important: the map view may be configured for black-on-white or white-on-black display. In the first case, pencolor is initialized to black and brushcolor to white; in the second case, these initial colors are inversed. You should never directly set pencolor or brushcolor to black or white, but you should save and reuse their initial colors. If you don’t do this, you would possibly draw lines with the same color as the background. Note: solid and texured modes are always considered white-on-black.
clicktarget(obj, x, y) Finds all objects that belong to obj and that are concerned by a mouse click at coordinates x,y. Only finds objects between the minimum and maximum depths in depth. Returns a list of tuples (projpt, obj, extra), where projpt is the projected point where the mouse clicked, obj is the target object, and extra, if not None, is a second target object (for clicks on polyhedrons, obj is the polyhedrons and extra is the exact face on which we clicked). The list is not sorted; using its sort method will sort it in the order from nearest to farthest, because tuples are first sorted according to their first item, and projected vectors compare according to their distance to the camera.
scrollto(x,y) Sets the scroll bars position to (x,y). If x or y is None, the position of the corresponding scroll bar is not changed.
setrange(x,y)
setrange(x,y, center)
Sets the scroll bars range. center is the 3D point that should be at the center of the full visible range (default 0 0 0).
drawgrid(vx, vy, color)
drawgrid(vx, vy, color, flags_n)
drawgrid(vx, vy, color, flags_n, color2)
drawgrid(vx, vy, color, flags_n, color2, origin)
Draws a grid using dots of color color. One grid dots is put at each of the 3D positions i*vx+j*vy, where i and j range over the integers. Grids cannot be drawn on perspective views (ask me if you need this feature). flags can be a set of DG_XXX flags (see qeditor.py). To highlight every nth grid line, add n to flags and set the highlight color in color2. origin is the 3D point from which the grid display begins (by default 0 0 0).
scale()
scale(point)
Returns the current projection scaling factor. In 2D projection modes, this is always the scale value given to setprojmode. In 3D projection mode, the scaling factor is computed at the given point. If no point is given in 3D mode, or if the computation fails for another reason, scale returns 1.0.
full3DFX(1)
full3DFX(0)
full3DFX(-1)
When called with 1 as parameter, this Map View image is sent to the full- screen 3DFX display. If two monitors are connected on the computer, the full-screen 3DFX image can be displayed together with the normal 2D image; otherwise, as long as the user doesn't press Esc or click a mouse button, he cannot do anything else. full3DFX only works with a true 3DFX card, not with the Software emulation; use a maximized window instead. Note that some features of common Map Views do not apply in full-screen 3DFX. For example, the user cannot (yet?) use the mouse on 3DFX screens, and no wireframe lines can be rendered (yet?). In general, consider the full-screen 3DFX mode as for viewing only, not editing. This method returns 0 in case of error. With one monitor, it returns 1 but only after the user finished walking in the view. With two monitors, it immediately returns 2. In the latter case only it makes sense to call full3DFX with the other parameter values: 0 to turn off the display on the second monitor, or -1 to query the current full-screen status.

 Additional attributes of Map View controls

Armin Rigo - 05 Aug 2020   [ Top ] 

Methods are described above. The following table describes the other attributes only.

border Whether this mapview has to draw a border (1) or not (0).
color
darkcolor
The background color in wireframe mode. darkcolor is used as background for selected objects (in draw mode DM_BACKGROUND).
cursor
handlecursor
Mouse cursor shape. handlecursor is the shape when the mouse is over a handle, if the handle doesn’t have its own cursor shape. Handles are described below. See qeditor.CR_XXX for a list of cursor shapes.
depth The (min,max) depth, as set by setdepth(min,max). Avoid to change this value directly; call setdepth instead.
flags Map View flags. See qeditor.MV_XXX.
redlines Red lines position. The flags corresponding to the red lines to show must be set first.
redlinesrect The (left,top,right,bottom) rectangular area considered to be the visible part of the map view. Use this instead of clientarea, because it excludes the parts outside the red lines.
scrollbars Scroll bars position and range. Returns ((hpos,hposend,hrange), (vpos,vposend,vrange)) where pos is the current position, posend is the same plus the width or the height of the control, and range is the maximal value that posend can take.
screencenter 3D point at the center of the screen. Can be modified on non-perspective views.
setup An Internal Objects that describes the 3D perspective display parameters. Defaults to the setup page “ 3D view ”. To force the Map View to reload the parameters, write setup=setup. Set it to another value only if you want to have several 3D views that don’t share the same parameters.
viewmode View mode: "wire" (for wireframe rendering), "solid" (for solid color rendering), or "tex" (for textured rendering). All values are valid in both flat and perspective projection modes. If the view doesn’t display a map at all (e.g. the shadowed texture panel of the Polyhedron page), use the mode "wire". The background is painted with the color before drawmap is called; if you want to avoid this, set color to NOCOLOR.
viewtype View type: "editor", "panel", "window", "fullscreen". Indicates what type of mapview this is, and controls how and when its rendering should be performed.
viewname Key values: "editors3Dview", "new3Dwindow", "full3Dview" or "opengl3Dview". Although not part of the actual quarkx source code, new keys have been added to all the required view layout python files for easier detection and control of these 3D views. Not required for 2D views, their key word "type" gives those view names already. Use of the new key can be coded by first qualifying for the 3D "type" views, then for their key "value" for example:
  for view in editor.layout.views:
      if view.info["type"] != "3D": continue
      viewname = view.info["viewname"]
      if viewname == "editors3Dview":
          print "got the Editors 3D view"
      if viewname == "new3Dwindow":
          print "got the Floating 3D view"
      if viewname == "full3Dview":
          print "GOT THE FULL 3D VIEW"
      if viewname == "opengl3Dview":
          print "got the OpenGL view"
Any new 3D views added can also use this method by assigning a new value to its view info for example:
  from quarkpy.mapmgr import *

  class New3DLayout(MapLayout):
      def buildscreen(self, form):
          self.bs_leftpanel(form)
          self.View3D = form.mainpanel.newmapview()
          self.views[:] = [self.View3D]
          self.baseviews = self.views[:]
          self.View3D.info = {"type": "3D", "viewname": "new3Dlayout"}
See the various map layout files in the python folder for more examples.
boundingboxes List of Internal objects from which QuArK can load bounding box sizes and model file paths. See mapeditor.py for an example.
handles List of handles. See below.
ondraw Callback function. Called when the control content must be drawn. It takes a single parameter: the Map view object itself. Call drawmap() and/or canvas() to draw in the Map view.
onmouse Callback function. Called in answer to a mouse event, as onmouse(mapview, x, y, flags, handle), where x,y is the mouse position, handle is the handle it is on (if any), and flags describes the mouse operation. See qeditor.MB_XXX. Values 1 to 64 are flags that indicate which keys and mouse buttons were down when the event begun, and may be combined together. Values 256 and above describe the event, and only one may be set.
onkey Callback function. Called when a key is pressed or released, as onkey(mapview, key, flags). flags are the same as above. key is a single character that describes the key. See qkeys.py for a list of possible values.
cameraposition In 3D modes, the camera position, as a 3-tuple (position, horzangle, pitchangle), where position is the 3D point of the camera position, horzangle is the direction on the Compass the camera is looking to, and pitchangle is used to look up or down. Returns None if not in 3D mode. Angles are in radians. This variable is read-write, but should not be used for animations (ask me if you need this).
oncameramove Callback function. Called when the camera moved, for any reason.
animation Are we currently doing an animation? Change this attribute to start (1) or end (0) an animation sequence. The only type of animation allowed is repeatedly changing cameraposition.
background Background image settings (center, scale, offset, multiple), where center is the 3D position of the center of the image, scale is the scale, offset to center the image, and multiple to fill the entire view with copies of the image. (sorry, the image won’t rotate when you rotate the view!)
backgroundimage Background image filename, where filename is the name of any supported image file or a loaded QImage object, put inside a tuple.

A useful feature of Map views is their ability to work with handles: the attribute handles can be set to a list of Python instances (like a menu bar or a list of buttons), where each instance must have an attribute pos corresponding to the 3D location of the handle, and an attribute cursor giving the cursor shape to use when the mouse cursor is over the handle. cursor can be a CR_XXX value or a callback function that will be called with the map view as single parameter and that should return a CR_XXX value. The value CR_DEFAULT is replaced by the value set in the map view’s handlecursor attribute.

Normally, the area around the handle center where you can click is 10 by 10 pixels large, that is, the distance between the mouse click and the handle center must be less than 5 pixels horizontally and vertically. You can give a custom horizontal and vertical size in the handle's size attribute, which defaults to the tuple (5,5).

You can set a string in the hint attribute. This string will be displayed in a small pop-up rectangle when the mouse is over the handle. To display hints over a blue background (for entity-specific information only), make the hint string begin with a question mark ("?"). QuArK does not draw the handles itself. The Python code is responsible for that. See maphandles.py.


 Internal objects related to the Model Editor

cdunde - 05 Apr 2018   [ Top ] 

From version 5.3, there are a few new types of QuArK Internal Objects. When editing a Model, the generic object in the tree view is of type MdlObject, which inherits all attributes and methods from 3Dobject (see above). A "component" of the Model is an object of type Component. A "frame" of the Model is an object of type Frame. A "skin" is a standard Image object.

Here are the attributes and methods of the Component objects.

currentskin The current skin used for textured display. Also see Texture functions of the module quarkx above for functions to change these skin textures such as Painting them, as can now be done in the Model Editor.
currentframe The current frame.
mergevertices(framelist) Reduces the component triangles and vertices by merging together the vertices that are at the same position in all frames.
filltris This list specify how the triangles should be drawn. The list should be as long as the number of triangles in the Tris Specific; if shorter, it is assumed that missing values are all None. For each triangle, the corresponding item in the list can be None (no filling) or a tuple of two "patterns", one for if the triangle is displayed from front, and one for if it is displayed from back. Each "pattern" can be None (no filling), an integer (a color), or a tuple of two integers (two colors to be combined in a small checkerboard pattern).
backtris Triangles whose background must be filled (like in the map editor's polyhedron backgrounds: without masking any line, even from objects behind the triangle) (not implemented in 5.3)
info Not used by QuArK. Reserved for Python code.
triangles List of all the triangles (read-write attribute). Each triangle is a tuple of three tuples (vertexnumber, skin_s, skin_t).

Additionally, the Component objects have a Tris Specific that lists the triangles of the component. Each triangle is given as three points of six bytes each: two for the vertex number, two for the first coordinate on the skin, and two for the second coordinate on the skin.

Here are the attributes and methods of the Frame objects.

index The frame's position in a component.dictitems['Frames:fg'].subitems list, as shown in the tree-view.
info Not used by QuArK. Reserved for Python code.
vertices This attribute is a way to quickly read or set a Vertices Specific of a frame (see below). It returns a list of Vector objects or can be used to set one.

Frame objects usually have a Vertices Specific that gives the 3D position of all vertices in a frame. This is a single large list of Vector objects that give the X, Y and Z coordinates of each vertices.

For additional information, please see the files mdl*.py.



Copyright (c) 2022, GNU General Public License by The QuArK (Quake Army Knife) Community - https://quark.sourceforge.io/

 [ Prev - Top - Next ]